Package org.apache.openjpa.kernel.exps

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


    protected Value getDefinedVariable(String id) {
        return ctx().getVariable(id);
    }

    protected boolean isSeenVariable(String var) {
        Context c = ctx().findContext(var);
        if (c != null)
            return true;
        return false;
    }
View Full Code Here


    private Value getSubquery(JPQLNode node) {
        final boolean subclasses = true;

        // parse the subquery
        ParsedJPQL parsed = new ParsedJPQL(node.parser.jpql, node);
        Context subContext = new Context(parsed, null, ctx());
        contexts.push(subContext);

        ClassMetaData candidate = getCandidateMetaData(node);
        Subquery subq = subContext.getSubquery();
        if (subq == null) {
            subq = factory.newSubquery(candidate, subclasses, nextAlias());
            subContext.setSubquery(subq);
        }
        subq.setMetaData(candidate);
       
        // evaluate from clause for resolving variables defined in subquery
        JPQLNode from = node.getChild(1);
View Full Code Here

        return ctx().parsed.root;
    }

    private ClassMetaData getMetaDataForAlias(String alias) {
        for (int i = contexts.size() - 1; i >= 0; i--) {
            Context context =  contexts.get(i);
            if (alias.equalsIgnoreCase(context.schemaAlias))
                return context.meta;
        }

        return null;
View Full Code Here

    protected void addVariableToContext(String id, Value var) {
        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);

        return null;
    }
View Full Code Here

        if (lctx.cloneFrom == cloneFrom)
            return lctx;
        java.util.List<Context> subselCtxs = lctx.getSubselContexts();
        if (subselCtxs != null) {
            for (Context subselCtx : subselCtxs) {
                Context ctx = getThreadLocalContext(subselCtx, cloneFrom);
                if (ctx != null)
                    return ctx;
            }
        }
        return null;
View Full Code Here

        }
        return newCtx;
    }

    private static Context clone(Context orig, Context parent) {
        Context myParent = null;
        if (parent == null) {
            Context origParent = orig.getParent();
            if (origParent != null)
                myParent = clone(orig.getParent(), null);
        } else
            myParent = parent;

        Context newCtx = new Context(orig.parsed, null, myParent);
        newCtx.from = orig.from;
        newCtx.meta = orig.meta;
        newCtx.schemaAlias = orig.schemaAlias;
        newCtx.setSchemas(orig.getSchemas());
        newCtx.setVariables(orig.getVariables());
        newCtx.cloneFrom = orig;
        Object select = orig.getSelect();
        if (select != null)
            newCtx.setSelect(((SelectImpl)select).clone(newCtx));
        newCtx.subquery = orig.subquery;
        List<Context> subsels = orig.getSubselContexts();
        if (subsels != null) {
            for (Context subsel : subsels)
                newCtx.addSubselContext(clone(subsel, newCtx));
        }

        return newCtx;       
    }
View Full Code Here

        String alias = q.getAlias(this);
        ClassMetaData candidate = getCandidate();
        _subq = factory.newSubquery(candidate, subclasses, alias);
        _subq.setMetaData(candidate);
        Stack<Context> contexts = getContexts();
        Context context = new Context(null, _subq, contexts.peek());
        contexts.push(context);
        _delegate.setContexts(contexts);
        QueryExpressions subexp = exprBuilder.getQueryExpressions(factory, _delegate);
        _subq.setQueryExpressions(subexp);
        if (subexp.projections.length > 0)
View Full Code Here

     * Populate a kernel expression tree by translating the components of this
     * receiver with the help of the given {@link ExpressionFactory}.
     */
    QueryExpressions getQueryExpressions(ExpressionFactory factory) {
        _contexts = new Stack<Context>();
        Context context = new Context(null, null, null);
        _contexts.push(context);
        return new CriteriaExpressionBuilder().getQueryExpressions(factory, this);
    }   
View Full Code Here

    public void addToContext(ExpressionFactory factory, MetamodelImpl model, CriteriaQueryImpl<?> q) {
        String alias = q.getAlias(this);
        Value var = factory.newBoundVariable(alias, AbstractExpressionBuilder.TYPE_OBJECT);
        var.setMetaData(_entity.meta);
        Context currContext = q.ctx();
        currContext.addSchema(alias, _entity.meta);
        currContext.addVariable(alias, var);
        if (currContext.schemaAlias == null)
            currContext.schemaAlias = alias;
    }
View Full Code Here

        sel.setAutoDistinct((exps.distinct & exps.DISTINCT_AUTO) != 0);
        sel.setJoinSyntax(ctx.fetch.getJoinSyntax());
        sel.setParent(parent, alias);

        Context[] qryCtx = JDBCStoreQuery.getThreadLocalContext();
        Context lctx = null;
        for (int i = 0; i < qryCtx.length; i++) {
            if (qryCtx[i].cloneFrom == exps.ctx()) {
                lctx = qryCtx[i];
                break;
            }
        }

        if (sel.ctx() == null)
            sel.setContext(lctx);

        if (parent == null && lctx.getSubselContexts() != null) {
            // this is the case subselect was created before parent got created
            List<Context> subselCtxs = lctx.getSubselContexts();
            for (Context subselCtx : subselCtxs) {
                Select subsel = (Select) subselCtx.getSelect();
                Subquery subquery = subselCtx.getSubquery();
                subsel.setParent(sel, subquery.getCandidateAlias());
            }
View Full Code Here

TOP

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

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.