Examples of Union


Examples of org.apache.openjpa.jdbc.sql.Union

        final JDBCFetchConfiguration fetch, final int eagerMode) {
        final ClassMapping[] clss = field.getIndependentTypeMappings();
        if (!(sel instanceof Union))
            selectEagerParallel((Select) sel, clss[0], store, fetch, eagerMode);
        else {
            Union union = (Union) sel;
            if (fetch.getSubclassFetchMode (field.getTypeMapping())
                != JDBCFetchConfiguration.EAGER_JOIN)
                union.abortUnion();
            union.select(new Union.Selector() {
                public void select(Select sel, int idx) {
                    selectEagerParallel(sel, clss[idx], store, fetch,
                        eagerMode);
                }
            });
View Full Code Here

Examples of org.apache.openjpa.jdbc.sql.Union

        final Joins[] resJoins = new Joins[rels.length];

        // select related mapping columns; joining from the related type
        // back to our fk table if not an inverse mapping (in which case we
        // can just make sure the inverse cols == our pk values)
        Union union = store.getSQLFactory().newUnion(rels.length);
        union.setExpectedResultCount(1, false);
        if (fetch.getSubclassFetchMode(field.getTypeMapping())
            != JDBCFetchConfiguration.EAGER_JOIN)
            union.abortUnion();
        union.select(new Union.Selector() {
            public void select(Select sel, int idx) {
                if (field.getJoinDirection() == field.JOIN_INVERSE)
                    sel.whereForeignKey(field.getForeignKey(rels[idx]),
                        sm.getObjectId(), field.getDefiningMapping(), store);
                else {
                    resJoins[idx] = sel.newJoins().joinRelation(field.getName(),
                        field.getForeignKey(rels[idx]), rels[idx],
                        field.getSelectSubclasses(), false, false);
                    field.wherePrimaryKey(sel, sm, store);
                }
                sel.select(rels[idx], subs, store, fetch, fetch.EAGER_JOIN,
                    resJoins[idx]);
            }
        });

        Result res = union.execute(store, fetch);
        try {
            Object val = null;
            if (res.next())
                val = res.load(rels[res.indexOf()], store, fetch,
                    resJoins[res.indexOf()]);
View Full Code Here

Examples of org.apache.openjpa.jdbc.sql.Union

        if (!(sel instanceof Union))
            selectEager((Select) sel, getDefaultElementMapping(true), sm,
                store, fetch, eagerMode, true, false);
        else {
            final ClassMapping[] elems = getIndependentElementMappings(true);
            Union union = (Union) sel;
            if (fetch.getSubclassFetchMode(field.getElementMapping().
                getTypeMapping()) != fetch.EAGER_JOIN)
                union.abortUnion();
            union.select(new Union.Selector() {
                public void select(Select sel, int idx) {
                    selectEager(sel, elems[idx], sm, store, fetch, eagerMode,
                        true, false);
                }
            });
View Full Code Here

Examples of org.apache.openjpa.jdbc.sql.Union

        }

        // select data for this sm
        final ClassMapping[] elems = getIndependentElementMappings(true);
        final Joins[] resJoins = new Joins[Math.max(1, elems.length)];
        Union union = store.getSQLFactory().newUnion
            (Math.max(1, elems.length));
        union.select(new Union.Selector() {
            public void select(Select sel, int idx) {
                ClassMapping elem = (elems.length == 0) ? null : elems[idx];
                resJoins[idx] = selectAll(sel, elem, sm, store, fetch,
                    JDBCFetchConfiguration.EAGER_PARALLEL);
            }
        });

        // create proxy
        ChangeTracker ct = null;
        if (delayed) {
            if (sm.isDetached() || sm.getOwner() == null) {
                sm.getPersistenceCapable().pcProvideField(fieldIndex);
                coll =
                    ((FieldManager)sm.getPersistenceCapable().pcGetStateManager()).fetchObjectField(fieldIndex);
            } else {
                coll = sm.fetchObjectField(fieldIndex);
            }
            if (coll instanceof Proxy)
                ct = ((Proxy) coll).getChangeTracker();
        } else {
            if (field.getTypeCode() == JavaTypes.ARRAY)
                coll = new ArrayList();
            else {
                if (coll == null) {
                    coll = sm.newProxy(fieldIndex);
                }
                if (coll instanceof Proxy)
                    ct = ((Proxy) coll).getChangeTracker();
            }
        }

        // load values
        Result res = union.execute(store, fetch);
        try {
            int seq = -1;
            while (res.next()) {
                if (ct != null && field.getOrderColumn() != null)
                    seq = res.getInt(field.getOrderColumn());
View Full Code Here

Examples of org.apache.openjpa.jdbc.sql.Union

            return fq.execute(sm, this, fetch);
        final JDBCStoreManager store = this;
        final int eager = Math.min(fetch.getEagerFetchMode(),
            JDBCFetchConfiguration.EAGER_JOIN);

        Union union = _sql.newUnion(mappings.length);
        union.setExpectedResultCount(1, false);
        if (fetch.getSubclassFetchMode(mapping) != EagerFetchModes.EAGER_JOIN)
            union.abortUnion();
        union.select(new Union.Selector() {
            public void select(Select sel, int i) {
                sel.select(mappings[i], Select.SUBS_ANY_JOINABLE, store, fetch,
                    eager);
                sel.wherePrimaryKey(sm.getObjectId(), mappings[i], store);
            }
        });
        Result result = union.execute(this, fetch);
        cacheFinder(mapping, union, fetch);
        return result;
    }
View Full Code Here

Examples of org.apache.openjpa.jdbc.sql.Union

                    return rops[0];
                return new MergedResultObjectProvider(rops);
            }

            // perform a union on all independent classes
            Union union = _sql.newUnion(mappings.length);
            union.setLRS(true);
            final BitSet[] paged = new BitSet[mappings.length];
            union.select(new Union.Selector() {
                public void select(Select sel, int idx) {
                    paged[idx] = selectExtent(sel, mappings[idx], jfetch,
                        subclasses);
                }
            });
View Full Code Here

Examples of org.apache.openjpa.jdbc.sql.Union

        final JDBCFetchConfiguration fetch, final int eagerMode) {
        final ClassMapping[] clss = field.getIndependentTypeMappings();
        if (!(sel instanceof Union))
            selectEagerParallel((Select) sel, clss[0], store, fetch, eagerMode);
        else {
            Union union = (Union) sel;
            if (fetch.getSubclassFetchMode (field.getTypeMapping())
                != JDBCFetchConfiguration.EAGER_JOIN)
                union.abortUnion();
            union.select(new Union.Selector() {
                public void select(Select sel, int idx) {
                    selectEagerParallel(sel, clss[idx], store, fetch,
                        eagerMode);
                }
            });
View Full Code Here

Examples of org.apache.openjpa.jdbc.sql.Union

        final int subs = field.getSelectSubclasses();
        final Joins[] resJoins = new Joins[rels.length];

        //cache union for field here
        //select data for this sm
        Union union = null;
        SelectImpl sel = null;
        List parmList = null;

        if (!((JDBCStoreManager)store).isQuerySQLCacheOn())
            union = newUnion(sm, store, fetch, rels, subs, resJoins);
        else {
            if (relationFieldUnionCache == null) {
                relationFieldUnionCache =
                    ((JDBCStoreManager) store)
                        .getCacheMapFromQuerySQLCache(RelationFieldStrategy.class);
            }
            boolean found = true;
            JDBCFetchConfiguration fetchClone = new JDBCFetchConfigurationImpl();
            fetchClone.copy(fetch);
            JDBCStoreManager.SelectKey selKey =
                new JDBCStoreManager.SelectKey(null, field, fetch);
            Object[] obj = relationFieldUnionCache.get(selKey);
            if (obj != null) {
                union = (Union) obj[0];
                resJoins[0] = (Joins)obj[1];
            } else {
                synchronized(relationFieldUnionCache) {
                    obj = relationFieldUnionCache.get(selKey);
                    if (obj != null) {
                        union = (Union) obj[0];
                        resJoins[0] = (Joins) obj[1];
                    } else {
                        // select related mapping columns; joining from the
                        // related type back to our fk table if not an inverse
                        // mapping (in which case we can just make sure the
                        // inverse cols == our pk values)
                        union = newUnion(sm, store, fetch, rels, subs,
                                resJoins);
                        found = false;               
                    }
                    sel = ((LogicalUnion.UnionSelect)union.getSelects()[0]).
                        getDelegate();
                    SQLBuffer buf = sel.getSQL();
                    if (buf == null) {
                      ((SelectImpl)sel).setSQL(store, fetch);
                        found = false;
                    }

                    // only cache the union when elems length is 1 for now
                    if (!found && rels.length == 1) {
                        Object[] obj1 = new Object[2];
                        obj1[0] = union;
                        obj1[1] = resJoins[0];
                        ((JDBCStoreManager)store).addToSqlCache(
                            relationFieldUnionCache, selKey, obj1);
                    }
                }
            }
            Log log = store.getConfiguration().
                getLog(JDBCConfiguration.LOG_JDBC);
            if (log.isTraceEnabled()){
                if (found)
                    log.trace(_loc.get("cache-hit", field, this.getClass()));                       
                else
                    log.trace(_loc.get("cache-missed", field, this.getClass()));
            }

            parmList = new ArrayList();
            ClassMapping mapping = field.getDefiningMapping();
            Object oid = sm.getObjectId();
            Column[] cols = mapping.getPrimaryKeyColumns();
            if (sel == null)
                sel = ((LogicalUnion.UnionSelect)union.getSelects()[0]).
                getDelegate();

            sel.wherePrimaryKey(mapping, cols, cols, oid, store,
              null, null, parmList);
        }
       
        Result res = union.execute(store, fetch, parmList);
        try {
            Object val = null;
            if (res.next())
                val = res.load(rels[res.indexOf()], store, fetch,
                    resJoins[res.indexOf()]);
View Full Code Here

Examples of org.apache.openjpa.jdbc.sql.Union

   
    protected Union newUnion(final OpenJPAStateManager sm,
        final JDBCStore store, final JDBCFetchConfiguration fetch,
        final ClassMapping[] rels, final int subs,
        final Joins[] resJoins) {
        Union union = store.getSQLFactory().newUnion(rels.length);
        union.setExpectedResultCount(1, false);
        if (fetch.getSubclassFetchMode(field.getTypeMapping())
            != JDBCFetchConfiguration.EAGER_JOIN)
            union.abortUnion();
        union.select(new Union.Selector() {
            public void select(Select sel, int idx) {
                if (field.getJoinDirection() == field.JOIN_INVERSE)
                    sel.whereForeignKey(field.getForeignKey(rels[idx]),
                        sm.getObjectId(), field.getDefiningMapping(), store);
                else {
View Full Code Here

Examples of org.apache.openjpa.jdbc.sql.Union

        final JDBCFetchConfiguration fetch) throws SQLException {
        final JDBCStoreManager store = this;
        final int eager = Math.min(fetch.getEagerFetchMode(),
            JDBCFetchConfiguration.EAGER_JOIN);

        Union union = _sql.newUnion(mappings.length);
        union.setExpectedResultCount(1, false);
        if (fetch.getSubclassFetchMode(mapping) != fetch.EAGER_JOIN)
            union.abortUnion();
        union.select(new Union.Selector() {
            public void select(Select sel, int i) {
                sel.select(mappings[i], Select.SUBS_ANY_JOINABLE, store, fetch,
                    eager);
                sel.wherePrimaryKey(sm.getObjectId(), mappings[i], store);
            }
        });
        return union.execute(this, fetch);
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.