本文整理汇总了Java中org.apache.ibatis.exceptions.PersistenceException类的典型用法代码示例。如果您正苦于以下问题:Java PersistenceException类的具体用法?Java PersistenceException怎么用?Java PersistenceException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
PersistenceException类属于org.apache.ibatis.exceptions包,在下文中一共展示了PersistenceException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: convertParameter
import org.apache.ibatis.exceptions.PersistenceException; //导入依赖的package包/类
/**
* 对参数进行转换和检查
*
* @param parameterObject
* 参数对象
* @param pageVO
* 参数VO
* @return 参数VO
* @throws NoSuchFieldException
* 无法找到参数
*/
protected static Page convertParameter(Object parameter, Page page)
throws NoSuchFieldException {
if (parameter instanceof Page) {
page = (Pagination) parameter;
} else {
// 参数为某个实体,该实体拥有Page属性
Paging paging = parameter.getClass().getAnnotation(Paging.class);
String field = paging.field();
Field pageField = Reflection.getAccessibleField(parameter, field);
if (null != pageField) {
page = (Pagination) Reflection.getFieldValue(parameter, field);
if (null != page)
throw new PersistenceException("分页参数不能为空");
// 通过反射,对实体对象设置分页对象
Reflection.setFieldValue(parameter, field, page);
} else {
throw new NoSuchFieldException(parameter.getClass().getName()
+ "不存在分页参数属性!");
}
}
return page;
}
示例2: write
import org.apache.ibatis.exceptions.PersistenceException; //导入依赖的package包/类
@Timed("db_storage_write_operation")
@Override
public <T, E extends Exception> T write(MutateWork<T, E> work) throws StorageException, E {
// NOTE: Async work is intentionally executed regardless of whether the transaction succeeded.
// Doing otherwise runs the risk of cross-talk between transactions and losing async tasks
// due to failure of an unrelated transaction. This matches behavior prior to the
// introduction of DbStorage, but should be revisited.
// TODO(wfarner): Consider revisiting to execute async work only when the transaction is
// successful.
return gatedWorkQueue.closeDuring((GatedOperation<T, E>) () -> {
try {
return transactionedWrite(work);
} catch (PersistenceException e) {
throw new StorageException(e.getMessage(), e);
}
});
}
示例3: runOneIteration
import org.apache.ibatis.exceptions.PersistenceException; //导入依赖的package包/类
@VisibleForTesting
@Override
public void runOneIteration() {
LOG.info("Scanning database tables for unreferenced rows.");
final AtomicLong deletedCount = new AtomicLong();
for (Class<? extends GarbageCollectedTableMapper> tableClass : TABLES) {
storage.write((NoResult.Quiet) storeProvider -> {
try (SqlSession session = sessionFactory.openSession(true)) {
GarbageCollectedTableMapper table = session.getMapper(tableClass);
for (long rowId : table.selectAllRowIds()) {
try {
table.deleteRow(rowId);
deletedCount.incrementAndGet();
} catch (PersistenceException e) {
// Expected for rows that are still referenced.
}
}
}
});
}
LOG.info("Deleted " + deletedCount.get() + " unreferenced rows.");
}
示例4: failingCauseByUnknownColumn
import org.apache.ibatis.exceptions.PersistenceException; //导入依赖的package包/类
@Test
public void failingCauseByUnknownColumn() {
sqlSessionFactory.getConfiguration().setAutoMappingUnknownColumnBehavior(AutoMappingUnknownColumnBehavior.FAILING);
SqlSession session = sqlSessionFactory.openSession();
try {
Mapper mapper = session.getMapper(Mapper.class);
mapper.selectAuthor(101);
} catch (PersistenceException e) {
assertThat(e.getCause(), instanceOf(SqlSessionException.class));
assertThat(e.getCause().getMessage(), is("Unknown column is detected on 'org.apache.ibatis.session.AutoMappingUnknownColumnBehaviorTest$Mapper.selectAuthor' auto-mapping. Mapping parameters are [columnName=USERNAMEEEE,propertyName=USERNAMEEEE,propertyType=null]"));
} finally {
session.close();
}
}
示例5: testUnorderedGetPersonWithHandler
import org.apache.ibatis.exceptions.PersistenceException; //导入依赖的package包/类
@Test(expected=PersistenceException.class)
public void testUnorderedGetPersonWithHandler() {
SqlSession sqlSession = sqlSessionFactory.openSession();
try {
sqlSession.select("getPersonsWithItemsOrdered", new ResultHandler() {
public void handleResult(ResultContext context) {
Person person = (Person) context.getResultObject();
if ("grandma".equals(person.getName())) {
Assert.assertEquals(2, person.getItems().size());
}
}
});
} finally {
sqlSession.close();
}
}
示例6: shouldFailBecauseThereIsAPropertyWithoutTypeHandler
import org.apache.ibatis.exceptions.PersistenceException; //导入依赖的package包/类
@Test(expected=PersistenceException.class)
public void shouldFailBecauseThereIsAPropertyWithoutTypeHandler() throws Exception {
// create a SqlSessionFactory
Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/unknownobject/mybatis-config.xml");
sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader);
reader.close();
// populate in-memory database
SqlSession session = sqlSessionFactory.openSession();
Connection conn = session.getConnection();
reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/unknownobject/CreateDB.sql");
ScriptRunner runner = new ScriptRunner(conn);
runner.setLogWriter(null);
runner.runScript(reader);
reader.close();
session.close();
}
示例7: storeData
import org.apache.ibatis.exceptions.PersistenceException; //导入依赖的package包/类
@Override
public void storeData(IFallback object) throws IDBPersistenceException {
SqlSession session = null;
try {
session = sqlSessionFactory.openSession();
LoggerMapper<T> loggerMapper = session.getMapper(mapperInterface);
loggerMapper.insertLog((T) object);
session.commit();
} catch (PersistenceException ex1) {
String message = "Exception caught while persisting an object to the history";
LOGGER.error(message, ex1);
if (session != null)
session.rollback();
throw new IDBPersistenceException(message, ex1);
} finally {
if (session != null)
session.close();
}
}
示例8: logStartEvent
import org.apache.ibatis.exceptions.PersistenceException; //导入依赖的package包/类
private synchronized void logStartEvent(final ServerLifecycleEvent event) {
try {
serverLifecycleEventMapper.logEvent(event);
if (relogTimer != null){
relogTimer.cancel();
}
} catch (PersistenceException e) {
LOGGER.error("Exception caught when logging start event, will try again in 2 minutes time: {}", e.getMessage());
if (relogTimer == null){
relogTimer = new Timer("Lifecycle-start-log-timer");
}
if (running) {
relogTimer.schedule(new TimerTask() {
@Override
public void run() {
logStartEvent(event);
}
}, timeBetweenRelogs);
}
}
}
示例9: stop
import org.apache.ibatis.exceptions.PersistenceException; //导入依赖的package包/类
/**
* Will not shutdown correctly until all elements can be persisted.
*/
@Override
public synchronized void stop() {
LOGGER.info("Shutting down cache persistence manager (" + cache.getClass().getSimpleName() + ")");
started = false;
cachePersistenceThreadPoolTaskExecutor.shutdown();
//may be none-empty if added using addElementToPersist
while (!toBePersisted.isEmpty()) {
LOGGER.debug("Detected cache objects that need persisting... trying to persist them.");
toBePersistedLock.writeLock().lock();
try {
cachePersistenceDAO.persistBatch(new ArrayList<>(toBePersisted));
toBePersisted.clear();
} catch (PersistenceException e) {
LOGGER.error("Exception caught while persisting final batch of cache objects - will try again in 1s", e);
try {
Thread.sleep(1000);
} catch (InterruptedException e1) {
LOGGER.error("Interrupted during sleep", e1);
}
} finally {
toBePersistedLock.writeLock().unlock();
}
}
}
示例10: retryStartProcess
import org.apache.ibatis.exceptions.PersistenceException; //导入依赖的package包/类
protected void retryStartProcess(String runningUser) {
int retries = MAX_RETRIES;
int timeout = 200;
boolean success = false;
while (retries > 0 && !success) {
try {
runtimeService.startProcessInstanceByKey("concurrentProcess", Collections.singletonMap("assignee", (Object) runningUser));
success = true;
} catch (PersistenceException pe) {
retries = retries - 1;
LOGGER.debug("Retrying process start - {}", (MAX_RETRIES - retries));
try {
Thread.sleep(timeout);
} catch (InterruptedException ignore) {
}
timeout = timeout + 200;
}
}
if (!success) {
LOGGER.debug("Retrying process start FAILED {} times", MAX_RETRIES);
}
}
示例11: retryFinishTask
import org.apache.ibatis.exceptions.PersistenceException; //导入依赖的package包/类
protected void retryFinishTask(String taskId) {
int retries = MAX_RETRIES;
int timeout = 200;
boolean success = false;
while (retries > 0 && !success) {
try {
taskService.complete(taskId);
success = true;
} catch (PersistenceException pe) {
retries = retries - 1;
LOGGER.debug("Retrying task completion - {}", (MAX_RETRIES - retries));
try {
Thread.sleep(timeout);
} catch (InterruptedException ignore) {
}
timeout = timeout + 200;
}
}
if (!success) {
LOGGER.debug("Retrying task completion FAILED {} times", MAX_RETRIES);
}
}
示例12: testBatchWithError
import org.apache.ibatis.exceptions.PersistenceException; //导入依赖的package包/类
@Test(expected = PersistenceException.class)
public void testBatchWithError() {
try {
setupBatchStatements();
session = SqlSessionUtils.getSqlSession(sqlSessionFactory, ExecutorType.BATCH, exceptionTranslator);
session.getMapper(TestMapper.class).insertTest("test1");
session.getMapper(TestMapper.class).insertTest("test2");
session.update("org.mybatis.spring.TestMapper.insertFail");
session.getMapper(TestMapper.class).insertTest("test3");
session.commit(true);
SqlSessionUtils.closeSqlSession(session, sqlSessionFactory);
assertCommit();
assertSingleConnection();
assertExecuteCount(4);
} finally {
SqlSessionUtils.closeSqlSession(session, sqlSessionFactory);
}
}
示例13: testIntegerArrayWithTooLargeValue
import org.apache.ibatis.exceptions.PersistenceException; //导入依赖的package包/类
@Test
public void testIntegerArrayWithTooLargeValue() {
String testName = "too large value test";
boolean exceptionWasCaught = false;
IntegerArrayBean t = new IntegerArrayBean();
Integer[] intArray = new Integer[] { 1, Integer.MAX_VALUE, 3 };
t.setIntegerArray(intArray);
t.setName(testName);
try {
session.insert("test.insertSmallIntArray", t);
} catch (PersistenceException e) {
log.info("caught expected exception: ", e);
exceptionWasCaught = true;
} finally {
session.rollback(true);
}
Assert.assertTrue(exceptionWasCaught, "Integers larger than PostgreSQL smallint need to throw exeption.");
}
示例14: unregisterDevice
import org.apache.ibatis.exceptions.PersistenceException; //导入依赖的package包/类
public void unregisterDevice(DeviceType type, String model)
throws ActionException {
boolean previouslyContained = false;
try {
previouslyContained = devService.contains(type.name(), model);
if (previouslyContained) {
devService.remove(type.name(), model);
}
} catch (PersistenceException e) {
throw new ActionException(e.getMessage());
}
if (!previouslyContained)
throw new ActionException("device model does not exist");
}
示例15: unregisterObservatory
import org.apache.ibatis.exceptions.PersistenceException; //导入依赖的package包/类
public void unregisterObservatory(String observatory)
throws ActionException {
boolean previouslyContained = false;
try {
previouslyContained = obsService.contains(observatory);
if (!previouslyContained) {
obsService.remove(observatory);
}
} catch (PersistenceException e) {
throw new ActionException(e.getMessage());
}
if (!previouslyContained)
throw new ActionException("observatory does not exist");
}