Package org.apache.openjpa.jdbc.meta

Examples of org.apache.openjpa.jdbc.meta.ClassMapping


        throws SQLException {
        if (mapping.customLoad(sm, this, fetch, res))
            return eagerToMany;

        // load superclass data; base class loads version
        ClassMapping parent = mapping.getJoinablePCSuperclassMapping();
        if (parent != null)
            eagerToMany = load(parent, sm, fetch, res, eagerToMany);
        else if (sm.getVersion() == null)
            mapping.getVersion().load(sm, this, res);
View Full Code Here


     */
    private int selectBaseMappings(Select sel, ClassMapping mapping,
        ClassMapping orig, OpenJPAStateManager sm, BitSet fields,
        JDBCFetchConfiguration fetch, int eager, FieldMapping eagerToMany,
        boolean ident, boolean joined) {
        ClassMapping parent = mapping.getJoinablePCSuperclassMapping();
        if (parent == null && !mapping.isMapped())
            throw new InvalidStateException(_loc.get("virtual-mapping", mapping.
                getDescribedType()));

        int seld = -1;
        int pseld = -1;

        // base class selects pks, etc
        if (parent == null) {
            // if no instance, select pks
            if (sm == null) {
                if (ident)
                    sel.selectIdentifier(mapping.getPrimaryKeyColumns());
                else
                    sel.select(mapping.getPrimaryKeyColumns());
                seld = 1;
            }

            // if no instance or not initialized and not exact oid, select type
            if ((sm == null || (sm.getPCState() == PCState.TRANSIENT
                && (!(sm.getObjectId() instanceof OpenJPAId)
                || ((OpenJPAId) sm.getObjectId()).hasSubclasses())))
                && mapping.getDiscriminator().select(sel, orig))
                seld = 1;

            // if no instance or no version, select version
            if ((sm == null || sm.getVersion() == null)
                && mapping.getVersion().select(sel, orig))
                seld = 1;
        } else {
            // recurse on parent
            pseld = selectBaseMappings(sel, parent, orig, sm, fields,
                fetch, eager, eagerToMany, ident, joined);
        }

        // select the mappings in the given fields set, or based on fetch
        // configuration if no fields given
        FieldMapping[] fms = mapping.getDefinedFieldMappings();
        SelectExecutor esel;
        int fseld;
        for (int i = 0; i < fms.length; i++) {
            // skip eager to-many select; we do that separately in calling
            // method
            if (fms[i] == eagerToMany)
                continue;

            // check for eager select
            esel = sel.getEager(fms[i]);
            if (esel != null) {
                if (esel == sel)
                    fms[i].selectEagerJoin(sel, sm, this,
                      fetch.traverseJDBC(fms[i]), eager);
                else
                    fms[i].selectEagerParallel(esel, sm, this,
                      fetch.traverseJDBC(fms[i]), eager);
                seld = Math.max(0, seld);
            } else if (requiresSelect(fms[i], sm, fields, fetch)) {
                fseld = fms[i].select(sel, sm, this,
                  fetch.traverseJDBC(fms[i]), eager);
                seld = Math.max(fseld, seld);
            } else if (optSelect(fms[i], sel, sm, fetch)) {
                fseld = fms[i].select(sel, sm, this,
                  fetch.traverseJDBC(fms[i]), fetch.EAGER_NONE);

                // don't upgrade seld to > 0 based on these fields, since
                // they're not in the calculated field set
                if (fseld >= 0 && seld < 0)
                    seld = 0;
            }
        }

        // join to parent table if the parent / any ancestors have selected
        // anything
        if (!joined && pseld >= 0 && parent.getTable() != mapping.getTable())
            sel.where(mapping.joinSuperclass(sel.newJoins(), false));

        // return the highest value
        return Math.max(pseld, seld);
    }
View Full Code Here

        if (sub == base || sub.getTable() == base.getTable()
            || sel.isSelected(sub.getTable()))
            return null;

        // recurse first so we go least->most derived
        ClassMapping sup = sub.getJoinablePCSuperclassMapping();
        joins = joinSubclass(sel, base, sup, joins);
        if (joins == null)
            joins = sel.newJoins();
        return sub.joinSuperclass(joins, true);
    }
View Full Code Here

    /**
     * Throw the proper exception if the given handler-controlled value
     * represents an unjoinable relation.
     */
    public static void assertJoinable(ValueMapping vm) {
        ClassMapping rel = vm.getTypeMapping();
        if (rel != null && (rel.getTable() == null
            || !rel.getTable().equals(vm.getFieldMapping().getTable())))
            throw RelationStrategies.unjoinable(vm);
    }
View Full Code Here

    public void map(boolean adapt) {
        if (cls.getEmbeddingMetaData() != null)
            throw new MetaDataException(_loc.get("not-full", cls));

        ClassMapping sup = cls.getMappedPCSuperclassMapping();
        ClassMappingInfo info = cls.getMappingInfo();
        if (sup != null && info.isJoinedSubclass())
            throw new MetaDataException(_loc.get("not-full", cls));

        info.assertNoJoin(cls, true);
View Full Code Here

     */
    protected abstract Class getClass(Object val, JDBCStore store)
        throws ClassNotFoundException;

    public void map(boolean adapt) {
        ClassMapping cls = disc.getClassMapping();
        if (cls.getJoinablePCSuperclassMapping() != null
            || cls.getEmbeddingMetaData() != null)
            throw new MetaDataException(_loc.get("not-base-disc", cls));

        DiscriminatorMappingInfo info = disc.getMappingInfo();
        info.assertNoJoin(disc, true);
        info.assertNoForeignKey(disc, !adapt);
View Full Code Here

            if (i.hasNext())
                sql.append(", ");
        }

        if (augmentUpdates) {
            ClassMapping meta =
                ((FieldMapping) updateParams.keySet().iterator().next())
                    .getDeclaringMapping();
            Map updates = meta.getVersion().getBulkUpdateValues();
            for (Iterator iter = updates.entrySet().iterator();
                iter.hasNext(); ) {
                Map.Entry e = (Map.Entry) iter.next();
                Column col = (Column) e.getKey();
                String val = (String) e.getValue();
View Full Code Here

        JDBCStore store, JDBCFetchConfiguration fetch, Result res)
        throws SQLException {
        // do same joins as for load
        //### cheat: we know typical result joins only care about the relation
        //### path; thus we can ignore different mappings
        ClassMapping elem = getDefaultElementMapping(true);
        Joins dataJoins = res.newJoins().setVariable("*");
        dataJoins = join(dataJoins, elem);
        dataJoins = joinElementRelation(dataJoins, elem);
        Joins orderJoins = null;
        if (field.getOrderColumn() != null) {
            orderJoins = res.newJoins().setVariable("*");
            orderJoins = join(orderJoins, elem);
        }

        Map rels = new HashMap();
        ClassMapping ownerMapping = field.getDefiningMapping();
        Object nextOid, oid = null;
        Object coll = null;
        int seq = 0;
        while (res.next()) {
            // extract the owner id value
View Full Code Here

        Joins dataJoins = null;
        Joins refJoins = res.newJoins().setVariable("*");
        join(refJoins, false);

        ClassMapping ownerMapping = field.getDefiningMapping();
        Object ref = null;
        int seq = 0;
        int typeIdx = res.indexOf();
        for (int i = 0; true; i++) {
            // extract the owner id value
View Full Code Here

                StringBuffer sql = new StringBuffer();
                sql.append("MAX(").
                    append(sel.getColumnAlias(field.getOrderColumn())).
                    append(")");
                sel.select(sql.toString(), field);
                ClassMapping rel = getDefaultElementMapping(false);
                sel.whereForeignKey(getJoinForeignKey(rel),
                    sm.getObjectId(), field.getDefiningMapping(), store);

                Result res = sel.execute(store, fetch);
                try {
                    res.next();
                    coll.getChangeTracker().setNextSequence
                        (res.getInt(field) + 1);
                } finally {
                    res.close();
                }
            }
            sm.storeObjectField(field.getIndex(), coll);
            return;
        }

        // 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);
            }
        });
View Full Code Here

TOP

Related Classes of org.apache.openjpa.jdbc.meta.ClassMapping

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.