use of org.seasar.doma.jdbc.JdbcException in project doma by domaframework.
the class LocalTransaction method setSavepoint.
/**
* Creates a save point with the specified name.
*
* @param savepointName the name of the save point
* @throws DomaNullPointerException if the {@code savepointName} is {@code null}
* @throws TransactionNotYetBegunException if this transaction is not yet begun
* @throws SavepointAlreadyExistsException if the save point already exists
* @throws JdbcException if a JDBC related error occurs
*/
public void setSavepoint(String savepointName) {
if (savepointName == null) {
rollbackInternal("setSavepoint");
throw new DomaNullPointerException("savepointName");
}
LocalTransactionContext context = localTxContextHolder.get();
if (!isActiveInternal(context)) {
throw new TransactionNotYetBegunException(Message.DOMA2053, savepointName);
}
String id = context.getId();
Savepoint savepoint = context.getSavepoint(savepointName);
if (savepoint != null) {
rollbackInternal("setSavepoint");
throw new SavepointAlreadyExistsException(savepointName);
}
LocalTransactionConnection connection = context.getConnection();
try {
savepoint = connection.setSavepoint(savepointName);
} catch (SQLException e) {
rollbackInternal("setSavepoint");
throw new JdbcException(Message.DOMA2051, e, savepointName, e);
}
context.addSavepoint(savepointName, savepoint);
jdbcLogger.logTransactionSavepointCreated(className, "setSavepoint", id, savepointName);
}
use of org.seasar.doma.jdbc.JdbcException in project doma by domaframework.
the class NodePreparedSqlBuilderTest method testEmbeddedVariable_containsSingleQuote.
@Test
public void testEmbeddedVariable_containsSingleQuote() {
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'"));
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.DOMA2116, expected.getMessageResource());
}
}
use of org.seasar.doma.jdbc.JdbcException in project doma by domaframework.
the class NodePreparedSqlBuilderTest method testLiteralVariable_containsSingleQuote.
@Test
public void testLiteralVariable_containsSingleQuote() {
ExpressionEvaluator evaluator = new ExpressionEvaluator();
evaluator.add("name", new Value(String.class, "hog'e"));
evaluator.add("salary", new Value(BigDecimal.class, new BigDecimal(10000)));
String testSql = "select * from aaa where ename = /*^name*/'aaa' and sal = /*salary*/-2000";
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.DOMA2224, expected.getMessageResource());
}
}
use of org.seasar.doma.jdbc.JdbcException in project doma by domaframework.
the class NodePreparedSqlBuilderTest method testEmbeddedVariable_blockComment.
@Test
public void testEmbeddedVariable_blockComment() {
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.DOMA2123, expected.getMessageResource());
}
}
use of org.seasar.doma.jdbc.JdbcException in project doma by domaframework.
the class SqlParserTest method testLiteralVariable_endsWithLiteralVariableComment.
@Test
public void testLiteralVariable_endsWithLiteralVariableComment() {
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());
}
}
Aggregations