org.castor.persist.resolver
Class ManyRelationResolver

java.lang.Object
  extended by org.castor.persist.resolver.ManyRelationResolver
All Implemented Interfaces:
ResolverStrategy
Direct Known Subclasses:
ManyToManyRelationResolver, OneToManyRelationResolver

public abstract class ManyRelationResolver
extends java.lang.Object
implements ResolverStrategy

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
protected  ClassMolder _classMolder
          Associated ClassMolder.
protected  boolean _debug
          ???
protected  FieldMolder _fieldMolder
          Associated FieldMolder.
 
Constructor Summary
ManyRelationResolver(ClassMolder classMolder, FieldMolder fieldMolder, boolean debug)
          Creates an instance of ManyRelationResolver
 
Method Summary
 java.lang.Object create(TransactionContext tx, java.lang.Object object)
          Create an object of the base class with specified identity into the persistence storage.
 void expireCache(TransactionContext tx, java.lang.Object field)
          Inspect the fields stored in the object passed as an argument for contained objects.
 void load(TransactionContext tx, OID oid, ProposedObject proposedObject, AccessMode suggestedAccessMode, java.lang.Object field)
          Load an object with specified identity from the persistent storage.
abstract  boolean markCreate(TransactionContext tx, OID oid, java.lang.Object object)
          Walk the object model and mark object that should be created.
abstract  void markDelete(TransactionContext tx, java.lang.Object object, java.lang.Object field)
          Prepare to delete an object with the specified identity.
abstract  java.lang.Object postCreate(TransactionContext tx, OID oid, java.lang.Object object, java.lang.Object field, java.lang.Object createdId)
          Called after successful creation of an object of the base class.
abstract  UpdateFlags preStore(TransactionContext tx, OID oid, java.lang.Object object, int timeout, java.lang.Object field)
          Check the object for modification.
 UpdateAndRemovedFlags removeRelation(TransactionContext tx, java.lang.Object object, ClassMolder relatedMolder, java.lang.Object relatedObject)
          Remove the reference of a related object from an object of the base class.
 void revertObject(TransactionContext tx, OID oid, java.lang.Object object, java.lang.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.
 java.lang.Object store(TransactionContext tx, java.lang.Object object, java.lang.Object field)
          Store a data object into the persistent storage of the base class of this ClassMolder.
abstract  void update(TransactionContext tx, OID oid, java.lang.Object object, AccessMode suggestedAccessMode, java.lang.Object field)
          Update the object which loaded or created in the other transaction to the persistent storage.
 java.lang.Object updateCache(TransactionContext tx, OID oid, java.lang.Object object)
          Update the dirty checking cache.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_classMolder

protected ClassMolder _classMolder
Associated ClassMolder.


_fieldMolder

protected FieldMolder _fieldMolder
Associated FieldMolder.


_debug

protected boolean _debug
???

Constructor Detail

ManyRelationResolver

public ManyRelationResolver(ClassMolder classMolder,
                            FieldMolder fieldMolder,
                            boolean debug)
Creates an instance of ManyRelationResolver

Parameters:
classMolder - Associated ClassMolder
fieldMolder - Associated FieldMolder
debug - ???
Method Detail

create

public java.lang.Object create(TransactionContext tx,
                               java.lang.Object object)
Description copied from interface: ResolverStrategy
Create an object of the base class with specified identity into the persistence storage.

Specified by:
create in interface ResolverStrategy
Parameters:
tx - transaction in action
object - the object to be created
Returns:
the identity of the object
See Also:
#create(org.castor.persist.TransactionContext, java.lang.Object)

markCreate

public abstract boolean markCreate(TransactionContext tx,
                                   OID oid,
                                   java.lang.Object object)
                            throws DuplicateIdentityException,
                                   PersistenceException
Description copied from interface: ResolverStrategy
Walk the object model and mark object that should be created.

Specified by:
markCreate in interface ResolverStrategy
Parameters:
tx - transaction in action
oid - 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:
DuplicateIdentityException
PersistenceException

preStore

public abstract UpdateFlags preStore(TransactionContext tx,
                                     OID oid,
                                     java.lang.Object object,
                                     int timeout,
                                     java.lang.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.

Specified by:
preStore in interface ResolverStrategy
Parameters:
tx - transaction in action
oid - the object identity of the object
object - the data object to be checked
timeout - timeout of updating the lock if needed
field - 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.

store

public java.lang.Object store(TransactionContext tx,
                              java.lang.Object object,
                              java.lang.Object field)
Description copied from interface: ResolverStrategy
Store a data object into the persistent storage of the base class of this ClassMolder.

Specified by:
store in interface ResolverStrategy
Parameters:
tx - Transaction in action
object - the object to be stored
field - The field value as returned by the SQLEngine

update

public abstract void update(TransactionContext tx,
                            OID oid,
                            java.lang.Object object,
                            AccessMode suggestedAccessMode,
                            java.lang.Object field)
                     throws PersistenceException,
                            ObjectModifiedException
Description copied from interface: ResolverStrategy
Update the object which loaded or created in the other transaction to the persistent storage.

Specified by:
update in interface ResolverStrategy
Parameters:
tx - Transaction in action
oid - the object identity of the stored object
object - the object to be stored
suggestedAccessMode - Suggested access mode
field - The field value as returned by the SQLEngine
Throws:
PersistenceException - If it is not possible to successfully complete this method.
ObjectModifiedException

updateCache

public java.lang.Object updateCache(TransactionContext tx,
                                    OID oid,
                                    java.lang.Object object)
Description copied from interface: ResolverStrategy
Update the dirty checking cache. This method is called after a transaction completed successfully.

Specified by:
updateCache in interface ResolverStrategy
Parameters:
tx - - transaction in action
oid - - object's identity of the target object
object - - the target object
Returns:
The object tha twas stored in the cache previously.

markDelete

public abstract void markDelete(TransactionContext tx,
                                java.lang.Object object,
                                java.lang.Object field)
                         throws ObjectNotFoundException,
                                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.

Specified by:
markDelete in interface ResolverStrategy
Parameters:
tx - - transaction in action
object - - the target object
field - The field value as returned by the SQLEngine
Throws:
PersistenceException - If it is not possible to successfully complete this method.
ObjectNotFoundException

revertObject

public void revertObject(TransactionContext tx,
                         OID oid,
                         java.lang.Object object,
                         java.lang.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.

Specified by:
revertObject in interface ResolverStrategy
Parameters:
tx - - transaction in action
oid - - the object identity of the target object
object - - the target object
field - The field value as returned by the SQLEngine
Throws:
PersistenceException - If it is not possible to successfully complete this method.

expireCache

public void expireCache(TransactionContext tx,
                        java.lang.Object field)
                 throws PersistenceException
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.

Specified by:
expireCache in interface ResolverStrategy
Parameters:
tx - The TransactionContext
field - The field value as returned by the SQLEngine
Throws:
PersistenceException - If it is not possible to successfully complete this method.

load

public void load(TransactionContext tx,
                 OID oid,
                 ProposedObject proposedObject,
                 AccessMode suggestedAccessMode,
                 java.lang.Object field)
          throws ObjectNotFoundException,
                 PersistenceException
Description copied from interface: ResolverStrategy
Load an object with specified identity from the persistent storage.

Specified by:
load in interface ResolverStrategy
Parameters:
tx - the TransactionContext in action
oid - the object identity of the desired object
proposedObject - Object holder storing information about assumed and actual object instances
suggestedAccessMode - the acessMode for the object
field - The field value as returned by the SQLEngine
Throws:
PersistenceException - If it is not possible to successfully complete this method.
ObjectNotFoundException

postCreate

public abstract java.lang.Object postCreate(TransactionContext tx,
                                            OID oid,
                                            java.lang.Object object,
                                            java.lang.Object field,
                                            java.lang.Object createdId)
                                     throws DuplicateIdentityException,
                                            PersistenceException
Description copied from interface: ResolverStrategy
Called after successful creation of an object of the base class.

Specified by:
postCreate in interface ResolverStrategy
Parameters:
tx - transaction in action
oid - the object identity of the object to be created.
object - the object to be created
field - The field value as returned by the SQLEngine
createdId - ???
Returns:
the identity of the object
Throws:
DuplicateIdentityException
PersistenceException

removeRelation

public UpdateAndRemovedFlags removeRelation(TransactionContext tx,
                                            java.lang.Object object,
                                            ClassMolder relatedMolder,
                                            java.lang.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.

Specified by:
removeRelation in interface ResolverStrategy
Parameters:
tx - the TransactionContext of the transaction in action
object - the target object of the base type of this ClassMolder
relatedMolder - the ClassMolder of the related object to be removed from the object
relatedObject - the object to be removed
Returns:
Various flags related to updating/removing object instances.


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