Package org.apache.openjpa.kernel.exps

Examples of org.apache.openjpa.kernel.exps.Value


     * @param val3 the length of the returned string as per JPQL semantics
     *
     */
    public static Value convertSubstringArguments(ExpressionFactory factory,
        Value val1, Value val2, Value val3) {
        Value start = null;
        Value end = null;
        if (val2 instanceof Literal &&
            (val3 == null || val3 instanceof Literal)) {
            // optimize SQL for the common case of two literals
            long jpqlStart = ((Number) ((Literal) val2).getValue())
                .longValue();
View Full Code Here


    private Value getNumberValue(JPQLNode node) {
        return getTypeValue(node, TYPE_NUMBER);
    }

    private Value getTypeValue(JPQLNode node, Class<?> implicitType) {
        Value val = getValue(node);
        setImplicitType(val, implicitType);
        return val;
    }
View Full Code Here

            return 1;
    }

    private Value getIdentifier(JPQLNode node) {
        final String name = node.text;
        final Value val = getVariable(name, false);

        ClassMetaData cmd = getMetaDataForAlias(name);

        if (cmd != null) {
            // handle the case where the class name is the alias
            // for the candidate (we don't use variables for this)
            Value thiz = null;
            if (ctx().subquery == null ||
                ctx().getSchema(name.toLowerCase()) == null) {
                if (ctx().subquery != null && inAssignSubselectProjection)
                    thiz = factory.newPath(ctx().subquery);
                else
                    thiz = factory.getThis();
            } else {
                thiz = factory.newPath(ctx().subquery);
            }
            ((Path)thiz).setSchemaAlias(name);
            thiz.setMetaData(cmd);
            return thiz;
        } else if (val instanceof Path) {
            return (Path) val;
        } else if (val instanceof Value) {
            if (val.isVariable()) {
                // can be an entity type literal
                Class<?> c = resolver.classForName(name, null);
                if (c != null) {
                    Value lit = factory.newTypeLiteral(c, Literal.TYPE_CLASS);
                    Class<?> candidate = getCandidateType();
                    ClassMetaData can = getClassMetaData(candidate.getName(),
                            false);
                    ClassMetaData meta = getClassMetaData(name, false);
                    if (candidate.isAssignableFrom(c))
                        lit.setMetaData(meta);
                    else
                        lit.setMetaData(can);
                    return lit;
                }
            }
            return (Value) val;
        }
View Full Code Here

    private Path validateMapPath(JPQLNode node, JPQLNode id) {
        Path path = (Path) getValue(id);
        FieldMetaData fld = path.last();

        if (fld == null && ctx().subquery != null) {
            Value var = getVariable(id.text, false);
            if (var != null) {
                path = factory.newPath(var);
                fld = path.last();
            }
        }
View Full Code Here

        Path path = validateMapPath(node, id);

        if (node.id == JJTVALUE)
            return path;

        Value value = getValue(id);
        if (node.id == JJTKEY)
            return factory.mapKey(path, value);
        else           
            return factory.mapEntry(path, value);
    }
View Full Code Here

    }

    private Value getTypeLiteral(JPQLNode node) {
        JPQLNode type = onlyChild(node);
        final String name = type.text;
        final Value val = getVariable(name, false);

        if (val instanceof Value && val.isVariable()) {
            Class<?> c = resolver.classForName(name, null);
            if (c != null) {
                Value typeLit = factory.newTypeLiteral(c, Literal.TYPE_CLASS);
                typeLit.setMetaData(getClassMetaData(name, false));
                return typeLit;
            }
        }

        throw parseException(EX_USER, "not-type-literal",
View Full Code Here

            // A single_valued_object_field is designated by the name of
            // an association field in a one-to-one or many-to-one relationship
            // or a field of embeddable class type.
            // The type of a single_valued_object_field is the abstract schema
            // type of the related entity or embeddable class
            Value path = getPath(node, false, true);
            return factory.type(path);
        }
    }
View Full Code Here

        // i.e., the path "SELECT x.id FROM SomeClass x where x.id > 10"
        // will need to have "x" in the alias map in order to resolve
        Path path = null;

        final String name = firstChild(node).text;
        final Value val = getVariable(name, false);

        // handle the case where the class name is the alias
        // for the candidate (we don't use variables for this)
        if (name.equalsIgnoreCase(ctx().schemaAlias)) {
            if (ctx().subquery != null) {
                path = factory.newPath(ctx().subquery);
                path.setMetaData(ctx().subquery.getMetaData());
            } else {
                path = factory.newPath();
                path.setMetaData(ctx().meta);
            }
        } else if (getMetaDataForAlias(name) != null)
            path = newPath(null, getMetaDataForAlias(name));
        else if (val instanceof Path)
            path = (Path) val;
        else if (val.getMetaData() != null)
            path = newPath(val, val.getMetaData());
        else
            throw parseException(EX_USER, "path-invalid",
                new Object[]{ assemble(node), name }, null);

        path.setSchemaAlias(name);
View Full Code Here

    /**
     * Returns a Value for the given node by eval'ing it.
     */
    private Value getValue(JPQLNode node, int handleVar) {
        Value val = (Value) eval(node);

        // determined how to evaluate a variable
        if (!val.isVariable())
            return val;
        else if (handleVar == VAR_PATH && !(val instanceof Path))
            return newPath(val, val.getMetaData());
        else if (handleVar == VAR_ERROR)
            throw parseException(EX_USER, "unexpected-var",
                new Object[]{ node.text }, null);
        else
            return val;
View Full Code Here

        ctx().addVariable(id, var);
    }

    protected Value getVariable(String var) {
        Context c = ctx();
        Value v = c.getVariable(var);
        if (v != null)
            return v;
        if (c.getParent() != null)
            return c.getParent().findVariable(var);
View Full Code Here

TOP

Related Classes of org.apache.openjpa.kernel.exps.Value

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.