Package org.apache.openjpa.kernel

Examples of org.apache.openjpa.kernel.OpenJPAStateManager


        return !_broker.isCloseInvoked();
    }

    public void dirty(Object o, String field) {
        assertNotCloseInvoked();
        OpenJPAStateManager sm = _broker.getStateManager(o);
        try {
            if (sm != null)
                sm.dirty(field);
        } catch (Exception e) {
            throw PersistenceExceptions.toPersistenceException(e);
        }
    }
View Full Code Here


    /**
     * Throw IllegalArgumentExceptionif if entity is not a valid entity or
     * if it is detached.
     */
    void assertValidAttchedEntity(String call, Object entity) {
        OpenJPAStateManager sm = _broker.getStateManager(entity);
        if (sm == null || !sm.isPersistent() || sm.isDetached() || (call.equals(REFRESH) && sm.isDeleted())) {
            throw new IllegalArgumentException(_loc.get("invalid_entity_argument",
                call, entity == null ? "null" : Exceptions.toString(entity)).getMessage());
        }
    }
View Full Code Here

                        itr.hasNext();) {
                        PersistenceCapable pc = (PersistenceCapable) itr.next();
                        if (pc == null) {
                            continue;
                        }
                        OpenJPAStateManager sm = (OpenJPAStateManager) pc.pcGetStateManager();
                        ClassMapping cm =
                            (ClassMapping) _conf.getMetaDataRepositoryInstance().getCachedMetaData(pc.getClass());
                        FieldMapping[] fmd = cm.getFieldMappings();
                        for (int j = 0; j < fmd.length; j++) {
                            // don't check the oids for basic fields.
                            if (fmd[j].isTypePC()) {
                                Object oid = sm.getIntermediate(fmd[j].getIndex());
                                // if oid was setIntermediate() previously and it is the same as the owner,generate
                                // then set the inverse relation
                                if (oid != null && oid.equals(owner.getObjectId())) {
                                    sm.storeObject(fmd[j].getIndex(), owner.getPersistenceCapable());
                                    break;
                                }
                            }
                        }
                    }
View Full Code Here

        } else if (proxy.getOwner() == null) {
            // no StateManager (DetachedStateField==false), so no $proxy to remove
            return proxy;
        } else {
            // using a StateManager, so determine what DetachedState is being used
            OpenJPAStateManager sm = proxy.getOwner()// null checked for above
            ClassMetaData meta = null;          // if null, no proxies?
            boolean useDSFForUnproxy = false;   // default to false for old 1.0 behavior

            // Don't rely on sm.isDetached() method because if we are serializing an attached Entity
            // the sm will still be a StateManagerImpl, but isDetached() will return true.

            // Using a DetachedStateManager, so use the new flag since there is no context or
            // metadata
            if (sm instanceof DetachedStateManager) {
                useDSFForUnproxy = ((DetachedStateManager) sm).getUseDSFForUnproxy();
            } else{
                // DetachedStateManager has no context or metadata, so we can't get configuration settings
                Compatibility compat = null;
                meta = sm.getMetaData();
                if (meta != null) {
                    compat = meta.getRepository().getConfiguration().getCompatibilityInstance();
                } else if (sm.getContext() != null && sm.getContext().getConfiguration() != null) {
                    compat = sm.getContext().getConfiguration().getCompatibilityInstance();
                } else {
                    // no-op - using a StateManager, but no Compatibility settings available
                }
                if (compat != null) {
                    // new 2.0 behavior of using DetachedStateField to determine unproxy during serialization
View Full Code Here

        boolean ret;
        FieldMetaData[] pks = meta.getPrimaryKeyFields();
        if (meta.isOpenJPAIdentity()
            && pks[0].getDeclaredTypeCode() == JavaTypes.OID) {
            OpenJPAStateManager oidsm = new ObjectIdStateManager
                (sm.fetchObjectField(pks[0].getIndex()), sm, pks[0]);
            ret = assign(oidsm, store, pks[0].getEmbeddedMetaData().
                getFields(), preFlush);
            sm.storeObjectField(pks[0].getIndex(),
                oidsm.getManagedInstance());
        } else
            ret = assign(sm, store, meta.getPrimaryKeyFields(), preFlush);
        if (!ret)
            return false;
View Full Code Here

            }

            // update pcdatas for updates
            if (_updates != null) {
                BitSet fields;
                OpenJPAStateManager sm;
                for (Map.Entry<OpenJPAStateManager, BitSet> entry : _updates.entrySet()) {
                    sm = entry.getKey();
                    fields = entry.getValue();

                    cache = _mgr.selectCache(sm);
                    if (cache == null) {
                        continue;
                    }

                    // it's ok not to clone the object that we get from the cache,
                    // since we're inside the commit() method, so any modifications
                    // to the underlying cache are valid. If the commit had not
                    // already succeeded, then we'd want to clone the retrieved
                    // object.
                    data = cache.get(sm.getObjectId());
                    mods = getModifications(modMap, cache);

                    // data should always be non-null, since the object is
                    // dirty, but maybe it got dropped from the cache in the
                    // interim
                    if (data == null) {
                        data = newPCData(sm);
                        data.store(sm);
                        mods.newUpdates.add(new PCDataHolder(data, sm));
                    } else {
                        data.store(sm, fields);
                        mods.existingUpdates.add(new PCDataHolder(data, sm));
                    }
                    CacheStatistics stats = cache.getStatistics();
                    if (stats.isEnabled()) {
                        ((CacheStatisticsSPI)stats).newPut(data.getType());
                    }
                }
            }

            // remove pcdatas for deletes
            if (_deletes != null) {
                for (OpenJPAStateManager sm : _deletes) {
                    cache = _mgr.selectCache(sm);
                    if (cache == null)
                        continue;

                    mods = getModifications(modMap, cache);
                    mods.deletes.add(sm.getObjectId());
                }
            }

            // notify the caches of the changes
            if (modMap != null) {
View Full Code Here

        // for each loaded instance, merge loaded state into cached data

        boolean isNew;

        for(Map.Entry<OpenJPAStateManager, BitSet> entry : unloaded.entrySet()) {
            OpenJPAStateManager sm = entry.getKey();
            fields = entry.getValue();

            cache = _mgr.selectCache(sm);
            if (cache == null || sm.isEmbedded() || (failed != null
                && failed.contains(sm.getId())))
                continue;

            // make sure that we're not trying to cache an old version
            cache.writeLock();
            try {
                data = cache.get(sm.getObjectId());
                if (data != null && compareVersion(sm, sm.getVersion(),
                    data.getVersion()) == VERSION_EARLIER)
                    continue;

                isNew = data == null;
                if (isNew)
View Full Code Here

     * somewhat tolerant of such behavior, in that the cache will be cleaned
     * up as failures occur.
     */
    private void notifyOptimisticLockFailure(OptimisticException e) {
        Object o = e.getFailedObject();
        OpenJPAStateManager sm = _ctx.getStateManager(o);
        if (sm == null)
            return;
        Object oid = sm.getId();
        boolean remove;

        // this logic could be more efficient -- we could aggregate
        // all the cache->oid changes, and then use DataCache.removeAll()
        // and less write locks to do the mutation.
        DataCache cache = _mgr.selectCache(sm);
        if (cache == null)
            return;

        cache.writeLock();
        try {
            DataCachePCData data = cache.get(oid);
            if (data == null)
                return;

            switch (compareVersion(sm, sm.getVersion(), data.getVersion())) {
                case StoreManager.VERSION_LATER:
                case StoreManager.VERSION_SAME:
                    // This tx's current version is later than or the same as
                    // the data cache version. In this case, the commit should
                    // have succeeded from the standpoint of the cache. Remove
                    // the instance from cache in the hopes that the cache is
                    // out of sync.
                    remove = true;
                    break;
                case StoreManager.VERSION_EARLIER:
                    // This tx's current version is earlier than the data
                    // cache version. This is a normal optimistic lock failure.
                    // Do not clean up the cache; it probably already has the
                    // right values, and if not, it'll get cleaned up by a tx
                    // that fails in one of the other case statements.
                    remove = false;
                    break;
                case StoreManager.VERSION_DIFFERENT:
                    // The version strategy for the failed object does not
                    // store enough information to optimize for expected
                    // failures. Clean up the cache.
                    remove = true;
                    break;
                default:
                    // Unexpected return value. Remove to be future-proof.
                    remove = true;
                    break;
            }
            if (remove)
                // remove directly instead of via the RemoteCommitListener
                // since we have a write lock here already, so this is more
                // efficient than read-locking and then write-locking later.
                cache.remove(sm.getId());
        } finally {
            cache.writeUnlock();
        }

        // fire off a remote commit stalenesss detection event.
View Full Code Here

     * with the given oid.
     */
    private void updateInverse(StoreContext ctx, Object inverse,
        ClassMapping rel, RowManager rm, OpenJPAStateManager sm, int idx)
        throws SQLException {
        OpenJPAStateManager invsm = RelationStrategies.getStateManager(inverse,
            ctx);
        if (invsm == null)
            return;

        ValueMapping elem = field.getElementMapping();
        ForeignKey fk = elem.getForeignKey();
        ColumnIO io = elem.getColumnIO();
        Column order = field.getOrderColumn();

        int action;
        boolean writeable;
        boolean orderWriteable;
        if (invsm.isNew() && !invsm.isFlushed()) {
            // no need to null inverse columns of new instance
            if (sm == null || sm.isDeleted())
                return;
            writeable = io.isAnyInsertable(fk, false);
            orderWriteable = _orderInsert;
            action = Row.ACTION_INSERT;
        } else if (invsm.isDeleted()) {
            // no need to null inverse columns of deleted instance
            if (invsm.isFlushed() || sm == null || !sm.isDeleted())
                return;
            writeable = true;
            orderWriteable = false;
            action = Row.ACTION_DELETE;
        } else {
View Full Code Here

    public void insert(OpenJPAStateManager sm, JDBCStore store, RowManager rm)
        throws SQLException {
        if (field.getMappedBy() != null)
            return;

        OpenJPAStateManager rel = RelationStrategies.getStateManager
            (sm.fetchObjectField(field.getIndex()), store.getContext());
        if (field.getJoinDirection() == field.JOIN_INVERSE)
            updateInverse(sm, rel, store, rm);
        else {
            Row row = field.getRow(sm, store, rm, Row.ACTION_INSERT);
View Full Code Here

TOP

Related Classes of org.apache.openjpa.kernel.OpenJPAStateManager

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.