use of org.seasar.doma.internal.jdbc.sql.SqlParser in project doma by domaframework.
the class BatchSqlValidatorTest method testIf.
@Test
void testIf() throws Exception {
Class<?> target = BatchSqlValidationDao.class;
addCompilationUnit(target);
addProcessor(new TestProcessor() {
@Override
protected void run() {
ExecutableElement methodElement = createMethodElement(target, "testIf");
LinkedHashMap<String, TypeMirror> parameterTypeMap = createParameterTypeMap(methodElement);
BatchSqlValidator validator = new BatchSqlValidator(ctx, methodElement, parameterTypeMap, "aaa/bbbDao/ccc.sql", false, false);
SqlParser parser = new SqlParser("select * from emp where /*%if true*/ id = 1 /*%end */");
SqlNode sqlNode = parser.parse();
sqlNode.accept(validator, null);
}
});
compile();
assertTrue(getCompiledResult());
assertMessage(Message.DOMA4182);
}
use of org.seasar.doma.internal.jdbc.sql.SqlParser in project doma by domaframework.
the class BatchSqlValidatorTest method testPopulate.
@Test
void testPopulate() throws Exception {
Class<?> target = BatchSqlValidationDao.class;
addCompilationUnit(target);
addProcessor(new TestProcessor() {
@Override
protected void run() {
ExecutableElement methodElement = createMethodElement(target, "testPopulate", String.class);
LinkedHashMap<String, TypeMirror> parameterTypeMap = createParameterTypeMap(methodElement);
BatchSqlValidator validator = new BatchSqlValidator(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());
assertNoMessage();
}
use of org.seasar.doma.internal.jdbc.sql.SqlParser in project doma by domaframework.
the class BatchSqlValidatorTest method testIfSuppressed.
@Test
void testIfSuppressed() throws Exception {
Class<?> target = BatchSqlValidationDao.class;
addCompilationUnit(target);
addProcessor(new TestProcessor() {
@Override
protected void run() {
ExecutableElement methodElement = createMethodElement(target, "testIfSuppressed");
LinkedHashMap<String, TypeMirror> parameterTypeMap = createParameterTypeMap(methodElement);
BatchSqlValidator validator = new BatchSqlValidator(ctx, methodElement, parameterTypeMap, "aaa/bbbDao/ccc.sql", false, false);
SqlParser parser = new SqlParser("select * from emp where /*%if true*/ id = 1 /*%end */");
SqlNode sqlNode = parser.parse();
sqlNode.accept(validator, null);
}
});
compile();
assertTrue(getCompiledResult());
assertNoMessage();
}
use of org.seasar.doma.internal.jdbc.sql.SqlParser in project doma by domaframework.
the class BatchSqlValidatorTest method testIfAndEmbeddedVariableSuppressed.
@Test
void testIfAndEmbeddedVariableSuppressed() throws Exception {
Class<?> target = BatchSqlValidationDao.class;
addCompilationUnit(target);
addProcessor(new TestProcessor() {
@Override
protected void run() {
ExecutableElement methodElement = createMethodElement(target, "testIfAndEmbeddedVariableSuppressed", String.class);
LinkedHashMap<String, TypeMirror> parameterTypeMap = createParameterTypeMap(methodElement);
BatchSqlValidator validator = new BatchSqlValidator(ctx, methodElement, parameterTypeMap, "aaa/bbbDao/ccc.sql", false, false);
SqlParser parser = new SqlParser("select * from emp where /*%if true*/ id = 1 /*%end */ /*# orderBy */");
SqlNode sqlNode = parser.parse();
sqlNode.accept(validator, null);
}
});
compile();
assertTrue(getCompiledResult());
assertNoMessage();
}
use of org.seasar.doma.internal.jdbc.sql.SqlParser 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