Search in sources :

Example 1 with ExpressionNodeBuilder

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;
}
Also used : ExpressionNodeBuilder(org.apache.cayenne.access.sqlbuilder.ExpressionNodeBuilder) DbAttribute(org.apache.cayenne.map.DbAttribute) DbJoin(org.apache.cayenne.map.DbJoin)

Example 2 with 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());
}
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 3 with ExpressionNodeBuilder

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;
}
Also used : ExpressionNodeBuilder(org.apache.cayenne.access.sqlbuilder.ExpressionNodeBuilder) DbAttribute(org.apache.cayenne.map.DbAttribute)

Example 4 with ExpressionNodeBuilder

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();
}
Also used : ExpressionNodeBuilder(org.apache.cayenne.access.sqlbuilder.ExpressionNodeBuilder) DbAttribute(org.apache.cayenne.map.DbAttribute) EmbeddableObject(org.apache.cayenne.EmbeddableObject) ASTFullObject(org.apache.cayenne.exp.parser.ASTFullObject)

Example 5 with ExpressionNodeBuilder

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

ExpressionNodeBuilder (org.apache.cayenne.access.sqlbuilder.ExpressionNodeBuilder)5 DbAttribute (org.apache.cayenne.map.DbAttribute)3 ArrayList (java.util.ArrayList)2 FunctionNode (org.apache.cayenne.access.sqlbuilder.sqltree.FunctionNode)2 InNode (org.apache.cayenne.access.sqlbuilder.sqltree.InNode)2 LimitOffsetNode (org.apache.cayenne.access.sqlbuilder.sqltree.LimitOffsetNode)2 Node (org.apache.cayenne.access.sqlbuilder.sqltree.Node)2 OpExpressionNode (org.apache.cayenne.access.sqlbuilder.sqltree.OpExpressionNode)2 TextNode (org.apache.cayenne.access.sqlbuilder.sqltree.TextNode)2 ValueNode (org.apache.cayenne.access.sqlbuilder.sqltree.ValueNode)2 EmbeddableObject (org.apache.cayenne.EmbeddableObject)1 ColumnNode (org.apache.cayenne.access.sqlbuilder.sqltree.ColumnNode)1 EmptyNode (org.apache.cayenne.access.sqlbuilder.sqltree.EmptyNode)1 TrimmingColumnNode (org.apache.cayenne.access.sqlbuilder.sqltree.TrimmingColumnNode)1 FirebirdLimitNode (org.apache.cayenne.dba.firebird.sqltree.FirebirdLimitNode)1 FirebirdSubstringFunctionNode (org.apache.cayenne.dba.firebird.sqltree.FirebirdSubstringFunctionNode)1 ASTFullObject (org.apache.cayenne.exp.parser.ASTFullObject)1 DbJoin (org.apache.cayenne.map.DbJoin)1