Examples of PersistenceCapable


Examples of org.apache.openjpa.enhance.PersistenceCapable

                return;
            if (!mappedByIdFields.contains(this))
                return;
            if (!isMappedById())
                return;
            PersistenceCapable pc = (PersistenceCapable)sm.
                fetchObject(getIndex());
            if (pc == null)
                return;
            StateManagerImpl pkSm = (StateManagerImpl)pc.
                pcGetStateManager();
            Object pkVal = getPKValue(pkSm);
            if (pkVal == null)
                return;
            setPKValue((StateManagerImpl)sm, pkVal);
View Full Code Here

Examples of org.apache.openjpa.enhance.PersistenceCapable

     *            The new state of the underlying persistence capable object.
     */
    public StateManagerImpl(StateManagerImpl sm, PCState newState) {
        this(sm.getId(), sm.getMetaData(), sm.getBroker());

        PersistenceCapable origPC = sm.getPersistenceCapable();
        _pc = origPC.pcNewInstance(sm, false);
       
        int[] fields = new int[sm.getMetaData().getFields().length];
        for (int i = 0; i < fields.length; i++) {
            fields[i] = i;
        }
View Full Code Here

Examples of org.apache.openjpa.enhance.PersistenceCapable

                }
            }
            _meta = sub;
        }

        PersistenceCapable inst = PCRegistry.newInstance(cls, this, _oid, true);
        if (inst == null) {
            // the instance was null: check to see if the instance is
            // abstract (as can sometimes be the case when the
            // class discriminator strategy is not configured correctly)
            if (Modifier.isAbstract(cls.getModifiers()))
View Full Code Here

Examples of org.apache.openjpa.enhance.PersistenceCapable

                            //if (newVal != null && newVal.equals(curVal))
                            //    return;
                            //else {
                                if (curVal != null && newVal != null &&
                                    curVal instanceof PersistenceCapable && newVal instanceof PersistenceCapable) {
                                    PersistenceCapable curPc = (PersistenceCapable) curVal;
                                    PersistenceCapable newPc = (PersistenceCapable) newVal;
                                    if (curPc.pcFetchObjectId().equals(newPc.pcFetchObjectId()))
                                        return;
                                   
                                }
                            //}
                        } else    
View Full Code Here

Examples of org.apache.openjpa.enhance.PersistenceCapable

        Object o = in.readObject();

        if (o == null)
            return null;

        PersistenceCapable pc;
        if (!(o instanceof PersistenceCapable))
            pc = ImplHelper.toPersistenceCapable(o, this);
        else
            pc = (PersistenceCapable) o;

        pc.pcReplaceStateManager(this);
        return pc;
    }
View Full Code Here

Examples of org.apache.openjpa.enhance.PersistenceCapable

            }
            return sm;
        }

        // ACT_RUN
        PersistenceCapable pc;
        if (sm != null) {
            if (sm.isDetached()) {
                throw new ObjectExistsException(_loc.get("persist-detached", Exceptions.toString(obj)))
                    .setFailedObject(obj);
            }

            if (!sm.isEmbedded()) {
                sm.persist();
                _cache.persist(sm);
                if ((action & OpCallbacks.ACT_CASCADE) != 0) {
                    sm.cascadePersist(call);
                }
                return sm;
            }

            // an embedded field; notify the owner that the value has
            // changed by becoming independently persistent
            sm.getOwner().dirty(sm.getOwnerIndex());
            _cache.persist(sm);
            pc = sm.getPersistenceCapable();
        } else {
            pc = assertPersistenceCapable(obj);
            if (pc.pcIsDetached() == Boolean.TRUE) {
                throw new ObjectExistsException(_loc.get("persist-detached", Exceptions.toString(obj)))
                    .setFailedObject(obj);
            }
        }

        ClassMetaData meta = _repo.getMetaData(obj.getClass(), _loader, true);
        if (fireEvent) {
            fireLifecycleEvent(obj, null, meta, LifecycleEvent.BEFORE_PERSIST);
        }

        // create id for instance
        if (id == null) {
            int idType = meta.getIdentityType();
            if (idType == ClassMetaData.ID_APPLICATION) {
                id = ApplicationIds.create(pc, meta);
            } else if (idType == ClassMetaData.ID_UNKNOWN) {
                throw new UserException(_loc.get("meta-unknownid", meta));
            } else {
                id = StateManagerId.newInstance(this);
            }
        }

        // make sure we don't already have the instance cached
        checkForDuplicateId(id, obj, meta);

        // if had embedded sm, null it
        if (sm != null) {
            pc.pcReplaceStateManager(null);
        }

        // create new sm
        sm = newStateManagerImpl(id, meta);
        if ((_flags & FLAG_ACTIVE) != 0) {
View Full Code Here

Examples of org.apache.openjpa.enhance.PersistenceCapable

     * Temporarily manage the given instance in order to cascade the given
     * operation through it.
     */
    private void cascadeTransient(int op, Object obj, OpCallbacks call,
        String errOp) {
        PersistenceCapable pc = assertPersistenceCapable(obj);

        // if using detached state manager, don't replace
        if (pc.pcGetStateManager() != null)
            throw newDetachedException(obj, errOp);

        ClassMetaData meta = _repo.getMetaData(obj.getClass(), _loader, true);
        StateManagerImpl sm = newStateManagerImpl(StateManagerId.
            newInstance(this), meta);
View Full Code Here

Examples of org.apache.openjpa.enhance.PersistenceCapable

                id = StateManagerId.newInstance(this);

            StateManagerImpl sm = newStateManagerImpl(id, meta);
            sm.setOwner((StateManagerImpl) owner, ownerMeta);

            PersistenceCapable copy;
            PCState state;
            Class<?> type = meta.getDescribedType();
            if (obj != null) {
                // give copy and the original instance the same state manager
                // so that we can copy fields from one to the other
                StateManagerImpl copySM;
                PersistenceCapable pc;
                if (orig == null) {
                    copySM = sm;
                    pc = assertPersistenceCapable(obj);
                    pc.pcReplaceStateManager(sm);
                } else {
                    copySM = orig;
                    pc = orig.getPersistenceCapable();
                }

                try {
                    // copy the instance.  we do this even if it doesn't already
                    // have a state manager in case it is later assigned to a
                    // PC field; at that point it's too late to copy
                    copy = PCRegistry.newInstance(type, copySM, false);
                    int[] fields = new int[meta.getFields().length];
                    for (int i = 0; i < fields.length; i++)
                        fields[i] = i;
                    copy.pcCopyFields(pc, fields);
                    state = PCState.ECOPY;
                    copy.pcReplaceStateManager(null);
                } finally {
                    // if the instance didn't have a state manager to start,
                    // revert it to being transient
                    if (orig == null)
                        pc.pcReplaceStateManager(null);
                }
            } else {
                copy = PCRegistry.newInstance(type, sm, false);
                if ((_flags & FLAG_ACTIVE) != 0 && !_optimistic)
                    state = PCState.ECLEAN;
View Full Code Here

Examples of org.apache.openjpa.enhance.PersistenceCapable

    }

    public Object getObjectId(Object obj) {
        assertOpen();
        if (ImplHelper.isManageable(obj)) {
            PersistenceCapable pc = ImplHelper.toPersistenceCapable(obj, _conf);
            if (pc != null) {
                if (pc.pcGetStateManager() == null) {
                    // If the statemanager is null the call to pcFetchObjectId always returns null. Create a new object
                    // id.
                    return ApplicationIds.create(pc, _repo.getMetaData(pc.getClass(), null, true));
                }
                return pc.pcFetchObjectId();
            }
        }
        return null;
    }
View Full Code Here

Examples of org.apache.openjpa.enhance.PersistenceCapable

    }

    public boolean isDirty(Object obj) {
        assertOpen();
        if (ImplHelper.isManageable(obj)) {
            PersistenceCapable pc = ImplHelper.toPersistenceCapable(obj, _conf);
            return pc.pcIsDirty();
        }
        return false;
    }
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.