Package org.datanucleus.store

Examples of org.datanucleus.store.ObjectProvider


            }
            stmtMapping.addParameterOccurrence(jdbcParamPositions);
            mappingDefinition.addMappingForMember(absFieldNum, stmtMapping);
        }

        ObjectProvider elementSM = bcs.getStateManagerForEmbeddedPCObject(sm, element, ownerFieldMetaData,
            ObjectProvider.EMBEDDED_COLLECTION_ELEMENT_PC);
        MappedStoreManager storeMgr = (MappedStoreManager)sm.getExecutionContext().getStoreManager();
        elementSM.provideFields(elementFieldNumbers,
            storeMgr.getFieldManagerForStatementGeneration(elementSM, ps, mappingDefinition, true));

        return jdbcPosition;
    }
View Full Code Here


            }
            stmtMapping.addParameterOccurrence(jdbcParamPositions);
            mappingDefinition.addMappingForMember(absFieldNum, stmtMapping);
        }

        ObjectProvider elementSM = mapStore.getStateManagerForEmbeddedPCObject(sm, key,
            joinTable.getOwnerMemberMetaData(), ObjectProvider.EMBEDDED_MAP_KEY_PC);
        MappedStoreManager storeMgr = (MappedStoreManager)sm.getExecutionContext().getStoreManager();
        elementSM.provideFields(elementFieldNumbers,
            storeMgr.getFieldManagerForStatementGeneration(elementSM, ps, mappingDefinition, true));

        return jdbcPosition;
    }
View Full Code Here

            }
            stmtMapping.addParameterOccurrence(jdbcParamPositions);
            mappingDefinition.addMappingForMember(absFieldNum, stmtMapping);
        }

        ObjectProvider elementSM = mapStore.getStateManagerForEmbeddedPCObject(sm, value,
            joinTable.getOwnerMemberMetaData(), ObjectProvider.EMBEDDED_MAP_VALUE_PC);
        MappedStoreManager storeMgr = (MappedStoreManager)sm.getExecutionContext().getStoreManager();
        elementSM.provideFields(elementFieldNumbers,
            storeMgr.getFieldManagerForStatementGeneration(elementSM, ps, mappingDefinition, true));

        return jdbcPosition;
    }
View Full Code Here

        if (obj != null && needToSetVersion)
        {
            // Set the version of the object where possible
            if (surrogateVersion != null)
            {
                ObjectProvider objSM = ec.findObjectProvider(obj);
                objSM.setVersion(surrogateVersion);
            }
            else
            {
                if (vermd != null && vermd.getFieldName() != null)
                {
                    // Version stored in a normal field
                    int versionFieldNumber = acmd.getMetaDataForMember(vermd.getFieldName()).getAbsoluteFieldNumber();
                    if (stmtMapping.getMappingForMemberPosition(versionFieldNumber) != null)
                    {
                        ObjectProvider objSM = ec.findObjectProvider(obj);
                        Object verFieldValue = objSM.provideField(versionFieldNumber);
                        if (verFieldValue != null)
                        {
                            objSM.setVersion(verFieldValue);
                        }
                    }
                }
            }
        }
View Full Code Here

        if (obj != null)
        {
            Object paramFieldValue = null;
            if (ec.getApiAdapter().isPersistable(obj))
            {
                ObjectProvider paramSM = ec.findObjectProvider(obj);
                AbstractClassMetaData paramCmd = ec.getMetaDataManager().getMetaDataForClass(obj.getClass(), clr);
                AbstractMemberMetaData paramFieldMmd = paramCmd.getMetaDataForMember(fieldName);
                if (paramSM != null)
                {
                    ec.getApiAdapter().isLoaded(paramSM, paramFieldMmd.getAbsoluteFieldNumber());
                    paramFieldValue = paramSM.provideField(paramFieldMmd.getAbsoluteFieldNumber());
                }
                else
                {
                    paramFieldValue = ClassUtils.getValueOfFieldByReflection(obj, fieldName);
                }
View Full Code Here

     * @param op the current StateManager
     */
    public void insertPostProcessing(ObjectProvider op)
    {
        Object value = op.provideField(mmd.getAbsoluteFieldNumber());
        ObjectProvider sm = null;
        if (value != null)
        {
            sm = op.getExecutionContext().findObjectProvider(value);
            if (sm == null || sm.getExecutionContext().getApiAdapter().getExecutionContext(value) == null)
            {
                // Assign a StateManager to the serialised object since none present
                sm = ObjectProviderFactory.newForEmbedded(op.getExecutionContext(), value, false, op, mmd.getAbsoluteFieldNumber());
            }
        }

        if (sm != null)
        {
            sm.setStoringPC();
        }

        // Generate the contents for the BLOB
        byte[] bytes = new byte[0];
        if (value != null)
        {
            try
            {
                ByteArrayOutputStream baos = new ByteArrayOutputStream();
                ObjectOutputStream oos = new ObjectOutputStream(baos);
                oos.writeObject(value);
                bytes = baos.toByteArray();
            }
            catch (IOException e1)
            {
                // Do Nothing
            }
        }

        // Update the BLOB
        OracleBlobRDBMSMapping.updateBlobColumn(op, getDatastoreContainer(), getDatastoreMapping(0), bytes);

        if (sm != null)
        {
            sm.unsetStoringPC();
        }
    }
View Full Code Here

            {
                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

     */
    public ObjectProvider getStateManagerForEmbeddedPCObject(ObjectProvider sm, Object obj,
            AbstractMemberMetaData ownerMmd, short pcType)
    {
        ExecutionContext ec = sm.getExecutionContext();
        ObjectProvider objSM = ec.findObjectProvider(obj);
        if (objSM == null)
        {
            objSM = ObjectProviderFactory.newForEmbedded(ec, obj, false, sm, ownerMmd.getAbsoluteFieldNumber());
        }
        objSM.setPcObjectType(pcType);
        return objSM;
    }
View Full Code Here

                        // Update any detached reference to refer to the attached variant
                        ownerSM.replaceFieldMakeDirty(ownerFieldNumber, pcNew);
                        int relationType = mmd.getRelationType(clr);
                        if (relationType == Relation.ONE_TO_ONE_BI)
                        {
                            ObjectProvider relatedSM = ec.findObjectProvider(pcNew);
                            AbstractMemberMetaData[] relatedMmds = mmd.getRelatedMemberMetaData(clr);
                            // TODO Allow for multiple related fields
                            relatedSM.replaceFieldMakeDirty(relatedMmds[0].getAbsoluteFieldNumber(), ownerSM.getObject());
                        }
                        else if (relationType == Relation.MANY_TO_ONE_BI)
                        {
                            // TODO Update the container element with the attached variant
                            if (NucleusLogger.PERSISTENCE.isDebugEnabled())
                            {
                                NucleusLogger.PERSISTENCE.debug("PCMapping.setObject : object " + ownerSM.getInternalObjectId() +
                                    " has field " + ownerFieldNumber +
                                    " that is 1-N bidirectional - should really update the reference in the relation. Not yet supported");
                            }
                        }
                    }
                }

                if (getNumberOfDatastoreMappings() <= 0)
                {
                    // If the field doesn't map to any datastore fields, omit the set process
                    return;
                }
            }
        }

        if (pos == null)
        {
            return;
        }

        // Obtain StateManager for the value (if persistable)
        ObjectProvider sm = null;
        if (value != null)
        {
            sm = ec.findObjectProvider(value);
        }

        try
        {
            if (sm != null)
            {
                sm.setStoringPC();
            }

            int n = 0;
            NotYetFlushedException notYetFlushed = null;
            for (int i=0; i<javaTypeMappings.length; i++)
            {
                // Set the PreparedStatement positions for this implementation mapping
                int[] posMapping;
                if (n >= pos.length)
                {
                    n = 0; // store all implementations to the same columns, so we reset the index
                }
                if (javaTypeMappings[i].getReferenceMapping() != null)
                {
                    posMapping = new int[javaTypeMappings[i].getReferenceMapping().getNumberOfDatastoreMappings()];
                }
                else
                {
                    posMapping = new int[javaTypeMappings[i].getNumberOfDatastoreMappings()];
                }
                for (int j=0; j<posMapping.length; j++)
                {
                    posMapping[j] = pos[n++];
                }

                try
                {
                    if (javaTypeMappingNumber == -2 || (value != null && javaTypeMappingNumber == i))
                    {
                        // This mapping is where the value is to be stored, or using persistent interfaces
                        javaTypeMappings[i].setObject(ec, ps, posMapping, value);
                    }
                    else
                    {
                        // Set null for this mapping, since the value is null or is for something else
                        javaTypeMappings[i].setObject(ec, ps, posMapping, null);
                    }
                }
                catch (NotYetFlushedException e)
                {
                    notYetFlushed = e;
                }
            }
            if (notYetFlushed != null)
            {
                throw notYetFlushed;
            }
        }
        finally
        {
            if (sm != null)
            {
                sm.unsetStoringPC();
            }
        }
    }
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.