jodd.db
Class DbThreadSession

java.lang.Object
  extended by jodd.db.DbSession
      extended by jodd.db.DbThreadSession

public class DbThreadSession
extends DbSession

Thread assigned DbSession. Upon creation, it assigns the session to current thread. Useful when only one session (i.e. connection) is used per thread, through service layers.

DbThreadSession uses ThreadDbSessionHolder for storing created sessions in the thread storage. Note that holder may be manipulated from outside of this class.


Field Summary
 
Fields inherited from class jodd.db.DbSession
connection, DEFAULT_TX_MODE, queries, txActive, txMode
 
Constructor Summary
DbThreadSession()
          Creates new db session and assigns it to the current thread, using default connection provider.
DbThreadSession(ConnectionProvider connectionProvider)
          Creates new db session and assigns it to the current thread.
 
Method Summary
 void closeSession()
          Closes current session and remove the association from current thread.
static void closeThreadSession()
          Closes thread session.
static DbSession getCurrentSession()
          Returns current thread session or null if no session is assigned to a thread.
static DbThreadSession getThreadSession()
          Returns existing thread session, or new one if already not exist.
static void registerConnectionProvider(ConnectionProvider cp)
          Registers default connection provider.
 
Methods inherited from class jodd.db.DbSession
beginTransaction, beginTransaction, checkActiveTx, checkClosedTx, checkOpenSession, closeTx, commitTransaction, getConnection, getTotalActiveQueries, getTotalQueries, isSessionClosed, isTransactionActive, openConnectionForQuery, openTx, rollbackTransaction
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DbThreadSession

public DbThreadSession(ConnectionProvider connectionProvider)
Creates new db session and assigns it to the current thread. Closes already assigned session, if any exist.

Parameters:
connectionProvider - connection provider

DbThreadSession

public DbThreadSession()
Creates new db session and assigns it to the current thread, using default connection provider.

See Also:
registerConnectionProvider(jodd.db.connection.ConnectionProvider)
Method Detail

closeSession

public void closeSession()
Closes current session and remove the association from current thread.

Overrides:
closeSession in class DbSession
See Also:
DbSession.closeSession()

getCurrentSession

public static DbSession getCurrentSession()
Returns current thread session or null if no session is assigned to a thread.


registerConnectionProvider

public static void registerConnectionProvider(ConnectionProvider cp)
Registers default connection provider.


getThreadSession

public static DbThreadSession getThreadSession()
Returns existing thread session, or new one if already not exist. If session doesn't exist, it will be created using default connection provider.

See Also:
registerConnectionProvider(jodd.db.connection.ConnectionProvider)

closeThreadSession

public static void closeThreadSession()
Closes thread session.



Copyright ©2008 Jodd Team