Package org.jpox.sco

Examples of org.jpox.sco.SCO


        }
        else if (fmd.getOrderMetaData()!=null && type.isAssignableFrom(java.util.List.class))
        {
            type = java.util.List.class;
        }
        SCO sco = SCOUtils.newSCOInstance(ownerSM, fmd, fmd.getType(), type, value, forInsert, forUpdate, true);
        return sco;
    }
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

                    }
                    ((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 (JPOXLogger.PERSISTENCE.isDebugEnabled())
                {
View Full Code Here

            }
            else
            {
                // Make sure that the value is a SCO wrapper
                Object oldValue = smAttached.provideField(fieldNumber);
                SCO sco;
                if (oldValue == null || (oldValue != null && !(oldValue instanceof SCO)))
                {
                    // The field wasn't initialised at creation, so create an empty SCO wrapper and copy the new values in
                    if (JPOXLogger.JDO.isDebugEnabled())
                    {
                        JPOXLogger.JDO.debug(LOCALISER.msg("026029", StringUtils.toJVMIDString(smAttached.getObject()),
                            smAttached.getInternalObjectId(), fmd.getName()));
                    }
                    sco = SCOUtils.newSCOInstance(smAttached, fmd, fmd.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
                        if (sco instanceof Collection)
                        {
                            // Attach all PC elements of the collection
                            boolean elementsWithoutIdentity = SCOUtils.collectionHasElementsWithoutIdentity(fmd);
                            SCOUtils.attachForCollection(smAttached, ((Collection)sco).toArray(), elementsWithoutIdentity);
                            sco.unsetOwner();
                        }
                        else if (sco instanceof Map)
                        {
                            // Attach all PC keys/values of the map
                            boolean keysWithoutIdentity = SCOUtils.mapHasKeysWithoutIdentity(fmd);
                            boolean valuesWithoutIdentity = SCOUtils.mapHasValuesWithoutIdentity(fmd);
                            SCOUtils.attachForMap(smAttached, ((Map)sco).entrySet(), keysWithoutIdentity, valuesWithoutIdentity);
                            sco.unsetOwner();
                        }
                        else
                        {
                            // Initialise the SCO with the new value
                            sco.initialise(value, false, false);
                        }
                    }
                }

                if (dirtyFields[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 (copy)
                {
                    return sco.detachCopy(state);
                }

                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();
                }
                return sco;
            }
            else if (value instanceof Object[])
            {
                // Process object array
                if (!api.isPersistable(fmd.getType().getComponentType()))
                {
                    // Array element type is not persistable so just return
                    return value;
                }

                Object[] arrValue = (Object[])value;
                Object[] arrDetached = (Object[])Array.newInstance(fmd.getType().getComponentType(), arrValue.length);
                for (int j=0;j<arrValue.length;j++)
                {
                    // Detach elements as appropriate
                    arrDetached[j] = processPersistable(arrValue[j]);
                }
                return arrDetached;
            }
            else if (secondClassMutableFields[fieldNumber])
            {
                // Other SCO - what to do here ? unset owner?
                SCO sco;
                if (value instanceof SCO)
                {
                    sco = (SCO) value;
                }
                else
                {
                    // Replace with a SCO wrapper so that we can detach it
                    sco = (SCO) sm.wrapSCOField(fieldNumber, value, false, false, true);
                }
                if (copy)
                {
                    return sco.detachCopy(state);
                }

                return sco;
            }
            else
View Full Code Here

TOP

Related Classes of org.jpox.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.