Provides an aspect that allows to define persistent data. This aspect encapsulates the Hibernate framework.
Hibernate offers persistence over a DBMS using JDBC. Hibernate handles basic data types, collections, references. Hibernate offers a query language to fetch persistent objects according to some given criteria. Hibernate imposes a number of constraints on the way you write your code:
Point 1. and 2. are related to the way business objects are written.
Hence, this is a bit different from the other persistence aspect found in
the JAC distribution (org.objectweb.jac.aspects.persistence
)
where reflection is used to access fields.
Hibernate thus imposes some overhead on the business developper
(even if we could think of automatically generating setter/getter for all fields).
Point 3. is under the responsability of the aspect programmer that has to write this .xml file and the traditional .acc file for configuring the Hibernate persistence AC.
HibernateAC interface contains 4 configuration methods:
registerPersistentClass
, initStorage
,
registerPersistentObject
, delimitPersistentSession
.
registerPersistentClass
allows to register a new persistent
class with Hibernate,initStorage
is to tell Hibernate to create the tables
in the database,registerPersistentObject
is to declare which JAC object is
to be made persistent,delimitPersistentSession
is related to the way Hibernate
handles persistence: data are written in the database using a transaction
during a, so-called, Hibernate session. One may want to define a transaction
every time a field is written, but it may be too costly and unecessary.
Hence, Hibernate allows to group reads and writes to perform them transactionaly.
You can thus benefit from all the usual properties of transactions:
delimitPersistentSession
configuration method allows to define
two pointcuts: the first one gives the join point where the Hibernate session
will begin, and the second one the join point where it will end. Of course,
several sessions can be defined.
The typical usage scenario of this AC is illustrated below
(the example can also be found in the
org.objectweb.jac.samples.hibernate
application).
/** Declare a class to be persistent. */ registerPersistentClass User; /** * Create tables to hold data for persistent classes. * Only once if you want to keep data between two program runs * (Hibernate drop tables, before creating them, even if they exist yet). */ initStorage ; /** Tell which JAC objects (user0) are to be made persistent. */ registerPersistentObject user0; /** * Delimit the Hibernate persistent session. * The session will begin after the 1st pointcut (parameters 2,3,4), * and end before the 2nd one (parameters 5,6,7). * -> here the session is around method User.test1() */ delimitPersistentSession s0 User ".*" "test1.*" User ".*" "test1.*";