use of org.seasar.doma.jdbc.ResultMappingException 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.ResultMappingException in project doma by domaframework.
the class AutoFunctionTest method testResultSet_check.
@Test
@Run(unless = { Dbms.MYSQL, Dbms.SQLSERVER })
public void testResultSet_check(Config config) throws Exception {
FunctionDao dao = new FunctionDaoImpl(config);
try {
dao.func_resultset_check(Integer.valueOf(1));
fail();
} catch (ResultMappingException ignored) {
System.err.println(ignored);
}
}
use of org.seasar.doma.jdbc.ResultMappingException in project doma by domaframework.
the class AutoProcedureTest method testResultSet_check.
@Test
public void testResultSet_check(Config config) throws Exception {
ProcedureDao dao = new ProcedureDaoImpl(config);
List<Employee> employees = new ArrayList<>();
try {
dao.proc_resultset_check(employees, 1);
fail();
} catch (ResultMappingException ignored) {
System.err.println(ignored);
}
}
use of org.seasar.doma.jdbc.ResultMappingException in project doma by domaframework.
the class SqlFileSelectTest method testEnsureResultMappping_true.
@Test
public void testEnsureResultMappping_true(Config config) throws Exception {
EmployeeDao dao = new EmployeeDaoImpl(config);
try {
dao.selectOnlyNameWithMappingCheck();
fail();
} catch (ResultMappingException expected) {
System.err.print(expected);
}
}
use of org.seasar.doma.jdbc.ResultMappingException in project doma by domaframework.
the class EntityProvider method throwResultMappingException.
protected void throwResultMappingException(Set<EntityPropertyType<ENTITY, ?>> unmappedPropertySet) {
Naming naming = query.getConfig().getNaming();
int size = unmappedPropertySet.size();
List<String> unmappedPropertyNames = new ArrayList<>(size);
List<String> expectedColumnNames = new ArrayList<>(size);
for (EntityPropertyType<ENTITY, ?> propertyType : unmappedPropertySet) {
unmappedPropertyNames.add(propertyType.getName());
expectedColumnNames.add(propertyType.getColumnName(naming::apply));
}
Sql<?> sql = query.getSql();
throw new ResultMappingException(query.getConfig().getExceptionSqlLogType(), entityType.getEntityClass().getName(), unmappedPropertyNames, expectedColumnNames, sql.getKind(), sql.getRawSql(), sql.getFormattedSql(), sql.getSqlFilePath());
}
Aggregations