public interface DatabaseConnection
extends java.lang.AutoCloseable
Modifier and Type | Interface and Description |
---|---|
static interface |
DatabaseConnection.Function<C>
A database function
|
static interface |
DatabaseConnection.Operation
A database operation
|
static interface |
DatabaseConnection.Procedure<C>
A database procedure
|
Modifier and Type | Field and Description |
---|---|
static PropertyValue<java.lang.Integer> |
CONNECTION_VALIDITY_CHECK_TIMEOUT
Specifies the timeout (in seconds) to use when checking if database connections are valid.
|
Modifier and Type | Method and Description |
---|---|
void |
beginTransaction()
Begins a transaction on this connection, to end the transaction use
commitTransaction() or rollbackTransaction() . |
void |
commit()
Performs a commit
|
void |
commitTransaction()
Performs a commit and ends the current transaction
|
void |
disconnect()
Performs a rollback and disconnects this connection
|
java.sql.Connection |
getConnection()
Returns the underlying connection object, use
isConnected() to verify
that the connection is not null and valid. |
Database |
getDatabase() |
MethodLogger |
getMethodLogger() |
long |
getPoolTime() |
int |
getRetryCount() |
User |
getUser() |
boolean |
isConnected() |
boolean |
isTransactionOpen() |
int |
queryInteger(java.lang.String sql)
Performs the given query and returns the result as an integer
|
long |
queryLong(java.lang.String sql)
Performs the given query and returns the result as a long
|
void |
rollback()
Performs a rollback
|
void |
rollbackTransaction()
Performs a rollback and ends the current transaction
|
void |
setConnection(java.sql.Connection connection)
Sets the internal connection to use, note that no validation or
transaction checking is performed, it is simply used 'as is'
|
void |
setMethodLogger(MethodLogger methodLogger) |
void |
setPoolTime(long time)
Sets the time this connection was checked into a connection pool
|
void |
setRetryCount(int retryCount) |
static final PropertyValue<java.lang.Integer> CONNECTION_VALIDITY_CHECK_TIMEOUT
boolean isConnected()
java.sql.Connection getConnection()
isConnected()
to verify
that the connection is not null and valid.void setConnection(java.sql.Connection connection)
connection
- the JDBC connectionlong getPoolTime()
void setPoolTime(long time)
time
- the time this connection was pooledvoid setRetryCount(int retryCount)
retryCount
- the number of retries used to retrieve this connection from the poolint getRetryCount()
int queryInteger(java.lang.String sql) throws java.sql.SQLException
sql
- the query must select at least a single number column, any other subsequent columns are disregardedjava.sql.SQLException
- thrown if anything goes wrong during the execution or if no record is returnedlong queryLong(java.lang.String sql) throws java.sql.SQLException
sql
- the query must select at least a single number column, any other subsequent columns are disregardedjava.sql.SQLException
- thrown if anything goes wrong during the execution or if no record is returnedvoid beginTransaction()
commitTransaction()
or rollbackTransaction()
.java.lang.IllegalStateException
- in case a transaction is already openboolean isTransactionOpen()
void commitTransaction()
java.lang.IllegalStateException
- in case transaction is not openvoid rollbackTransaction()
java.lang.IllegalStateException
- in case transaction is not openvoid commit() throws java.sql.SQLException
java.sql.SQLException
- thrown if anything goes wrong during the executionjava.lang.IllegalStateException
- in case a transaction is openvoid rollback() throws java.sql.SQLException
java.sql.SQLException
- thrown if anything goes wrong during the executionjava.lang.IllegalStateException
- in case a transaction is openvoid disconnect()
User getUser()
Database getDatabase()
void setMethodLogger(MethodLogger methodLogger)
methodLogger
- the MethodLogger to useMethodLogger getMethodLogger()