use of org.apache.cayenne.access.sqlbuilder.sqltree.ValueNode in project cayenne by apache.
the class DB2SQLTreeProcessor method onValueNode.
@Override
protected void onValueNode(Node parent, ValueNode child, int index) {
Node replacement = new DerbyValueNode(child.getValue(), child.isArray(), child.getAttribute());
replaceChild(parent, index, replacement, false);
}
use of org.apache.cayenne.access.sqlbuilder.sqltree.ValueNode in project cayenne by apache.
the class HavingTranslationStageTest method perform.
@Test
public void perform() {
HavingTranslationStage stage = new HavingTranslationStage();
stage.perform(context);
Node select = context.getSelectBuilder().build();
// Content of "select" node:
//
// Having
// |
// OpExpression
// / \
// Column Value
assertEquals(1, select.getChildrenCount());
assertThat(select.getChild(0), instanceOf(HavingNode.class));
Node op = select.getChild(0).getChild(0);
assertThat(op, instanceOf(OpExpressionNode.class));
assertEquals(">=", ((OpExpressionNode) op).getOp());
assertEquals(2, op.getChildrenCount());
assertThat(op.getChild(0), instanceOf(ColumnNode.class));
assertThat(op.getChild(1), instanceOf(ValueNode.class));
ColumnNode columnNode = (ColumnNode) op.getChild(0);
ValueNode valueNode = (ValueNode) op.getChild(1);
assertEquals("path", columnNode.getColumn());
assertEquals(10, valueNode.getValue());
}
use of org.apache.cayenne.access.sqlbuilder.sqltree.ValueNode 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.sqltree.ValueNode in project cayenne by apache.
the class OracleSQLTreeProcessor method newSliceNode.
private InNode newSliceNode(InNode child, Node arg, ValueNode valueNode, Object slice) {
InNode nextNode = new InNode(child.isNot());
nextNode.addChild(arg.deepCopy());
nextNode.addChild(new ValueNode(slice, valueNode.isArray(), valueNode.getAttribute()));
return nextNode;
}
use of org.apache.cayenne.access.sqlbuilder.sqltree.ValueNode 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