use of org.seasar.doma.jdbc.JdbcException in project doma by domaframework.
the class NodePreparedSqlBuilderTest method testEmbeddedVariable_containsSemicolon.
@Test
public void testEmbeddedVariable_containsSemicolon() {
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.DOMA2117, expected.getMessageResource());
}
}
use of org.seasar.doma.jdbc.JdbcException in project doma by domaframework.
the class StandardDialectTest method testTransformSelectSqlNode_forUpdateWait_alias.
@Test
public void testTransformSelectSqlNode_forUpdateWait_alias() {
StandardDialect dialect = new StandardDialectStab();
SqlParser parser = new SqlParser("select * from emp order by emp.id");
SqlNode sqlNode = parser.parse();
SelectOptions options = SelectOptions.get().forUpdateWait(1, "emp");
try {
dialect.transformSelectSqlNode(sqlNode, options);
fail();
} catch (JdbcException ex) {
System.out.println(ex.getMessage());
assertEquals("DOMA2081", ex.getMessageResource().getCode());
}
}
use of org.seasar.doma.jdbc.JdbcException in project doma by domaframework.
the class KeepAliveLocalTransactionTest method testBegin_failedToBegin.
@Test
public void testBegin_failedToBegin() {
final SQLException exception = new SQLException();
MockConnection connection = new MockConnection() {
@Override
public void setAutoCommit(boolean autoCommit) throws SQLException {
throw exception;
}
};
LocalTransactionDataSource dataSource = new LocalTransactionDataSource(new MockDataSource(connection));
LocalTransaction transaction = dataSource.getKeepAliveLocalTransaction(jdbcLogger);
try {
transaction.begin();
dataSource.getConnection();
fail();
} catch (JdbcException expected) {
System.out.println(expected.getMessage());
assertEquals(exception, expected.getCause());
}
}
use of org.seasar.doma.jdbc.JdbcException in project doma by domaframework.
the class LocalTransactionTest method testBeginAndGetConnection_failedToSetAutoCommit.
@Test
public void testBeginAndGetConnection_failedToSetAutoCommit() {
final SQLException exception = new SQLException();
MockConnection connection = new MockConnection() {
@Override
public void setAutoCommit(boolean autoCommit) throws SQLException {
throw exception;
}
};
LocalTransactionDataSource dataSource = new LocalTransactionDataSource(new MockDataSource(connection));
LocalTransaction transaction = dataSource.getLocalTransaction(jdbcLogger);
try {
transaction.begin();
dataSource.getConnection();
fail();
} catch (JdbcException expected) {
System.out.println(expected.getMessage());
assertEquals(exception, expected.getCause());
}
}
use of org.seasar.doma.jdbc.JdbcException in project doma by domaframework.
the class SqlParser method validate.
protected void validate() {
if (isAfterValueNode()) {
ValueNode valueNode = pop();
throw new JdbcException(Message.DOMA2110, sql, tokenizer.getLineNumber(), tokenizer.getPosition(), valueNode.getText());
}
if (isInIfBlockNode()) {
removeNodesTo(IfBlockNode.class);
IfBlockNode ifBlockNode = pop();
SqlLocation location = ifBlockNode.getIfNode().getLocation();
throw new JdbcException(Message.DOMA2133, sql, location.getLineNumber(), location.getPosition());
}
if (isInForBlockNode()) {
removeNodesTo(ForBlockNode.class);
ForBlockNode forBlockNode = pop();
SqlLocation location = forBlockNode.getForNode().getLocation();
throw new JdbcException(Message.DOMA2134, sql, location.getLineNumber(), location.getPosition());
}
}
Aggregations