|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--org.objectweb.jac.core.AspectComponent | +--org.objectweb.jac.aspects.persistence.PersistenceAC
This AC defines a generic and configurable persistence aspect.
Nested Class Summary | |
static class |
PersistenceAC.NoSuchWrapperException
|
Field Summary | |
protected org.objectweb.jac.aspects.persistence.PersistenceAC.StorageSpec |
defaultStorage
The default storage. |
static String |
DISABLE_PRELOAD
|
static String |
NO_CACHE
|
static String |
PERSISTENT
The global identifier for a persistent class in the RTTI. |
static String |
PRELOAD_FIELD
|
static String |
RESTORE
|
static String |
ROOT
The global identifier for a persistence root class in the RTTI. |
protected Vector |
storages
List of StorageSpec |
static String |
VALUE_CONVERTER
|
Fields inherited from class org.objectweb.jac.core.AspectComponent |
application, blockKeywords, cr, currentConfigMethod, currentImports, firstCall, NOT_SHARED, SHARED, startWeavingCCount, startWeavingCount, startWeavingMethod, startWeavingType, systemListener, wrappers |
Fields inherited from interface org.objectweb.jac.core.BaseProgramListener |
FOUND_OBJECT |
Constructor Summary | |
PersistenceAC()
|
Method Summary | |
boolean |
beforeRunningWrapper(Wrapper wrapper,
String wrappingMethod)
This method is called when a wrapper is going to be applied to a wrappee. |
void |
checkUnload()
This method is a callback for the timer that defines the max idle time. |
void |
configureStorage(ClassItem storageClass,
String[] storageParameters)
Specify which the default storage class to use and the parameters to use to instanciate it. |
void |
configureStorage(String id,
ClassItem storageClass,
String[] storageParameters)
Specify which storage class to use and the parameters to use to instanciate it. |
void |
defineMaxIdleCheckPeriod(long period)
Defines the period that is used to check that the collection max idle time has not been reached. |
void |
disableCache(CollectionItem collection)
This configuration method allows to disable the cache for a given collection. |
String[] |
getDefaultConfigs()
Returns defaults configuration files that must be loaded before the user's configuration |
void |
getNameCounters(Map counters)
|
OID |
getOID(Wrappee wrappee)
|
Storage |
getStorage(ClassItem cli)
Returns the storage for a given class |
Storage |
getStorage(Object obj)
Returns the storage for a given object |
protected Storage |
getStorage(String id)
Gets the storage with a given id, or null. |
protected Storage[] |
getStorages()
|
org.objectweb.jac.aspects.persistence.PersistenceAC.StorageSpec |
getStorageSpec(String storageId)
|
static boolean |
isFieldPreloaded(FieldItem field)
|
void |
makePersistent(String classExpr,
String nameExpr)
Configure persistence for one class. |
void |
maxIdle(CollectionItem collection,
long maxIdle)
Set a max idle time for a collection. |
void |
onExit()
Close every storage |
LongOID |
parseLongOID(String str,
Storage defaultStorage)
Converts a String into a LongOID. |
void |
preloadAllFields(ClassItem cl)
Set all fields of a class to be preloaded Same as preloadField, but for all fields of the class |
void |
preloadField(FieldItem field)
Sets a field or collection to be preloaded By default, persistent fields are loaded when accessed. |
protected void |
registerObject(OID oid,
Object object)
Add an object in the list of persistent objects. |
void |
registerStatics(String classExpr,
String nameExpr)
Registers a static name, that is a name that will not be changed by the persistence AC. |
void |
setStorage(String classExpr,
String storageId)
Sets the storage to use for some classes. |
void |
setValueConverter(ClassItem cl,
ClassItem converterClass)
Associate a String-Object converter with a class In order to stock objects in database, those objects must be converted in a String format. |
void |
updateNameCounters(Map counters)
|
void |
whenConfigured()
This method should be defined by the programmer when specific actions are needed once the aspect component has be configured. |
void |
whenDeleted(Wrappee object)
Upcalled when an object is deleted. |
void |
whenDeserialized(SerializedJacObject orgObject)
This method allows the deserialization of the OID of a persistent object. |
void |
whenFree(Wrappee object)
Upcalled when an object is freed from the memory. |
void |
whenGetObjects(Collection objects,
ClassItem cl)
Load objects from the storage when required. |
String |
whenNameObject(Object object,
String name)
Delegates naming to the storage |
void |
whenObjectMiss(String name)
The persistence aspect checks whether an object was in the storage when a NameRepository.getObject call
failed. |
void |
whenSerialized(SerializedJacObject finalObject)
This method add the OID info to the serialized JAC object when a serialization is requested by another aspect. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public static final String ROOT
public static final String PERSISTENT
public static final String VALUE_CONVERTER
public static final String PRELOAD_FIELD
public static final String DISABLE_PRELOAD
public static final String NO_CACHE
public static final String RESTORE
protected org.objectweb.jac.aspects.persistence.PersistenceAC.StorageSpec defaultStorage
protected Vector storages
Constructor Detail |
public PersistenceAC()
Method Detail |
protected Storage getStorage(String id)
id
- id of the storage to get. If null, returns the defaultStorage.protected Storage[] getStorages()
public void onExit()
onExit
in interface BaseProgramListener
onExit
in class AspectComponent
public void setValueConverter(ClassItem cl, ClassItem converterClass)
PersistenceConf
In order to stock objects in database, those objects must be converted in a String format. Basic classes are already implemented, but for new classes (such as java.awt.Dimension) new converters must be used. New converters can be used with fhis function.
setValueConverter
in interface PersistenceConf
cl
- the class to convertconverterClass
- the converter used. The class must implement
org.objectweb.jac.aspects.persistenceconf.StringConverter
.StringConverter
public void checkUnload()
For all the collections that have a max idle time, it checks that this time is not reached. If it is reached, it unloads the collection.
defineMaxIdleCheckPeriod(long)
,
maxIdle(CollectionItem,long)
public void defineMaxIdleCheckPeriod(long period)
PersistenceConf
If a collection max idle time is defined and that it has not been used for this time, then the collection is unloaded from the memory by the peristence.
This method is not mandatory, by default, a check period of 200.000 ms is defined.
defineMaxIdleCheckPeriod
in interface PersistenceConf
period
- the period time check in msPersistenceConf.maxIdle(CollectionItem,long)
public void maxIdle(CollectionItem collection, long maxIdle)
PersistenceConf
The idle time corresponds to the time the collection is loaded in memory without having been accessed. By default, a collection stays in memory when it is loaded. For big collections, it might be interested to define a max idle time. When the max idle time is reached, the persistence aspect unloads this collection from the memory. The collection will be reloaded on the next access.
The frequency the max idle time has be reached is global to
all collection and can be defined by
defineMaxIdleCheckPeriod
maxIdle
in interface PersistenceConf
collection
- the collection that has a max idlemaxIdle
- the max idle time in msPersistenceConf.defineMaxIdleCheckPeriod(long)
public void whenConfigured()
AspectComponent
whenConfigured
in class AspectComponent
public void configureStorage(ClassItem storageClass, String[] storageParameters)
PersistenceConf
FSStorage
and
PostgresStorage
configureStorage
in interface PersistenceConf
storageClass
- the storage class. Constructors of this
class must have PersistenceAC as first parameter.storageParameters
- the parametersPersistenceConf.configureStorage(String,ClassItem,String[])
,
FSStorage
,
PostgresStorage
public void configureStorage(String id, ClassItem storageClass, String[] storageParameters)
PersistenceConf
FSStorage
and
PostgresStorage
configureStorage
in interface PersistenceConf
id
- identifier for the storage. It must not contain the character ':'storageClass
- the storage class. Constructors of this
class must have PersistenceAC as first parameter.storageParameters
- the parametersPersistenceConf.configureStorage(ClassItem,String[])
,
FSStorage
,
PostgresStorage
public void setStorage(String classExpr, String storageId)
PersistenceConf
setStorage
in interface PersistenceConf
classExpr
- the classes to configurestorageId
- the storage ID to use for those classes. It
must have been declared with PersistenceConf.configureStorage(String,ClassItem,String[])
PersistenceConf.configureStorage(String,ClassItem,String[])
public void registerStatics(String classExpr, String nameExpr)
PersistenceConf
Note that the root objects, as defined by the rtti aspect are automatically considered as static objects by the persistence aspect. Thus, it is useless to define a root object static.
registerStatics
in interface PersistenceConf
classExpr
- class expression of static objectsnameExpr
- name expression of static objectspublic void makePersistent(String classExpr, String nameExpr)
PersistenceConf
The persistence type must be PersistenceAC.ROOT (a named object that is an entry point in the storage) or PersistenceAC.PERSISTENT for a regular persistent class.
ROOT objects are always wrapped, PERSISTENT are only wrapped when they become persistent, that is when they are linked to an already persistent object.
makePersistent
in interface PersistenceConf
classExpr
- class expression of static objectsnameExpr
- name expression of static objectspublic Storage getStorage(ClassItem cli)
cli
- a class
public org.objectweb.jac.aspects.persistence.PersistenceAC.StorageSpec getStorageSpec(String storageId)
public Storage getStorage(Object obj)
obj
- object to get the storage for
public void whenObjectMiss(String name)
NameRepository.getObject
call
failed.
whenObjectMiss
in interface BaseProgramListener
whenObjectMiss
in class AspectComponent
name
- the name of the objectBaseProgramListener.whenObjectMiss(String)
public String whenNameObject(Object object, String name)
whenNameObject
in interface BaseProgramListener
whenNameObject
in class AspectComponent
object
- the object to namename
- current name of the object or null
public void getNameCounters(Map counters)
getNameCounters
in class AspectComponent
public void updateNameCounters(Map counters)
updateNameCounters
in class AspectComponent
protected void registerObject(OID oid, Object object)
oid
- the OID of the objectobject
- the objectpublic OID getOID(Wrappee wrappee)
public void whenDeserialized(SerializedJacObject orgObject)
orgObject
- the JAC object structure that is beeing
deserializedwhenSerialized(SerializedJacObject)
public void whenSerialized(SerializedJacObject finalObject)
This adding allows, for instance, the OID to be transmitted to remote containers.
finalObject
- the object that is being serializedpublic void whenGetObjects(Collection objects, ClassItem cl)
whenGetObjects
in interface BaseProgramListener
whenGetObjects
in class AspectComponent
objects
- the returned list (can be modified)cl
- the class that was used by the program to filter its
instances (can be null for all the objects)ObjectRepository
public boolean beforeRunningWrapper(Wrapper wrapper, String wrappingMethod)
AspectComponent
By overloading this method, the aspect component can skip the
wrapper, for instance if the current collaboration shows that
the wrapper has allready been applied.
If the method returns true, then the wrapper is run, else it
is skipped. Default: return true.
beforeRunningWrapper
in interface BaseProgramListener
beforeRunningWrapper
in class AspectComponent
wrapper
- the wrapper that is going to be runnedwrappingMethod
- the name of the may-be runned wrapping
method
Wrappee
,
Wrapping.wrap(Wrappee,Wrapper,AbstractMethodItem)
,
Wrapper
,
Wrapper.proceed(Invocation)
public void whenDeleted(Wrappee object)
BaseProgramListener
whenDeleted
in interface BaseProgramListener
whenDeleted
in class AspectComponent
object
- the deleted objectpublic void whenFree(Wrappee object)
BaseProgramListener
whenFree
in interface BaseProgramListener
whenFree
in class AspectComponent
object
- the deleted objectpublic void preloadField(FieldItem field)
PersistenceConf
By default, persistent fields are loaded when accessed. Preloading a field force it to be loaded when the object is created : in the constructor.
preloadField
in interface PersistenceConf
field
- the field to preloadpublic void preloadAllFields(ClassItem cl)
PersistenceConf
Same as preloadField, but for all fields of the class
preloadAllFields
in interface PersistenceConf
cl
- the classPersistenceConf.preloadField(FieldItem)
public static boolean isFieldPreloaded(FieldItem field)
public void disableCache(CollectionItem collection)
PersistenceConf
Then, the collection will never be loaded in the memory but the objects will be accessed directly in the storage.
disableCache
in interface PersistenceConf
public String[] getDefaultConfigs()
AspectComponent
getDefaultConfigs
in class AspectComponent
public LongOID parseLongOID(String str, Storage defaultStorage)
str
- the string representing the OID. If it's like
"defaultStorage
- storage to use to build the OID if the
string does not contain an OID part.
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |