Package org.datanucleus.state
Class ObjectProviderFactoryImpl
- java.lang.Object
-
- org.datanucleus.state.ObjectProviderFactoryImpl
-
- All Implemented Interfaces:
ObjectProviderFactory
public class ObjectProviderFactoryImpl extends Object implements ObjectProviderFactory
Factory for ObjectProviders. Makes use of a pool to allow reuse to save recreation of objects.
-
-
Field Summary
Fields Modifier and Type Field Description static Class[]
OBJECT_PROVIDER_CTR_ARG_CLASSES
-
Constructor Summary
Constructors Constructor Description ObjectProviderFactoryImpl(PersistenceNucleusContext nucCtx)
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description void
close()
void
disconnectObjectProvider(ObjectProvider op)
Hook to allow an ObjectProvider to mark itself as disconnected so that it is returned to the pool.protected ObjectProvider
getObjectProvider(ExecutionContext ec, AbstractClassMetaData cmd)
<T> ObjectProvider<T>
newForCachedPC(ExecutionContext ec, Object id, CachedPC cachedPC)
Constructor to create an ObjectProvider for an object taken from the L2 cache with the specified id.<T> ObjectProvider<T>
newForDetached(ExecutionContext ec, T pc, Object id, Object version)
Constructor for creating an ObjectProvider to manage a persistable object in detached state.ObjectProvider
newForEmbedded(ExecutionContext ec, AbstractClassMetaData cmd, ObjectProvider ownerOP, int ownerFieldNumber)
Constructs an ObjectProvider for an object of the specified type, creating the PC object to hold the values where this object will be EMBEDDED/SERIALISED into another persistable object.<T> ObjectProvider<T>
newForEmbedded(ExecutionContext ec, T pc, boolean copyPc, ObjectProvider ownerOP, int ownerFieldNumber)
Constructs an ObjectProvider to manage a persistable instance that will be EMBEDDED/SERIALISED into another persistable object.<T> ObjectProvider<T>
newForHollow(ExecutionContext ec, Class<T> pcClass, Object id)
Constructs an ObjectProvider to manage a hollow instance having the given object ID.<T> ObjectProvider<T>
newForHollow(ExecutionContext ec, Class<T> pcClass, Object id, FieldValues fv)
Constructs an ObjectProvider to manage a recently populated hollow instance having the given object ID and the given field values.<T> ObjectProvider<T>
newForHollowPopulatedAppId(ExecutionContext ec, Class<T> pcClass, FieldValues fv)
Deprecated.Use newForHollowPopulated instead<T> ObjectProvider<T>
newForHollowPreConstructed(ExecutionContext ec, Object id, T pc)
Constructs an ObjectProvider to manage a hollow instance having the given object ID.<T> ObjectProvider<T>
newForPersistentClean(ExecutionContext ec, Object id, T pc)
Constructs an ObjectProvider to manage the specified persistent instance having the given object ID.<T> ObjectProvider<T>
newForPersistentNew(ExecutionContext ec, T pc, FieldValues preInsertChanges)
Constructs an ObjectProvider to manage a transient instance that is becoming newly persistent.<T> ObjectProvider<T>
newForPNewToBeDeleted(ExecutionContext ec, T pc)
Constructor for creating an ObjectProvider to manage a persistable object that is not persistent yet is about to be deleted.<T> ObjectProvider<T>
newForTransactionalTransient(ExecutionContext ec, T pc)
Constructs an ObjectProvider to manage a transactional-transient instance.
-
-
-
Field Detail
-
OBJECT_PROVIDER_CTR_ARG_CLASSES
public static final Class[] OBJECT_PROVIDER_CTR_ARG_CLASSES
-
-
Constructor Detail
-
ObjectProviderFactoryImpl
public ObjectProviderFactoryImpl(PersistenceNucleusContext nucCtx)
-
-
Method Detail
-
close
public void close()
- Specified by:
close
in interfaceObjectProviderFactory
-
newForHollow
public <T> ObjectProvider<T> newForHollow(ExecutionContext ec, Class<T> pcClass, Object id)
Constructs an ObjectProvider to manage a hollow instance having the given object ID. This constructor is used for creating new instances of existing persistent objects.- Specified by:
newForHollow
in interfaceObjectProviderFactory
- Type Parameters:
T
- Type of the persistable class- Parameters:
ec
- the ExecutionContextpcClass
- the class of the new instance to be created.id
- the identity of the object.- Returns:
- The ObjectProvider
-
newForHollow
public <T> ObjectProvider<T> newForHollow(ExecutionContext ec, Class<T> pcClass, Object id, FieldValues fv)
Constructs an ObjectProvider to manage a recently populated hollow instance having the given object ID and the given field values. This constructor is used for creating new instances of persistent objects obtained e.g. via a Query or backed by a view.- Specified by:
newForHollow
in interfaceObjectProviderFactory
- Type Parameters:
T
- Type of the persistable class- Parameters:
ec
- ExecutionContextpcClass
- the class of the new instance to be created.id
- the identity of the object.fv
- the initial field values of the object.- Returns:
- The ObjectProvider
-
newForHollowPreConstructed
public <T> ObjectProvider<T> newForHollowPreConstructed(ExecutionContext ec, Object id, T pc)
Constructs an ObjectProvider to manage a hollow instance having the given object ID. The instance is already supplied.- Specified by:
newForHollowPreConstructed
in interfaceObjectProviderFactory
- Type Parameters:
T
- Type of the persistable class- Parameters:
ec
- ExecutionContextid
- the identity of the object.pc
- The object that is hollow that we are going to manage- Returns:
- The ObjectProvider
-
newForHollowPopulatedAppId
public <T> ObjectProvider<T> newForHollowPopulatedAppId(ExecutionContext ec, Class<T> pcClass, FieldValues fv)
Deprecated.Use newForHollowPopulated insteadConstructs an ObjectProvider to manage a hollow (or P-clean) instance having the given FieldValues. This constructor is used for creating new instances of existing persistent objects using application identity.- Specified by:
newForHollowPopulatedAppId
in interfaceObjectProviderFactory
- Type Parameters:
T
- Type of the persistable class- Parameters:
ec
- ExecutionContextpcClass
- the class of the new instance to be created.fv
- the initial field values of the object.- Returns:
- The ObjectProvider
-
newForPersistentClean
public <T> ObjectProvider<T> newForPersistentClean(ExecutionContext ec, Object id, T pc)
Constructs an ObjectProvider to manage the specified persistent instance having the given object ID.- Specified by:
newForPersistentClean
in interfaceObjectProviderFactory
- Type Parameters:
T
- Type of the persistable class- Parameters:
ec
- ExecutionContextid
- the identity of the object.pc
- The object that is persistent that we are going to manage- Returns:
- The ObjectProvider
-
newForEmbedded
public <T> ObjectProvider<T> newForEmbedded(ExecutionContext ec, T pc, boolean copyPc, ObjectProvider ownerOP, int ownerFieldNumber)
Constructs an ObjectProvider to manage a persistable instance that will be EMBEDDED/SERIALISED into another persistable object. The instance will not be assigned an identity in the process since it is a SCO.- Specified by:
newForEmbedded
in interfaceObjectProviderFactory
- Type Parameters:
T
- Type of the persistable class- Parameters:
ec
- ExecutionContextpc
- The persistable to manage (see copyPc also)copyPc
- Whether the SM should manage a copy of the passed PC or that oneownerOP
- Owner ObjectProviderownerFieldNumber
- Field number in owner object where this is stored- Returns:
- The ObjectProvider
-
newForEmbedded
public ObjectProvider newForEmbedded(ExecutionContext ec, AbstractClassMetaData cmd, ObjectProvider ownerOP, int ownerFieldNumber)
Constructs an ObjectProvider for an object of the specified type, creating the PC object to hold the values where this object will be EMBEDDED/SERIALISED into another persistable object. The instance will not be assigned an identity in the process since it is a SCO.- Specified by:
newForEmbedded
in interfaceObjectProviderFactory
- Parameters:
ec
- ExecutionContextcmd
- Meta-data for the class that this is an instance of.ownerOP
- Owner ObjectProviderownerFieldNumber
- Field number in owner object where this is stored- Returns:
- The ObjectProvider
-
newForPersistentNew
public <T> ObjectProvider<T> newForPersistentNew(ExecutionContext ec, T pc, FieldValues preInsertChanges)
Constructs an ObjectProvider to manage a transient instance that is becoming newly persistent. A new object ID for the instance is obtained from the store manager and the object is inserted in the data store. This constructor is used for assigning ObjectProviders to existing instances that are transitioning to a persistent state.- Specified by:
newForPersistentNew
in interfaceObjectProviderFactory
- Type Parameters:
T
- Type of the persistable class- Parameters:
ec
- ExecutionContextpc
- the instance being make persistent.preInsertChanges
- Any changes to make before inserting- Returns:
- The ObjectProvider
-
newForTransactionalTransient
public <T> ObjectProvider<T> newForTransactionalTransient(ExecutionContext ec, T pc)
Constructs an ObjectProvider to manage a transactional-transient instance. A new object ID for the instance is obtained from the store manager and the object is inserted in the data store. This constructor is used for assigning an ObjectProvider to a transient instance that is transitioning to a transient clean state.- Specified by:
newForTransactionalTransient
in interfaceObjectProviderFactory
- Type Parameters:
T
- Type of the persistable class- Parameters:
ec
- ExecutionContextpc
- the instance being make persistent.- Returns:
- The ObjectProvider
-
newForDetached
public <T> ObjectProvider<T> newForDetached(ExecutionContext ec, T pc, Object id, Object version)
Constructor for creating an ObjectProvider to manage a persistable object in detached state.- Specified by:
newForDetached
in interfaceObjectProviderFactory
- Type Parameters:
T
- Type of the persistable class- Parameters:
ec
- ExecutionContextpc
- the detached objectid
- the identity of the object.version
- the detached version- Returns:
- The ObjectProvider
-
newForPNewToBeDeleted
public <T> ObjectProvider<T> newForPNewToBeDeleted(ExecutionContext ec, T pc)
Constructor for creating an ObjectProvider to manage a persistable object that is not persistent yet is about to be deleted. Consequently the initial lifecycle state will be P_NEW, but will soon move to P_NEW_DELETED.- Specified by:
newForPNewToBeDeleted
in interfaceObjectProviderFactory
- Type Parameters:
T
- Type of the persistable class- Parameters:
ec
- Execution Contextpc
- the object being deleted from persistence- Returns:
- The ObjectProvider
-
newForCachedPC
public <T> ObjectProvider<T> newForCachedPC(ExecutionContext ec, Object id, CachedPC cachedPC)
Constructor to create an ObjectProvider for an object taken from the L2 cache with the specified id. Creates an object that the cached object represents, assigns a ObjectProvider to it, and copies across the fields that were cached, and its version (if available).- Specified by:
newForCachedPC
in interfaceObjectProviderFactory
- Type Parameters:
T
- Type of the persistable class- Parameters:
ec
- ExecutionContextid
- Id to assign to the persistable objectcachedPC
- CachedPC object from the L2 cache- Returns:
- The ObjectProvider
-
disconnectObjectProvider
public void disconnectObjectProvider(ObjectProvider op)
Hook to allow an ObjectProvider to mark itself as disconnected so that it is returned to the pool.- Specified by:
disconnectObjectProvider
in interfaceObjectProviderFactory
- Parameters:
op
- The ObjectProvider to re-pool
-
getObjectProvider
protected ObjectProvider getObjectProvider(ExecutionContext ec, AbstractClassMetaData cmd)
-
-