Search in sources :

Example 21 with SqlParser

use of org.seasar.doma.internal.jdbc.sql.SqlParser in project doma by domaframework.

the class BuildingHelper method getSqlNode.

SqlNode getSqlNode() {
    StringBuilder buf = new StringBuilder(200);
    for (Item item : items) {
        switch(item.kind) {
            case SQL:
                buf.append(item.sql);
                break;
            case PARAM:
                buf.append("/*");
                if (item.param.literal) {
                    buf.append("^");
                }
                buf.append(item.param.name);
                buf.append("*/0");
                break;
            default:
                assertUnreachable();
                break;
        }
    }
    SqlParser parser = new SqlParser(buf.toString());
    return parser.parse();
}
Also used : SqlParser(org.seasar.doma.internal.jdbc.sql.SqlParser)

Example 22 with SqlParser

use of org.seasar.doma.internal.jdbc.sql.SqlParser in project doma by domaframework.

the class SqlValidatorTest method testFor_identifier.

@Test
void testFor_identifier() throws Exception {
    Class<?> target = SqlValidationDao.class;
    addCompilationUnit(target);
    addProcessor(new TestProcessor() {

        @Override
        protected void run() {
            ExecutableElement methodElement = createMethodElement(target, "testFor", List.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 = /*%for e : names*/ /*x*/'aaa' /*%if e_has_next*/or/*%end*//*%end*/");
            SqlNode sqlNode = parser.parse();
            try {
                sqlNode.accept(validator, null);
                fail();
            } catch (AptException expected) {
                System.out.println(expected.getMessage());
                assertEquals(Message.DOMA4092, expected.getMessageResource());
            }
        }
    });
    compile();
    assertTrue(getCompiledResult());
}
Also used : ExecutableElement(javax.lang.model.element.ExecutableElement) SqlParser(org.seasar.doma.internal.jdbc.sql.SqlParser) AptException(org.seasar.doma.internal.apt.AptException) TestProcessor(org.seasar.doma.internal.apt.TestProcessor) List(java.util.List) LinkedHashMap(java.util.LinkedHashMap) SqlNode(org.seasar.doma.jdbc.SqlNode) Test(org.junit.jupiter.api.Test)

Example 23 with SqlParser

use of org.seasar.doma.internal.jdbc.sql.SqlParser in project doma by domaframework.

the class SqlValidatorTest method testFor_noTypeArgument.

@Test
void testFor_noTypeArgument() throws Exception {
    Class<?> target = SqlValidationDao.class;
    addCompilationUnit(target);
    addProcessor(new TestProcessor() {

        @Override
        protected void run() {
            ExecutableElement methodElement = createMethodElement(target, "testFor_noTypeArgument", List.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 = /*%for e : names*/ /*e*/'aaa' /*%if e_has_next*/or/*%end*//*%end*/");
            SqlNode sqlNode = parser.parse();
            try {
                sqlNode.accept(validator, null);
                fail();
            } catch (AptException expected) {
                System.out.println(expected.getMessage());
                assertEquals(Message.DOMA4150, expected.getMessageResource());
            }
        }
    });
    compile();
    assertTrue(getCompiledResult());
}
Also used : ExecutableElement(javax.lang.model.element.ExecutableElement) SqlParser(org.seasar.doma.internal.jdbc.sql.SqlParser) AptException(org.seasar.doma.internal.apt.AptException) TestProcessor(org.seasar.doma.internal.apt.TestProcessor) List(java.util.List) LinkedHashMap(java.util.LinkedHashMap) SqlNode(org.seasar.doma.jdbc.SqlNode) Test(org.junit.jupiter.api.Test)

Example 24 with SqlParser

use of org.seasar.doma.internal.jdbc.sql.SqlParser in project doma by domaframework.

the class SqlValidatorTest method testBindVariable_list.

@Test
void testBindVariable_list() throws Exception {
    Class<?> target = SqlValidationDao.class;
    addCompilationUnit(target);
    addProcessor(new TestProcessor() {

        @Override
        protected void run() {
            ExecutableElement methodElement = createMethodElement(target, "testBindVariable_list", List.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 in /* names */('aaa')");
            SqlNode sqlNode = parser.parse();
            sqlNode.accept(validator, null);
        }
    });
    compile();
    assertTrue(getCompiledResult());
}
Also used : ExecutableElement(javax.lang.model.element.ExecutableElement) SqlParser(org.seasar.doma.internal.jdbc.sql.SqlParser) TestProcessor(org.seasar.doma.internal.apt.TestProcessor) List(java.util.List) LinkedHashMap(java.util.LinkedHashMap) SqlNode(org.seasar.doma.jdbc.SqlNode) Test(org.junit.jupiter.api.Test)

Example 25 with SqlParser

use of org.seasar.doma.internal.jdbc.sql.SqlParser in project doma by domaframework.

the class SqlValidatorTest method testFormalTypeParameterResolution.

@Test
void testFormalTypeParameterResolution() throws Exception {
    Class<?> target = SqlValidationDao.class;
    addCompilationUnit(target);
    addProcessor(new TestProcessor() {

        @Override
        protected void run() {
            ExecutableElement methodElement = createMethodElement(target, "testTypeParameterResolution", CriteriaHolder.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 in /* criteriaHolder.criteria.list */(0)");
            SqlNode sqlNode = parser.parse();
            sqlNode.accept(validator, null);
        }
    });
    compile();
    assertTrue(getCompiledResult());
}
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)

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