Methods Summary |
---|
public static void | bind(org.hibernate.Session session)Associates the given session with the current thread of execution.
SessionFactory factory = session.getSessionFactory();
cleanupAnyOrphanedSession( factory );
doBind( session, factory );
|
protected org.hibernate.context.ThreadLocalSessionContext$CleanupSynch | buildCleanupSynch()
return new CleanupSynch( factory );
|
protected org.hibernate.classic.Session | buildOrObtainSession()Strictly provided for subclassing purposes; specifically to allow long-session
support.
This implementation always just opens a new session.
return factory.openSession(
null,
isAutoFlushEnabled(),
isAutoCloseEnabled(),
getConnectionReleaseMode()
);
|
private static void | cleanupAnyOrphanedSession(org.hibernate.SessionFactory factory)
Session orphan = doUnbind( factory, false );
if ( orphan != null ) {
log.warn( "Already session bound on call to bind(); make sure you clean up your sessions!" );
try {
if ( orphan.getTransaction() != null && orphan.getTransaction().isActive() ) {
try {
orphan.getTransaction().rollback();
}
catch( Throwable t ) {
log.debug( "Unable to rollback transaction for orphaned session", t );
}
}
orphan.close();
}
catch( Throwable t ) {
log.debug( "Unable to close orphaned session", t );
}
}
|
public final org.hibernate.classic.Session | currentSession()
Session current = existingSession( factory );
if (current == null) {
current = buildOrObtainSession();
// register a cleanup synch
current.getTransaction().registerSynchronization( buildCleanupSynch() );
// wrap the session in the transaction-protection proxy
if ( needsWrapping( current ) ) {
current = wrap( current );
}
// then bind it
doBind( current, factory );
}
return current;
|
private static void | doBind(org.hibernate.Session session, org.hibernate.SessionFactory factory)
Map sessionMap = sessionMap();
if ( sessionMap == null ) {
sessionMap = new HashMap();
context.set( sessionMap );
}
sessionMap.put( factory, session );
|
private static org.hibernate.classic.Session | doUnbind(org.hibernate.SessionFactory factory, boolean releaseMapIfEmpty)
Map sessionMap = sessionMap();
Session session = null;
if ( sessionMap != null ) {
session = ( Session ) sessionMap.remove( factory );
if ( releaseMapIfEmpty && sessionMap.isEmpty() ) {
context.set( null );
}
}
return session;
|
private static org.hibernate.classic.Session | existingSession(org.hibernate.SessionFactory factory)
Map sessionMap = sessionMap();
if ( sessionMap == null ) {
return null;
}
else {
return ( Session ) sessionMap.get( factory );
}
|
protected org.hibernate.ConnectionReleaseMode | getConnectionReleaseMode()Mainly for subclass usage. This impl always returns after_transaction.
return factory.getSettings().getConnectionReleaseMode();
|
protected org.hibernate.engine.SessionFactoryImplementor | getFactory()
return factory;
|
protected boolean | isAutoCloseEnabled()Mainly for subclass usage. This impl always returns true.
return true;
|
protected boolean | isAutoFlushEnabled()Mainly for subclass usage. This impl always returns true.
return true;
|
private boolean | needsWrapping(org.hibernate.classic.Session session)
// try to make sure we don't wrap and already wrapped session
return session != null
&& ! Proxy.isProxyClass( session.getClass() )
|| ( Proxy.getInvocationHandler( session ) != null
&& ! ( Proxy.getInvocationHandler( session ) instanceof TransactionProtectionWrapper ) );
|
protected static java.util.Map | sessionMap()
return ( Map ) context.get();
|
public static org.hibernate.classic.Session | unbind(org.hibernate.SessionFactory factory)Unassociate a previously bound session from the current thread of execution.
return doUnbind( factory, true );
|
protected org.hibernate.classic.Session | wrap(org.hibernate.classic.Session session)
TransactionProtectionWrapper wrapper = new TransactionProtectionWrapper( session );
Session wrapped = ( Session ) Proxy.newProxyInstance(
Session.class.getClassLoader(),
SESS_PROXY_INTERFACES,
wrapper
);
// yick! need this for proper serialization/deserialization handling...
wrapper.setWrapped( wrapped );
return wrapped;
|