Class ClassMolder
Persistence
. For example, when ClassMolder is asked to load
an object, it acquires the field values from Persistence
and binds
them into the target object.
It resolves relations via TransactionContext
and subsequently binds
these related objects into the target object, too.
Apart from loading, ClassMolder is also responsible for storing, removing, creating an object to and from a persistence storage, as well as reverting an object to its previous state.
Each instance of ClassMolder deals with exactly one persistable type,
interacts with one instance of Persistent and belongs to one
LockEngine
.
- Author:
- Thomas Yip, Bruce Snyder, Werner Guttmann
-
Field Summary
FieldsModifier and TypeFieldDescriptionboolean
Is a key kenerator used for the base class? -
Constructor Summary
ConstructorsConstructorDescriptionClassMolder
(DatingService ds, ClassDescriptorResolver classDescriptorResolver, LockEngine lock, ClassDescriptor classDescriptor, Persistence persistenceEngine) Creates an instance of this class. -
Method Summary
Modifier and TypeMethodDescription(package private) void
addDependent
(ClassMolder dep) Mutator method to add a dependent ClassMolder.(package private) void
addExtendent
(ClassMolder ext) Mutator method to add a extent ClassMolder.create
(TransactionContext tx, OID oid, DepositBox locker, Object object) Create an object of the base class with specified identity into the persistence storage.void
delete
(TransactionContext tx, OID oid) Delete an object of the base type from the persistence storage.void
expireCache
(TransactionContext tx, ObjectLock locker) Inspect the fields stored in the object passed as an argument for contained objects.getAccessMode
(AccessMode txMode) Get the effective accessMode of the the base type.getActualIdentity
(ClassLoader loader, Object o) Get the identity from a object of the base type.Get the identity from a object of the base type.Returns the active cache parameters.Get the callback interceptor of the base type.Get the depends class' ClassMolder.Get the extends class' ClassMolder.getIdentity
(TransactionContext tx, Object o) Get the identity from a object of the base type.Class<?>
getJavaClass
(ClassLoader loader) Get the base class of this ClassMolder given a ClassLoader.Get the LockEngine which this ClassMolder belongs to.getName()
Get the fully qualified name of the base type of this ClassMolder.getNamedNativeQuery
(String name) Returns the actual (SQL) statement for the specified named native query.getNamedQuery
(String name) Returns the actual (OQL) statement for the specified named query.Get the Persisetence of the base type.int
Determines the create priority of the data object class represented by this ClassMolder.boolean
isAssignableFrom
(Class<?> cls) check if the current ClassModlder is assignable from theclass
instance.boolean
isDefaultIdentity
(Identity identity) Test if the specified identity is the default value of the type.boolean
Return true if the base type of this ClassMolder is an dependent class.boolean
Return true if a key generator is used for the base type of this ClassMolder.boolean
Return true if a key generator is used for the base type of this ClassMolder.void
load
(TransactionContext tx, DepositBox locker, ProposedEntity proposedObject, AccessMode accessMode, QueryResults results) Loads the field values.void
loadTimeStamp
(TransactionContext tx, DepositBox locker, AccessMode suggestedAccessMode) void
markCreate
(TransactionContext tx, OID oid, DepositBox locker, Object object) Walk the object model and mark object that should be created.void
markDelete
(TransactionContext tx, OID oid, DepositBox locker, Object object) Prepare to delete an object with the specified identity.void
mold
(TransactionContext tx, DepositBox locker, ProposedEntity proposedObject, AccessMode accessMode) newInstance
(ClassLoader loader) Return a new instance of the base class with the provided ClassLoader object.boolean
preStore
(TransactionContext tx, OID oid, DepositBox locker, Object object, int timeout) Check the object for modification.boolean
removeRelation
(TransactionContext tx, Object object, ClassMolder relatedMolder, Object relatedObject) Remove the reference of a related object from an object of the base class.void
void
revertObject
(TransactionContext tx, OID oid, DepositBox locker, Object object) Revert the object back to the state of begining of the transaction If the object is loaded, it will be revert as it was loaded.(package private) void
setDepends
(ClassMolder dep) Mutator method to set the depends ClassMolder.(package private) void
setExtends
(ClassMolder ext) Mutator method to set the extends ClassMolder.void
setIdentity
(TransactionContext tx, Object object, Identity identity) Set the identity into an object.void
store
(TransactionContext tx, OID oid, DepositBox locker, Object object) Store a data object into the persistent storage of the base class of this ClassMolder.toString()
boolean
update
(TransactionContext tx, OID oid, DepositBox locker, Object object, AccessMode suggestedAccessMode) Update the object which loaded or created in the other transaction to the persistent storage.void
updateCache
(TransactionContext tx, OID oid, DepositBox locker, Object object) Update the dirty checking cache.
-
Field Details
-
_isKeyGenUsed
public boolean _isKeyGenUsedIs a key kenerator used for the base class?
-
-
Constructor Details
-
ClassMolder
ClassMolder(DatingService ds, ClassDescriptorResolver classDescriptorResolver, LockEngine lock, ClassDescriptor classDescriptor, Persistence persistenceEngine) throws ClassNotFoundException, MappingException Creates an instance of this class.- Parameters:
ds
- is the helper class for resolving depends and extends relationship among all the ClassMolder in the same LockEngine.classDescriptorResolver
-ClassDescriptorResolver
instancelock
- the lock engine.classDescriptor
- the classDescriptor for the base class.persistenceEngine
- the Persistence for the base class.- Throws:
ClassNotFoundException
- If a class cannot be loaded.MappingException
- if an error occurred with analyzing the mapping information.
-
-
Method Details
-
getClassDescriptor
-
removeRelation
public boolean removeRelation(TransactionContext tx, Object object, ClassMolder relatedMolder, Object relatedObject) Remove the reference of a related object from an object of the base class.If the related object is PersistanceCapable, the field will be set null. If the related object is a Collection, then the related object will be removed from the Collection.
If any changed occurred, transactionContext.markModified will be called, to indicate the object is modified.
It method will iterate through all of the object's field and try to remove all the occurrence.
- Parameters:
tx
- the TransactionContext of the transaction in actionobject
- the target object of the base type of this ClassMolderrelatedMolder
- the ClassMolder of the related object to be removed from the objectrelatedObject
- the object to be removed
-
getPriority
public int getPriority()Determines the create priority of the data object class represented by this ClassMolder. Concpetually, this method determines the order of which data object should be created. A priority of 0 indicates that an object represented by this ClassMolder can be created independently, without having to consider any other data object. This method should only be called after DatingService is closed. -
loadTimeStamp
public void loadTimeStamp(TransactionContext tx, DepositBox locker, AccessMode suggestedAccessMode) throws PersistenceException - Throws:
PersistenceException
-
load
public void load(TransactionContext tx, DepositBox locker, ProposedEntity proposedObject, AccessMode accessMode, QueryResults results) throws PersistenceException Loads the field values.- Parameters:
tx
- Currently active transaction contextlocker
- Current cache instanceproposedObject
- ProposedEntity instanceaccessMode
- Suggested access moderesults
- OQL QueryResults instance- Throws:
ObjectNotFoundException
- If the object in question cannot be found.PersistenceException
- For any other persistence-related problem.
-
mold
public void mold(TransactionContext tx, DepositBox locker, ProposedEntity proposedObject, AccessMode accessMode) throws PersistenceException - Throws:
PersistenceException
-
create
public Identity create(TransactionContext tx, OID oid, DepositBox locker, Object object) throws PersistenceException Create an object of the base class with specified identity into the persistence storage.- Parameters:
tx
- transaction in actionoid
- the object identity of the object to be created.locker
- the dirty checking cache of the objectobject
- the object to be created- Returns:
- the identity of the object
- Throws:
PersistenceException
-
markCreate
public void markCreate(TransactionContext tx, OID oid, DepositBox locker, Object object) throws PersistenceException Walk the object model and mark object that should be created.- Parameters:
tx
- transaction in actionoid
- the object identity of the object to be created.locker
- the dirty checking cache of the objectobject
- the object to be created- Throws:
PersistenceException
-
preStore
public boolean preStore(TransactionContext tx, OID oid, DepositBox locker, Object object, int timeout) throws PersistenceException Check the object for modification. If dpendent object is dereferenced, it method will remove the object thru the transaction. If an related object is dereferenced, it method will make sure the formally object will be dereferenced from the other side as well. This method is called in prepare (for commit) state of the transaction. This method indicates if the object needed to be persist or cache should be update using TransactionContext.markDelete.- Parameters:
tx
- transaction in actionoid
- the object identity of the objectlocker
- the dirty check cache for the objectobject
- the data object to be checkedtimeout
- timeout of updating the lock if needed- Returns:
- true if the object is modified
- Throws:
PersistenceException
-
store
public void store(TransactionContext tx, OID oid, DepositBox locker, Object object) throws PersistenceException Store a data object into the persistent storage of the base class of this ClassMolder.- Parameters:
tx
- Transaction in actionoid
- the object identity of the stored objectlocker
- the dirty check cache of the objectobject
- the object to be stored- Throws:
PersistenceException
- If identity is missing for storage or the identity is modified
-
update
public boolean update(TransactionContext tx, OID oid, DepositBox locker, Object object, AccessMode suggestedAccessMode) throws PersistenceException Update the object which loaded or created in the other transaction to the persistent storage.- Parameters:
tx
- Transaction in actionoid
- the object identity of the stored objectlocker
- the dirty check cache of the objectobject
- the object to be stored- Returns:
- boolean true if the updating object should be created
- Throws:
PersistenceException
-
updateCache
Update the dirty checking cache. This method is called after a transaction completed successfully.- Parameters:
tx
- - transaction in actionoid
- - object's identity of the target objectlocker
- - the dirty checking cache of the target objectobject
- - the target object
-
delete
Delete an object of the base type from the persistence storage. All object to be deleted by this method will be markDelete before it method is called.- Parameters:
tx
- - transaction in actionoid
- - the object identity of the target object- Throws:
PersistenceException
-
markDelete
public void markDelete(TransactionContext tx, OID oid, DepositBox locker, Object object) throws PersistenceException Prepare to delete an object with the specified identity. If any sub-object should be deleted along with the target object, it should be deleted by this method.- Parameters:
tx
- - transaction in actionoid
- - object's identity of the target objectlocker
- - the dirty checking cache of the target objectobject
- - the target object- Throws:
PersistenceException
-
revertObject
public void revertObject(TransactionContext tx, OID oid, DepositBox locker, Object object) throws PersistenceException Revert the object back to the state of begining of the transaction If the object is loaded, it will be revert as it was loaded. If the object is created, it will be revert as it was just created.- Parameters:
tx
- - transaction in actionoid
- - the object identity of the target objectlocker
- - the dirty checking cache of the target objectobject
- - the target object- Throws:
PersistenceException
-
newInstance
public Object newInstance(ClassLoader loader) throws InstantiationException, IllegalAccessException, ClassNotFoundException Return a new instance of the base class with the provided ClassLoader object.- Parameters:
loader
- the ClassLoader object to use to create a new object.- Returns:
- Object the object reprenseted by this ClassMolder, and instanciated with the provided ClassLoader instance.
- Throws:
ClassNotFoundException
IllegalAccessException
InstantiationException
-
getAccessMode
Get the effective accessMode of the the base type.- Parameters:
txMode
- - the default transaction accessMode.- Returns:
- the effective acessMode of the base type.
-
getCallback
Get the callback interceptor of the base type. -
isDefaultIdentity
Test if the specified identity is the default value of the type. -
getIdentity
Get the identity from a object of the base type. If object isn't persistent and key generator is used, returns null.- Parameters:
tx
- the transaction context.o
- - object of the base type.- Returns:
- return an Object[] which contains the identity of the object.
-
getActualIdentity
Get the identity from a object of the base type.- Parameters:
tx
- the transaction context.o
- - object of the base type.- Returns:
- return an Object[] which contains the identity of the object.
-
getActualIdentity
Get the identity from a object of the base type.- Parameters:
loader
- the current class loader.o
- - object of the base type.- Returns:
- return an Object[] which contains the identity of the object.
-
setIdentity
public void setIdentity(TransactionContext tx, Object object, Identity identity) throws PersistenceException Set the identity into an object.- Parameters:
tx
- the transaction context.object
- the object to set the identity.identity
- the new identity for the object.- Throws:
PersistenceException
-
getPersistence
Get the Persisetence of the base type. -
getJavaClass
Get the base class of this ClassMolder given a ClassLoader.- Parameters:
loader
- the classloader.- Returns:
- the
Class
instance.
-
isAssignableFrom
check if the current ClassModlder is assignable from theclass
instance.- Parameters:
cls
- the Class to check the assignation- Returns:
- true if assignable
-
getName
Get the fully qualified name of the base type of this ClassMolder. -
getExtends
Get the extends class' ClassMolder. -
getDepends
Get the depends class' ClassMolder. -
getLockEngine
Get the LockEngine which this ClassMolder belongs to. -
getCacheParams
Returns the active cache parameters.- Returns:
- Active cache parameters.
-
isDependent
public boolean isDependent()Return true if the base type of this ClassMolder is an dependent class. -
addExtendent
Mutator method to add a extent ClassMolder. -
addDependent
Mutator method to add a dependent ClassMolder. -
setExtends
Mutator method to set the extends ClassMolder. -
setDepends
Mutator method to set the depends ClassMolder. -
toString
-
isKeyGenUsed
public boolean isKeyGenUsed()Return true if a key generator is used for the base type of this ClassMolder. -
isKeyGeneratorUsed
public boolean isKeyGeneratorUsed()Return true if a key generator is used for the base type of this ClassMolder. -
expireCache
Inspect the fields stored in the object passed as an argument for contained objects. Request an expireCache for each contained object.- Parameters:
tx
- TheTransactionContext
locker
- The object that contains the fields to be inspected- Throws:
PersistenceException
-
resetResolvers
public void resetResolvers() -
getNamedQuery
Returns the actual (OQL) statement for the specified named query.- Parameters:
name
- Named query name.- Returns:
- The actual (OQL) statement.
-
getNamedNativeQuery
Returns the actual (SQL) statement for the specified named native query.- Parameters:
name
- Named query name.- Returns:
- The actual (SQL) statement.
-