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  javax.persistence.EntityTransaction entityTransaction
           
protected  org.apache.commons.logging.Log log
           
 
Constructor Summary
AbstractEntityManagerWrapper()
           
 
Method Summary
 void close()
          Closes the current EntityManager, commiting the transaction if necessary.
 void closeOnError()
          Closes the current EntityManager, rollback the transaction if necessary.
protected abstract  javax.persistence.EntityManager doGetEntityManager()
           
protected abstract  javax.persistence.EntityTransaction doGetEntityTransaction()
           
 javax.persistence.EntityManager getEntityManager()
          Returns the EntityManager opened by the wrapper open operation.
 void open()
          Opens the warpper for a session of reading enteties for indexing.
 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

entityTransaction

protected javax.persistence.EntityTransaction entityTransaction
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
Description copied from interface: EntityManagerWrapper
Opens the warpper for a session of reading enteties for indexing.

Specified by:
open in interface EntityManagerWrapper
Throws:
JpaGpsDeviceException

close

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

Specified by:
close in interface EntityManagerWrapper
Throws:
JpaGpsDeviceException

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

doGetEntityManager

protected abstract javax.persistence.EntityManager doGetEntityManager()
                                                               throws javax.persistence.PersistenceException
Throws:
javax.persistence.PersistenceException

doGetEntityTransaction

protected abstract javax.persistence.EntityTransaction doGetEntityTransaction()
                                                                       throws javax.persistence.PersistenceException
Throws:
javax.persistence.PersistenceException

shouldCloseEntityManager

protected abstract boolean shouldCloseEntityManager()


Copyright (c) 2004-2006 The Compass Project.