use of org.seasar.doma.internal.jdbc.sql.node.SqlLocation in project doma by domaframework.
the class NodePreparedSqlBuilder method visitEmbeddedVariableNode.
@Override
public Void visitEmbeddedVariableNode(EmbeddedVariableNode node, Context p) {
SqlLocation location = node.getLocation();
String name = node.getVariableName();
EvaluationResult result = p.evaluate(location, name);
Object value = result.getValue();
if (value != null) {
String fragment = value.toString();
if (fragment.indexOf('\'') > -1) {
throw new JdbcException(Message.DOMA2116, location.getSql(), location.getLineNumber(), location.getPosition(), node.getVariableName());
}
if (fragment.indexOf(';') > -1) {
throw new JdbcException(Message.DOMA2117, location.getSql(), location.getLineNumber(), location.getPosition(), node.getVariableName());
}
if (fragment.contains("--")) {
throw new JdbcException(Message.DOMA2122, location.getSql(), location.getLineNumber(), location.getPosition(), node.getVariableName());
}
if (fragment.contains("/*")) {
throw new JdbcException(Message.DOMA2123, location.getSql(), location.getLineNumber(), location.getPosition(), node.getVariableName());
}
if (!startsWithClauseKeyword(fragment)) {
p.setAvailable(true);
}
p.appendRawSql(fragment);
p.appendFormattedSql(fragment);
}
for (SqlNode child : node.getChildren()) {
child.accept(this, p);
}
return null;
}
use of org.seasar.doma.internal.jdbc.sql.node.SqlLocation in project doma by domaframework.
the class NodePreparedSqlBuilder method handleElseifNode.
protected boolean handleElseifNode(IfBlockNode node, Context p) {
for (ElseifNode elseifNode : node.getElseifNodes()) {
SqlLocation location = elseifNode.getLocation();
String expression = elseifNode.getExpression();
EvaluationResult elseifResult = p.evaluate(location, expression);
if (elseifResult.getBooleanValue()) {
elseifNode.accept(this, p);
return true;
}
}
return false;
}
use of org.seasar.doma.internal.jdbc.sql.node.SqlLocation 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.SqlLocation in project doma by domaframework.
the class NodePreparedSqlBuilder method handleIfNode.
protected boolean handleIfNode(IfBlockNode node, Context p) {
IfNode ifNode = node.getIfNode();
SqlLocation location = ifNode.getLocation();
String expression = ifNode.getExpression();
EvaluationResult ifResult = p.evaluate(location, expression);
if (ifResult.getBooleanValue()) {
ifNode.accept(this, p);
return true;
}
return false;
}
use of org.seasar.doma.internal.jdbc.sql.node.SqlLocation 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());
}
}
Aggregations