Package org.datanucleus.store

Examples of org.datanucleus.store.ObjectProvider


            if (listener.forClass(pc.getClass()) && listener.getListener() instanceof StoreLifecycleListener)
            {
                ExecutionContext ec = nucleusCtx.getApiAdapter().getExecutionContext(pc);
                String[] fieldNames = null;
                // PRE_STORE will return the fields being stored (JPOX extension)
                ObjectProvider op = ec.findObjectProvider(pc);
                fieldNames = op.getDirtyFieldNames();
                if (fieldNames == null)
                {
                    // Must be persisting so just return all loaded fields
                    fieldNames = op.getLoadedFieldNames();
                }
                ((StoreLifecycleListener)listener.getListener()).preStore(new FieldInstanceLifecycleEvent(pc, InstanceLifecycleEvent.STORE, null, fieldNames));
            }
        }
View Full Code Here


                    return;
                }
            }

            // Process all fields of the embedded object
            ObjectProvider embSM = ec.findObjectProviderForEmbedded(value, sm, embMmd);
            FieldManager ffm = new StoreEmbeddedFieldManager(embSM, dbObject, embMmd);
            embSM.provideFields(embcmd.getAllMemberPositions(), ffm);
            return;
        }

        String fieldName = MongoDBUtils.getFieldName(ownerMmd, fieldNumber);
        if (value == null)
View Full Code Here

            if (isNull)
            {
                return null;
            }

            ObjectProvider embSM = ec.newObjectProviderForEmbedded(embMmd, embcmd, sm, fieldNumber);
            FieldManager ffm = new FetchEmbeddedFieldManager(embSM, dbObject, embMmd);
            embSM.replaceFields(embcmd.getAllMemberPositions(), ffm);
            return embSM.getObject();
        }

        String fieldName = MongoDBUtils.getFieldName(ownerMmd, fieldNumber);
        if (!dbObject.containsField(fieldName))
        {
View Full Code Here

            }, null, ignoreCache);

        if (cmd.hasVersionStrategy())
        {
            // Set the version on the retrieved object
            ObjectProvider sm = ec.findObjectProvider(pc);
            Object version = null;
            if (cmd.getVersionMetaData().getFieldName() != null)
            {
                // Get the version from the field value
                AbstractMemberMetaData verMmd = cmd.getMetaDataForMember(cmd.getVersionMetaData().getFieldName());
                version = sm.provideField(verMmd.getAbsoluteFieldNumber());
            }
            else
            {
                // Get the surrogate version from the datastore
                version = dbObject.get(MongoDBUtils.getFieldName(cmd.getVersionMetaData()));
            }
            sm.setVersion(version);
        }
        return pc;
    }
View Full Code Here

            }, null, ignoreCache);

        if (cmd.hasVersionStrategy())
        {
            // Set the version on the retrieved object
            ObjectProvider sm = ec.findObjectProvider(pc);
            Object version = null;
            if (cmd.getVersionMetaData().getFieldName() != null)
            {
                // Get the version from the field value
                AbstractMemberMetaData verMmd = cmd.getMetaDataForMember(cmd.getVersionMetaData().getFieldName());
                version = sm.provideField(verMmd.getAbsoluteFieldNumber());
            }
            else
            {
                // Get the surrogate version from the datastore
                version = dbObject.get(MongoDBUtils.getFieldName(cmd.getVersionMetaData()));
            }
            sm.setVersion(version);
        }
        return pc;
    }
View Full Code Here

                        // TODO Delete any fields for the embedded object
                        return;
                    }
                }

                ObjectProvider embSM = ec.findObjectProviderForEmbedded(value, sm, mmd);

                if (nested)
                {
                    // Nested embedding, as nested document
                    BasicDBObject embeddedObject = new BasicDBObject();
                    StoreFieldManager sfm = new StoreFieldManager(embSM, embeddedObject, embcmd);
                    sfm.ownerMmd = mmd;
                    embSM.provideFields(embcmd.getAllMemberPositions(), sfm);
                    dbObject.put(fieldName, embeddedObject);
                    return;
                }
                else
                {
                    // Flat embedding as fields of the owning document
                    FieldManager ffm = new StoreEmbeddedFieldManager(embSM, dbObject, mmd);
                    embSM.provideFields(embcmd.getAllMemberPositions(), ffm);
                    return;
                }
            }
            else if (Relation.isRelationMultiValued(relationType))
            {
                if (value == null)
                {
                    dbObject.removeField(MongoDBUtils.getFieldName(mmd));
                    return;
                }

                if (ownerMmd != null && Relation.isBidirectional(relationType))
                {
                    if ((ownerMmd.getMappedBy() != null && mmd.getName().equals(ownerMmd.getMappedBy())) ||
                        (mmd.getMappedBy() != null && ownerMmd.getName().equals(mmd.getMappedBy())))
                    {
                        // Other side of owner bidirectional, so omit
                        // TODO Need to store the collection somehow since no way of getting it back after
                        return;
                    }
                }

                if (mmd.hasCollection())
                {
                    AbstractClassMetaData embcmd = mmd.getCollection().getElementClassMetaData(clr, ec.getMetaDataManager());
                    Collection coll = new ArrayList();
                    Collection valueColl = (Collection)value;
                    Iterator collIter = valueColl.iterator();
                    while (collIter.hasNext())
                    {
                        Object element = collIter.next();
                        ObjectProvider embSM = ec.findObjectProviderForEmbedded(element, sm, mmd);
                        embSM.setPcObjectType(ObjectProvider.EMBEDDED_COLLECTION_ELEMENT_PC);
                        BasicDBObject embeddedObject = new BasicDBObject();
                        StoreFieldManager sfm = new StoreFieldManager(embSM, embeddedObject, embcmd);
                        sfm.ownerMmd = mmd;
                        embSM.provideFields(embcmd.getAllMemberPositions(), sfm);
                        coll.add(embeddedObject);
                    }
                    dbObject.put(fieldName, coll); // Store as List<DBObject>
                    return;
                }
                else if (mmd.hasArray())
                {
                    AbstractClassMetaData embcmd = mmd.getArray().getElementClassMetaData(clr, ec.getMetaDataManager());
                    Object[] array = new Object[Array.getLength(value)];
                    for (int i=0;i<array.length;i++)
                    {
                        Object element = Array.get(value, i);
                        ObjectProvider embSM = ec.findObjectProviderForEmbedded(element, sm, mmd);
                        embSM.setPcObjectType(ObjectProvider.EMBEDDED_COLLECTION_ELEMENT_PC);
                        BasicDBObject embeddedObject = new BasicDBObject();
                        StoreFieldManager sfm = new StoreFieldManager(embSM, embeddedObject, embcmd);
                        sfm.ownerMmd = mmd;
                        embSM.provideFields(embcmd.getAllMemberPositions(), sfm);
                        array[i] = embeddedObject;
                    }
                    dbObject.put(fieldName, array); // Store as DBObject[]
                    return;
                }
                else
                {
                    AbstractClassMetaData keyCmd = mmd.getMap().getKeyClassMetaData(clr, ec.getMetaDataManager());
                    AbstractClassMetaData valCmd = mmd.getMap().getValueClassMetaData(clr, ec.getMetaDataManager());

                    Collection entryList = new ArrayList();
                    Map valueMap = (Map)value;
                    Iterator<Map.Entry> mapEntryIter = valueMap.entrySet().iterator();
                    while (mapEntryIter.hasNext())
                    {
                        Map.Entry entry = mapEntryIter.next();
                        BasicDBObject entryObj = new BasicDBObject();

                        if (keyCmd == null)
                        {
                            processContainerNonRelationField("key", ec, entry.getKey(), entryObj);
                        }
                        else
                        {
                            ObjectProvider embSM = ec.findObjectProviderForEmbedded(entry.getKey(), sm, mmd);
                            embSM.setPcObjectType(ObjectProvider.EMBEDDED_MAP_KEY_PC);
                            BasicDBObject embeddedKey = new BasicDBObject();
                            StoreFieldManager sfm = new StoreFieldManager(embSM, embeddedKey, keyCmd);
                            sfm.ownerMmd = mmd;
                            embSM.provideFields(keyCmd.getAllMemberPositions(), sfm);
                            entryObj.append("key", embeddedKey);
                        }

                        if (valCmd == null)
                        {
                            processContainerNonRelationField("value", ec, entry.getValue(), entryObj);
                        }
                        else
                        {
                            ObjectProvider embSM = ec.findObjectProviderForEmbedded(entry.getValue(), sm, mmd);
                            embSM.setPcObjectType(ObjectProvider.EMBEDDED_MAP_VALUE_PC);
                            BasicDBObject embeddedVal = new BasicDBObject();
                            StoreFieldManager sfm = new StoreFieldManager(embSM, embeddedVal, valCmd);
                            sfm.ownerMmd = mmd;
                            embSM.provideFields(valCmd.getAllMemberPositions(), sfm);
                            entryObj.append("value", embeddedVal);
                        }
                        entryList.add(entryObj);
                    }
                    dbObject.put(fieldName, entryList);
View Full Code Here

                    {
                        return null;
                    }

                    DBObject embeddedValue = (DBObject)dbObject.get(fieldName);
                    ObjectProvider embSM = ec.newObjectProviderForEmbedded(mmd, embcmd, sm, fieldNumber);
                    FetchFieldManager ffm = new FetchFieldManager(embSM, embeddedValue, embcmd);
                    ffm.ownerMmd = mmd;
                    ffm.embedded = true;
                    embSM.replaceFields(embcmd.getAllMemberPositions(), ffm);
                    return embSM.getObject();
                }
                else
                {
                    // Flat embedding as fields of the owning document

                    // TODO Cater for null (use embmd.getNullIndicatorColumn/Value)
                    EmbeddedMetaData embmd = mmd.getEmbeddedMetaData();
                    AbstractMemberMetaData[] embmmds = embmd.getMemberMetaData();
                    boolean isNull = true;
                    for (int i=0;i<embmmds.length;i++)
                    {
                        String embFieldName = MongoDBUtils.getFieldName(mmd, i);
                        if (dbObject.containsField(embFieldName))
                        {
                            isNull = false;
                            break;
                        }
                    }
                    if (isNull)
                    {
                        return null;
                    }

                    ObjectProvider embSM = ec.newObjectProviderForEmbedded(mmd, embcmd, sm, fieldNumber);
                    FieldManager ffm = new FetchEmbeddedFieldManager(embSM, dbObject, mmd);
                    embSM.replaceFields(embcmd.getAllMemberPositions(), ffm);
                    return embSM.getObject();
                }
            }
            else if (Relation.isRelationMultiValued(relationType))
            {
                if (mmd.hasCollection())
                {
                    String fieldName = MongoDBUtils.getFieldName(mmd);
                    if (!dbObject.containsField(fieldName))
                    {
                        return null;
                    }
                    Object value = dbObject.get(fieldName);
                    Collection<Object> coll;
                    AbstractClassMetaData elemCmd = mmd.getCollection().getElementClassMetaData(clr, ec.getMetaDataManager());
                    try
                    {
                        Class instanceType = SCOUtils.getContainerInstanceType(mmd.getType(), mmd.getOrderMetaData() != null);
                        coll = (Collection<Object>) instanceType.newInstance();
                    }
                    catch (Exception e)
                    {
                        throw new NucleusDataStoreException(e.getMessage(), e);
                    }

                    Collection collValue = (Collection)value;
                    Iterator collIter = collValue.iterator();
                    while (collIter.hasNext())
                    {
                        DBObject elementObj = (DBObject)collIter.next();
                        ObjectProvider embSM = ec.newObjectProviderForEmbedded(mmd, elemCmd, sm, fieldNumber);
                        embSM.setPcObjectType(ObjectProvider.EMBEDDED_COLLECTION_ELEMENT_PC);
                        FetchFieldManager ffm = new FetchFieldManager(embSM, elementObj, elemCmd);
                        ffm.ownerMmd = mmd;
                        ffm.embedded = true;
                        embSM.replaceFields(elemCmd.getAllMemberPositions(), ffm);
                        coll.add(embSM.getObject());
                    }

                    if (sm != null)
                    {
                        return sm.wrapSCOField(fieldNumber, coll, false, false, true);
                    }
                    return coll;
                }
                else if (mmd.hasArray())
                {
                    String fieldName = MongoDBUtils.getFieldName(mmd);
                    if (!dbObject.containsField(fieldName))
                    {
                        return null;
                    }

                    AbstractClassMetaData elemCmd = mmd.getArray().getElementClassMetaData(clr, ec.getMetaDataManager());
                    Object value = dbObject.get(fieldName);
                    Object[] array = new Object[Array.getLength(value)];
                    for (int i=0;i<array.length;i++)
                    {
                        DBObject elementObj = (DBObject)Array.get(value, i);
                        ObjectProvider embSM = ec.newObjectProviderForEmbedded(mmd, elemCmd, sm, fieldNumber);
                        embSM.setPcObjectType(ObjectProvider.EMBEDDED_COLLECTION_ELEMENT_PC);
                        FetchFieldManager ffm = new FetchFieldManager(embSM, elementObj, elemCmd);
                        ffm.ownerMmd = mmd;
                        ffm.embedded = true;
                        embSM.replaceFields(elemCmd.getAllMemberPositions(), ffm);
                        array[i] = embSM.getObject();
                    }

                    return array;
                }
                else
                {
                    String fieldName = MongoDBUtils.getFieldName(mmd);
                    if (!dbObject.containsField(fieldName))
                    {
                        return null;
                    }
                    Object value = dbObject.get(fieldName);
                    Map map = null;
                    try
                    {
                        Class instanceType = SCOUtils.getContainerInstanceType(mmd.getType(), null);
                        map = (Map) instanceType.newInstance();
                    }
                    catch (Exception e)
                    {
                        throw new NucleusDataStoreException(e.getMessage(), e);
                    }

                    AbstractClassMetaData keyCmd = mmd.getMap().getKeyClassMetaData(clr, ec.getMetaDataManager());
                    AbstractClassMetaData valCmd = mmd.getMap().getValueClassMetaData(clr, ec.getMetaDataManager());
                    Collection<DBObject> entryColl = (Collection)value;
                    Iterator<DBObject> entryIter = entryColl.iterator();
                    while (entryIter.hasNext())
                    {
                        DBObject entryObj = entryIter.next();
                        Object keyObj = entryObj.get("key");
                        Object valObj = entryObj.get("value");

                        Object mapKey = null;
                        if (keyCmd != null)
                        {
                            // Key is embedded object
                            DBObject keyDbObj = (DBObject)keyObj;
                            ObjectProvider embSM = ec.newObjectProviderForEmbedded(mmd, keyCmd, sm, fieldNumber);
                            embSM.setPcObjectType(ObjectProvider.EMBEDDED_MAP_KEY_PC);
                            FetchFieldManager ffm = new FetchFieldManager(embSM, keyDbObj, keyCmd);
                            ffm.ownerMmd = mmd;
                            ffm.embedded = true;
                            embSM.replaceFields(keyCmd.getAllMemberPositions(), ffm);
                            mapKey = embSM.getObject();
                        }
                        else
                        {
                            mapKey = getMapKeyForReturnValue(mmd, keyObj);
                        }

                        Object mapVal = null;
                        if (valCmd != null)
                        {
                            // Value is embedded object
                            DBObject valDbObj = (DBObject)valObj;
                            ObjectProvider embSM = ec.newObjectProviderForEmbedded(mmd, valCmd, sm, fieldNumber);
                            embSM.setPcObjectType(ObjectProvider.EMBEDDED_MAP_VALUE_PC);
                            FetchFieldManager ffm = new FetchFieldManager(embSM, valDbObj, valCmd);
                            ffm.ownerMmd = mmd;
                            ffm.embedded = true;
                            embSM.replaceFields(valCmd.getAllMemberPositions(), ffm);
                            mapVal = embSM.getObject();
                        }
                        else
                        {
                            mapVal = getMapValueForReturnValue(mmd, valObj);
                        }
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.