Package org.castor.persist.resolver
Class ManyRelationResolver
java.lang.Object
org.castor.persist.resolver.BaseRelationResolver
org.castor.persist.resolver.ManyRelationResolver
- All Implemented Interfaces:
ResolverStrategy
- Direct Known Subclasses:
ManyToManyRelationResolver
,OneToManyRelationResolver
Implementation of
ResolverStrategy
for many relations.
This class carries behaviour common to 1:M and M:N relations.- Since:
- 0.9.9
- Author:
- Werner Guttmann
-
Field Summary
Fields inherited from class org.castor.persist.resolver.BaseRelationResolver
_classMolder, _fieldMolder
-
Constructor Summary
ConstructorsConstructorDescriptionManyRelationResolver
(ClassMolder classMolder, FieldMolder fieldMolder, int fieldIndex) Creates an instance of ManyRelationResolver. -
Method Summary
Modifier and TypeMethodDescriptionfinal Object
create
(TransactionContext tx, Object object) Create an object of the base class with specified identity into the persistence storage.final void
expireCache
(TransactionContext tx, Object field) Inspect the fields stored in the object passed as an argument for contained objects.final void
load
(TransactionContext tx, OID oid, ProposedEntity proposedObject, AccessMode suggestedAccessMode) Load an object with specified identity from the persistent storage.abstract boolean
markCreate
(TransactionContext tx, OID oid, Object object) Walk the object model and mark object that should be created.abstract void
markDelete
(TransactionContext tx, Object object, Object field) Prepare to delete an object with the specified identity.abstract Object
postCreate
(TransactionContext tx, OID oid, Object object, Object field, Identity createdId) Called after successful creation of an object of the base class.abstract UpdateFlags
preStore
(TransactionContext tx, OID oid, Object object, int timeout, Object field) Check the object for modification.final UpdateAndRemovedFlags
removeRelation
(TransactionContext tx, Object object, ClassMolder relatedMolder, Object relatedObject) Remove the reference of a related object from an object of the base class.final void
revertObject
(TransactionContext tx, OID oid, Object object, Object field) 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.final Object
store
(TransactionContext tx, Object object, Object field) Store a data object into the persistent storage of the base class of this ClassMolder.abstract void
update
(TransactionContext tx, OID oid, Object object, AccessMode suggestedAccessMode, Object field) Update the object which loaded or created in the other transaction to the persistent storage.final Object
updateCache
(TransactionContext tx, OID oid, Object object) Update the dirty checking cache.Methods inherited from class org.castor.persist.resolver.BaseRelationResolver
isCascadingCreate, isCascadingDelete, isCascadingUpdate
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.castor.persist.resolver.ResolverStrategy
updateWhenNoTimestampSet
-
Constructor Details
-
ManyRelationResolver
Creates an instance of ManyRelationResolver.- Parameters:
classMolder
- AssociatedClassMolder
fieldMolder
- AssociatedFieldMolder
fieldIndex
- Field index within all fields of parent class molder.
-
-
Method Details
-
create
Description copied from interface:ResolverStrategy
Create an object of the base class with specified identity into the persistence storage.- Parameters:
tx
- transaction in actionobject
- the object to be created- Returns:
- the identity of the object
- See Also:
-
markCreate
public abstract boolean markCreate(TransactionContext tx, OID oid, Object object) throws PersistenceException Description copied from interface:ResolverStrategy
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.object
- the object to be created- Returns:
- true if there's objects that should be created
- Throws:
PersistenceException
- See Also:
-
preStore
public abstract UpdateFlags preStore(TransactionContext tx, OID oid, Object object, int timeout, Object field) throws PersistenceException Description copied from interface:ResolverStrategy
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 objectobject
- the data object to be checkedtimeout
- timeout of updating the lock if neededfield
- The field value as returned by the SQLEngine- Returns:
- true if the object is modified
- Throws:
PersistenceException
- If it is not possible to successfully complete this method.- See Also:
-
store
Description copied from interface:ResolverStrategy
Store a data object into the persistent storage of the base class of this ClassMolder.- Parameters:
tx
- Transaction in actionobject
- the object to be storedfield
- The field value as returned by the SQLEngine- See Also:
-
update
public abstract void update(TransactionContext tx, OID oid, Object object, AccessMode suggestedAccessMode, Object field) throws PersistenceException Description copied from interface:ResolverStrategy
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 objectobject
- the object to be storedsuggestedAccessMode
- Suggested access modefield
- The field value as returned by the SQLEngine- Throws:
PersistenceException
- If it is not possible to successfully complete this method.- See Also:
-
updateCache
Description copied from interface:ResolverStrategy
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 objectobject
- - the target object- Returns:
- The object tha twas stored in the cache previously.
- See Also:
-
markDelete
public abstract void markDelete(TransactionContext tx, Object object, Object field) throws PersistenceException Description copied from interface:ResolverStrategy
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 actionobject
- - the target objectfield
- The field value as returned by the SQLEngine- Throws:
PersistenceException
- If it is not possible to successfully complete this method.- See Also:
-
revertObject
public final void revertObject(TransactionContext tx, OID oid, Object object, Object field) throws PersistenceException Description copied from interface:ResolverStrategy
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 objectobject
- - the target objectfield
- The field value as returned by the SQLEngine- Throws:
PersistenceException
- If it is not possible to successfully complete this method.- See Also:
-
expireCache
Description copied from interface:ResolverStrategy
Inspect the fields stored in the object passed as an argument for contained objects. Request an expireCache for each contained object.- Parameters:
tx
- TheTransactionContext
field
- The field value as returned by the SQLEngine- Throws:
PersistenceException
- If it is not possible to successfully complete this method.- See Also:
-
load
public final void load(TransactionContext tx, OID oid, ProposedEntity proposedObject, AccessMode suggestedAccessMode) throws PersistenceException Description copied from interface:ResolverStrategy
Load an object with specified identity from the persistent storage.- Parameters:
tx
- the TransactionContext in actionoid
- the object identity of the desired objectproposedObject
- Object holder storing information about assumed and actual object instances.suggestedAccessMode
- the acessMode for the object- Throws:
PersistenceException
- If it is not possible to successfully complete this method.- See Also:
-
postCreate
public abstract Object postCreate(TransactionContext tx, OID oid, Object object, Object field, Identity createdId) throws PersistenceException Description copied from interface:ResolverStrategy
Called after successful creation of an object of the base class.- Parameters:
tx
- transaction in actionoid
- the object identity of the object to be created.object
- the object to be createdfield
- The field value as returned by the SQLEnginecreatedId
- ???- Returns:
- the identity of the object
- Throws:
PersistenceException
- See Also:
-
removeRelation
public final UpdateAndRemovedFlags removeRelation(TransactionContext tx, Object object, ClassMolder relatedMolder, Object relatedObject) Description copied from interface:ResolverStrategy
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 occured, transactionContext.markModified will be called, to indicate the object is modified.
It method will iterate thur 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- Returns:
- Various flags related to updating/removing object instances.
- See Also:
-