Search in sources :

Example 1 with ValueNode

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);
}
Also used : ValueNode(org.apache.cayenne.access.sqlbuilder.sqltree.ValueNode) MysqlLimitOffsetNode(org.apache.cayenne.dba.mysql.sqltree.MysqlLimitOffsetNode) ColumnNode(org.apache.cayenne.access.sqlbuilder.sqltree.ColumnNode) Node(org.apache.cayenne.access.sqlbuilder.sqltree.Node) OpExpressionNode(org.apache.cayenne.access.sqlbuilder.sqltree.OpExpressionNode) FunctionNode(org.apache.cayenne.access.sqlbuilder.sqltree.FunctionNode) LimitOffsetNode(org.apache.cayenne.access.sqlbuilder.sqltree.LimitOffsetNode) DerbyValueNode(org.apache.cayenne.dba.derby.sqltree.DerbyValueNode) TrimmingColumnNode(org.apache.cayenne.access.sqlbuilder.sqltree.TrimmingColumnNode) DerbyValueNode(org.apache.cayenne.dba.derby.sqltree.DerbyValueNode)

Example 2 with ValueNode

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());
}
Also used : HavingNode(org.apache.cayenne.access.sqlbuilder.sqltree.HavingNode) OpExpressionNode(org.apache.cayenne.access.sqlbuilder.sqltree.OpExpressionNode) Node(org.apache.cayenne.access.sqlbuilder.sqltree.Node) OpExpressionNode(org.apache.cayenne.access.sqlbuilder.sqltree.OpExpressionNode) ValueNode(org.apache.cayenne.access.sqlbuilder.sqltree.ValueNode) ColumnNode(org.apache.cayenne.access.sqlbuilder.sqltree.ColumnNode) HavingNode(org.apache.cayenne.access.sqlbuilder.sqltree.HavingNode) ColumnNode(org.apache.cayenne.access.sqlbuilder.sqltree.ColumnNode) ValueNode(org.apache.cayenne.access.sqlbuilder.sqltree.ValueNode) Test(org.junit.Test)

Example 3 with ValueNode

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());
}
Also used : ExpressionNodeBuilder(org.apache.cayenne.access.sqlbuilder.ExpressionNodeBuilder) TextNode(org.apache.cayenne.access.sqlbuilder.sqltree.TextNode) Node(org.apache.cayenne.access.sqlbuilder.sqltree.Node) FunctionNode(org.apache.cayenne.access.sqlbuilder.sqltree.FunctionNode) OpExpressionNode(org.apache.cayenne.access.sqlbuilder.sqltree.OpExpressionNode) LimitOffsetNode(org.apache.cayenne.access.sqlbuilder.sqltree.LimitOffsetNode) EmptyNode(org.apache.cayenne.access.sqlbuilder.sqltree.EmptyNode) InNode(org.apache.cayenne.access.sqlbuilder.sqltree.InNode) ValueNode(org.apache.cayenne.access.sqlbuilder.sqltree.ValueNode) ColumnNode(org.apache.cayenne.access.sqlbuilder.sqltree.ColumnNode) TrimmingColumnNode(org.apache.cayenne.access.sqlbuilder.sqltree.TrimmingColumnNode) ArrayList(java.util.ArrayList) ValueNode(org.apache.cayenne.access.sqlbuilder.sqltree.ValueNode)

Example 4 with ValueNode

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;
}
Also used : InNode(org.apache.cayenne.access.sqlbuilder.sqltree.InNode) ValueNode(org.apache.cayenne.access.sqlbuilder.sqltree.ValueNode)

Example 5 with ValueNode

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());
}
Also used : ExpressionNodeBuilder(org.apache.cayenne.access.sqlbuilder.ExpressionNodeBuilder) TextNode(org.apache.cayenne.access.sqlbuilder.sqltree.TextNode) FirebirdSubstringFunctionNode(org.apache.cayenne.dba.firebird.sqltree.FirebirdSubstringFunctionNode) Node(org.apache.cayenne.access.sqlbuilder.sqltree.Node) FunctionNode(org.apache.cayenne.access.sqlbuilder.sqltree.FunctionNode) OpExpressionNode(org.apache.cayenne.access.sqlbuilder.sqltree.OpExpressionNode) LimitOffsetNode(org.apache.cayenne.access.sqlbuilder.sqltree.LimitOffsetNode) FirebirdLimitNode(org.apache.cayenne.dba.firebird.sqltree.FirebirdLimitNode) InNode(org.apache.cayenne.access.sqlbuilder.sqltree.InNode) ValueNode(org.apache.cayenne.access.sqlbuilder.sqltree.ValueNode) ArrayList(java.util.ArrayList) ValueNode(org.apache.cayenne.access.sqlbuilder.sqltree.ValueNode)

Aggregations

ValueNode (org.apache.cayenne.access.sqlbuilder.sqltree.ValueNode)7 Node (org.apache.cayenne.access.sqlbuilder.sqltree.Node)5 OpExpressionNode (org.apache.cayenne.access.sqlbuilder.sqltree.OpExpressionNode)5 ColumnNode (org.apache.cayenne.access.sqlbuilder.sqltree.ColumnNode)4 InNode (org.apache.cayenne.access.sqlbuilder.sqltree.InNode)4 FunctionNode (org.apache.cayenne.access.sqlbuilder.sqltree.FunctionNode)3 LimitOffsetNode (org.apache.cayenne.access.sqlbuilder.sqltree.LimitOffsetNode)3 ArrayList (java.util.ArrayList)2 ExpressionNodeBuilder (org.apache.cayenne.access.sqlbuilder.ExpressionNodeBuilder)2 TextNode (org.apache.cayenne.access.sqlbuilder.sqltree.TextNode)2 TrimmingColumnNode (org.apache.cayenne.access.sqlbuilder.sqltree.TrimmingColumnNode)2 Test (org.junit.Test)2 EmptyNode (org.apache.cayenne.access.sqlbuilder.sqltree.EmptyNode)1 HavingNode (org.apache.cayenne.access.sqlbuilder.sqltree.HavingNode)1 WhereNode (org.apache.cayenne.access.sqlbuilder.sqltree.WhereNode)1 DerbyValueNode (org.apache.cayenne.dba.derby.sqltree.DerbyValueNode)1 FirebirdLimitNode (org.apache.cayenne.dba.firebird.sqltree.FirebirdLimitNode)1 FirebirdSubstringFunctionNode (org.apache.cayenne.dba.firebird.sqltree.FirebirdSubstringFunctionNode)1 MysqlLimitOffsetNode (org.apache.cayenne.dba.mysql.sqltree.MysqlLimitOffsetNode)1