org.compass.gps.device.jpa
Class AbstractEntityManagerWrapper

java.lang.Object
  extended by org.compass.gps.device.jpa.AbstractEntityManagerWrapper
All Implemented Interfaces:
EntityManagerWrapper
Direct Known Subclasses:
DefaultEntityManagerWrapper, JtaEntityManagerWrapper, ResourceLocalEntityManagerWrapper

public abstract class AbstractEntityManagerWrapper
extends Object
implements EntityManagerWrapper

A simple base class for EntityManagerWrapper implementations. Calls the subclasses for EntityManager, and an optioan EntityTransaction. Takes care of all the rest.

Author:
kimchy

Field Summary
protected  javax.persistence.EntityManager entityManager
           
protected  javax.persistence.EntityManagerFactory entityManagerFactory
           
protected  org.apache.commons.logging.Log log
           
 
Constructor Summary
AbstractEntityManagerWrapper()
           
 
Method Summary
protected abstract  void beginTransaction()
           
 void close()
          Closes the current EntityManager, commiting the transaction if necessary.
 void closeOnError()
          Closes the current EntityManager, rollback the transaction if necessary.
protected abstract  void commitTransaction()
           
protected  void doCreateEntityManager()
           
 javax.persistence.EntityManager getEntityManager()
          Returns the EntityManager opened by the wrapper open operation.
 EntityManagerWrapper newInstance()
          Creates a new instance of this entity manager wrapper for multi threaded usage.
 void open()
          Opens the warpper for a session of reading enteties for indexing.
protected abstract  void rollbackTransaction()
           
 void setUp(javax.persistence.EntityManagerFactory entityManagerFactory)
          Sets up the entity manager wrapper with the EntityManagerFactory.
protected abstract  boolean shouldCloseEntityManager()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

protected org.apache.commons.logging.Log log

entityManagerFactory

protected javax.persistence.EntityManagerFactory entityManagerFactory

entityManager

protected javax.persistence.EntityManager entityManager
Constructor Detail

AbstractEntityManagerWrapper

public AbstractEntityManagerWrapper()
Method Detail

setUp

public void setUp(javax.persistence.EntityManagerFactory entityManagerFactory)
Description copied from interface: EntityManagerWrapper
Sets up the entity manager wrapper with the EntityManagerFactory.

Specified by:
setUp in interface EntityManagerWrapper
Parameters:
entityManagerFactory - The EntityManagerFactory the wrapper will use

getEntityManager

public javax.persistence.EntityManager getEntityManager()
Description copied from interface: EntityManagerWrapper
Returns the EntityManager opened by the wrapper open operation.

Specified by:
getEntityManager in interface EntityManagerWrapper
Returns:
The current EntityManager

open

public void open()
          throws JpaGpsDeviceException,
                 javax.persistence.PersistenceException
Description copied from interface: EntityManagerWrapper
Opens the warpper for a session of reading enteties for indexing.

Specified by:
open in interface EntityManagerWrapper
Throws:
JpaGpsDeviceException
javax.persistence.PersistenceException

close

public void close()
           throws JpaGpsDeviceException,
                  javax.persistence.PersistenceException
Description copied from interface: EntityManagerWrapper
Closes the current EntityManager, commiting the transaction if necessary.

Specified by:
close in interface EntityManagerWrapper
Throws:
JpaGpsDeviceException
javax.persistence.PersistenceException

closeOnError

public void closeOnError()
                  throws JpaGpsDeviceException
Description copied from interface: EntityManagerWrapper
Closes the current EntityManager, rollback the transaction if necessary.

Specified by:
closeOnError in interface EntityManagerWrapper
Throws:
JpaGpsDeviceException

newInstance

public EntityManagerWrapper newInstance()
Description copied from interface: EntityManagerWrapper
Creates a new instance of this entity manager wrapper for multi threaded usage.

Specified by:
newInstance in interface EntityManagerWrapper

doCreateEntityManager

protected void doCreateEntityManager()
                              throws javax.persistence.PersistenceException
Throws:
javax.persistence.PersistenceException

beginTransaction

protected abstract void beginTransaction()
                                  throws javax.persistence.PersistenceException
Throws:
javax.persistence.PersistenceException

commitTransaction

protected abstract void commitTransaction()
                                   throws javax.persistence.PersistenceException
Throws:
javax.persistence.PersistenceException

rollbackTransaction

protected abstract void rollbackTransaction()
                                     throws javax.persistence.PersistenceException
Throws:
javax.persistence.PersistenceException

shouldCloseEntityManager

protected abstract boolean shouldCloseEntityManager()


Copyright (c) 2004-2009 The Compass Project.