|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.apache.click.extras.hibernate.SessionContext
public class SessionContext
Provides a thread local Hibernate Session context class. The Hibernate configuration should be defined in class path file:
/hibernate.cfg.xmlOr alternatively by using System properties. The Hibernate initialization code used by SessionContext is:
Configuration configuration = createConfiguration(); configuration.setProperties(System.getProperties()); configuration.configure(); SessionFactory sessionFactory = configuration.buildSessionFactory();To support the SessionContext class configure a
SessionFilter
in
your web application.
SessionFilter
,
HibernateForm
Constructor Summary | |
---|---|
SessionContext()
|
Method Summary | |
---|---|
static void |
close()
Close the Session held by the current Thread. |
Configuration |
createConfiguration()
Creates and returns a new Configuration instance. |
static Session |
getSession()
Get the Session for the current Thread, creating one if necessary. |
static SessionFactory |
getSessionFactory()
Return the Hibernate SessionFactory. |
static boolean |
hasSession()
Return true if a session is open. |
void |
initConfiguration(Configuration configuration)
Initialize the configuration instance. |
void |
onInit(ServletContext servletContext)
Initializes the SessionContext instance. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public SessionContext()
Method Detail |
---|
public void onInit(ServletContext servletContext)
createConfiguration()
and then initializes the configuration
by invoking initConfiguration(org.hibernate.cfg.Configuration)
.
servletContext
- the servlet contextpublic Configuration createConfiguration()
public void initConfiguration(Configuration configuration)
public Configuration createConfiguration() { configuration.setProperties(System.getProperties()); configuration.configure(); }
configuration
- the configuration to initializepublic static Session getSession() throws HibernateException
HibernateException
- if an error occurs opening the sessionpublic static void close() throws HibernateException
HibernateException
- if an error occurs closing the sessionpublic static boolean hasSession()
public static SessionFactory getSessionFactory()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |