Package org.apache.openjpa.jdbc.meta

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


            + "where o.oplock = 0").getResultList();
        em.close();
    }

    public void testOplockFieldMapping() {
        ClassMapping cm = (ClassMapping) JPAFacadeHelper.getMetaData(
            emf, OptimisticLockInstance.class);
        FieldMapping fm = cm.getFieldMapping("oplock");
        assertEquals(1, fm.getColumns().length);
    }
View Full Code Here


    public void setUp() {
        setUp(NonstandardMappingEntity.class);
    }

    public void testPersistentMapMetaData() {
        ClassMapping cm = (ClassMapping) JPAFacadeHelper.getMetaData(emf,
            NonstandardMappingEntity.class);
        assertEquals("NONSTD_MAPPING_MAP",
            cm.getFieldMapping("map").getTable().getName());
    }
View Full Code Here

    }

    public boolean exists(OpenJPAStateManager sm, Object context) {
        // add where conditions on base class to avoid joins if subclass
        // doesn't use oid as identifier
        ClassMapping mapping = (ClassMapping) sm.getMetaData();
        return exists(mapping, sm.getObjectId(), context);
    }
View Full Code Here

            throw SQLExceptions.getStore(se, _dict);
        }
    }

    public boolean syncVersion(OpenJPAStateManager sm, Object context) {
        ClassMapping mapping = (ClassMapping) sm.getMetaData();
        try {
            return mapping.getVersion().checkVersion(sm, this, true);
        } catch (SQLException se) {
            throw SQLExceptions.getStore(se, _dict);
        }
    }
View Full Code Here

            throw SQLExceptions.getStore(se, _dict);
        }
    }

    public int compareVersion(OpenJPAStateManager state, Object v1, Object v2) {
        ClassMapping mapping = (ClassMapping) state.getMetaData();
        return mapping.getVersion().compareVersion(v1, v2);
    }
View Full Code Here

     */
    private boolean initializeState(OpenJPAStateManager sm, PCState state,
        JDBCFetchConfiguration fetch, ConnectionInfo info)
        throws ClassNotFoundException, SQLException {
        Object oid = sm.getObjectId();
        ClassMapping mapping = (ClassMapping) sm.getMetaData();
        Result res = null;
        try {
            if (info != null && info.result != null) {
                res = info.result;
                info.sm = sm;
                if (info.mapping == null)
                    info.mapping = mapping;
                mapping = info.mapping;
            } else if (oid instanceof OpenJPAId
                && !((OpenJPAId) oid).hasSubclasses()) {
                Boolean custom = customLoad(sm, mapping, state, fetch);
                if (custom != null)
                    return custom.booleanValue();
                res = getInitializeStateResult(sm, mapping, fetch,
                    Select.SUBS_EXACT);
                if (res == null && !selectPrimaryKey(sm, mapping, fetch))
                    return false;
                if (res != null && !res.next())
                    return false;
            } else {
                ClassMapping[] mappings = mapping.
                    getIndependentAssignableMappings();
                if (mappings.length == 1) {
                    mapping = mappings[0];
                    Boolean custom = customLoad(sm, mapping, state, fetch);
                    if (custom != null)
                        return custom.booleanValue();
                    res = getInitializeStateResult(sm, mapping, fetch,
                        Select.SUBS_ANY_JOINABLE);
                    if (res == null && !selectPrimaryKey(sm, mapping, fetch))
                        return false;
                } else
                    res = getInitializeStateUnionResult(sm, mapping, mappings,
                        fetch);
                if (res != null && !res.next())
                    return false;
            }

            // figure out what type of object this is; the state manager
            // only guarantees to provide a base class
            Class type;
            if (res == null)
                type = mapping.getDescribedType();
            else {
                if (res.getBaseMapping() != null)
                    mapping = res.getBaseMapping();
                res.startDataRequest(mapping.getDiscriminator());
                try {
                    type = mapping.getDiscriminator().getClass(this, mapping,
                        res);
                } finally {
                    res.endDataRequest();
                }
            }

            // initialize the state manager; this may change the mapping
            // and the object id instance if the type as determined
            // from the indicator is a subclass of expected type
            sm.initialize(type, state);

            // load the selected mappings into the given state manager
            if (res != null) {
                // re-get the mapping in case the instance was a subclass
                mapping = (ClassMapping) sm.getMetaData();
                load(mapping, sm, fetch, res);
                mapping.getVersion().afterLoad(sm, this);
            }
            return true;
        } finally {
            if (res != null && (info == null || res != info.result))
                res.close();
View Full Code Here

    private boolean selectPrimaryKey(OpenJPAStateManager sm,
        ClassMapping mapping, JDBCFetchConfiguration fetch)
        throws SQLException {
        // select pks from base class record to ensure it exists and lock
        // it if needed
        ClassMapping base = mapping;
        while (base.getJoinablePCSuperclassMapping() != null)
            base = base.getJoinablePCSuperclassMapping();

        Select sel = _sql.newSelect();
        sel.select(base.getPrimaryKeyColumns());
        sel.wherePrimaryKey(sm.getObjectId(), base, this);
        Result exists = sel.execute(this, fetch);
        try {
            if (!exists.next())
                return false;
View Full Code Here

                res = info.result;
            info.sm = null;
        }
        try {
            // if there's an existing result, load all we can from it
            ClassMapping mapping = (ClassMapping) sm.getMetaData();
            if (res != null) {
                load(mapping, sm, jfetch, res);
                removeLoadedFields(sm, fields);
            }

            // if the instance is hollow and there's a customized
            // get by id method, use it
            if (sm.getLoaded().length() == 0
                && mapping.customLoad(sm, this, null, jfetch))
                removeLoadedFields(sm, fields);

            //### select is kind of a big object, and in some cases we don't
            //### use it... would it be worth it to have a small shell select
            //### object that only creates a real select when actually used?

            Select sel = _sql.newSelect();
            if (select(sel, mapping, Select.SUBS_EXACT, sm, fields, jfetch,
                EagerFetchModes.EAGER_JOIN, true, false)) {
                sel.wherePrimaryKey(sm.getObjectId(), mapping, this);
                res = sel.execute(this, jfetch, lockLevel);
                try {
                    if (!res.next())
                        return false;
                    load(mapping, sm, jfetch, res);
                } finally {
                    res.close();
                }
            }

            // now allow the fields to load themselves individually too
            FieldMapping[] fms = mapping.getFieldMappings();
            for (int i = 0; i < fms.length; i++)
                if (fields.get(i) && !sm.getLoaded().get(i))
                    fms[i].load(sm, this, jfetch.traverseJDBC(fms[i]));
            mapping.getVersion().afterLoad(sm, this);
            return true;
        } catch (ClassNotFoundException cnfe) {
            throw new StoreException(cnfe);
        } catch (SQLException se) {
            throw SQLExceptions.getStore(se, _dict);
View Full Code Here

        return new Id(mapping.getDescribedType(), id, subs);
    }

    public ResultObjectProvider executeExtent(ClassMetaData meta,
        final boolean subclasses, FetchConfiguration fetch) {
        ClassMapping mapping = (ClassMapping) meta;
        final ClassMapping[] mappings;
        if (subclasses)
            mappings = mapping.getIndependentAssignableMappings();
        else
            mappings = new ClassMapping[] { mapping };

        ResultObjectProvider[] rops = null;
        final JDBCFetchConfiguration jfetch = (JDBCFetchConfiguration) fetch;
View Full Code Here

        if (!mapping.isMapped())
            throw new InvalidStateException(_loc.get("virtual-mapping",
                mapping));

        // get the object id for the row; base class selects pk columns
        ClassMapping base = mapping;
        while (base.getJoinablePCSuperclassMapping() != null)
            base = base.getJoinablePCSuperclassMapping();
        Object oid = base.getObjectId(this, result, null, true, null);
        if (oid == null)
            return null;

        ConnectionInfo info = new ConnectionInfo();
        info.result = result;
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.