Exemplo n.º 1
0
 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());
 }
Exemplo n.º 2
0
  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();
  }
Exemplo n.º 3
0
  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);
  }
Exemplo n.º 4
0
  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());
  }