JAC project
AOPSYS
CEDRIC & LIP6 labs

org.objectweb.jac.aspects.persistence
Class PersistenceWrapper

java.lang.Object
  |
  +--org.objectweb.jac.core.Wrapper
        |
        +--org.objectweb.jac.aspects.persistence.PersistenceWrapper
All Implemented Interfaces:
Serializable
Direct Known Subclasses:
CollectionWrapper

public class PersistenceWrapper
extends Wrapper

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
           
 
Field Summary
static String ATTR_ADDED
           
 
Fields inherited from class org.objectweb.jac.core.Wrapper
ac
 
Constructor Summary
PersistenceWrapper(AspectComponent ac)
           
 
Method Summary
protected  void addToCollection(Interaction interaction, 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.
 void checkOid(Wrappee wrappee)
           
 PersistenceAC getAC()
           
 void getCollection(Wrappee wrappee, CollectionItem collection)
          This method loads alls the persistent objects that are contained in this collection from the storage.
 OID getOID(Wrappee wrappee)
           
 void getReference(Wrappee wrappee, FieldItem reference)
          This method loads the persistent object that is pointed by the reference from the storage.
 Storage getStorage()
           
 Object handleStatic(Interaction interaction)
          This wrapping method is called on static objects constructors as defined by the pointcut of PersistenceAC.
 void initAllFields(Wrappee wrappee)
          Initialize all fields of an object in the storage.
 void initCollections(Wrappee wrappee, CollectionItem[] collections)
           
 boolean isPersistent(Wrappee wrappee)
          Tells if the current object is persistent (role method).
 void loadAllFields(Wrappee wrappee)
          Load all the fields of an object from the storage and initialize the object.
 void makePersistent(Wrappee wrappee)
          Makes an object persistent if it is not already.
 Object normalizeInput(Object value)
          Performs various stuff before storing a value in a storage.
 Object normalizeOutput(Object value)
          Gets the object in memory object for a "storage" value.
protected  void removeFromCollection(Interaction interaction, CollectionItem collection, Object value)
          This method delete the persistent object that is removed from the collection from the storage.
protected  void setField(Wrappee wrappee, FieldItem field)
          This method stores the field into the storage.
protected  void setReference(Wrappee wrappee, 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, 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.core.Wrapper
attr, attrdef, defines, getAspectComponent, getAspectComponentName, getExceptionHandlers, proceed, setAspectComponent, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

ATTR_ADDED

public static final String ATTR_ADDED
See Also:
Constant Field Values
Constructor Detail

PersistenceWrapper

public PersistenceWrapper(AspectComponent ac)
Method Detail

normalizeOutput

public Object normalizeOutput(Object value)
                       throws Exception
Gets the object in memory object for a "storage" value.

Parameters:
value - the "storage" value
Returns:
if value is an OID, a reference to the object with that OID is returned, otherwise, value is returned.
Exception
See Also:
normalizeInput(Object)

normalizeInput

public Object normalizeInput(Object value)
                      throws Exception
Performs various stuff before storing a value in a storage. If the value is a Wrappee, it is made persistent.

Parameters:
value - the value to be stored
Returns:
if value is a wrappee, the OID of the object is returned, otherwise, value is returned.
Exception
See Also:
normalizeInput(Object)

getOID

public OID getOID(Wrappee wrappee)

isPersistent

public boolean isPersistent(Wrappee wrappee)
Tells if the current object is persistent (role method).

Returns:
true if persistent

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 void makePersistent(Wrappee wrappee)
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

loadAllFields

public void loadAllFields(Wrappee wrappee)
                   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,
                            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:
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,CollectionItem), getReference(Wrappee,FieldItem), addToCollection(Interaction,CollectionItem,Object), removeFromCollection(Interaction,CollectionItem,Object), setReference(Wrappee,FieldItem,Wrappee), setField(Wrappee,FieldItem), AbstractMethodItem.getWrittenFields(), org.objectweb.jac.core.rtti

getCollection

public void getCollection(Wrappee wrappee,
                          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,
                               CollectionItem collection,
                               Object value)
                        throws Exception
This method stores the persistent object that is added to the collection into the storage.

Parameters:
collection - the collection to add to
Exception
See Also:
removeFromCollection(Interaction,CollectionItem,Object), getCollection(Wrappee,CollectionItem)

removeFromCollection

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

Parameters:
collection - the collection to remove from
Exception
See Also:
addToCollection(Interaction,CollectionItem,Object), getCollection(Wrappee,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,
                         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,FieldItem,Wrappee)

setReference

protected void setReference(Wrappee wrappee,
                            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,FieldItem)

setField

protected void setField(Wrappee wrappee,
                        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,
                            CollectionItem[] collections)
                     throws Exception
Exception

initAllFields

public void initAllFields(Wrappee wrappee)
                   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 initializer object
Exception

getStorage

public Storage getStorage()

getAC

public final PersistenceAC getAC()

checkOid

public void checkOid(Wrappee wrappee)
              throws PersistenceWrapper.InvalidOidException
PersistenceWrapper.InvalidOidException

Contact JAC development team:
Renaud Pawlak
Lionel Seinturier
Laurent Martelli