Search in sources :

Example 1 with ElseNode

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

the class NodePreparedSqlBuilderTest method testElseNode.

@Test
public void testElseNode() {
    SelectClauseNode select = new SelectClauseNode("select");
    select.appendNode(OtherNode.of(" * "));
    FromClauseNode from = new FromClauseNode("from");
    from.appendNode(WhitespaceNode.of(" "));
    from.appendNode(new WordNode("aaa"));
    from.appendNode(WhitespaceNode.of(" "));
    WhereClauseNode where = new WhereClauseNode("where");
    where.appendNode(WhitespaceNode.of(" "));
    IfNode ifNode = new IfNode(location, "false", "/*if false*/");
    ifNode.appendNode(new WordNode("bbb"));
    ifNode.appendNode(OtherNode.of(" = "));
    ifNode.appendNode(new WordNode("ccc"));
    ElseNode elseNode = new ElseNode("/*else*/");
    elseNode.appendNode(new WordNode("ddd"));
    elseNode.appendNode(OtherNode.of(" = "));
    elseNode.appendNode(new WordNode("eee"));
    EndNode endNode = new EndNode("/*end*/");
    IfBlockNode ifBlock = new IfBlockNode();
    ifBlock.setIfNode(ifNode);
    ifBlock.setElseNode(elseNode);
    ifBlock.setEndNode(endNode);
    where.appendNode(ifBlock);
    SelectStatementNode statement = new SelectStatementNode();
    statement.setSelectClauseNode(select);
    statement.setFromClauseNode(from);
    statement.setWhereClauseNode(where);
    AnonymousNode root = new AnonymousNode();
    root.appendNode(statement);
    ExpressionEvaluator evaluator = new ExpressionEvaluator();
    NodePreparedSqlBuilder builder = new NodePreparedSqlBuilder(config, SqlKind.SELECT, "dummyPath", evaluator, SqlLogType.FORMATTED);
    PreparedSql sql = builder.build(statement, Function.identity());
    assertEquals("select * from aaa where ddd = eee", sql.getRawSql());
}
Also used : FromClauseNode(org.seasar.doma.internal.jdbc.sql.node.FromClauseNode) SelectStatementNode(org.seasar.doma.internal.jdbc.sql.node.SelectStatementNode) PreparedSql(org.seasar.doma.jdbc.PreparedSql) WordNode(org.seasar.doma.internal.jdbc.sql.node.WordNode) SelectClauseNode(org.seasar.doma.internal.jdbc.sql.node.SelectClauseNode) IfNode(org.seasar.doma.internal.jdbc.sql.node.IfNode) ExpressionEvaluator(org.seasar.doma.internal.expr.ExpressionEvaluator) AnonymousNode(org.seasar.doma.internal.jdbc.sql.node.AnonymousNode) EndNode(org.seasar.doma.internal.jdbc.sql.node.EndNode) ElseNode(org.seasar.doma.internal.jdbc.sql.node.ElseNode) IfBlockNode(org.seasar.doma.internal.jdbc.sql.node.IfBlockNode) WhereClauseNode(org.seasar.doma.internal.jdbc.sql.node.WhereClauseNode) Test(org.junit.jupiter.api.Test)

Example 2 with ElseNode

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

the class SqlParser method parseElseBlockComment.

protected void parseElseBlockComment() {
    if (!isInIfBlockNode()) {
        throw new JdbcException(Message.DOMA2140, sql, tokenizer.getLineNumber(), tokenizer.getPosition());
    }
    removeNodesTo(IfBlockNode.class);
    IfBlockNode ifBlockNode = peek();
    if (ifBlockNode.isElseNodeExistent()) {
        throw new JdbcException(Message.DOMA2141, sql, tokenizer.getLineNumber(), tokenizer.getPosition());
    }
    ElseNode node = new ElseNode(token);
    ifBlockNode.setElseNode(node);
    push(node);
}
Also used : IfBlockNode(org.seasar.doma.internal.jdbc.sql.node.IfBlockNode) ElseNode(org.seasar.doma.internal.jdbc.sql.node.ElseNode) JdbcException(org.seasar.doma.jdbc.JdbcException)

Aggregations

ElseNode (org.seasar.doma.internal.jdbc.sql.node.ElseNode)2 IfBlockNode (org.seasar.doma.internal.jdbc.sql.node.IfBlockNode)2 Test (org.junit.jupiter.api.Test)1 ExpressionEvaluator (org.seasar.doma.internal.expr.ExpressionEvaluator)1 AnonymousNode (org.seasar.doma.internal.jdbc.sql.node.AnonymousNode)1 EndNode (org.seasar.doma.internal.jdbc.sql.node.EndNode)1 FromClauseNode (org.seasar.doma.internal.jdbc.sql.node.FromClauseNode)1 IfNode (org.seasar.doma.internal.jdbc.sql.node.IfNode)1 SelectClauseNode (org.seasar.doma.internal.jdbc.sql.node.SelectClauseNode)1 SelectStatementNode (org.seasar.doma.internal.jdbc.sql.node.SelectStatementNode)1 WhereClauseNode (org.seasar.doma.internal.jdbc.sql.node.WhereClauseNode)1 WordNode (org.seasar.doma.internal.jdbc.sql.node.WordNode)1 JdbcException (org.seasar.doma.jdbc.JdbcException)1 PreparedSql (org.seasar.doma.jdbc.PreparedSql)1