Search in sources :

Example 1 with ParensNode

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

the class NodePreparedSqlBuilder method visitValueNode.

@SuppressWarnings("SameReturnValue")
protected Void visitValueNode(ValueNode node, Context p, Consumer<Scalar<?, ?>> valueHandler) {
    SqlLocation location = node.getLocation();
    String name = node.getVariableName();
    EvaluationResult result = p.evaluate(location, name);
    Object value = result.getValue();
    Class<?> valueClass = result.getValueClass();
    p.setAvailable(true);
    if (node.isWordNodeIgnored()) {
        handleSingleValueNode(node, p, value, valueClass, valueHandler);
    } else if (node.isParensNodeIgnored()) {
        ParensNode parensNode = node.getParensNode();
        OtherNode openedFragmentNode = parensNode.getOpenedFragmentNode();
        openedFragmentNode.accept(this, p);
        if (Iterable.class.isAssignableFrom(valueClass)) {
            handleIterableValueNode(node, p, (Iterable<?>) value, valueClass, valueHandler);
        } else if (valueClass.isArray()) {
            handleIterableValueNode(node, p, Arrays.asList((Object[]) value), valueClass, valueHandler);
        } else {
            throw new JdbcException(Message.DOMA2112, location.getSql(), location.getLineNumber(), location.getPosition(), node.getVariableName(), valueClass);
        }
        OtherNode closedFragmentNode = parensNode.getClosedFragmentNode();
        closedFragmentNode.accept(this, p);
    } else {
        assertUnreachable();
    }
    return null;
}
Also used : ParensNode(org.seasar.doma.internal.jdbc.sql.node.ParensNode) OtherNode(org.seasar.doma.internal.jdbc.sql.node.OtherNode) SqlLocation(org.seasar.doma.internal.jdbc.sql.node.SqlLocation) JdbcException(org.seasar.doma.jdbc.JdbcException) EvaluationResult(org.seasar.doma.internal.expr.EvaluationResult)

Example 2 with ParensNode

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

the class SqlParser method appendNode.

protected void appendNode(SqlNode node) {
    if (isAfterValueNode()) {
        ValueNode valueNode = pop();
        if (node instanceof WordNode) {
            WordNode wordNode = (WordNode) node;
            String word = wordNode.getWord();
            Matcher matcher = LITERAL_PATTERN.matcher(word);
            if (matcher.lookingAt()) {
                valueNode.setWordNode(wordNode);
            } else {
                throw new JdbcException(Message.DOMA2142, sql, tokenizer.getLineNumber(), tokenizer.getPosition(), valueNode.getText(), word);
            }
        } else if (node instanceof ParensNode) {
            ParensNode parensNode = (ParensNode) node;
            parensNode.setAttachedWithValue(true);
            valueNode.setParensNode(parensNode);
        } else {
            throw new JdbcException(Message.DOMA2110, sql, tokenizer.getLineNumber(), tokenizer.getPosition(), valueNode.getText());
        }
    } else if (isAfterExpandNode()) {
        ExpandNode expandNode = pop();
        if (node instanceof OtherNode) {
            OtherNode otherNode = (OtherNode) node;
            if (!otherNode.getOther().equals("*")) {
                throw new JdbcException(Message.DOMA2143, sql, tokenizer.getLineNumber(), tokenizer.getPosition(), expandNode.getText());
            }
        } else {
            throw new JdbcException(Message.DOMA2143, sql, tokenizer.getLineNumber(), tokenizer.getPosition(), expandNode.getText());
        }
    } else {
        peek().appendNode(node);
    }
}
Also used : ParensNode(org.seasar.doma.internal.jdbc.sql.node.ParensNode) OtherNode(org.seasar.doma.internal.jdbc.sql.node.OtherNode) WordNode(org.seasar.doma.internal.jdbc.sql.node.WordNode) Matcher(java.util.regex.Matcher) ExpandNode(org.seasar.doma.internal.jdbc.sql.node.ExpandNode) ValueNode(org.seasar.doma.internal.jdbc.sql.node.ValueNode) JdbcException(org.seasar.doma.jdbc.JdbcException)

Example 3 with ParensNode

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

the class SqlParser method validateParensClosed.

protected void validateParensClosed() {
    if (isInParensNode()) {
        removeNodesTo(ParensNode.class);
        ParensNode parensNode = pop();
        SqlLocation location = parensNode.getLocation();
        throw new JdbcException(Message.DOMA2135, sql, location.getLineNumber(), location.getPosition());
    }
}
Also used : ParensNode(org.seasar.doma.internal.jdbc.sql.node.ParensNode) SqlLocation(org.seasar.doma.internal.jdbc.sql.node.SqlLocation) JdbcException(org.seasar.doma.jdbc.JdbcException)

Example 4 with ParensNode

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

the class SqlParser method parseClosedParens.

protected void parseClosedParens() {
    if (!isInParensNode()) {
        throw new JdbcException(Message.DOMA2109, sql, tokenizer.getLineNumber(), tokenizer.getPosition());
    }
    validate();
    removeNodesTo(ParensNode.class);
    ParensNode parensNode = pop();
    for (SqlNode child : parensNode.getChildren()) {
        if (!(child instanceof WhitespaceNode) && !(child instanceof CommentNode)) {
            parensNode.setEmpty(false);
            break;
        }
    }
    parensNode.close();
}
Also used : ParensNode(org.seasar.doma.internal.jdbc.sql.node.ParensNode) CommentNode(org.seasar.doma.internal.jdbc.sql.node.CommentNode) WhitespaceNode(org.seasar.doma.internal.jdbc.sql.node.WhitespaceNode) JdbcException(org.seasar.doma.jdbc.JdbcException) SqlNode(org.seasar.doma.jdbc.SqlNode) AppendableSqlNode(org.seasar.doma.internal.jdbc.sql.node.AppendableSqlNode)

Example 5 with ParensNode

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

the class SqlParser method parseOpenedParens.

protected void parseOpenedParens() {
    ParensNode parensNode = new ParensNode(getLocation());
    appendNode(parensNode);
    push(parensNode);
}
Also used : ParensNode(org.seasar.doma.internal.jdbc.sql.node.ParensNode)

Aggregations

ParensNode (org.seasar.doma.internal.jdbc.sql.node.ParensNode)5 JdbcException (org.seasar.doma.jdbc.JdbcException)4 OtherNode (org.seasar.doma.internal.jdbc.sql.node.OtherNode)2 SqlLocation (org.seasar.doma.internal.jdbc.sql.node.SqlLocation)2 Matcher (java.util.regex.Matcher)1 EvaluationResult (org.seasar.doma.internal.expr.EvaluationResult)1 AppendableSqlNode (org.seasar.doma.internal.jdbc.sql.node.AppendableSqlNode)1 CommentNode (org.seasar.doma.internal.jdbc.sql.node.CommentNode)1 ExpandNode (org.seasar.doma.internal.jdbc.sql.node.ExpandNode)1 ValueNode (org.seasar.doma.internal.jdbc.sql.node.ValueNode)1 WhitespaceNode (org.seasar.doma.internal.jdbc.sql.node.WhitespaceNode)1 WordNode (org.seasar.doma.internal.jdbc.sql.node.WordNode)1 SqlNode (org.seasar.doma.jdbc.SqlNode)1