Provides a generic persistence aspect for JAC objects.

This aspect is centered around a Storage interface which allows the programmer to adapt the persitence to any kind of storage (file based, databases, and so on).

A default implementation using the java.sql API (based on JDBC) is provided in the SQLStorage abtsract class. In order to create a concrete class, you only have to define the getNextVal(String sequence) method. As of today, the only storage available is PostgresStorage, which supports the Postgresql database.

The persitence aspect stores object's attributes in a storage so that a program can stopped and relaunched without losing data.

Here's a basic configuration for this aspect:

configureClass "org.objectweb.jac.samples.photos.Photo" "persistent"
configureClass "org.objectweb.jac.samples.photos.PhotoRepository" "root"
configureClass "org.objectweb.jac.samples.photos.Person" "root"
wrapCollection "org.objectweb.jac.samples.photos.PhotoRepository" "photos"
registerStatic "photorepository0"
configureStorage "org.objectweb.jac.aspects.persistence.PostgresStorage" { "photo" "jac" "" }
    

Classes can be configured to be persistence root, or just persistent. Instances of root classes are made persistent immediatly after you create them. Instances of persistent classes or made persistent only when they are attached to an already persistent object.

If you have a attribute of type Collection you want it to be stored in the storage, you should use wrapCollection. This is not very convenient and will not be needed any more in a forthcoming release.

Static objects are objects which are only created and saved once in the storage. The next time you create them, they will be reloaded from the storage.

Consider the following application:

public static void main( String[] args )
{
      PhotoRepository rep = new PhotoRepository();
}
    

It creates a PhotoRepository to work with. If the PhotoRepository rep is not declared static to the persistence aspect, a new PhotoRepository will be created each time you run this application, which is probably not what you want.

The configuration methods for this aspect are:

Related Documentation

For overviews, sources, tutorials, examples, guides, and tool documentation, please see: