Package org.apache.openjpa.kernel

Examples of org.apache.openjpa.kernel.ResultShape


        Class<?> type = s.getJavaType();
        if (type == null)
            type = Object.class;
        if (s.isCompoundSelection()) {
            CompoundSelection<?> cs = (CompoundSelection<?>)s;
            result = new ResultShape(s.getJavaType(), CompoundSelections.getFillStrategy(cs));
            List<Selection<?>> terms = cs.getCompoundSelectionItems();
            for (Selection<?> term : terms) {
                result.nest(getShape(q, result, term));
            }
        } else {
            if (parent.getType().isArray() && q.isMultiselect()) {
                Class<?> componentType = parent.getType().getComponentType();
                if (componentType == Tuple.class) {
                    result = new ResultShape(componentType,
                         new FillStrategy.Factory(new TupleFactory(s), TupleImpl.PUT), false);
                } else {
                    result = new ResultShape(componentType, new FillStrategy.Assign(), true);
                }
            } else {
                result = new ResultShape(type, new FillStrategy.Assign(), true);
            }
        }
        return result;
    }
View Full Code Here


    private ResultShape<?> evalResultShape(CriteriaQueryImpl<?> q) {
        List<Selection<?>> selections = q.getSelectionList();
        Class<?> resultClass = q.getResultType();
        ResultShape<?> result = null;
        if (q.isMultiselect()) {
           result = new ResultShape(resultClass, CompoundSelections.getFillStrategy(q.getSelection()));
           for (Selection<?> term : selections) {
               result.nest(getShape(q, result, term));
           }
        } else { // not multiselect
            FillStrategy<?> strategy = new FillStrategy.Assign();
            if (Tuple.class.isAssignableFrom(resultClass)) {
                TupleFactory factory = new TupleFactory(selections.toArray(new TupleElement[selections.size()]));
                strategy = new FillStrategy.Factory<Tuple>(factory,  TupleImpl.PUT);
            }
            result = new ResultShape(resultClass, strategy);
            if (q.getSelectionList() == null) {
                return result;
            }
            if (q.getSelectionList().size() == 1) {
                result = getShape(q, result, q.getSelectionList().get(0));
View Full Code Here

        Class<?> resultClass = null;
        ResultShape<?> resultShape = null;
        if (count > 1) {
            // muti-selection
            resultClass = Object[].class;
            resultShape = new ResultShape(resultClass, new FillStrategy.Array<Object[]>(Object[].class));
        }

        for (int i = 0; i < count; i++) {
            JPQLNode parent = selectionsNode.getChild(i);
            JPQLNode node = firstChild(parent);
            if (node.id == JJTCONSTRUCTOR) {
                // build up the fully-qualified result class name by
                // appending together the components of the children
                String resultClassName = assemble(left(node));
                Class<?> constructor = resolver.classForName(resultClassName, null);
                if (constructor == null) {
                    // try resolve it again using simple name
                    int n = left(node).getChildCount();
                    String baseName = left(node).getChild(n-1).text;
                    constructor = resolver.classForName(baseName, null);
                }
                if (constructor == null)
                    throw parseException(EX_USER, "no-constructor",
                            new Object[]{ resultClassName }, null);

                List<Value> terms = new ArrayList<Value>();
                List<String> aliases = new ArrayList<String>();
                List<String> clauses = new ArrayList<String>();
                // now assign the arguments to the select clause as the projections
                assignProjections(right(node), exps, terms, aliases, clauses);
                FillStrategy fill = new FillStrategy.NewInstance(constructor);
                ResultShape<?> cons = new ResultShape(constructor, fill);
                for (Value val : terms) {
                    Class<?> type = val.getType();
                    cons.nest(new ResultShape(type, new FillStrategy.Assign(), type.isPrimitive()));
                }
                if (count == 1) {
                    resultClass = constructor;
                    resultShape = cons;
                }
                else
                    resultShape.nest(cons);
                projections.addAll(terms);
                projectionAliases.addAll(aliases);
                projectionClauses.addAll(clauses);

            } else {
                JPQLNode aliasNode = parent.children.length > 1 ? right(parent)
                        : null;
                Value proj = getValue(node);
                String alias = aliasNode != null ? aliasNode.text :
                    projectionClause(node.id == JJTSCALAREXPRESSION ?
                            firstChild(node) : node);
                if (aliasNode != null)
                    proj.setAlias(alias);
                projections.add(proj);
                projectionClauses.add(alias);
                projectionAliases.add(alias);
                Class<?> type = proj.getType();
                ResultShape<?> projShape = new ResultShape(type, new FillStrategy.Assign(), type.isPrimitive());

                if (count == 1)
                    resultShape = projShape;
                else
                    resultShape.nest(projShape);
View Full Code Here

        Class<?> resultClass = null;
        ResultShape<?> resultShape = null;
        if (count > 1) {
            // muti-selection
            resultClass = Object[].class;
            resultShape = new ResultShape(resultClass, new FillStrategy.Array<Object[]>(Object[].class));
        }

        for (int i = 0; i < count; i++) {
            JPQLNode parent = selectionsNode.getChild(i);
            JPQLNode node = firstChild(parent);
            if (node.id == JJTCONSTRUCTOR) {
                // build up the fully-qualified result class name by
                // appending together the components of the children
                String resultClassName = assemble(left(node));
                Class<?> constructor = resolver.classForName(resultClassName, null);
                if (constructor == null) {
                    // try resolve it again using simple name
                    int n = left(node).getChildCount();
                    String baseName = left(node).getChild(n-1).text;
                    constructor = resolver.classForName(baseName, null);
                }
                if (constructor == null)
                    throw parseException(EX_USER, "no-constructor",
                            new Object[]{ resultClassName }, null);

                List<Value> terms = new ArrayList<Value>();
                List<String> aliases = new ArrayList<String>();
                List<String> clauses = new ArrayList<String>();
                // now assign the arguments to the select clause as the projections
                assignProjections(right(node), exps, terms, aliases, clauses);
                FillStrategy fill = new FillStrategy.NewInstance(constructor);
                ResultShape<?> cons = new ResultShape(constructor, fill);
                for (Value val : terms) {
                    Class<?> type = val.getType();
                    cons.nest(new ResultShape(type, new FillStrategy.Assign(), type.isPrimitive()));
                }
                if (count == 1) {
                    resultClass = constructor;
                    resultShape = cons;
                }
                else
                    resultShape.nest(cons);
                projections.addAll(terms);
                projectionAliases.addAll(aliases);
                projectionClauses.addAll(clauses);

            } else {
                JPQLNode aliasNode = parent.children.length > 1 ? right(parent)
                        : null;
                Value proj = getValue(node);
                String alias = aliasNode != null ? aliasNode.text :
                    projectionClause(node.id == JJTSCALAREXPRESSION ?
                            firstChild(node) : node);
                if (aliasNode != null)
                    proj.setAlias(alias);
                projections.add(proj);
                projectionClauses.add(alias);
                projectionAliases.add(alias);
                Class<?> type = proj.getType();
                ResultShape<?> projShape = new ResultShape(type, new FillStrategy.Assign(), type.isPrimitive());

                if (count == 1)
                    resultShape = projShape;
                else
                    resultShape.nest(projShape);
View Full Code Here

        Class<?> resultClass = null;
        ResultShape<?> resultShape = null;
        if (count > 1) {
            // muti-selection
            resultClass = Object[].class;
            resultShape = new ResultShape(resultClass, new FillStrategy.Array<Object[]>(Object[].class));
        }

        for (int i = 0; i < count; i++) {
            JPQLNode parent = selectionsNode.getChild(i);
            JPQLNode node = firstChild(parent);
            if (node.id == JJTCONSTRUCTOR) {
                // build up the fully-qualified result class name by
                // appending together the components of the children
                String resultClassName = assemble(left(node));
                Class<?> constructor = resolver.classForName(resultClassName, null);
                if (constructor == null) {
                    // try resolve it again using simple name
                    int n = left(node).getChildCount();
                    String baseName = left(node).getChild(n-1).text;
                    constructor = resolver.classForName(baseName, null);
                }
                if (constructor == null)
                    throw parseException(EX_USER, "no-constructor",
                            new Object[]{ resultClassName }, null);

                List<Value> terms = new ArrayList<Value>();
                List<String> aliases = new ArrayList<String>();
                List<String> clauses = new ArrayList<String>();
                // now assign the arguments to the select clause as the projections
                assignProjections(right(node), exps, terms, aliases, clauses);
                FillStrategy fill = new FillStrategy.NewInstance(constructor);
                ResultShape<?> cons = new ResultShape(constructor, fill);
                for (Value val : terms) {
                    Class<?> type = val.getType();
                    cons.nest(new ResultShape(type, new FillStrategy.Assign(), type.isPrimitive()));
                }
                if (count == 1) {
                    resultClass = constructor;
                    resultShape = cons;
                }
                else
                    resultShape.nest(cons);
                projections.addAll(terms);
                projectionAliases.addAll(aliases);
                projectionClauses.addAll(clauses);

            } else {
                JPQLNode aliasNode = parent.children.length > 1 ? right(parent)
                        : null;
                Value proj = getValue(node);
                String alias = aliasNode != null ? aliasNode.text :
                    projectionClause(node.id == JJTSCALAREXPRESSION ?
                            firstChild(node) : node);
                if (aliasNode != null)
                    proj.setAlias(alias);
                projections.add(proj);
                projectionClauses.add(alias);
                projectionAliases.add(alias);
                Class<?> type = proj.getType();
                ResultShape<?> projShape = new ResultShape(type, new FillStrategy.Assign(), type.isPrimitive());

                if (count == 1)
                    resultShape = projShape;
                else
                    resultShape.nest(projShape);
View Full Code Here

        Class<?> resultClass = null;
        ResultShape<?> resultShape = null;
        if (count > 1) {
            // muti-selection
            resultClass = Object[].class;
            resultShape = new ResultShape(resultClass, new FillStrategy.Array<Object[]>(Object[].class));
        }

        for (int i = 0; i < count; i++) {
            JPQLNode parent = selectionsNode.getChild(i);
            JPQLNode node = firstChild(parent);
            if (node.id == JJTCONSTRUCTOR) {
                // build up the fully-qualified result class name by
                // appending together the components of the children
                String resultClassName = assemble(left(node));
                Class<?> constructor = resolver.classForName(resultClassName, null);
                if (constructor == null) {
                    // try resolve it again using simple name
                    int n = left(node).getChildCount();
                    String baseName = left(node).getChild(n-1).text;
                    constructor = resolver.classForName(baseName, null);
                }
                if (constructor == null)
                    throw parseException(EX_USER, "no-constructor",
                            new Object[]{ resultClassName }, null);

                List<Value> terms = new ArrayList<Value>();
                List<String> aliases = new ArrayList<String>();
                List<String> clauses = new ArrayList<String>();
                // now assign the arguments to the select clause as the projections
                assignProjections(right(node), exps, terms, aliases, clauses);
                FillStrategy fill = new FillStrategy.NewInstance(constructor);
                ResultShape<?> cons = new ResultShape(constructor, fill);
                for (Value val : terms) {
                    Class<?> type = val.getType();
                    cons.nest(new ResultShape(type, new FillStrategy.Assign(), type.isPrimitive()));
                }
                if (count == 1) {
                    resultClass = constructor;
                    resultShape = cons;
                }
                else
                    resultShape.nest(cons);
                projections.addAll(terms);
                projectionAliases.addAll(aliases);
                projectionClauses.addAll(clauses);

            } else {
                JPQLNode aliasNode = parent.children.length > 1 ? right(parent)
                        : null;
                Value proj = getValue(node);
                String alias = aliasNode != null ? aliasNode.text :
                    projectionClause(node.id == JJTSCALAREXPRESSION ?
                            firstChild(node) : node);
                if (aliasNode != null)
                    proj.setAlias(alias);
                projections.add(proj);
                projectionClauses.add(alias);
                projectionAliases.add(alias);
                Class<?> type = proj.getType();
                ResultShape<?> projShape = new ResultShape(type, new FillStrategy.Assign(), type.isPrimitive());

                if (count == 1)
                    resultShape = projShape;
                else
                    resultShape.nest(projShape);
View Full Code Here

        Class<?> type = s.getJavaType();
        if (type == null)
            type = Object.class;
        if (s.isCompoundSelection()) {
            CompoundSelection<?> cs = (CompoundSelection<?>)s;
            result = new ResultShape(s.getJavaType(), CompoundSelections.getFillStrategy(cs));
            List<Selection<?>> terms = cs.getCompoundSelectionItems();
            for (Selection<?> term : terms) {
                result.nest(getShape(q, result, term));
            }
        } else {
            if (parent.getType().isArray() && q.isMultiselect()) {
                Class<?> componentType = parent.getType().getComponentType();
                if (componentType == Tuple.class) {
                    result = new ResultShape(componentType,
                         new FillStrategy.Factory(new TupleFactory(s), TupleImpl.PUT), false);
                } else {
                    result = new ResultShape(componentType, new FillStrategy.Assign(), true);
                }
            } else {
                result = new ResultShape(type, new FillStrategy.Assign(), true);
            }
        }
        return result;
    }
View Full Code Here

    private ResultShape<?> evalResultShape(CriteriaQueryImpl<?> q) {
        List<Selection<?>> selections = q.getSelectionList();
        Class<?> resultClass = q.getResultType();
        ResultShape<?> result = null;
        if (q.isMultiselect()) {
           result = new ResultShape(resultClass, CompoundSelections.getFillStrategy(q.getSelection()));
           for (Selection<?> term : selections) {
               result.nest(getShape(q, result, term));
           }
        } else { // not multiselect
            FillStrategy<?> strategy = new FillStrategy.Assign();
            if (Tuple.class.isAssignableFrom(resultClass)) {
                TupleFactory factory = new TupleFactory(selections.toArray(new TupleElement[selections.size()]));
                strategy = new FillStrategy.Factory<Tuple>(factory,  TupleImpl.PUT);
            }
            result = new ResultShape(resultClass, strategy);
            if (q.getSelectionList() == null) {
                return result;
            }
            if (q.getSelectionList().size() == 1) {
                result = getShape(q, result, q.getSelectionList().get(0));
View Full Code Here

        Class<?> resultClass = null;
        ResultShape<?> resultShape = null;
        if (count > 1) {
            // muti-selection
            resultClass = Object[].class;
            resultShape = new ResultShape(resultClass, new FillStrategy.Array<Object[]>(Object[].class));
        }

        for (int i = 0; i < count; i++) {
            JPQLNode parent = selectionsNode.getChild(i);
            JPQLNode node = firstChild(parent);
            if (node.id == JJTCONSTRUCTOR) {
                // build up the fully-qualified result class name by
                // appending together the components of the children
                String resultClassName = assemble(left(node));
                Class<?> constructor = resolver.classForName(resultClassName, null);
                if (constructor == null) {
                    // try resolve it again using simple name
                    int n = left(node).getChildCount();
                    String baseName = left(node).getChild(n-1).text;
                    constructor = resolver.classForName(baseName, null);
                }
                if (constructor == null)
                    throw parseException(EX_USER, "no-constructor",
                            new Object[]{ resultClassName }, null);

                List<Value> terms = new ArrayList<Value>();
                List<String> aliases = new ArrayList<String>();
                List<String> clauses = new ArrayList<String>();
                // now assign the arguments to the select clause as the projections
                assignProjections(right(node), exps, terms, aliases, clauses);
                FillStrategy fill = new FillStrategy.NewInstance(constructor);
                ResultShape<?> cons = new ResultShape(constructor, fill);
                for (Value val : terms) {
                    Class<?> type = val.getType();
                    cons.nest(new ResultShape(type, new FillStrategy.Assign(), type.isPrimitive()));
                }
                if (count == 1) {
                    resultClass = constructor;
                    resultShape = cons;
                }
                else
                    resultShape.nest(cons);
                projections.addAll(terms);
                projectionAliases.addAll(aliases);
                projectionClauses.addAll(clauses);

            } else {
                JPQLNode aliasNode = parent.children.length > 1 ? right(parent)
                        : null;
                Value proj = getValue(node);
                String alias = aliasNode != null ? aliasNode.text :
                    projectionClause(node.id == JJTSCALAREXPRESSION ?
                            firstChild(node) : node);
                if (aliasNode != null)
                    proj.setAlias(alias);
                projections.add(proj);
                projectionClauses.add(alias);
                projectionAliases.add(alias);
                Class<?> type = proj.getType();
                ResultShape<?> projShape = new ResultShape(type, new FillStrategy.Assign(), type.isPrimitive());

                if (count == 1)
                    resultShape = projShape;
                else
                    resultShape.nest(projShape);
View Full Code Here

        Class<?> resultClass = null;
        ResultShape<?> resultShape = null;
        if (count > 1) {
            // muti-selection
            resultClass = Object[].class;
            resultShape = new ResultShape(resultClass, new FillStrategy.Array<Object[]>(Object[].class));
        }

        for (int i = 0; i < count; i++) {
            JPQLNode parent = selectionsNode.getChild(i);
            JPQLNode node = firstChild(parent);
            if (node.id == JJTCONSTRUCTOR) {
                // build up the fully-qualified result class name by
                // appending together the components of the children
                String resultClassName = assemble(left(node));
                Class<?> constructor = resolver.classForName(resultClassName, null);
                if (constructor == null) {
                    // try resolve it again using simple name
                    int n = left(node).getChildCount();
                    String baseName = left(node).getChild(n-1).text;
                    constructor = resolver.classForName(baseName, null);
                }
                if (constructor == null)
                    throw parseException(EX_USER, "no-constructor",
                            new Object[]{ resultClassName }, null);

                List<Value> terms = new ArrayList<Value>();
                List<String> aliases = new ArrayList<String>();
                List<String> clauses = new ArrayList<String>();
                // now assign the arguments to the select clause as the projections
                assignProjections(right(node), exps, terms, aliases, clauses);
                FillStrategy fill = new FillStrategy.NewInstance(constructor);
                ResultShape<?> cons = new ResultShape(constructor, fill);
                for (Value val : terms) {
                    Class<?> type = val.getType();
                    cons.nest(new ResultShape(type, new FillStrategy.Assign(), type.isPrimitive()));
                }
                if (count == 1) {
                    resultClass = constructor;
                    resultShape = cons;
                }
                else
                    resultShape.nest(cons);
                projections.addAll(terms);
                projectionAliases.addAll(aliases);
                projectionClauses.addAll(clauses);

            } else {
                JPQLNode aliasNode = parent.children.length > 1 ? right(parent)
                        : null;
                Value proj = getValue(node);
                String alias = aliasNode != null ? aliasNode.text :
                    projectionClause(node.id == JJTSCALAREXPRESSION ?
                            firstChild(node) : node);
                if (aliasNode != null)
                    proj.setAlias(alias);
                projections.add(proj);
                projectionClauses.add(alias);
                projectionAliases.add(alias);
                Class<?> type = proj.getType();
                ResultShape<?> projShape = new ResultShape(type, new FillStrategy.Assign(), type.isPrimitive());

                if (count == 1)
                    resultShape = projShape;
                else
                    resultShape.nest(projShape);
View Full Code Here

TOP

Related Classes of org.apache.openjpa.kernel.ResultShape

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.