Package org.datanucleus.enhancer
Class EnhancementHelper
java.lang.Object
org.datanucleus.enhancer.EnhancementHelper
Helper class for the DN bytecode enhancement contract.
It contains methods to register metadata for persistable classes and to perform common operations needed by implementations, not by end users.
It allows construction of instances of persistable classes without using reflection.
Persistable classes register themselves via a static method at class load time. There is no security restriction on this access. TODO Provide a mechanism to automatically deregister classes when their class loader exits? or register against the NucleusContext?
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescription(package private) static class
Helper class to manage persistable classes.static interface
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final List
<EnhancementHelper.RegisterClassListener> This list contains the registered listeners forRegisterClassEvent
s.private static Map
<Class, EnhancementHelper.Meta> Static mapping ofPersistable
class to an instance of that class.private static EnhancementHelper
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
Add the specifiedRegisterClassListener
to the listener list.static EnhancementHelper
private static Persistable
getPersistableForClass
(Class pcClass) Look up the instance for a Persistable class.Returns a collection of class objects of the registered persistable classes.newInstance
(Class pcClass, StateManager sm) Create a new instance of the class and assign its StateManager.newInstance
(Class pcClass, StateManager sm, Object oid) Create a new instance of the class and assign its StateManager and key values from the ObjectId.newObjectIdInstance
(Class pcClass) Create a new instance of the ObjectId class of thisPersistable
class.newObjectIdInstance
(Class pcClass, Object obj) Create a new instance of the class used by the parameter Class for JDO identity, using the key constructor of the object id class.static void
registerClass
(Class pcClass, Persistable pc) Register metadata by class.void
Remove the specifiedRegisterClassListener
from the listener list.void
Unregister all classes for the specified class loader.
-
Field Details
-
singletonHelper
-
registeredClasses
Static mapping ofPersistable
class to an instance of that class. New entries are added by the static method in eachPersistable
class initialisation. Entries are never removed. -
listeners
This list contains the registered listeners forRegisterClassEvent
s.
-
-
Constructor Details
-
EnhancementHelper
private EnhancementHelper()
-
-
Method Details
-
getInstance
-
newInstance
Create a new instance of the class and assign its StateManager.- Parameters:
pcClass
- thePersistable
class.sm
- theStateManager
which will own the new instance.- Returns:
- the new instance, or
null
if the class is not registered. - See Also:
-
newInstance
Create a new instance of the class and assign its StateManager and key values from the ObjectId. If the oid parameter isnull
, no key values are copied. The new instance has itsdnFlags
set toLOAD_REQUIRED
.- Parameters:
pcClass
- thePersistable
class.sm
- theStateManager
which will own the new instance.oid
- the ObjectId instance from which to copy key field values.- Returns:
- the new instance, or
null
if the class is not registered. - See Also:
-
newObjectIdInstance
Create a new instance of the ObjectId class of thisPersistable
class. It is intended only for application identity. This method should not be called for classes that use single field identity; newObjectIdInstance(Class, Object) should be used instead. If the class has been enhanced for datastore identity, or if the class is abstract, null is returned.- Parameters:
pcClass
- thePersistable
class.- Returns:
- the new ObjectId instance, or
null
if the class is not registered.
-
newObjectIdInstance
Create a new instance of the class used by the parameter Class for JDO identity, using the key constructor of the object id class. It is intended for single field identity. The identity instance returned has no relationship with the values of the primary key fields of the persistence-capable instance on which the method is called. If the key is the wrong class for the object id class, null is returned.For classes that use single field identity, if the parameter is of one of the following types, the behavior must be as specified:
Number
orCharacter
: the parameter must be the single field type or the wrapper class of the primitive field type; the parameter is passed to the single field identity constructorObjectIdFieldSupplier
: the field value is fetched from theObjectIdFieldSupplier
and passed to the single field identity constructorString
: the String is passed to the single field identity constructor
- Parameters:
pcClass
- thePersistable
class.obj
- theObject
form of the object id- Returns:
- the new ObjectId instance, or
null
if the class is not registered.
-
registerClass
Register metadata by class. This is called by the enhanced constructor of thePersistable
class.- Parameters:
pcClass
- thePersistable
class used as the key for lookup.pc
- an instance of thePersistable
class. TODO We can just do pcClass.newInstance() to get one!
-
unregisterClasses
Unregister all classes for the specified class loader.- Parameters:
cl
- ClassLoader
-
addRegisterClassListener
Add the specifiedRegisterClassListener
to the listener list.- Parameters:
crl
- the listener to be added
-
removeRegisterClassListener
Remove the specifiedRegisterClassListener
from the listener list.- Parameters:
crl
- the listener to be removed
-
getRegisteredClasses
Returns a collection of class objects of the registered persistable classes.- Returns:
- registered persistable classes
-
getPersistableForClass
Look up the instance for a Persistable class.- Parameters:
pcClass
- theClass
.- Returns:
- the Persistable instance for the
Class
.
-