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 DbManager |
dbManager |
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()
Creates new database session using default connection provider.
|
DbSession(ConnectionProvider connectionProvider)
Creates new database session with default transaction mode and in autocommit mode.
|
| Modifier and Type | Method and Description |
|---|---|
protected void |
attachQuery(jodd.db.DbQueryBase query)
Attaches a new
DbQuery. |
void |
beginTransaction()
Starts transaction with default transaction mode.
|
void |
beginTransaction(DbTransactionMode mode)
Starts a transaction.
|
protected void |
checkActiveTx() |
protected void |
checkClosedTx() |
protected void |
checkOpenSession() |
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 DbManager dbManager
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()
public DbSession(ConnectionProvider connectionProvider)
public void closeSession()
ConnectionProvider.
Closed session is no longer available for usage.public void close()
throws java.lang.Exception
close in interface java.lang.AutoCloseablejava.lang.Exceptionpublic 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 beginTransaction()
public void commitTransaction()
public void rollbackTransaction()
protected void checkOpenSession()
protected void checkClosedTx()
protected void checkActiveTx()
Copyright © 2003-2013 Jodd Team