use of org.seasar.doma.internal.jdbc.sql.SqlParser in project doma by domaframework.
the class SqlValidatorTest method testPopulate_notPopulatable.
@Test
void testPopulate_notPopulatable() throws Exception {
Class<?> target = SqlValidationDao.class;
addCompilationUnit(target);
addProcessor(new TestProcessor() {
@Override
protected void run() {
ExecutableElement methodElement = createMethodElement(target, "testPopulate", String.class);
LinkedHashMap<String, TypeMirror> parameterTypeMap = createParameterTypeMap(methodElement);
SqlValidator validator = new SqlValidator(ctx, methodElement, parameterTypeMap, "aaa/bbbDao/ccc.sql", false, false);
SqlParser parser = new SqlParser("update emp set /*%populate*/ id = id");
SqlNode sqlNode = parser.parse();
try {
sqlNode.accept(validator, null);
fail();
} catch (AptException expected) {
System.out.println(expected.getMessage());
assertEquals(Message.DOMA4270, expected.getMessageResource());
}
}
});
compile();
assertTrue(getCompiledResult());
}
use of org.seasar.doma.internal.jdbc.sql.SqlParser in project doma by domaframework.
the class SqlValidatorTest method testBindVariable.
@Test
void testBindVariable() throws Exception {
Class<?> target = SqlValidationDao.class;
addCompilationUnit(target);
addProcessor(new TestProcessor() {
@Override
protected void run() {
ExecutableElement methodElement = createMethodElement(target, "testBindVariable", String.class);
LinkedHashMap<String, TypeMirror> parameterTypeMap = createParameterTypeMap(methodElement);
SqlValidator validator = new SqlValidator(ctx, methodElement, parameterTypeMap, "aaa/bbbDao/ccc.sql", false, false);
SqlParser parser = new SqlParser("select * from emp where name = /* name */'aaa'");
SqlNode sqlNode = parser.parse();
sqlNode.accept(validator, null);
}
});
compile();
assertTrue(getCompiledResult());
}
use of org.seasar.doma.internal.jdbc.sql.SqlParser in project doma by domaframework.
the class SqlValidatorTest method testPopulate.
@Test
void testPopulate() throws Exception {
Class<?> target = SqlValidationDao.class;
addCompilationUnit(target);
addProcessor(new TestProcessor() {
@Override
protected void run() {
ExecutableElement methodElement = createMethodElement(target, "testPopulate", String.class);
LinkedHashMap<String, TypeMirror> parameterTypeMap = createParameterTypeMap(methodElement);
SqlValidator validator = new SqlValidator(ctx, methodElement, parameterTypeMap, "aaa/bbbDao/ccc.sql", false, true);
SqlParser parser = new SqlParser("update emp set /*%populate*/ id = id");
SqlNode sqlNode = parser.parse();
sqlNode.accept(validator, null);
}
});
compile();
assertTrue(getCompiledResult());
}
use of org.seasar.doma.internal.jdbc.sql.SqlParser in project doma by domaframework.
the class Db2ForUpdateTransformerTest method testForUpdateNormal.
@Test
public void testForUpdateNormal() {
String expected = "select * from emp order by emp.id for update with rs";
Db2ForUpdateTransformer transformer = new Db2ForUpdateTransformer(SelectForUpdateType.NORMAL, 0);
SqlParser parser = new SqlParser("select * from emp order by emp.id");
SqlNode sqlNode = transformer.transform(parser.parse());
NodePreparedSqlBuilder sqlBuilder = new NodePreparedSqlBuilder(new MockConfig(), SqlKind.SELECT, "dummyPath");
PreparedSql sql = sqlBuilder.build(sqlNode, Function.identity());
assertEquals(expected, sql.getRawSql());
}
use of org.seasar.doma.internal.jdbc.sql.SqlParser in project doma by domaframework.
the class Db2PagingTransformerTest method testOffsetOnly.
@Test
public void testOffsetOnly() {
String expected = "select * from ( select temp_.*, row_number() over( order by temp_.id ) as doma_rownumber_ from ( select emp.id from emp ) as temp_ ) as temp2_ where doma_rownumber_ > 5";
Db2PagingTransformer transformer = new Db2PagingTransformer(5, -1);
SqlParser parser = new SqlParser("select emp.id from emp order by emp.id");
SqlNode sqlNode = transformer.transform(parser.parse());
NodePreparedSqlBuilder sqlBuilder = new NodePreparedSqlBuilder(new MockConfig(), SqlKind.SELECT, "dummyPath");
PreparedSql sql = sqlBuilder.build(sqlNode, Function.identity());
assertEquals(expected, sql.getRawSql());
}
Aggregations