use of org.seasar.doma.jdbc.UnknownColumnException 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.UnknownColumnException in project doma by domaframework.
the class EntityProviderTest method testGetEntity_UnknownColumnException.
@Test
public void testGetEntity_UnknownColumnException() throws Exception {
MockResultSetMetaData metaData = new MockResultSetMetaData();
metaData.columns.add(new ColumnMetaData("id"));
metaData.columns.add(new ColumnMetaData("name"));
metaData.columns.add(new ColumnMetaData("salary"));
metaData.columns.add(new ColumnMetaData("version"));
metaData.columns.add(new ColumnMetaData("unknown"));
MockResultSet resultSet = new MockResultSet(metaData);
resultSet.rows.add(new RowData(1, "aaa", new BigDecimal(10), 100, "bbb"));
resultSet.next();
_Emp entityType = _Emp.getSingletonInternal();
EntityProvider<Emp> provider = new EntityProvider<>(entityType, new MySelectQuery(new MockConfig()), false);
try {
provider.get(resultSet);
fail();
} catch (UnknownColumnException expected) {
}
}
Aggregations