Package org.datanucleus.store

Examples of org.datanucleus.store.ObjectProvider


                ExecutionContext ec = ownerSM.getExecutionContext();
                Iterator iter = c.iterator();
                while (iter.hasNext())
                {
                    Object pc = iter.next();
                    ObjectProvider objSM = ec.findObjectProvider(pc);
                    if (objSM == null)
                    {
                        objSM = ObjectProviderFactory.newForEmbedded(ec, pc, false, ownerSM, fieldNumber);
                    }
                }
View Full Code Here


                    Map.Entry entry = (Map.Entry)iter.next();
                    Object key = entry.getKey();
                    Object value = entry.getValue();
                    if (fmd.getMap().keyIsPersistent())
                    {
                        ObjectProvider objSM = ec.findObjectProvider(key);
                        if (objSM == null)
                        {
                            objSM = ObjectProviderFactory.newForEmbedded(ec, key, false, ownerSM, fieldNumber);
                        }
                    }
                    if (fmd.getMap().valueIsPersistent())
                    {
                        ObjectProvider objSM = ec.findObjectProvider(value);
                        if (objSM == null)
                        {
                            objSM = ObjectProviderFactory.newForEmbedded(ec, value, false, ownerSM, fieldNumber);
                        }
                    }
View Full Code Here

     */
    protected String getReferenceStringForObject(ExecutionContext ec, Object value)
    {
        if (ec.getApiAdapter().isPersistable(value))
        {
            ObjectProvider sm = ec.findObjectProvider(value);
            if (sm == null)
            {
                // Referenced object is not yet persistent, so persist it
                ec.persistObjectInternal(value, null, -1, ObjectProvider.PC);
                sm = ec.findObjectProvider(value);
                sm.flush(); // Make sure the object is in the datastore so the id is set
            }

            String refString = null;
            if (mappingStrategy == ID_MAPPING)
            {
                refString = value.getClass().getName() + ":" + sm.getInternalObjectId();
            }
            else if (mappingStrategy == XCALIA_MAPPING)
            {
                AbstractClassMetaData cmd = sm.getClassMetaData();
                DiscriminatorMetaData dismd = cmd.getDiscriminatorMetaData();
                String definer = null;
                if (dismd != null && dismd.getValue() != null)
                {
                    definer = dismd.getValue();
                }
                else
                {
                    definer = cmd.getFullClassName();
                }
                if (cmd.getIdentityType() == IdentityType.DATASTORE)
                {
                    refString = definer + ":" + ((OID)sm.getInternalObjectId()).getKeyValue();
                }
                else
                {
                    refString = definer + ":" + sm.getInternalObjectId().toString();
                }
            }
            return refString;
        }
        else
View Full Code Here

                throw new NucleusException(LOCALISER.msg("041016",
                    value.getClass(), value)).setFatal();
            }

            AbstractClassMetaData embCmd = ec.getMetaDataManager().getMetaDataForClass(value.getClass(), ec.getClassLoaderResolver());
            ObjectProvider embSM = ec.findObjectProvider(value);
            if (embSM == null || api.getExecutionContext(value) == null)
            {
                // Assign a StateManager to manage our embedded object
                embSM = ObjectProviderFactory.newForEmbedded(ec, value, false, ownerSM, ownerFieldNumber);
                embSM.setPcObjectType(objectType);
            }

            int n = 0;
            for (int i=0; i<javaTypeMappings.size(); i++)
            {
                JavaTypeMapping mapping = ((JavaTypeMapping)javaTypeMappings.get(i));
                int[] posMapping = new int[mapping.getNumberOfDatastoreMappings()];
                for (int j=0; j<posMapping.length; j++)
                {
                    posMapping[j] = param[n++];
                }

                // Retrieve value of field from Embedded StateManager
                int embAbsFieldNum = embCmd.getAbsolutePositionOfMember(mapping.getMemberMetaData().getName());
                Object fieldValue = embSM.provideField(embAbsFieldNum);

                if (mapping instanceof EmbeddedPCMapping)
                {
                    mapping.setObject(ec, ps, posMapping, fieldValue, embSM, embAbsFieldNum);
                }
View Full Code Here

        if (mmd.getFieldTypes() != null && mmd.getFieldTypes().length > 0)
        {
            // Embedded type has field-type defined so use that as our embedded type
            embeddedType = ec.getClassLoaderResolver().classForName(mmd.getFieldTypes()[0]);
        }
        ObjectProvider embSM = ObjectProviderFactory.newForHollow(ec, embeddedType, (Object)null);
        embSM.setPcObjectType(objectType);
        value = embSM.getObject();

        String nullColumn = null;
        String nullValue = null;
        if (emd != null)
        {
            nullColumn = emd.getNullIndicatorColumn();
            nullValue = emd.getNullIndicatorValue();
        }

        int n = 0;
        for (int i=0; i<javaTypeMappings.size(); i++)
        {
            JavaTypeMapping mapping = ((JavaTypeMapping)javaTypeMappings.get(i));
            int embAbsFieldNum = embCmd.getAbsolutePositionOfMember(mapping.getMemberMetaData().getName());
            if (mapping instanceof EmbeddedPCMapping)
            {
                // We have a nested embedded
                int numSubParams = mapping.getNumberOfDatastoreMappings();
                int[] subParam = new int[numSubParams];
                int k = 0;
                for (int j=n;j<n+numSubParams;j++)
                {
                    subParam[k++] = param[j];
                }
                n += numSubParams;

                // Use the sub-object mapping to extract the value for that object
                Object subValue = mapping.getObject(ec, rs, subParam, embSM, embAbsFieldNum);
                if (subValue != null)
                {
                    embSM.replaceFieldMakeDirty(embAbsFieldNum, subValue);
                }

                // TODO Check the null column and its value in the sub-embedded ?
            }
            else
            {
                // Extract the value(s) for this field and update the PC if it is not null
                int[] posMapping = new int[mapping.getNumberOfDatastoreMappings()];
                for (int j=0; j<posMapping.length; j++)
                {
                    posMapping[j] = param[n++];
                }
                Object fieldValue = mapping.getObject(ec, rs, posMapping);
                if (fieldValue != null)
                {
                    embSM.replaceFieldMakeDirty(embAbsFieldNum, fieldValue);
                }
                else
                {
                    // If the value is null, but the field is not a primitive update it
                    AbstractMemberMetaData embFmd = embCmd.getMetaDataForManagedMemberAtAbsolutePosition(embAbsFieldNum);
                    if (!embFmd.getType().isPrimitive())
                    {
                        embSM.replaceFieldMakeDirty(embAbsFieldNum, fieldValue);
                    }
                }

                // Check for the null column and its value
                if (nullColumn != null &&
                    mapping.getMemberMetaData().getColumnMetaData()[0].getName().equals(nullColumn))
                {
                    if ((nullValue == null && fieldValue == null) ||
                        (nullValue != null && fieldValue.toString().equals(nullValue)))
                    {
                        value = null;
                        break;
                    }
                }
            }
        }

        // Update owner field in the element (if present)
        if (emd != null)
        {
            String ownerField = emd.getOwnerMember();
            if (ownerField != null)
            {
                int ownerFieldNumberInElement = embCmd.getAbsolutePositionOfMember(ownerField);
                if (ownerFieldNumberInElement >= 0)
                {
                    embSM.replaceFieldMakeDirty(ownerFieldNumberInElement, ownerSM.getObject());
                }
            }
        }
       
        // Register our owner now that we have our values set
        if (value != null && ownerSM != null)
        {
            embSM.addEmbeddedOwner(ownerSM, ownerFieldNumber);
        }

        return value;
    }
View Full Code Here

                ExecutionContext ec = ownerSM.getExecutionContext();
                Iterator iter = c.iterator();
                while (iter.hasNext())
                {
                    Object pc = iter.next();
                    ObjectProvider objSM = ec.findObjectProvider(pc);
                    if (objSM == null)
                    {
                        objSM = ObjectProviderFactory.newForEmbedded(ec, pc, false, ownerSM, fieldNumber);
                    }
                }
View Full Code Here

                    Map.Entry entry = (Map.Entry)iter.next();
                    Object key = entry.getKey();
                    Object value = entry.getValue();
                    if (fmd.getMap().keyIsPersistent())
                    {
                        ObjectProvider objSM = ec.findObjectProvider(key);
                        if (objSM == null)
                        {
                            objSM = ObjectProviderFactory.newForEmbedded(ec, key, false, ownerSM, fieldNumber);
                        }
                    }
                    if (fmd.getMap().valueIsPersistent())
                    {
                        ObjectProvider objSM = ec.findObjectProvider(value);
                        if (objSM == null)
                        {
                            objSM = ObjectProviderFactory.newForEmbedded(ec, value, false, ownerSM, fieldNumber);
                        }
                    }
View Full Code Here

     * Utility method to process the passed persistable object.
     * @param pc The PC object
     */
    protected void processPersistable(Object pc)
    {
        ObjectProvider pcSM = sm.getExecutionContext().findObjectProvider(pc);
        if (pcSM != null)
        {
            if (pcSM.isDeleting() || pcSM.becomingDeleted())
            {
                // Already becoming deleted so jump out
                return;
            }
        }
View Full Code Here

                    Map.Entry entry = (Map.Entry)iter.next();
                    Object key = entry.getKey();
                    Object value = entry.getValue();
                    if (fmd.getMap().keyIsPersistent())
                    {
                        ObjectProvider objSM = ec.findObjectProvider(key);
                        if (objSM == null)
                        {
                            objSM = ObjectProviderFactory.newForEmbedded(ec, key, false, ownerSM, fieldNumber);
                        }
                    }
                    if (fmd.getMap().valueIsPersistent())
                    {
                        ObjectProvider objSM = ec.findObjectProvider(value);
                        if (objSM == null)
                        {
                            objSM = ObjectProviderFactory.newForEmbedded(ec, value, false, ownerSM, fieldNumber);
                        }
                    }
View Full Code Here

            // Element is embedded/serialised so has no id
        }
        else
        {
            ExecutionContext ec = ownerOP.getExecutionContext();
            ObjectProvider elementSM = ec.findObjectProvider(element);
            if (elementSM != null && elementSM.isEmbedded())
            {
                // Element is already with StateManager and is embedded in another field!
                throw new NucleusUserException(LOCALISER.msg("056028",
                    ownerMemberMetaData.getFullFieldName(), element));
            }
View Full Code Here

TOP

Related Classes of org.datanucleus.store.ObjectProvider

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.