Examples of PersistenceCapable


Examples of javax.jdo.spi.PersistenceCapable

     * stored in the L2 cached object. See CORE-3215.
     * @return The L2 cacheable object
     */
    public CachedPC getL2CacheableObject()
    {
        PersistenceCapable pcCopy = myPC.jdoNewInstance(this, myPC.jdoGetObjectId());

        // Make a copy of the field values from the original object - basic fields + PC fields + SCO fields (omit SCO containers)
        int[] allFieldNumbers = getAllFieldNumbers();
        boolean[] l2loadedFields = new boolean[allFieldNumbers.length];

        // Pass 1 to find the number of cacheable fields TODO Embody this in AbstractMemberMetaData
        ClassLoaderResolver clr = getObjectManager().getClassLoaderResolver();
        int numCacheableFields = 0;
        for (int i=0;i<allFieldNumbers.length;i++)
        {
            AbstractMemberMetaData fmd = cmd.getMetaDataForManagedMemberAtAbsolutePosition(i);
            if (fmd.getRelationType(clr) == Relation.NONE)
            {
                numCacheableFields++;
            }
        }
        int[] cacheableFieldNumbers = new int[numCacheableFields];

        // Pass 2 to set up the loaded fields info for all cacheable fields
        int cacheableNum = 0;
        for (int i=0;i<allFieldNumbers.length;i++)
        {
            boolean cacheable = true;
            AbstractMemberMetaData fmd = cmd.getMetaDataForManagedMemberAtAbsolutePosition(i);
            if (fmd.getRelationType(clr) != Relation.NONE)
            {
                cacheable = false;
            }
            if (cacheable)
            {
                cacheableFieldNumbers[cacheableNum++] = allFieldNumbers[i];
                l2loadedFields[i] = (cacheable && loadedFields[i]);
            }
            else
            {
                l2loadedFields[i] = false;
            }
        }
        if (cacheableFieldNumbers != null && cacheableFieldNumbers.length > 0)
        {
            pcCopy.jdoCopyFields(myPC, cacheableFieldNumbers);
        }

        // Reset jdoFlags in the copy to PersistenceCapable.READ_WRITE_OK and clear its state manager.
        pcCopy.jdoReplaceFlags();
        pcCopy.jdoReplaceStateManager(null);
        return new CachedPC(pcCopy, l2loadedFields, transactionalVersion);
    }
View Full Code Here

Examples of javax.jdo.spi.PersistenceCapable

                ((Detachable)myPC).jdoReplaceDetachedState();

                // Call any "post-detach" listeners
                getCallbackHandler().postDetach(myPC, myPC); // there is no copy, so give the same object

                PersistenceCapable toCheckPC = myPC;
                Object toCheckID = myID;
                disconnect();

                if (!toCheckPC.jdoIsDetached())
                {
                    // Sanity check on the objects detached state
                    throw new JPOXUserException(LOCALISER.msg("026025", toCheckPC.getClass().getName(), toCheckID));
                }
            }
            else
            {
                // Make the object transient
View Full Code Here

Examples of javax.jdo.spi.PersistenceCapable

        myPC = (PersistenceCapable)pc;
        replaceStateManager(myPC, this); // Set SM for embedded PC to be this
        if (copyPc)
        {
            // Create a new PC with the same field values
            PersistenceCapable pcCopy = myPC.jdoNewInstance(this);
            pcCopy.jdoCopyFields(myPC, getAllFieldNumbers());

            // Swap the managed PC to be the copy and not the input
            replaceStateManager(pcCopy, this);
            myPC = pcCopy;
            disconnectClone((PersistenceCapable)pc);
View Full Code Here

Examples of javax.jdo.spi.PersistenceCapable

                                FieldManager prevFM = currFM;
                                try
                                {
                                    currFM = new SingleValueFieldManager();
                                    myPC.jdoProvideField(fieldNumber);
                                    PersistenceCapable pkFieldPC =
                                        (PersistenceCapable) ((SingleValueFieldManager) currFM).fetchObjectField(fieldNumber);
                                    if (pkFieldPC == null)
                                    {
                                        throw new NucleusUserException(
                                            LOCALISER.msg("026016", fmd.getFullFieldName()));
View Full Code Here

Examples of javax.jdo.spi.PersistenceCapable

        }
        if (!(obj instanceof PersistenceCapable))
        {
            throw new NucleusUserException("Must be PersistenceCapable");
        }
        PersistenceCapable pc = (PersistenceCapable)obj;

        // Assign the new object to this StateManager temporarily so that we can copy its fields
        replaceStateManager(pc, this);
        myPC.jdoCopyFields(pc, fieldNumbers);
View Full Code Here

Examples of javax.jdo.spi.PersistenceCapable

                    // Remove the values from the detached object - not required by the spec
                    int[] unloadedFields = getFlagsSetTo(loadedFields, getAllFieldNumbers(), false);
                    if (unloadedFields != null && unloadedFields.length > 0)
                    {
                        PersistenceCapable dummyPC = myPC.jdoNewInstance(this);
                        myPC.jdoCopyFields(dummyPC, unloadedFields);
                        replaceStateManager(dummyPC, null);
                    }
                }
            }

            // Detach all (loaded) fields in the FetchPlan
            FieldManager detachFieldManager = new DetachFieldManager(this, getSecondClassMutableFields(),
                myFP, state, false);
            for (int i = 0; i < loadedFields.length; i++)
            {
                if (loadedFields[i])
                {
                    try
                    {
                        // Just fetch the field since we are usually called in postCommit() so dont want to update it
                        detachFieldManager.fetchObjectField(i);
                    }
                    catch (EndOfFetchPlanGraphException eofpge)
                    {
                        Object value = provideField(i);
                        if (api.isPersistable(value))
                        {
                            // PC field beyond end of graph
                            org.datanucleus.state.StateManager valueSM = myOM.findStateManager(value);
                            if (!api.isDetached(value) && !(valueSM != null && valueSM.isDetaching()))
                            {
                                // Field value is not detached or being detached so unload it
                                String fieldName = cmd.getMetaDataForManagedMemberAtAbsolutePosition(i).getName();
                                if (NucleusLogger.PERSISTENCE.isDebugEnabled())
                                {
                                    NucleusLogger.PERSISTENCE.debug(LOCALISER.msg("026032",
                                        StringUtils.toJVMIDString(myPC), myOM.getIdentityAsString(myID), fieldName));
                                }
                                unloadField(fieldName);
                            }
                        }
                        // TODO What if we have collection/map that includes some objects that are not detached?
                        // Currently we just leave as persistent etc but should we????
                        // The problem is that with 1-N bidir fields we could unload the field incorrectly
                    }
                }
            }

            if (detachable)
            {
                // Migrate the lifecycle state to DETACHED_CLEAN
                myLC = myLC.transitionDetach(this);

                // Update the object with its detached state
                myPC.jdoReplaceFlags();
                ((Detachable)myPC).jdoReplaceDetachedState();

                // Call any "post-detach" listeners
                getCallbackHandler().postDetach(myPC, myPC); // there is no copy, so give the same object

                PersistenceCapable toCheckPC = myPC;
                Object toCheckID = myID;
                disconnect();

                if (!toCheckPC.jdoIsDetached())
                {
                    // Sanity check on the objects detached state
                    throw new NucleusUserException(LOCALISER.msg("026025", toCheckPC.getClass().getName(), toCheckID));
                }
            }
            else
            {
                // Warn the user since they selected detachAllOnCommit
View Full Code Here

Examples of javax.jdo.spi.PersistenceCapable

        // Look for an existing detached copy
        DetachState detachState = (DetachState) state;
        DetachState.Entry existingDetached = detachState.getDetachedCopyEntry(myPC);

        PersistenceCapable detachedPC;
        if (existingDetached == null)
        {
            // No existing detached copy - create new one
            detachedPC = myPC.jdoNewInstance(this);
            detachState.setDetachedCopyEntry(myPC, detachedPC);
        }
        else
        {
            // Found one - if it's sufficient for current FetchPlanState, return it immediately
            detachedPC = (PersistenceCapable) existingDetached.getDetachedCopyObject();
            if (existingDetached.checkCurrentState())
            {
                return detachedPC;
            }

            // Need to process the detached copy using current FetchPlanState
        }

        referencedPC = detachedPC;

        // Check if detachable ... if so then we detach a copy, otherwise we return a transient copy
        boolean detachable = myOM.getApiAdapter().isDetachable(myPC);

        // make sure a detaching PC is not read by another thread while we are detaching
        synchronized (referencedPC)
        {
            if (detachable)
            {
                if (NucleusLogger.PERSISTENCE.isDebugEnabled())
                {
                    NucleusLogger.PERSISTENCE.debug(LOCALISER.msg("010010", StringUtils.toJVMIDString(myPC),
                        "" + state.getCurrentFetchDepth(), StringUtils.toJVMIDString(detachedPC)));
                }

                // Call any "pre-detach" listeners
                getCallbackHandler().preDetach(myPC);
            }
            try
            {
                flags |= FLAG_DETACHING;

                // Handle any field loading/unloading before the detach
                if ((myOM.getFetchPlan().getDetachmentOptions() & FetchPlan.DETACH_LOAD_FIELDS) != 0)
                {
                    // Load any unloaded fetch-plan fields
                    loadUnloadedFieldsInFetchPlan();
                }

                if (myLC == myOM.getNucleusContext().getApiAdapter().getLifeCycleState(LifeCycleState.HOLLOW) ||
                    myLC == myOM.getNucleusContext().getApiAdapter().getLifeCycleState(LifeCycleState.P_NONTRANS))
                {
                    // Migrate any HOLLOW/P_NONTRANS to P_CLEAN etc
                    myLC = myLC.transitionReadField(this, true);
                }

                // Create a SM for our copy object
                JDOStateManagerImpl smDetachedPC = new JDOStateManagerImpl(myOM, cmd);
                smDetachedPC.initialiseForDetached(detachedPC, getExternalObjectId(myPC), getVersion(myPC));
                smDetachedPC.referencedPC = myPC;

                // If detached copy already existed, take note of fields previously loaded
                if (existingDetached != null)
                {
                    smDetachedPC.retrieveDetachState(smDetachedPC);
                }

                smDetachedPC.replaceFields(getFieldsNumbersToDetach(), new DetachFieldManager(this,
                    getSecondClassMutableFields(), myFP, state, true));

                smDetachedPC.referencedPC = null;
                if (detachable)
                {
                    // Update the object with its detached state - not to be confused with the "state" object above
                    detachedPC.jdoReplaceFlags();
                    ((Detachable)detachedPC).jdoReplaceDetachedState();
                }
                else
                {
                    smDetachedPC.makeTransient(null);
                }

                // Remove its StateManager since now detached or transient
                replaceStateManager(detachedPC, null);
            }
            catch (Exception e)
            {
                // What could possible be thrown here ?
                NucleusLogger.PERSISTENCE.debug("DETACH ERROR : Error thrown while detaching " +
                    StringUtils.toJVMIDString(myPC) + " (id=" + myID + ")", e);
            }
            finally
            {
                flags &= ~FLAG_DETACHING;
                referencedPC = null;
            }

            if (detachable && !myOM.getApiAdapter().isDetached(detachedPC))
            {
                // Sanity check on the objects detached state
                throw new NucleusUserException(LOCALISER.msg("026025", detachedPC.getClass().getName(), myID));
            }

            if (detachable)
            {
                // Call any "post-detach" listeners
View Full Code Here

Examples of javax.jdo.spi.PersistenceCapable

     */
    public void storeObjectField(int fieldNumber, Object value)
    {
        if (ec.getApiAdapter().isPersistable(value))
        {
            PersistenceCapable pc = (PersistenceCapable)value;
            pc.jdoCopyKeyFieldsFromObjectId(this, pc.jdoGetObjectId());
        }
        else
        {
            JavaTypeMapping mapping = javaTypeMappings[mappingNum++];
            mapping.setObject(ec, statement, getParamsForField(mapping), value);
View Full Code Here

Examples of javax.jdo.spi.PersistenceCapable

        {
            return myPC;
        }
        flags |= FLAG_ATTACHING;

        PersistenceCapable detachedPC = (PersistenceCapable)obj;
        try
        {
            // Check if the object is already persisted
            boolean persistent = false;
            if (embedded)
View Full Code Here

Examples of org.apache.openjpa.enhance.PersistenceCapable

        if (!Modifier.isAbstract(meta.getDescribedType().getModifiers())
            && !hasPCPrimaryKeyFields(meta)) {
            Class type = meta.getInterfaceImpl();
            if (type == null)
                type = meta.getDescribedType();
            PersistenceCapable pc = PCRegistry.newInstance(type, null, oid,
                 false);
            Object copy = pc.pcNewObjectIdInstance();
            pc.pcCopyKeyFieldsToObjectId(copy);
            return copy;
        }

        Object copy = (!meta.isObjectIdTypeShared()) ? oid
            : ((ObjectId) oid).getId();
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.