Class PersistenceProvider

  extended by
Direct Known Subclasses:
HibernatePersistenceProvider, JdoPersistenceProvider, MockPersistenceProvider

public abstract class PersistenceProvider
extends java.lang.Object

Superclass for all persistence providers. This class is extended to provide persistence engine specific implementations. eg., HibernatePersistenceProvider and JdoPersistenceProvider. These objects are typically kept 'open' throughout multiple HTTP requests, for each request a transaction is begun at the start and commited (or rolled back) at the end. This implements the 'OpenSessionInView' (hibernate) or 'OpenPersistenceManagerInView' pattern. A future possible enhancement is to add an optional "free persistence provider' mechanism at the end of each HTTP request.

Field Summary
protected  int depth
          Depth of the deepest transaction.
 ModelExposer modelExposer
Constructor Summary
Method Summary
abstract  void beginTx()
          Begins a transaction.
abstract  void close()
          Closes the persistence provider.
abstract  void commitTx()
          Commits a transaction.
abstract  void delete(java.lang.Object object)
          Deletes the persistent object from the datastore.
abstract  boolean hasActiveTx()
          Returns true if the PersistenceProvider has an active transaction.
abstract  void open()
          Opens a persistence provider.
abstract  void persist(java.lang.Object object)
          Makes the given object persistent.
abstract  java.lang.RuntimeException processException(java.lang.RuntimeException e)
          Processes an exception thrown while in a transaction.
abstract  void rollbackTx()
          Rolls back a transaction.
 void setModelExposer(ModelExposer iModelExposer)
          Sets the owning ModelExposer.
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Field Detail


protected transient int depth
Depth of the deepest transaction. 0 = no active transaction. beginTx increments and commitTx and rollbackTx decrement depth. See rollbackTx for more information.


public ModelExposer modelExposer
Constructor Detail


public PersistenceProvider()
Method Detail


public abstract boolean hasActiveTx()
Returns true if the PersistenceProvider has an active transaction.


public void setModelExposer(ModelExposer iModelExposer)
Sets the owning ModelExposer.


public abstract void open()
Opens a persistence provider.


public abstract java.lang.RuntimeException processException(java.lang.RuntimeException e)
Processes an exception thrown while in a transaction. The exception could be relevent to the persistence technology or a generic RuntimeException. If it's an optimistic verification exception (optimistic locking check failed) then no exception is thrown and the persistence technology may or may not need clean. In the case of JDO a rollback as already been performed.


public abstract void close()
Closes the persistence provider. It can no longer be used after being closed.


public abstract void delete(java.lang.Object object)
Deletes the persistent object from the datastore.


public abstract void persist(java.lang.Object object)
Makes the given object persistent.


public abstract void rollbackTx()
Rolls back a transaction.


public abstract void commitTx()
Commits a transaction.


public abstract void beginTx()
Begins a transaction.