use of org.seasar.doma.jdbc.JdbcException 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.JdbcException in project doma by domaframework.
the class SqlParserTest method testBindVariable_endsWithBindVariableComment.
@Test
public void testBindVariable_endsWithBindVariableComment() {
ExpressionEvaluator evaluator = new ExpressionEvaluator();
evaluator.add("name", new Value(String.class, "hoge"));
String testSql = "select * from aaa where ename = /*name*/";
SqlParser parser = new SqlParser(testSql);
try {
parser.parse();
fail();
} catch (JdbcException expected) {
System.out.println(expected.getMessage());
assertEquals(Message.DOMA2110, expected.getMessageResource());
}
}
use of org.seasar.doma.jdbc.JdbcException in project doma by domaframework.
the class NodePreparedSqlBuilderTest method testEmbeddedVariable_lineComment.
@Test
public void testEmbeddedVariable_lineComment() {
ExpressionEvaluator evaluator = new ExpressionEvaluator();
evaluator.add("name", new Value(String.class, "hoge"));
evaluator.add("salary", new Value(BigDecimal.class, new BigDecimal(10000)));
evaluator.add("orderBy", new Value(String.class, "aaa--bbb"));
String testSql = "select * from aaa where ename = /*name*/'aaa' and sal = /*salary*/-2000 /*#orderBy*/";
SqlParser parser = new SqlParser(testSql);
SqlNode sqlNode = parser.parse();
try {
new NodePreparedSqlBuilder(config, SqlKind.SELECT, "dummyPath", evaluator, SqlLogType.FORMATTED).build(sqlNode, Function.identity());
fail();
} catch (JdbcException expected) {
System.out.println(expected.getMessage());
assertEquals(Message.DOMA2122, expected.getMessageResource());
}
}
use of org.seasar.doma.jdbc.JdbcException in project doma by domaframework.
the class BatchDeleteExecutorTest method testParamToLiteral.
@Test
public void testParamToLiteral() {
SqlBatchDeleteQuery query = mockQuery();
BatchBuilder builder = BatchBuilder.newInstance(query);
builder.sql("delete from Emp");
builder.sql("where");
builder.sql("name = ").param(String.class, "SMITH");
builder.sql("and");
builder.sql("salary = ").param(BigDecimal.class, new BigDecimal("1000"));
builder = builder.fixSql();
builder.sql("delete from Emp");
builder.sql("where");
builder = builder.sql("name = ");
try {
builder.literal(String.class, "ALLEN");
} catch (JdbcException e) {
assertEquals(Message.DOMA2230, e.getMessageResource());
return;
}
fail();
}
use of org.seasar.doma.jdbc.JdbcException in project doma by domaframework.
the class StandardDialectTest method testTransformSelectSqlNode_forUpdate_alias.
@Test
public void testTransformSelectSqlNode_forUpdate_alias() {
StandardDialect dialect = new StandardDialectStab();
SqlParser parser = new SqlParser("select * from emp order by emp.id");
SqlNode sqlNode = parser.parse();
SelectOptions options = SelectOptions.get().forUpdate("emp");
try {
dialect.transformSelectSqlNode(sqlNode, options);
fail();
} catch (JdbcException ex) {
System.out.println(ex.getMessage());
assertEquals("DOMA2024", ex.getMessageResource().getCode());
}
}
Aggregations