|
![]() |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectedu.nrao.sss.dao.HibernateDao
public class HibernateDao
This is the base class for Data access objects using Hibernate as their persistence mechanism. It provides basic support for creating SessionFactories and Sessions, and begining and commiting transactions. SessionFactories are saved in a static Map<String, SessionFactory> with keys being the file name of the hibernate configuration file used to create the Factory. This is done so that multiple instances of a dao that accesses the same database don't have to repeat the overhead of creating a SessionFactory. You can also specify a Hibernate Interceptor to be used when creating sessions. Note: This class is not threadsafe! To implement threadsafety, have your subclass synchronize appropriate access methods
Field Summary | |
---|---|
protected static Map<String,org.hibernate.SessionFactory> |
factories
|
Constructor Summary | |
---|---|
HibernateDao()
Creates a HibernateDao that uses the default configuration file name and no Interceptor. |
|
HibernateDao(String cfg,
org.hibernate.Interceptor i)
Creates a HibernateDao that uses cfg as it's configuration
file and creates Sessions with i as its Interceptor. |
Method Summary | |
---|---|
void |
addDaoListener(DaoListener listener)
Adds a listener that will be notified when the dao has to roll back a transaction |
void |
beginTransaction()
If a transaction has not already begun, start one. |
void |
closeSession()
If there is an open session, close it. |
void |
commitTransaction()
If a transaction is active, commit it. |
static void |
destroyAllFactories()
This method will close ALL SessionFactories that have been created. |
void |
destroyFactory()
This method ONLY closes the factory associated with getConfigurationFileName() . |
protected void |
fireRollbackEvent()
Notifies all DaoListeners that have been registered that a Rollback Event has occured for this Dao. |
String |
getConfigurationFileName()
Returns the Hibernate configuration file name used to create a SessionFactory for this Dao. |
org.hibernate.Interceptor |
getInterceptor()
Returns the Interceptor used when creating sessions returned by getSession(). |
org.hibernate.Session |
getSession()
Returns the currently open Session. |
org.hibernate.SessionFactory |
getSessionFactory()
returns a session factory that was configured using the config file pointed to by getConfigurationFileName() . |
void |
removeDaoListeners()
Removes all dao listeners from the listener list |
void |
rollbackTransaction()
If a transaction is active, roll it back. |
void |
setConfigurationFileName(String cfg)
Sets the Hibernate configuration file name used to create a SessionFactory for this Dao. |
void |
setInterceptor(org.hibernate.Interceptor i)
This method sets the Interceptor that is used to create sessions for this Dao. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected static Map<String,org.hibernate.SessionFactory> factories
Constructor Detail |
---|
public HibernateDao(String cfg, org.hibernate.Interceptor i)
cfg
as it's configuration
file and creates Sessions with i
as its Interceptor.
cfg
- File name of the main xml hibernate configuration file. Must
be on the classpath somewhere. If null, "/hibernate.cfg.xml" is used.i
- Interceptor used when creating Sessions. If null, no Interceptor
is used.public HibernateDao()
HibernateDao(String, Interceptor)
Method Detail |
---|
public String getConfigurationFileName()
public void setConfigurationFileName(String cfg) throws org.hibernate.HibernateException
org.hibernate.HibernateException
public org.hibernate.SessionFactory getSessionFactory() throws org.hibernate.HibernateException
getConfigurationFileName()
. If a SessionFactory has
already been configured for this configuration file, return the old one.
org.hibernate.HibernateException
public org.hibernate.Session getSession() throws org.hibernate.HibernateException
org.hibernate.HibernateException
public void setInterceptor(org.hibernate.Interceptor i)
i
!= the old interceptor and a session factory
already exists for this configuration, transactions are commited and
sessions are closed so that the next session to be asked for will have
the interceptor you assigned.
i
- can be null.Interceptor
public org.hibernate.Interceptor getInterceptor()
Interceptor
public void closeSession() throws org.hibernate.HibernateException
org.hibernate.HibernateException
public void beginTransaction() throws org.hibernate.HibernateException
org.hibernate.HibernateException
public void commitTransaction() throws org.hibernate.HibernateException
rollbackTransaction()
is called.
org.hibernate.HibernateException
public void rollbackTransaction() throws org.hibernate.HibernateException
org.hibernate.HibernateException
public void destroyFactory() throws org.hibernate.HibernateException
getConfigurationFileName()
. It does not commit
pending transactions nor does it close any sessions.
org.hibernate.HibernateException
public static void destroyAllFactories() throws org.hibernate.HibernateException
org.hibernate.HibernateException
public void addDaoListener(DaoListener listener)
listener
- public void removeDaoListeners()
protected void fireRollbackEvent()
|
![]() |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |