Search in sources :

Example 11 with SqlParser

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);
}
Also used : ExecutableElement(javax.lang.model.element.ExecutableElement) SqlParser(org.seasar.doma.internal.jdbc.sql.SqlParser) TestProcessor(org.seasar.doma.internal.apt.TestProcessor) LinkedHashMap(java.util.LinkedHashMap) SqlNode(org.seasar.doma.jdbc.SqlNode) Test(org.junit.jupiter.api.Test)

Example 12 with SqlParser

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();
}
Also used : ExecutableElement(javax.lang.model.element.ExecutableElement) SqlParser(org.seasar.doma.internal.jdbc.sql.SqlParser) TestProcessor(org.seasar.doma.internal.apt.TestProcessor) LinkedHashMap(java.util.LinkedHashMap) SqlNode(org.seasar.doma.jdbc.SqlNode) Test(org.junit.jupiter.api.Test)

Example 13 with SqlParser

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();
}
Also used : ExecutableElement(javax.lang.model.element.ExecutableElement) SqlParser(org.seasar.doma.internal.jdbc.sql.SqlParser) TestProcessor(org.seasar.doma.internal.apt.TestProcessor) LinkedHashMap(java.util.LinkedHashMap) SqlNode(org.seasar.doma.jdbc.SqlNode) Test(org.junit.jupiter.api.Test)

Example 14 with SqlParser

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();
}
Also used : ExecutableElement(javax.lang.model.element.ExecutableElement) SqlParser(org.seasar.doma.internal.jdbc.sql.SqlParser) TestProcessor(org.seasar.doma.internal.apt.TestProcessor) LinkedHashMap(java.util.LinkedHashMap) SqlNode(org.seasar.doma.jdbc.SqlNode) Test(org.junit.jupiter.api.Test)

Example 15 with SqlParser

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());
    }
}
Also used : SelectOptions(org.seasar.doma.jdbc.SelectOptions) SqlParser(org.seasar.doma.internal.jdbc.sql.SqlParser) JdbcException(org.seasar.doma.jdbc.JdbcException) SqlNode(org.seasar.doma.jdbc.SqlNode) Test(org.junit.jupiter.api.Test)

Aggregations

SqlParser (org.seasar.doma.internal.jdbc.sql.SqlParser)107 Test (org.junit.jupiter.api.Test)105 SqlNode (org.seasar.doma.jdbc.SqlNode)90 NodePreparedSqlBuilder (org.seasar.doma.internal.jdbc.sql.NodePreparedSqlBuilder)67 MockConfig (org.seasar.doma.internal.jdbc.mock.MockConfig)64 PreparedSql (org.seasar.doma.jdbc.PreparedSql)59 LinkedHashMap (java.util.LinkedHashMap)25 ExecutableElement (javax.lang.model.element.ExecutableElement)25 TestProcessor (org.seasar.doma.internal.apt.TestProcessor)25 List (java.util.List)7 AptException (org.seasar.doma.internal.apt.AptException)6 JdbcException (org.seasar.doma.jdbc.JdbcException)6 SelectOptions (org.seasar.doma.jdbc.SelectOptions)6 ExpressionEvaluator (org.seasar.doma.internal.expr.ExpressionEvaluator)3 Value (org.seasar.doma.internal.expr.Value)3 Iterator (java.util.Iterator)1