org.objectweb.jac.aspects.persistence
Class PersistenceWrapper

java.lang.Object
  |
  +--org.objectweb.jac.core.Wrapper
        |
        +--org.objectweb.jac.aspects.persistence.AbstractPersistenceWrapper
              |
              +--org.objectweb.jac.aspects.persistence.PersistenceWrapper
All Implemented Interfaces:
Advice, ConstructorInterceptor, Interceptor, MethodInterceptor, Serializable

public class PersistenceWrapper
extends AbstractPersistenceWrapper

This wrapper defines persistence extensions for objects that a defined persitent by a persistent aspect component.

See Also:
Serialized Form

Nested Class Summary
static class PersistenceWrapper.InvalidOidException
           
 
Nested classes inherited from class org.objectweb.jac.aspects.persistence.AbstractPersistenceWrapper
AbstractPersistenceWrapper.InvalidOidException
 
Field Summary
static String[] toWrapForLists
           
static String[] toWrapForMaps
           
static String[] toWrapForSets
           
 
Fields inherited from class org.objectweb.jac.aspects.persistence.AbstractPersistenceWrapper
ATTR_ADDED
 
Fields inherited from class org.objectweb.jac.core.Wrapper
ac, cr
 
Constructor Summary
PersistenceWrapper(AspectComponent ac)
           
PersistenceWrapper(AspectComponent ac, Boolean doStatics)
           
 
Method Summary
protected  void addToCollection(Interaction interaction, OID oid, CollectionItem collection, Object value)
          This method stores the persistent object that is added to the collection into the storage.
 Object applyPersistence(Interaction interaction)
          This wrapping method apply the persistence aspect for a given call on a persistent object.
 Object construct(ConstructorInvocation invocation)
           
 void getCollection(Wrappee wrappee, OID oid, CollectionItem collection)
          This method loads alls the persistent objects that are contained in this collection from the storage.
 void getReference(Wrappee wrappee, OID oid, FieldItem reference)
          This method loads the persistent object that is pointed by the reference from the storage.
 Object handleStatic(Interaction interaction)
          This wrapping method is called on static objects constructors as defined by the pointcut of PersistenceAC.
 void initAllFields(Wrappee wrappee, OID oid)
          Initialize all fields of an object in the storage.
 void initCollections(Wrappee wrappee, OID oid, CollectionItem[] collections)
           
 Object invoke(MethodInvocation invocation)
           
 void loadAllFields(Wrappee wrappee, OID oid)
          Load all the fields of an object from the storage and initialize the object.
 OID makePersistent(Wrappee wrappee)
          Makes an object persistent if it is not already.
protected  void removeFromCollection(Interaction interaction, OID oid, CollectionItem collection, Object value)
          This method delete the persistent object that is removed from the collection from the storage.
protected  void setField(Wrappee wrappee, OID oid, FieldItem field)
          This method stores the field into the storage.
protected  void setReference(Wrappee wrappee, OID oid, FieldItem reference, Wrappee value)
          This method stores the persistent object that is pointed by the reference into the storage.
 void updateCollection(CollectionItem collection, int position)
          Update the element of a collection at a gievn position
 void wrapCollections(Wrappee wrappee, OID oid, boolean isNew)
          This role method wraps all the collection of the current wrappee so that they will trigger the needed loads from the storage when they are accessed.
 
Methods inherited from class org.objectweb.jac.aspects.persistence.AbstractPersistenceWrapper
checkOid, getAC, getOID, getStorage, isPersistent, normalizeInput, normalizeOutput
 
Methods inherited from class org.objectweb.jac.core.Wrapper
attr, attrdef, defines, getAspectComponent, getAspectComponentName, getExceptionHandlers, proceed, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

toWrapForLists

public static final String[] toWrapForLists

toWrapForSets

public static final String[] toWrapForSets

toWrapForMaps

public static final String[] toWrapForMaps
Constructor Detail

PersistenceWrapper

public PersistenceWrapper(AspectComponent ac)

PersistenceWrapper

public PersistenceWrapper(AspectComponent ac,
                          Boolean doStatics)
Method Detail

handleStatic

public Object handleStatic(Interaction interaction)
This wrapping method is called on static objects constructors as defined by the pointcut of PersistenceAC.

See Also:
PersistenceAC.registerStatics(java.lang.String, java.lang.String)

makePersistent

public OID makePersistent(Wrappee wrappee)
                   throws Exception
Makes an object persistent if it is not already. Is is assigned an OID, and its members are saved in the storage.

Parameters:
wrappee - the object to make persistent
Exception

loadAllFields

public void loadAllFields(Wrappee wrappee,
                          OID oid)
                   throws Exception
Load all the fields of an object from the storage and initialize the object.

Parameters:
wrappee - the object
Exception

wrapCollections

public void wrapCollections(Wrappee wrappee,
                            OID oid,
                            boolean isNew)
This role method wraps all the collection of the current wrappee so that they will trigger the needed loads from the storage when they are accessed.

Parameters:
wrappee - the object whose collections to wrap
oid - the oid of wrappee
isNew - must true if the object is newly created, false if loaded from storage

applyPersistence

public Object applyPersistence(Interaction interaction)
                        throws Exception
This wrapping method apply the persistence aspect for a given call on a persistent object.

It uses the RTTI aspect to determine the accessed and written field types.

Default behavior is:

Returns:
the value returned by the wrapped method
Exception
See Also:
AbstractMethodItem.getAccessedFields(), getCollection(Wrappee,OID,CollectionItem), getReference(Wrappee,OID,FieldItem), addToCollection(Interaction,OID,CollectionItem,Object), removeFromCollection(Interaction,OID,CollectionItem,Object), setReference(Wrappee,OID,FieldItem,Wrappee), setField(Wrappee,OID,FieldItem), AbstractMethodItem.getWrittenFields(), org.objectweb.jac.core.rtti

getCollection

public void getCollection(Wrappee wrappee,
                          OID oid,
                          CollectionItem collection)
                   throws Exception
This method loads alls the persistent objects that are contained in this collection from the storage.

If the collection has already been loaded from the storage, do nothing.

Parameters:
collection - the collection to load
Exception

addToCollection

protected void addToCollection(Interaction interaction,
                               OID oid,
                               CollectionItem collection,
                               Object value)
                        throws Exception
This method stores the persistent object that is added to the collection into the storage.

Parameters:
interaction - the current interaction
oid - the oid of the object holding the collection
collection - the collection to add to
value - the value to add to the collection
Exception
See Also:
removeFromCollection(Interaction,OID,CollectionItem,Object), getCollection(Wrappee,OID,CollectionItem)

removeFromCollection

protected void removeFromCollection(Interaction interaction,
                                    OID oid,
                                    CollectionItem collection,
                                    Object value)
                             throws Exception
This method delete the persistent object that is removed from the collection from the storage.

Parameters:
interaction - the current interaction
oid - the oid of the object holding the collection
collection - the collection to remove from
value - the value to remove from the collection
Exception
See Also:
addToCollection(Interaction,OID,CollectionItem,Object), getCollection(Wrappee,OID,CollectionItem)

updateCollection

public void updateCollection(CollectionItem collection,
                             int position)
                      throws Exception
Update the element of a collection at a gievn position

Exception

getReference

public void getReference(Wrappee wrappee,
                         OID oid,
                         FieldItem reference)
                  throws Exception
This method loads the persistent object that is pointed by the reference from the storage.

If the reference has already been loaded from the storage, do nothing.

Parameters:
reference - the reference to load
Exception
See Also:
setReference(Wrappee,OID,FieldItem,Wrappee)

setReference

protected void setReference(Wrappee wrappee,
                            OID oid,
                            FieldItem reference,
                            Wrappee value)
                     throws Exception
This method stores the persistent object that is pointed by the reference into the storage.

Parameters:
reference - the reference to store
Exception
See Also:
getReference(Wrappee,OID,FieldItem)

setField

protected void setField(Wrappee wrappee,
                        OID oid,
                        FieldItem field)
                 throws Exception
This method stores the field into the storage.

Parameters:
field - the field to store
Exception

initCollections

public void initCollections(Wrappee wrappee,
                            OID oid,
                            CollectionItem[] collections)
                     throws Exception
Exception

initAllFields

public void initAllFields(Wrappee wrappee,
                          OID oid)
                   throws Exception
Initialize all fields of an object in the storage.

This method is called when a new object is made persistent. The references and collections are also recursively saved into the storage.

Parameters:
wrappee - the initialized object
Exception

invoke

public Object invoke(MethodInvocation invocation)
              throws Throwable
Specified by:
invoke in interface MethodInterceptor
Overrides:
invoke in class Wrapper
Throwable

construct

public Object construct(ConstructorInvocation invocation)
                 throws Throwable
Specified by:
construct in interface ConstructorInterceptor
Overrides:
construct in class Wrapper
Throwable