org.objectweb.easybeans.persistence
Class PersistenceUnitManager

java.lang.Object
  extended by org.objectweb.easybeans.persistence.PersistenceUnitManager
All Implemented Interfaces:
EZBPersistenceUnitManager

public class PersistenceUnitManager
extends java.lang.Object
implements EZBPersistenceUnitManager

This class manages persistence units ands allow to return EntityManager or EntityManagerFactory.

Author:
Florent Benoit

Field Summary
private  java.util.Map<java.lang.String,JPersistenceContext> persistenceContexts
          List of persistence unit objects managed by their name.
 
Constructor Summary
PersistenceUnitManager(JPersistenceUnitInfo[] persistenceUnitInfos)
          Build a new manager with given persistence units.
 
Method Summary
 void addCurrent()
          Create a new EntityManager on each PersistenceContext.
 void closeCurrentAndReturnToPrevious()
          Sets back to the previous entity manager and close the current entity manager for each persistence context.
 EntityManager getEntityManager(java.lang.String unitName, PersistenceContextType type)
          Gets an entity manager for the given unit name and the extra attributes.
 EntityManagerFactory getEntityManagerFactory(java.lang.String unitName)
          Gets an entity manager factory for the given unit name.
private  JPersistenceContext getPersistenceContext(java.lang.String unitName)
          Gets the persistence context associated to a given persistence unit name.
 void merge(EZBPersistenceUnitManager otherEZBPersistenceUnitManager)
          Merge the persistence context of a an other persistent unit manager in this one.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

persistenceContexts

private java.util.Map<java.lang.String,JPersistenceContext> persistenceContexts
List of persistence unit objects managed by their name.

Constructor Detail

PersistenceUnitManager

public PersistenceUnitManager(JPersistenceUnitInfo[] persistenceUnitInfos)
Build a new manager with given persistence units.

Parameters:
persistenceUnitInfos - a list of persistence unit infos.
Method Detail

getPersistenceContext

private JPersistenceContext getPersistenceContext(java.lang.String unitName)
Gets the persistence context associated to a given persistence unit name.

Parameters:
unitName - the name of the persistence unit object.
Returns:
the object which is found by matching the expected name.

getEntityManager

public EntityManager getEntityManager(java.lang.String unitName,
                                      PersistenceContextType type)
Gets an entity manager for the given unit name and the extra attributes.

Specified by:
getEntityManager in interface EZBPersistenceUnitManager
Parameters:
unitName - the name of the persistence unit
type - the type of the persistence context
Returns:
entity manager corresponding to arguments

getEntityManagerFactory

public EntityManagerFactory getEntityManagerFactory(java.lang.String unitName)
Gets an entity manager factory for the given unit name.

Specified by:
getEntityManagerFactory in interface EZBPersistenceUnitManager
Parameters:
unitName - the name of the persistence unit
Returns:
entity manager factory.

addCurrent

public void addCurrent()
Create a new EntityManager on each PersistenceContext. (Will be used for the method lifecycle)

Specified by:
addCurrent in interface EZBPersistenceUnitManager

closeCurrentAndReturnToPrevious

public void closeCurrentAndReturnToPrevious()
Sets back to the previous entity manager and close the current entity manager for each persistence context.

Specified by:
closeCurrentAndReturnToPrevious in interface EZBPersistenceUnitManager

merge

public void merge(EZBPersistenceUnitManager otherEZBPersistenceUnitManager)
Merge the persistence context of a an other persistent unit manager in this one. Note that as specified in chapter 6.2.2 (persistence unit scope), an EAR level component level will only be seen by a subcomponent if it was not redefined. In our case : don't merge the given unit-name if the current manager defines this unit-name.

Specified by:
merge in interface EZBPersistenceUnitManager
Parameters:
otherEZBPersistenceUnitManager - the other persistence unit manager that will be merged into this one.