public void testLimitOnly() throws Exception { String expected = "select * from emp order by emp.id limit 10"; H2PagingTransformer transformer = new H2PagingTransformer(-1, 10); 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); assertEquals(expected, sql.getRawSql()); }
public void testIfSuppressed() throws Exception { Class<?> target = BatchSqlValidationDao.class; addCompilationUnit(target); compile(); ExecutableElement methodElement = createMethodElement(target, "testIfSuppressed"); Map<String, TypeMirror> parameterTypeMap = createParameterTypeMap(methodElement); BatchSqlValidator validator = new BatchSqlValidator( getProcessingEnvironment(), methodElement, parameterTypeMap, "aaa/bbbDao/ccc.sql"); SqlParser parser = new SqlParser("select * from emp where /*%if true*/ id = 1 /*%end */"); SqlNode sqlNode = parser.parse(); sqlNode.accept(validator, null); assertNoMessage(); }
public void testEmbeddedVariable() throws Exception { Class<?> target = BatchSqlValidationDao.class; addCompilationUnit(target); compile(); ExecutableElement methodElement = createMethodElement(target, "testEmbeddedVariable", String.class); Map<String, TypeMirror> parameterTypeMap = createParameterTypeMap(methodElement); BatchSqlValidator validator = new BatchSqlValidator( getProcessingEnvironment(), methodElement, parameterTypeMap, "aaa/bbbDao/ccc.sql"); SqlParser parser = new SqlParser("select * from emp /*# orderBy */"); SqlNode sqlNode = parser.parse(); sqlNode.accept(validator, null); assertMessage(Message.DOMA4181); }
public void testIfAndEmbeddedVariable() throws Exception { Class<?> target = BatchSqlValidationDao.class; addCompilationUnit(target); compile(); ExecutableElement methodElement = createMethodElement(target, "testIfAndEmbeddedVariable", String.class); Map<String, TypeMirror> parameterTypeMap = createParameterTypeMap(methodElement); BatchSqlValidator validator = new BatchSqlValidator( getProcessingEnvironment(), methodElement, parameterTypeMap, "aaa/bbbDao/ccc.sql"); SqlParser parser = new SqlParser("select * from emp where /*%if true*/ id = 1 /*%end */ /*# orderBy */"); SqlNode sqlNode = parser.parse(); sqlNode.accept(validator, null); assertEquals(2, getDiagnostics().size()); }