Search in sources :

Example 1 with NodePreparedSqlBuilder

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

the class JdbcExceptionTest method testCollectionOfBindValueContainsNull.

@Test
public void testCollectionOfBindValueContainsNull() {
    SqlParser parser = new SqlParser("select * from aaa where bbb in /*bbb*/(1,2,3)");
    SqlNode sqlNode = parser.parse();
    ExpressionEvaluator evaluator = new ExpressionEvaluator();
    evaluator.add("bbb", new Value(List.class, Arrays.asList(1, null)));
    NodePreparedSqlBuilder builder = new NodePreparedSqlBuilder(config, SqlKind.SELECT, "dummyPath", evaluator, SqlLogType.FORMATTED);
    try {
        builder.build(sqlNode, Function.identity());
        fail();
    } catch (JdbcException e) {
        System.out.println(e.getMessage());
        assertEquals(Message.DOMA2115, e.getMessageResource());
    }
}
Also used : SqlParser(org.seasar.doma.internal.jdbc.sql.SqlParser) Value(org.seasar.doma.internal.expr.Value) List(java.util.List) NodePreparedSqlBuilder(org.seasar.doma.internal.jdbc.sql.NodePreparedSqlBuilder) ExpressionEvaluator(org.seasar.doma.internal.expr.ExpressionEvaluator) Test(org.junit.jupiter.api.Test)

Example 2 with NodePreparedSqlBuilder

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

the class StandardPagingTransformerTest method testOffsetLimit_forNode.

@Test
public void testOffsetLimit_forNode() {
    String expected = "select * from ( select temp_.*, row_number() over( order by temp_.name1, temp_.name2, temp_.id ) as doma_rownumber_ from ( select emp.id from emp ) as temp_ ) as temp2_ where doma_rownumber_ > 5 and doma_rownumber_ <= 15";
    StandardPagingTransformer transformer = new StandardPagingTransformer(5, 10);
    SqlParser parser = new SqlParser("select emp.id from emp order by /*%for e: values*/emp.name/*#e*/, /*%end*/emp.id");
    SqlNode sqlNode = transformer.transform(parser.parse());
    ExpressionEvaluator evaluator = new ExpressionEvaluator();
    evaluator.add("values", new Value(List.class, Arrays.asList(1, 2)));
    NodePreparedSqlBuilder sqlBuilder = new NodePreparedSqlBuilder(new MockConfig(), SqlKind.SELECT, "dummyPath", evaluator, SqlLogType.FORMATTED);
    PreparedSql sql = sqlBuilder.build(sqlNode, Function.identity());
    assertEquals(expected, sql.getRawSql());
}
Also used : SqlParser(org.seasar.doma.internal.jdbc.sql.SqlParser) Value(org.seasar.doma.internal.expr.Value) List(java.util.List) NodePreparedSqlBuilder(org.seasar.doma.internal.jdbc.sql.NodePreparedSqlBuilder) MockConfig(org.seasar.doma.internal.jdbc.mock.MockConfig) ExpressionEvaluator(org.seasar.doma.internal.expr.ExpressionEvaluator) Test(org.junit.jupiter.api.Test)

Example 3 with NodePreparedSqlBuilder

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

the class StandardPagingTransformerTest method testOffsetLimit.

@Test
public void testOffsetLimit() {
    String expected = "select * from ( select temp_.*, row_number() over( order by temp_.id ) as doma_rownumber_ from ( select emp.id from emp ) as temp_ ) as temp2_ where doma_rownumber_ > 5 and doma_rownumber_ <= 15";
    StandardPagingTransformer transformer = new StandardPagingTransformer(5, 10);
    SqlParser parser = new SqlParser("select emp.id 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, Function.identity());
    assertEquals(expected, sql.getRawSql());
}
Also used : SqlParser(org.seasar.doma.internal.jdbc.sql.SqlParser) NodePreparedSqlBuilder(org.seasar.doma.internal.jdbc.sql.NodePreparedSqlBuilder) MockConfig(org.seasar.doma.internal.jdbc.mock.MockConfig) Test(org.junit.jupiter.api.Test)

Example 4 with NodePreparedSqlBuilder

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

the class SqlFileModifyQuery method prepareSql.

protected void prepareSql() {
    SqlFile sqlFile = config.getSqlFileRepository().getSqlFile(method, sqlFilePath, config.getDialect());
    ExpressionEvaluator evaluator = new ExpressionEvaluator(parameters, config.getDialect().getExpressionFunctions(), config.getClassHelper());
    NodePreparedSqlBuilder sqlBuilder = new NodePreparedSqlBuilder(config, kind, sqlFile.getPath(), evaluator, sqlLogType, this::expandColumns, this::populateValues);
    sql = sqlBuilder.build(sqlFile.getSqlNode(), this::comment);
}
Also used : SqlFile(org.seasar.doma.jdbc.SqlFile) NodePreparedSqlBuilder(org.seasar.doma.internal.jdbc.sql.NodePreparedSqlBuilder) ExpressionEvaluator(org.seasar.doma.internal.expr.ExpressionEvaluator)

Example 5 with NodePreparedSqlBuilder

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

the class SqlFileSelectQuery method prepareSql.

protected void prepareSql() {
    sqlFile = config.getSqlFileRepository().getSqlFile(method, sqlFilePath, config.getDialect());
    SqlNode transformedSqlNode = config.getDialect().transformSelectSqlNode(sqlFile.getSqlNode(), options);
    buildSql((evaluator, expander) -> {
        NodePreparedSqlBuilder sqlBuilder = new NodePreparedSqlBuilder(config, SqlKind.SELECT, sqlFilePath, evaluator, sqlLogType, expander);
        return sqlBuilder.build(transformedSqlNode, this::comment);
    });
}
Also used : NodePreparedSqlBuilder(org.seasar.doma.internal.jdbc.sql.NodePreparedSqlBuilder) SqlNode(org.seasar.doma.jdbc.SqlNode)

Aggregations

NodePreparedSqlBuilder (org.seasar.doma.internal.jdbc.sql.NodePreparedSqlBuilder)75 Test (org.junit.jupiter.api.Test)67 SqlParser (org.seasar.doma.internal.jdbc.sql.SqlParser)67 MockConfig (org.seasar.doma.internal.jdbc.mock.MockConfig)64 SqlNode (org.seasar.doma.jdbc.SqlNode)62 PreparedSql (org.seasar.doma.jdbc.PreparedSql)61 ExpressionEvaluator (org.seasar.doma.internal.expr.ExpressionEvaluator)8 Value (org.seasar.doma.internal.expr.Value)5 List (java.util.List)2 LinkedHashMap (java.util.LinkedHashMap)1 SqlFile (org.seasar.doma.jdbc.SqlFile)1