Package org.datanucleus.sco

Examples of org.datanucleus.sco.SCO


                    }
                    ((SCO) oldValue).unsetOwner();
                }
                if (newValue instanceof SCO)
                {
                    SCO sco = (SCO) newValue;
                    Object owner = sco.getOwner();
                    if (owner != null)
                    {
                        throw new JDOUserException(LOCALISER.msg("026007",
                            sco.getFieldName(), owner));
                    }
                }

                writeField(field, newValue);
                postWriteField(wasDirty);
View Full Code Here


        {
            return value;
        }
        if (getSecondClassMutableFields()[fieldNumber] && value instanceof SCO)
        {
            SCO sco = (SCO)value;

            // Not a SCO wrapper, or is a SCO wrapper but not owned by this object
            Object unwrappedValue = sco.getValue();
            if (replaceFieldIfChanged)
            {
                AbstractMemberMetaData fmd = cmd.getMetaDataForManagedMemberAtAbsolutePosition(fieldNumber);
                if (NucleusLogger.PERSISTENCE.isDebugEnabled())
                {
View Full Code Here

            }

            if (needsAttaching)
            {
                // Create a wrapper and attach the elements (and add the others)
                SCO collWrapper = replaceFieldWithWrapper(sm, null, false, false);
                collWrapper.attachCopy(value);
            }
            else
            {
                if (value.size() > 0)
                {
View Full Code Here

        }
        else if (mmd.getOrderMetaData()!=null && type.isAssignableFrom(java.util.List.class))
        {
            type = java.util.List.class;
        }
        SCO sco = SCOUtils.newSCOInstance(ownerSM, mmd, mmd.getType(), type, value, forInsert, forUpdate, true);
        return sco;
    }
View Full Code Here

                    // Retrieve old value for field
                    smAttached.loadField(fieldNumber);
                    oldValue = smAttached.provideField(fieldNumber);
                }

                SCO sco;
                if (oldValue == null || (oldValue != null && !(oldValue instanceof SCO)))
                {
                    // Detached object didn't use wrapped field
                    if (NucleusLogger.JDO.isDebugEnabled())
                    {
                        NucleusLogger.JDO.debug(LOCALISER.msg("026029", StringUtils.toJVMIDString(smAttached.getObject()),
                            smAttached.getInternalObjectId(), mmd.getName()));
                    }
                    sco = SCOUtils.newSCOInstance(smAttached, mmd, mmd.getType(), null, null, false, false, false);
                    if (sco instanceof SCOContainer)
                    {
                        // Load any containers to avoid update issues
                        ((SCOContainer)sco).load();
                    }
                    smAttached.replaceField(fieldNumber, sco, true);
                }
                else
                {
                    // The field is already a SCO wrapper, so just copy the new values to it
                    sco = (SCO) oldValue;
                }

                if (cascadeAttach)
                {
                    // Only trigger the cascade when required
                    if (copy)
                    {
                        // Attach copy of the SCO
                        sco.attachCopy(value);
                    }
                    else
                    {
                        // Attach SCO in-situ
                        // TODO This doesn't seem to handle any removal of things while detached
                        // Should be changed to do things like in attachCopy above.
                        if (sco instanceof Collection)
                        {
                            // Attach all PC elements of the collection
                            SCOUtils.attachForCollection(smAttached, ((Collection)value).toArray(),
                                SCOUtils.collectionHasElementsWithoutIdentity(mmd));
                        }
                        else if (sco instanceof Map)
                        {
                            // Attach all PC keys/values of the map
                            SCOUtils.attachForMap(smAttached, ((Map)value).entrySet(),
                                SCOUtils.mapHasKeysWithoutIdentity(mmd),
                                SCOUtils.mapHasValuesWithoutIdentity(mmd));
                        }
                        else
                        {
                            // Initialise the SCO with the new value
                            sco.initialise(value, false, false);
                        }
                    }
                }

                if (fieldsToAttach[fieldNumber] || !persistent)
View Full Code Here

                if (!(value instanceof SCO))
                {
                    // Replace with SCO
                    value = sm.wrapSCOField(fieldNumber, value, false, false, true);
                }
                SCO sco = (SCO)value;

                Collection coll = (Collection)value;
                Iterator iter = coll.iterator();
                while (iter.hasNext())
                {
                    Object element = iter.next();
                    if (api.isPersistable(element))
                    {
                        processPersistable(element);
                    }
                }
                sco.unsetOwner();
            }
            else if (value instanceof Map)
            {
                // Process all keys, values of the Map that are PC
                if (!(value instanceof SCO))
                {
                    // Replace with SCO
                    value = sm.wrapSCOField(fieldNumber, value, false, false, true);
                }
                SCO sco = (SCO)value;

                Map map = (Map)value;

                // Process any keys that are PersistenceCapable
                Set keys = map.keySet();
                Iterator iter = keys.iterator();
                while (iter.hasNext())
                {
                    Object mapKey = iter.next();
                    if (api.isPersistable(mapKey))
                    {
                        processPersistable(mapKey);
                    }
                }

                // Process any values that are PersistenceCapable
                Collection values = map.values();
                iter = values.iterator();
                while (iter.hasNext())
                {
                    Object mapValue = iter.next();
                    if (api.isPersistable(mapValue))
                    {
                        processPersistable(mapValue);
                    }
                }

                sco.unsetOwner();
            }
            else if (value instanceof Object[])
            {
                Object[] array = (Object[]) value;
                for (int i=0;i<array.length;i++)
                {
                    Object element = array[i];
                    if (api.isPersistable(element))
                    {
                        processPersistable(element);
                    }
                }
            }
            else if (value instanceof SCO)
            {
                // Other SCO field, so unset its owner
                SCO sco = (SCO) value;
                sco.unsetOwner();
            }
            else
            {
                // Primitive, or primitive array, or some unsupported container type
            }
View Full Code Here

        sm.provideFields(new int[]{fieldNumber}, sfv);
        Object value = sfv.fetchObjectField(fieldNumber);

        if (value != null && secondClassMutableFields[fieldNumber])
        {
            SCO sco;
            if (value instanceof SCO)
            {
                // SCO field so unset its owner
                sco = (SCO) value;
                sco.unsetOwner();
            }
        }

        return value;
    }
View Full Code Here

                        if (!(value instanceof SCO))
                        {
                            // Replace with SCO so we can work with it
                            value = sm.wrapSCOField(fieldNumber, value, false, false, true);
                        }
                        SCO sco = (SCO)value;

                        if (sco instanceof Collection)
                        {
                            // Detach all PC elements of the collection
                            SCOUtils.detachForCollection(sm, ((Collection)sco).toArray(), state);
                            sco.unsetOwner();
                        }
                        else if (sco instanceof Map)
                        {
                            // Detach all PC keys/values of the map
                            SCOUtils.detachForMap(sm, ((Map)sco).entrySet(), state);
                            sco.unsetOwner();
                        }

                        if (SCOUtils.detachAsWrapped(sm))
                        {
                            return sco;
                        }
                        else
                        {
                            return sm.unwrapSCOField(fieldNumber, value, true);
                        }
                    }
                }
                else if (mmd.hasArray())
                {
                    // Process object array
                    if (!api.isPersistable(mmd.getType().getComponentType()))
                    {
                        // Array element type is not persistable so just return
                        return value;
                    }

                    Object[] arrValue = (Object[])value;
                    Object[] arrDetached = (Object[])Array.newInstance(mmd.getType().getComponentType(), arrValue.length);
                    for (int j=0;j<arrValue.length;j++)
                    {
                        // Detach elements as appropriate
                        arrDetached[j] = processPersistable(arrValue[j]);
                    }
                    return arrDetached;
                }
                break;

            default :
                if (secondClassMutableFields[fieldNumber])
                {
                    // Other SCO
                    if (copy)
                    {
                        if (!(value instanceof SCO))
                        {
                            // Replace with SCO so we can work with it
                            value = sm.wrapSCOField(fieldNumber, value, false, false, true);
                        }
                        return ((SCO)value).detachCopy(state);
                    }

                    if (!(value instanceof SCO))
                    {
                        // Replace with SCO so we can work with it
                        value = sm.wrapSCOField(fieldNumber, value, false, false, true);
                    }
                    SCO sco = (SCO)value;

                    if (SCOUtils.detachAsWrapped(sm))
                    {
                        return sco;
                    }
View Full Code Here

TOP

Related Classes of org.datanucleus.sco.SCO

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.