public class DbSession
extends java.lang.Object
implements java.lang.AutoCloseable
All invoked queries are stored within one session and closed implicitly on session closing.
For managed transaction see DbJtxTransactionManager
from jodd-tx.
Modifier and Type | Field and Description |
---|---|
protected java.sql.Connection |
connection |
protected ConnectionProvider |
connectionProvider |
protected java.util.Set<jodd.db.DbQueryBase> |
queries
Bag of all queries attached to this session.
|
protected boolean |
txActive |
protected DbTransactionMode |
txMode |
Constructor and Description |
---|
DbSession(ConnectionProvider connectionProvider)
Creates new database session with default transaction mode and in autocommit mode.
|
Modifier and Type | Method and Description |
---|---|
protected void |
assertSessionIsOpen() |
protected void |
assertTxIsActive() |
protected void |
assertTxIsClosed() |
protected void |
attachQuery(jodd.db.DbQueryBase query)
Attaches a new
DbQuery . |
void |
beginTransaction(DbTransactionMode mode)
Starts a transaction.
|
void |
close() |
void |
closeSession()
Closes current session and all allocated resources.
|
protected void |
closeTx()
Closes current transaction.
|
void |
commitTransaction()
Commit the current transaction, writing any unflushed changes to the database.
|
protected void |
detachQuery(jodd.db.DbQueryBase query)
Detach used
DbQuery . |
java.sql.Connection |
getConnection()
Returns current connection.
|
int |
getTotalQueries()
Returns total number of queries assigned to this session.
|
boolean |
isSessionClosed()
Indicates whether a session is closed.
|
boolean |
isSessionOpen()
Returns
true if session is open. |
boolean |
isTransactionActive()
Indicate whether a transaction is in progress.
|
protected void |
openConnectionForQuery()
Opens connection in auto-commit mode, if already not opened.
|
protected void |
openTx()
Opens a transaction.
|
void |
rollbackTransaction()
Roll back the current transaction.
|
protected final ConnectionProvider connectionProvider
protected java.sql.Connection connection
protected java.util.Set<jodd.db.DbQueryBase> queries
null
, session is closed.
If not null
, but empty, session is still considered as open.protected boolean txActive
protected DbTransactionMode txMode
public DbSession(ConnectionProvider connectionProvider)
public void closeSession()
ConnectionProvider
.
Closed session is no longer available for usage.public void close()
close
in interface java.lang.AutoCloseable
public boolean isSessionClosed()
public boolean isSessionOpen()
true
if session is open.public int getTotalQueries()
public java.sql.Connection getConnection()
protected void attachQuery(jodd.db.DbQueryBase query)
DbQuery
. May be invoked both inside and outside of transaction.protected void detachQuery(jodd.db.DbQueryBase query)
DbQuery
. Usually invoked by DbQueryBase.close()
.protected void openConnectionForQuery()
public boolean isTransactionActive()
protected void openTx()
protected void closeTx()
public void beginTransaction(DbTransactionMode mode)
public void commitTransaction()
public void rollbackTransaction()
protected void assertSessionIsOpen()
protected void assertTxIsClosed()
protected void assertTxIsActive()
Copyright © 2003-present Jodd Team