net.sf.easyweb4j.repository
Class RepositoryManager

java.lang.Object
  extended by net.sf.easyweb4j.repository.RepositoryManager
All Implemented Interfaces:
Serializable, RepositoryProvider

public class RepositoryManager
extends Object
implements RepositoryProvider, Serializable

A repository manager instance manages singleton instances of the different repositories required by the controllers. The singleton instance of the repositories are created lazily when required by the controller handling the request.

Author:
Chandra Sekar S
See Also:
Serialized Form

Constructor Summary
RepositoryManager(Map<Class<?>,PersistenceManager> persistenceManagers, Map<Class<?>,PersistenceContextManager> persistenceContextManagers)
          Initializes the repository map, builds the SessionFactory and EntityManagerFactory if appropriate configuration files are found..
 
Method Summary
 void closePersistence()
          Closes the SessionFactory and the EntityManagerFactory of the application.
 void closePersistenceContext()
          Closes the Hibernate session and JPA EntityManager for the current thread.
 void commit()
          Commits the transaction, if a transaction is currently active.
 void ensureTransaction()
          Begins a transaction.
 Repository<?> getRepository(Class<Repository<?>> repositoryClass)
          Retrieves an instance of the given repository class from the available repositories or creates a new instance.
 void markAsReadOnly()
          Sets the FlushMode of current Session to MANUAL and FlushModeType of current EntityManager to COMMIT.
 void rollback()
          Rolls back the transaction, if a transaction is currently active.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RepositoryManager

public RepositoryManager(Map<Class<?>,PersistenceManager> persistenceManagers,
                         Map<Class<?>,PersistenceContextManager> persistenceContextManagers)
Initializes the repository map, builds the SessionFactory and EntityManagerFactory if appropriate configuration files are found..

Method Detail

closePersistenceContext

public void closePersistenceContext()
Closes the Hibernate session and JPA EntityManager for the current thread.


ensureTransaction

public void ensureTransaction()
Begins a transaction.


commit

public void commit()
Commits the transaction, if a transaction is currently active.


rollback

public void rollback()
Rolls back the transaction, if a transaction is currently active.


markAsReadOnly

public void markAsReadOnly()
Sets the FlushMode of current Session to MANUAL and FlushModeType of current EntityManager to COMMIT. This method is called by Dispatcher before rendering view as all further operations would be reads. This can help in improving performance especially in the case of Hibernate sessions.


closePersistence

public void closePersistence()
Closes the SessionFactory and the EntityManagerFactory of the application.


getRepository

public Repository<?> getRepository(Class<Repository<?>> repositoryClass)
Retrieves an instance of the given repository class from the available repositories or creates a new instance.

Specified by:
getRepository in interface RepositoryProvider
Parameters:
repositoryClass - The class of the repository to be retrieved.
Returns:
Existing or new instance of the repository class.
Throws:
IllegalAccessException - - If creation of new repository fails.
NoSuchFieldException - - If creation of new repository fails.
InstantiationException - - If creation of new repository fails.


Copyright © 2009-2010 Chandra Sekar S. All Rights Reserved.