use of org.seasar.doma.jdbc.OptimisticLockException in project doma-spring-boot by domaframework.
the class DomaPersistenceExceptionTranslator method translateExceptionIfPossible.
@Override
public DataAccessException translateExceptionIfPossible(RuntimeException ex) {
if (!(ex instanceof JdbcException)) {
// Fallback to other translators if not JdbcException
return null;
}
if (ex instanceof OptimisticLockException) {
return new OptimisticLockingFailureException(ex.getMessage(), ex);
} else if (ex instanceof UniqueConstraintException) {
return new DuplicateKeyException(ex.getMessage(), ex);
} else if (ex instanceof NonUniqueResultException || ex instanceof NonSingleColumnException) {
return new IncorrectResultSizeDataAccessException(ex.getMessage(), 1, ex);
} else if (ex instanceof NoResultException) {
return new EmptyResultDataAccessException(ex.getMessage(), 1, ex);
} else if (ex instanceof UnknownColumnException || ex instanceof ResultMappingException) {
return new TypeMismatchDataAccessException(ex.getMessage(), ex);
}
if (ex.getCause() instanceof SQLException) {
SQLException e = (SQLException) ex.getCause();
String sql = null;
if (ex instanceof SqlExecutionException) {
sql = ((SqlExecutionException) ex).getRawSql();
}
DataAccessException dae = translator.translate(ex.getMessage(), sql, e);
return (dae != null ? dae : new UncategorizedSQLException(ex.getMessage(), sql, e));
}
return new UncategorizedDataAccessException(ex.getMessage(), ex) {
};
}
use of org.seasar.doma.jdbc.OptimisticLockException in project doma by domaframework.
the class AutoBatchUpdateTest method testOptimisticLockException.
@Test
public void testOptimisticLockException(Config config) throws Exception {
DepartmentDao dao = new DepartmentDaoImpl(config);
Department department1 = dao.selectById(1);
department1.setDepartmentName("hoge");
Department department2 = dao.selectById(2);
department2.setDepartmentName("foo");
Department department3 = dao.selectById(1);
department3.setDepartmentName("bar");
dao.update(department1);
try {
dao.update(Arrays.asList(department2, department3));
fail();
} catch (OptimisticLockException expected) {
}
}
use of org.seasar.doma.jdbc.OptimisticLockException in project doma by domaframework.
the class AutoDeleteTest method testOptimisticLockException.
@Test
public void testOptimisticLockException(Config config) throws Exception {
EmployeeDao dao = new EmployeeDaoImpl(config);
Employee employee1 = dao.selectById(Integer.valueOf(1));
employee1.setEmployeeName("hoge");
Employee employee2 = dao.selectById(Integer.valueOf(1));
employee2.setEmployeeName("foo");
dao.delete(employee1);
try {
dao.delete(employee2);
fail();
} catch (OptimisticLockException expected) {
}
}
use of org.seasar.doma.jdbc.OptimisticLockException in project doma by domaframework.
the class AutoUpdateTest method testTenantId.
@Test
public void testTenantId(Config config) throws Exception {
SalesmanDao dao = new SalesmanDaoImpl(config);
Salesman salesman = dao.selectById(1);
Integer tenantId = salesman.departmentId;
salesman.departmentId = -1;
try {
dao.update(salesman);
fail();
} catch (OptimisticLockException expected) {
}
salesman.departmentId = tenantId;
dao.update(salesman);
}
use of org.seasar.doma.jdbc.OptimisticLockException in project doma by domaframework.
the class AutoBatchDeleteTest method testTenantId.
@Test
public void testTenantId(Config config) throws Exception {
SalesmanDao dao = new SalesmanDaoImpl(config);
Salesman salesman = dao.selectById(1);
Integer tenantId = salesman.departmentId;
salesman.departmentId = -1;
try {
dao.delete(Arrays.asList(salesman));
fail();
} catch (OptimisticLockException expected) {
}
salesman.departmentId = tenantId;
dao.delete(Arrays.asList(salesman));
}
Aggregations