net.databinder.hib
Class Databinder

java.lang.Object
  extended by net.databinder.hib.Databinder

public class Databinder
extends java.lang.Object

Provides access to application-bound Hibernate session factories and current sessions. This class will work with a ManagedSessionContext and DataRequestCycle listener when present, but neither is required so long as a "current" session is available from the session factory supplied by the application.

Author:
Nathan Hamblen
See Also:
HibernateApplication

Constructor Summary
Databinder()
           
 
Method Summary
static java.lang.Object ensureSession(SessionUnit unit)
          Wraps SessionUnit callback in a temporary thread-bound Hibernate session from the default factory if necessary.
static java.lang.Object ensureSession(SessionUnit unit, java.lang.Object key)
          Wraps SessionUnit callback in a temporary thread-bound Hibernate session from the keyed factory if necessary.
static org.hibernate.classic.Session getHibernateSession()
           
static org.hibernate.classic.Session getHibernateSession(java.lang.Object key)
           
static org.hibernate.SessionFactory getHibernateSessionFactory()
           
static org.hibernate.SessionFactory getHibernateSessionFactory(java.lang.Object key)
           
static boolean hasBoundSession()
           
static boolean hasBoundSession(java.lang.Object key)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Databinder

public Databinder()
Method Detail

getHibernateSessionFactory

public static org.hibernate.SessionFactory getHibernateSessionFactory()
Returns:
default session factory, as returned by the application
Throws:
org.apache.wicket.WicketRuntimeException - if session factory can not be found
See Also:
HibernateApplication

getHibernateSessionFactory

public static org.hibernate.SessionFactory getHibernateSessionFactory(java.lang.Object key)
Parameters:
key - object, or null for the default factory
Returns:
session factory, as returned by the application
Throws:
org.apache.wicket.WicketRuntimeException - if session factory can not be found
See Also:
HibernateApplication

getHibernateSession

public static org.hibernate.classic.Session getHibernateSession()
Returns:
default Hibernate session bound to current thread

getHibernateSession

public static org.hibernate.classic.Session getHibernateSession(java.lang.Object key)
Parameters:
key - or null for the default factory
Returns:
Hibernate session bound to current thread

hasBoundSession

public static boolean hasBoundSession()
Returns:
true if a session is bound for the default factory

hasBoundSession

public static boolean hasBoundSession(java.lang.Object key)
Parameters:
key - or null for the default factory
Returns:
true if a session is bound for the keyed factory

ensureSession

public static java.lang.Object ensureSession(SessionUnit unit)
Wraps SessionUnit callback in a temporary thread-bound Hibernate session from the default factory if necessary. This is to be used outside of a regular a session-handling request cycle, such as during application init or an external Web service request. The temporary session and transaction, if created, are closed after the callback returns and uncommited transactions are rolled back. Be careful of returning detached Hibernate objects that may not be fully loaded with data; consider using projections / scalar queries instead.Note This method uses a ManagedSessionContext. With JTA or other forms of current session lookup a wrapping session will not be detected and a new one will always be created.

Parameters:
unit - work to be performed in thread-bound session
See Also:
SessionUnit

ensureSession

public static java.lang.Object ensureSession(SessionUnit unit,
                                             java.lang.Object key)
Wraps SessionUnit callback in a temporary thread-bound Hibernate session from the keyed factory if necessary. This is to be used outside of a regular a session-handling request cycle, such as during application init or an external Web service request. The temporary session and transaction, if created, are closed after the callback returns and uncommited transactions are rolled back. Be careful of returning detached Hibernate objects that may not be fully loaded with data; consider using projections / scalar queries instead. Note This method uses a ManagedSessionContext. With JTA or other forms of current session lookup a wrapping session will not be detected and a new one will always be created.

Parameters:
unit - work to be performed in thread-bound session
key - or null for the default factory
See Also:
SessionUnit


Copyright © 2005-2008 Nathan Hamblen. All Rights Reserved.