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;
}
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);
}
}
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());
}
}
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();
}
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);
}
Aggregations