Class ConnectionContext
java.lang.Object
org.deltava.jdbc.ConnectionContext
- Direct Known Subclasses:
HTTPContext,TaskContext
A Context object that allows fetching of connections from a JDBC connection pool.
- Since:
- 1.0
- Version:
- 11.4
- Author:
- Luke
-
Nested Class Summary
Nested Classes -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidcommitTX()Commits the current JDBC transaction.Reserves a JDBC Connection from the connection pool.getDB()Returns the default database name.booleanReturns whether a JDBC connection has been reserved by this context.longrelease()Returns a JDBC Connection to the connection pool.voidRolls back the current JDBC transaction.voidUpdates the default database name.voidstartTX()Starts a JDBC transaction block, by turning off autoCommit on the reserved Connection.
-
Constructor Details
-
ConnectionContext
public ConnectionContext()
-
-
Method Details
-
getConnection
Reserves a JDBC Connection from the connection pool.- Returns:
- a JDBC Connection
- Throws:
ConnectionContext.ConnectionPoolException- if an error occursIllegalStateException- if a connection has already been reserved by this context- See Also:
-
hasConnection
public boolean hasConnection()Returns whether a JDBC connection has been reserved by this context.- Returns:
- TRUE if a Connection has been reserved, otherwise FALSE
-
getDB
-
setDB
Updates the default database name.- Parameters:
dbName- the database name
-
startTX
Starts a JDBC transaction block, by turning off autoCommit on the reserved Connection.- Throws:
IllegalStateException- if no JDBC Connection is reservedTransactionException- if a JDBC error occurs
-
commitTX
Commits the current JDBC transaction.- Throws:
IllegalStateException- if no JDBC Connection is reservedTransactionException- if a JDBC error occurs
-
rollbackTX
public void rollbackTX()Rolls back the current JDBC transaction. This will consume all exceptions. -
release
public long release()Returns a JDBC Connection to the connection pool.- Returns:
- the time the connection was in use, in milliseconds
-