Package org.apache.openjpa.jdbc.meta

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


        JDBCStore store, JDBCFetchConfiguration fetch, int eagerMode) {
        // limit the eager mode to single on recursive eager fetching b/c
        // at this point the select has been modified and an attempt to
        // clone it for a to-many eager select can result in a clone that
        // produces invalid SQL
        ClassMapping cls = field.getIndependentTypeMappings()[0];
        sel.select(cls, field.getSelectSubclasses(), store, fetch,
            JDBCFetchConfiguration.EAGER_JOIN,
            eagerJoin(sel.newJoins(), cls, false));
    }
View Full Code Here


        ClassMapping[] clss = field.getIndependentTypeMappings();
        Joins joins = res.newJoins().setVariable("*");
        eagerJoin(joins, clss[0], true);

        Map rels = new HashMap();
        ClassMapping owner = field.getDefiningMapping();
        ClassMapping cls;
        Object oid;
        while (res.next()) {
            cls = res.getBaseMapping();
            if (cls == null)
                cls = clss[0];
View Full Code Here

    }

    public void loadEagerJoin(OpenJPAStateManager sm, JDBCStore store,
        JDBCFetchConfiguration fetch, Result res)
        throws SQLException {
        ClassMapping cls = field.getIndependentTypeMappings()[0];
        sm.storeObject(field.getIndex(), res.load(cls, store, fetch,
            eagerJoin(res.newJoins(), cls, false)));
    }
View Full Code Here

            return;
        if (!res.containsAll(field.getColumns()))
            return;

        // get the related object's oid
        ClassMapping relMapping = field.getTypeMapping();
        Object oid = null;
        if (relMapping.isMapped()) {
            oid = relMapping.getObjectId(store, res, field.getForeignKey(),
                field.getPolymorphic() != ValueMapping.POLY_FALSE, null);
        } else {
            Column[] cols = field.getColumns();
            if (relMapping.getIdentityType() == ClassMapping.ID_DATASTORE) {
                long id = res.getLong(cols[0]);
                if (!res.wasNull())
                    oid = store.newDataStoreId(id, relMapping, true);
            } else {
                // application id
View Full Code Here

    }

    public Object getPrimaryKeyValue(Result res, Column[] cols, ForeignKey fk,
        JDBCStore store, Joins joins)
        throws SQLException {
        ClassMapping relmapping = field.getTypeMapping();
        if (relmapping.getIdentityType() == ClassMapping.ID_DATASTORE) {
            Column col = cols[0];
            if (fk != null)
                col = fk.getColumn(col);  
            long id = res.getLong(col, joins);
            if (field.getObjectIdFieldTypeCode() == JavaTypes.LONG)
                return Numbers.valueOf(id);
            return store.newDataStoreId(id, relmapping, field.getPolymorphic()
                != ValueMapping.POLY_FALSE);
        }

        if (relmapping.isOpenJPAIdentity())
            return ((Joinable) relmapping.getPrimaryKeyFieldMappings()[0].
                getStrategy()).getPrimaryKeyValue(res, cols, fk, store, joins);

        if (cols == getColumns() && fk == null)
            fk = field.getForeignKey();
        else
            fk = createTranslatingForeignKey(relmapping, cols, fk);
        return relmapping.getObjectId(store, res, fk,
            field.getPolymorphic() != ValueMapping.POLY_FALSE, joins);
    }
View Full Code Here

            return o;
        col = field.getForeignKey().getPrimaryKeyColumn(col);
        if (col == null)
            throw new InternalException();

        ClassMapping relmapping = field.getTypeMapping();
        Joinable j = field.getTypeMapping().assertJoinable(col);
        if (ImplHelper.isManageable(fieldVal))
            fieldVal = store.getContext().getObjectId(fieldVal);
        if (fieldVal instanceof OpenJPAId)
            fieldVal = ((OpenJPAId) fieldVal).getIdObject();
        else if (relmapping.getObjectIdType() != null
            && relmapping.getObjectIdType().isInstance(fieldVal)) {
            Object[] pks = ApplicationIds.toPKValues(fieldVal, relmapping);
            fieldVal = pks[relmapping.getField(j.getFieldIndex()).
                getPrimaryKeyIndex()];
        }
        return j.getJoinValue(fieldVal, col, store);
    }
View Full Code Here

    }

    public void loadEmbedded(OpenJPAStateManager sm, JDBCStore store,
        JDBCFetchConfiguration fetch, Object val)
        throws SQLException {
        ClassMapping relMapping = field.getTypeMapping();
        Object oid;
        if (val == null)
            oid = null;
        else if (relMapping.getIdentityType() == ClassMapping.ID_DATASTORE)
            oid = store.newDataStoreId(((Number) val).longValue(), relMapping,
                field.getPolymorphic() != ValueMapping.POLY_FALSE);
        else {
            Object[] pks = (getColumns().length == 1) ? new Object[]{ val }
                : (Object[]) val;
            boolean nulls = true;
            for (int i = 0; nulls && i < pks.length; i++)
                nulls = pks[i] == null;
            if (nulls)
                oid = null;
            else {
                oid = ApplicationIds.fromPKValues(pks, relMapping);
                if (field.getPolymorphic() == ValueMapping.POLY_FALSE
                    && oid instanceof OpenJPAId) {
                    ((OpenJPAId) oid).setManagedInstanceType(relMapping.
                        getDescribedType());
                }
            }
        }
View Full Code Here

            return Boolean.TRUE;
        return Boolean.FALSE;
    }

    public Object toDataStoreValue(Object val, JDBCStore store) {
        ClassMapping type = field.getTypeMapping();
        return type.toDataStoreValue(val, type.getPrimaryKeyColumns(), store);
    }
View Full Code Here

        return ((Comparable) v1).compareTo(v2);
    }

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

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

            return;
        }
        if (set && !canSetAny(io, fromCols.length, false))
            return;

        ClassMapping toMapping = (ClassMapping) to.getMetaData();
        Joinable join;
        Object val;
        for (int i = 0; i < toCols.length; i++) {
            // don't even translate join value if unsettable
            if (set) {
                if (_action == ACTION_INSERT && fromCols[i].isAutoAssigned())
                    continue;
                if (!canSet(io, i, false))
                    continue;
            }

            join = toMapping.assertJoinable(toCols[i]);
            val = join.getJoinValue(to, toCols[i], (JDBCStore) to.
                getContext().getStoreManager().getInnermostDelegate());
            if (set && val == null) {
                if (canSet(io, i, true))
                    setNull(fromCols[i]);
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.