org.exolab.castor.persist

Class ClassMolder

public class ClassMolder extends Object

ClassMolder is a binder for one type of data object and its {@link Persistence}. For example, when ClassMolder is asked to load an object, it acquires values from {@link Persistence} and binds it into an target object. It also resolves relations via {@link TransactionContext} and bind related object into an target object.

Beside loading, ClassMolder is also repsonsible for storing, removing, creating an object to and from a persistence storage, as well as reverting an object to previous state.

Each instance of ClassMolder deals with exactly one persistable type, interacts with one instance of Persistent and belongs to one {@link LockEngine}.

Author: Thomas Yip

Constructor Summary
ClassMolder(DatingService ds, MappingLoader loader, LockEngine lock, ClassDescriptor clsDesc, Persistence persist)
Constructor
Method Summary
voidaddDependent(ClassMolder dep)
Mutator method to add a dependent ClassMolder
voidaddExtendent(ClassMolder ext)
Mutator method to add a extent ClassMolder
Objectcreate(TransactionContext tx, OID oid, DepositBox locker, Object object)
Create an object of the base class with specified identity into the persistence storage.
voiddelete(TransactionContext tx, OID oid)
Delete an object of the base type from the persistence storage.
AccessModegetAccessMode(AccessMode txMode)
Get the effective accessMode of the the base type
ObjectgetActualIdentity(TransactionContext tx, Object o)
Get the identity from a object of the base type
ObjectgetActualIdentity(ClassLoader loader, Object o)
Get the identity from a object of the base type
intgetCacheParam()
Return the preferred LRU cache capacity for caching object of this type
intgetCacheType()
Return the preferred LRU cache mechanism for caching object of this type
CallbackInterceptorgetCallback()
Get the callback interceptor of the base type
ClassMoldergetDepends()
Get the depends class' ClassMolder
ClassMoldergetExtends()
Get the extends class' ClassMolder
FieldMolder[]getFields()
Get the FieldMolder of the fields of the base type, except the identity fields.
ObjectgetIdentity(TransactionContext tx, Object o)
Get the identity from a object of the base type If object isn't persistent and key generator is used, returns null
FieldMolder[]getIds()
Get the FieldMolders of the identity fields
ClassgetJavaClass(ClassLoader loader)
Get the base class of this ClassMolder given a ClassLoader
LockEnginegetLockEngine()
Get the LockEngine which this ClassMolder belongs to.
StringgetName()
Get the fully qualified name of the base type of this ClassMolder
PersistencegetPersistence()
Get the Persisetence of the base type
intgetPriority()
Determines the create priority of the data object class represented by this ClassMolder.
booleanisAssignableFrom(Class cls)
check if the current ClassModlder is assignable from the class instance.
booleanisDefaultIdentity(Object identity)
Test if the specified identity is the default value of the type.
booleanisDependent()
Return true if the base type of this ClassMolder is an dependent class.
booleanisKeyGeneratorUsed()
Return true if a key generator is used for the base type of this ClassMolder
Objectload(TransactionContext tx, OID oid, DepositBox locker, Object object, AccessMode suggestedAccessMode)
Load an object with specified identity from the persistent storage.
Objectload(TransactionContext tx, OID oid, DepositBox locker, Object object, AccessMode suggestedAccessMode, QueryResults results)
voidmarkCreate(TransactionContext tx, OID oid, DepositBox locker, Object object)
Walk the object model and mark object that should be created.
voidmarkDelete(TransactionContext tx, OID oid, DepositBox locker, Object object)
Prepare to delete an object with the specified identity.
ObjectnewInstance(ClassLoader loader)
Return a new instance of the base class with the provided ClassLoader object
booleanpreStore(TransactionContext tx, OID oid, DepositBox locker, Object object, int timeout)
Check the object for modification.
static Vectorresolve(MappingLoader loader, LockEngine lock, PersistenceFactory factory, LogInterceptor logInterceptor)
Resolve and construct all the ClassMolders given a MappingLoader.
voidrevertObject(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.
voidsetDepends(ClassMolder dep)
Mutator method to set the depends ClassMolder
voidsetExtends(ClassMolder ext)
Mutator method to set the extends ClassMolder
voidsetFieldsNull(Object object)
Set all persistence fields of object of the base type to null.
voidsetIdentity(TransactionContext tx, Object object, Object identity)
Set the identity into an object
voidsetPersistence(Persistence persist)
Mutator method to set the PersistenceEngine of
voidstore(TransactionContext tx, OID oid, DepositBox locker, Object object)
Store a data object into the persistent storage of the base class of this ClassMolder.
StringtoString()
booleanupdate(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.
voidupdateCache(TransactionContext tx, OID oid, DepositBox locker, Object object)
Update the dirty checking cache.
voidwriteLock(TransactionContext tx, OID oid, DepositBox locker, Object object)
Acquire a write lock on an object of the base type with the specified identity from the persistence storage.

Constructor Detail

ClassMolder

ClassMolder(DatingService ds, MappingLoader loader, LockEngine lock, ClassDescriptor clsDesc, Persistence persist)
Constructor

Parameters: ds is the helper class for resolving depends and extends relationship among all the ClassMolder in the same LockEngine. loader is the mapping loader classDescriptor the classDescriptor for the base class persist the Persistent for the base class

Method Detail

addDependent

void addDependent(ClassMolder dep)
Mutator method to add a dependent ClassMolder

addExtendent

void addExtendent(ClassMolder ext)
Mutator method to add a extent ClassMolder

create

public Object create(TransactionContext tx, OID oid, DepositBox locker, Object object)
Create an object of the base class with specified identity into the persistence storage.

Parameters: tx transaction in action oid the object identity of the object to be created. locker the dirty checking cache of the object object the object to be created

Returns: the identity of the object

delete

public void delete(TransactionContext tx, OID oid)
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 action oid - the object identity of the target object

getAccessMode

public AccessMode getAccessMode(AccessMode txMode)
Get the effective accessMode of the the base type

Parameters: txMode - the default transaction accessMode

Returns: the effective acessMode of the base type

getActualIdentity

public Object getActualIdentity(TransactionContext tx, Object o)
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

public Object getActualIdentity(ClassLoader loader, Object o)
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

getCacheParam

public int getCacheParam()
Return the preferred LRU cache capacity for caching object of this type

getCacheType

public int getCacheType()
Return the preferred LRU cache mechanism for caching object of this type

getCallback

public CallbackInterceptor getCallback()
Get the callback interceptor of the base type

getDepends

public ClassMolder getDepends()
Get the depends class' ClassMolder

getExtends

public ClassMolder getExtends()
Get the extends class' ClassMolder

getFields

public FieldMolder[] getFields()
Get the FieldMolder of the fields of the base type, except the identity fields.

getIdentity

public Object getIdentity(TransactionContext tx, Object o)
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

getIds

public FieldMolder[] getIds()
Get the FieldMolders of the identity fields

getJavaClass

public Class getJavaClass(ClassLoader loader)
Get the base class of this ClassMolder given a ClassLoader

Parameters: loader the classloader

Returns: the Class instance

getLockEngine

public LockEngine getLockEngine()
Get the LockEngine which this ClassMolder belongs to.

getName

public String getName()
Get the fully qualified name of the base type of this ClassMolder

getPersistence

public Persistence getPersistence()
Get the Persisetence of the base type

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. Priority of zero means the object can be created without depending on other data object. This method should only be called after DatingService is closed.

isAssignableFrom

public boolean isAssignableFrom(Class cls)
check if the current ClassModlder is assignable from the class instance.

Parameters: cls the Class to check the assignation

Returns: true if assignable

isDefaultIdentity

public boolean isDefaultIdentity(Object identity)
Test if the specified identity is the default value of the type.

isDependent

public boolean isDependent()
Return true if the base type of this ClassMolder is an dependent class.

isKeyGeneratorUsed

public boolean isKeyGeneratorUsed()
Return true if a key generator is used for the base type of this ClassMolder

load

public Object load(TransactionContext tx, OID oid, DepositBox locker, Object object, AccessMode suggestedAccessMode)
Load an object with specified identity from the persistent storage.

Parameters: tx the TransactionContext in action oid the object identity of the desired object locker the {@link DepositBox} of the object which is used to store the dirty checking cache of the object. accessMode the acessMode for the object

Returns: the object stamp for the object in the persistent storage

load

public Object load(TransactionContext tx, OID oid, DepositBox locker, Object object, AccessMode suggestedAccessMode, QueryResults results)

markCreate

public void markCreate(TransactionContext tx, OID oid, DepositBox locker, Object object)
Walk the object model and mark object that should be created.

Parameters: tx transaction in action oid the object identity of the object to be created. locker the dirty checking cache of the object object the object to be created

markDelete

public void markDelete(TransactionContext tx, OID oid, DepositBox locker, Object object)
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 action oid - object's identity of the target object locker - the dirty checking cache of the target object object - the target object

newInstance

public Object newInstance(ClassLoader loader)
Return a new instance of the base class with the provided ClassLoader object

Parameters: laoder 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.

preStore

public boolean preStore(TransactionContext tx, OID oid, DepositBox locker, Object object, int timeout)
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 action oid the object identity of the object locker the dirty check cache for the object object the data object to be checked timeout timeout of updating the lock if needed

Returns: true if the object is modified

resolve

public static Vector resolve(MappingLoader loader, LockEngine lock, PersistenceFactory factory, LogInterceptor logInterceptor)
Resolve and construct all the ClassMolders given a MappingLoader.

Parameters: loader MappingLoader for the LockEngine lock LockEngine for all the ClassMolder factory factory class for getting Persistent of the ClassMolder

Returns: Vector of all of the ClassMolders from a MappingLoader

revertObject

public 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. If the object is created, it will be revert as it was just created.

Parameters: tx - transaction in action oid - the object identity of the target object locker - the dirty checking cache of the target object object - the target object

setDepends

void setDepends(ClassMolder dep)
Mutator method to set the depends ClassMolder

setExtends

void setExtends(ClassMolder ext)
Mutator method to set the extends ClassMolder

setFieldsNull

public void setFieldsNull(Object object)
Set all persistence fields of object of the base type to null.

Parameters: object - target object

setIdentity

public void setIdentity(TransactionContext tx, Object object, Object identity)
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

setPersistence

public void setPersistence(Persistence persist)
Mutator method to set the PersistenceEngine of

store

public 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.

Parameters: tx Transaction in action oid the object identity of the stored object locker the dirty check cache of the object object the object to be stored

toString

public String toString()

update

public 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.

Parameters: tx Transaction in action oid the object identity of the stored object locker the dirty check cache of the object object the object to be stored

Returns: boolean true if the updating object should be created

updateCache

public void updateCache(TransactionContext tx, OID oid, DepositBox locker, Object object)
Update the dirty checking cache. This method is called after a transaction completed successfully.

Parameters: tx - transaction in action oid - object's identity of the target object locker - the dirty checking cache of the target object object - the target object

writeLock

public void writeLock(TransactionContext tx, OID oid, DepositBox locker, Object object)
Acquire a write lock on an object of the base type with the specified identity from the persistence storage.

Parameters: tx - Transaction in action oid - the object identity of the target object locker - the dirty checking cache of the object object - the target object

Intalio Inc. (C) 1999-2003. All rights reserved http://www.intalio.com