use of org.apache.cayenne.access.sqlbuilder.ExpressionNodeBuilder in project cayenne by apache.
the class TableTreeStage method getJoinExpression.
private NodeBuilder getJoinExpression(TranslatorContext context, TableTreeNode node) {
List<DbJoin> joins = node.getRelationship().getJoins();
ExpressionNodeBuilder expressionNodeBuilder = null;
String sourceAlias = context.getTableTree().aliasForPath(node.getAttributePath().getParent());
for (DbJoin dbJoin : joins) {
DbAttribute src = dbJoin.getSource();
DbAttribute dst = dbJoin.getTarget();
ExpressionNodeBuilder joinExp = table(sourceAlias).column(src).eq(table(node.getTableAlias()).column(dst));
if (expressionNodeBuilder != null) {
expressionNodeBuilder = expressionNodeBuilder.and(joinExp);
} else {
expressionNodeBuilder = joinExp;
}
}
return expressionNodeBuilder;
}
use of org.apache.cayenne.access.sqlbuilder.ExpressionNodeBuilder in project cayenne by apache.
the class OracleSQLTreeProcessor method onInNode.
@Override
protected void onInNode(Node parent, InNode child, int index) {
boolean not = child.isNot();
Node arg = child.getChild(0);
Node childNode = child.getChild(1);
if (childNode.getType() != NodeType.VALUE) {
return;
}
ValueNode valueNode = (ValueNode) childNode;
Object value = valueNode.getValue();
if (!value.getClass().isArray()) {
return;
}
List<Node> newChildren = new ArrayList<>();
// need to slice for batches of 1000 values
if (value instanceof Object[]) {
for (Object[] slice : ArrayUtil.sliceArray((Object[]) value, ORACLE_IN_BATCH_SIZE)) {
newChildren.add(newSliceNode(child, arg, valueNode, slice));
}
} else if (value instanceof int[]) {
for (int[] slice : ArrayUtil.sliceArray((int[]) value, ORACLE_IN_BATCH_SIZE)) {
newChildren.add(newSliceNode(child, arg, valueNode, slice));
}
} else if (value instanceof long[]) {
for (long[] slice : ArrayUtil.sliceArray((long[]) value, ORACLE_IN_BATCH_SIZE)) {
newChildren.add(newSliceNode(child, arg, valueNode, slice));
}
} else if (value instanceof float[]) {
for (float[] slice : ArrayUtil.sliceArray((float[]) value, ORACLE_IN_BATCH_SIZE)) {
newChildren.add(newSliceNode(child, arg, valueNode, slice));
}
} else if (value instanceof double[]) {
for (double[] slice : ArrayUtil.sliceArray((double[]) value, ORACLE_IN_BATCH_SIZE)) {
newChildren.add(newSliceNode(child, arg, valueNode, slice));
}
} else if (value instanceof short[]) {
for (short[] slice : ArrayUtil.sliceArray((short[]) value, ORACLE_IN_BATCH_SIZE)) {
newChildren.add(newSliceNode(child, arg, valueNode, slice));
}
} else if (value instanceof char[]) {
for (char[] slice : ArrayUtil.sliceArray((char[]) value, ORACLE_IN_BATCH_SIZE)) {
newChildren.add(newSliceNode(child, arg, valueNode, slice));
}
} else if (value instanceof boolean[]) {
for (boolean[] slice : ArrayUtil.sliceArray((boolean[]) value, ORACLE_IN_BATCH_SIZE)) {
newChildren.add(newSliceNode(child, arg, valueNode, slice));
}
} else if (value instanceof byte[]) {
for (byte[] slice : ArrayUtil.sliceArray((byte[]) value, ORACLE_IN_BATCH_SIZE)) {
newChildren.add(newSliceNode(child, arg, valueNode, slice));
}
}
ExpressionNodeBuilder exp = exp(node(newChildren.get(0)));
for (int i = 1; i < newChildren.size(); i++) {
if (not) {
exp = exp.and(node(newChildren.get(i)));
} else {
exp = exp.or(node(newChildren.get(i)));
}
}
parent.replaceChild(index, exp.build());
}
use of org.apache.cayenne.access.sqlbuilder.ExpressionNodeBuilder in project cayenne by apache.
the class BaseBatchTranslator method buildQualifier.
protected ExpressionNodeBuilder buildQualifier(List<DbAttribute> attributeList) {
ExpressionNodeBuilder eq = null;
for (DbAttribute attr : attributeList) {
Integer value = isNullAttribute(attr) ? null : 1;
ExpressionNodeBuilder next = SQLBuilder.column(attr.getName()).attribute(attr).eq(SQLBuilder.value(value).attribute(attr));
if (eq == null) {
eq = next;
} else {
eq = eq.and(next);
}
}
return eq;
}
use of org.apache.cayenne.access.sqlbuilder.ExpressionNodeBuilder in project cayenne by apache.
the class QualifierTranslator method buildMultiValueComparison.
private Node buildMultiValueComparison(PathTranslationResult result, Map<String, Object> valueSnapshot) {
ExpressionNodeBuilder expressionNodeBuilder = null;
ExpressionNodeBuilder eq;
String path = result.getLastAttributePath();
String alias = context.getTableTree().aliasForPath(path);
for (DbAttribute attribute : result.getDbAttributes()) {
Object nextValue = valueSnapshot.get(attribute.getName());
eq = table(alias).column(attribute).eq(value(nextValue));
if (expressionNodeBuilder == null) {
expressionNodeBuilder = eq;
} else {
expressionNodeBuilder = expressionNodeBuilder.and(eq);
}
}
return expressionNodeBuilder.build();
}
use of org.apache.cayenne.access.sqlbuilder.ExpressionNodeBuilder in project cayenne by apache.
the class FirebirdSQLTreeProcessor method onInNode.
@Override
protected void onInNode(Node parent, InNode child, int index) {
Node arg = child.getChild(0);
Node childNode = child.getChild(1);
if (childNode.getType() != NodeType.VALUE) {
return;
}
ValueNode valueNode = (ValueNode) childNode;
Object value = valueNode.getValue();
if (!value.getClass().isArray()) {
return;
}
List<Node> newChildren = new ArrayList<>();
// need to slice for batches of 1500 values
if (value instanceof Object[]) {
for (Object[] slice : ArrayUtil.sliceArray((Object[]) value, FIREBIRD_IN_BATCH_SIZE)) {
newChildren.add(newSliceNode(child, arg, valueNode, slice));
}
} else if (value instanceof int[]) {
for (int[] slice : ArrayUtil.sliceArray((int[]) value, FIREBIRD_IN_BATCH_SIZE)) {
newChildren.add(newSliceNode(child, arg, valueNode, slice));
}
} else if (value instanceof long[]) {
for (long[] slice : ArrayUtil.sliceArray((long[]) value, FIREBIRD_IN_BATCH_SIZE)) {
newChildren.add(newSliceNode(child, arg, valueNode, slice));
}
} else if (value instanceof float[]) {
for (float[] slice : ArrayUtil.sliceArray((float[]) value, FIREBIRD_IN_BATCH_SIZE)) {
newChildren.add(newSliceNode(child, arg, valueNode, slice));
}
} else if (value instanceof double[]) {
for (double[] slice : ArrayUtil.sliceArray((double[]) value, FIREBIRD_IN_BATCH_SIZE)) {
newChildren.add(newSliceNode(child, arg, valueNode, slice));
}
} else if (value instanceof short[]) {
for (short[] slice : ArrayUtil.sliceArray((short[]) value, FIREBIRD_IN_BATCH_SIZE)) {
newChildren.add(newSliceNode(child, arg, valueNode, slice));
}
} else if (value instanceof char[]) {
for (char[] slice : ArrayUtil.sliceArray((char[]) value, FIREBIRD_IN_BATCH_SIZE)) {
newChildren.add(newSliceNode(child, arg, valueNode, slice));
}
} else if (value instanceof boolean[]) {
for (boolean[] slice : ArrayUtil.sliceArray((boolean[]) value, FIREBIRD_IN_BATCH_SIZE)) {
newChildren.add(newSliceNode(child, arg, valueNode, slice));
}
} else if (value instanceof byte[]) {
for (byte[] slice : ArrayUtil.sliceArray((byte[]) value, FIREBIRD_IN_BATCH_SIZE)) {
newChildren.add(newSliceNode(child, arg, valueNode, slice));
}
}
ExpressionNodeBuilder exp = exp(node(newChildren.get(0)));
for (int i = 1; i < newChildren.size(); i++) {
exp = exp.or(node(newChildren.get(i)));
}
parent.replaceChild(index, exp.build());
}
Aggregations