Search in sources :

Example 1 with OtherNode

use of org.seasar.doma.internal.jdbc.sql.node.OtherNode 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 OtherNode

use of org.seasar.doma.internal.jdbc.sql.node.OtherNode 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)

Aggregations

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