|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.jminor.common.db.DatabaseConnectionImpl
public class DatabaseConnectionImpl
A default DatabaseConnection implementation, which wraps a standard JDBC Connection object.
Nested Class Summary |
---|
Nested classes/interfaces inherited from interface org.jminor.common.db.DatabaseConnection |
---|
DatabaseConnection.Function, DatabaseConnection.Operation, DatabaseConnection.Procedure |
Constructor Summary | |
---|---|
DatabaseConnectionImpl(Database database,
User user)
Constructs a new DatabaseConnectionImpl instance, initialized and ready for usage |
|
DatabaseConnectionImpl(Database database,
User user,
Connection connection)
Constructs a new DatabaseConnectionImpl instance, based on the given Connection object. |
Method Summary | |
---|---|
void |
beginTransaction()
Begins a transaction on this connection |
void |
commit()
Performs a commit |
void |
commitTransaction()
Performs a commit and ends the current transaction |
void |
disconnect()
Disconnects this connection |
void |
execute(List<String> statements)
Executes the given statements, in a batch if possible, which can be anything except a select query. |
void |
execute(String sql)
Executes the given statement, which can be anything except a select query. |
Object |
executeCallableStatement(String sqlStatement,
int outParameterType)
Executes the statement. |
List<?> |
executeFunction(String functionID,
Object... arguments)
Executes the function with the given id |
void |
executeProcedure(String procedureID,
Object... arguments)
Executes the procedure with the given id |
Connection |
getConnection()
|
Database |
getDatabase()
|
List<LogEntry> |
getLogEntries()
|
MethodLogger |
getMethodLogger()
|
long |
getPoolTime()
|
int |
getRetryCount()
|
User |
getUser()
|
boolean |
isConnected()
|
boolean |
isLoggingEnabled()
|
boolean |
isTransactionOpen()
|
boolean |
isValid()
|
List |
query(String sql,
ResultPacker resultPacker,
int fetchCount)
Performs the given sql query and returns the result in a List |
int |
queryInteger(String sql)
Performs the given query and returns the result as an integer |
List<Integer> |
queryIntegers(String sql)
Performs the given query and returns the result as a List of Integers |
List<List> |
queryObjects(String sql,
int fetchCount)
|
List<String> |
queryStrings(String sql)
Performs the given query and returns the result as a List of Strings |
byte[] |
readBlobField(String tableName,
String columnName,
String whereClause)
Returns the contents of the given blob field. |
void |
rollback()
Performs a rollback |
void |
rollbackTransaction()
Performs a rollback and ends the current transaction |
void |
setLoggingEnabled(boolean enabled)
|
void |
setPoolTime(long time)
Sets the time this connection was checked into a connection pool |
void |
setRetryCount(int retryCount)
|
String |
toString()
|
void |
writeBlobField(byte[] blobData,
String tableName,
String columnName,
String whereClause)
Writes the given blob data into the given column. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public DatabaseConnectionImpl(Database database, User user) throws ClassNotFoundException, SQLException
database
- the databaseuser
- the user for the db-connection
SQLException
- in case there is a problem connecting to the database
ClassNotFoundException
- in case the database driver was not foundpublic DatabaseConnectionImpl(Database database, User user, Connection connection)
database
- the databaseuser
- the user for the db-connectionconnection
- the Connection object to base this DatabaseConnectionImpl onMethod Detail |
---|
public final void setPoolTime(long time)
setPoolTime
in interface PoolableConnection
time
- the time this connection was pooledpublic final long getPoolTime()
getPoolTime
in interface PoolableConnection
public final void setRetryCount(int retryCount)
setRetryCount
in interface PoolableConnection
retryCount
- the number of retries used to retrieve this connection from the poolpublic final int getRetryCount()
getRetryCount
in interface PoolableConnection
public final String toString()
toString
in class Object
public final User getUser()
getUser
in interface PoolableConnection
public final void setLoggingEnabled(boolean enabled)
setLoggingEnabled
in interface PoolableConnection
enabled
- true to enable logging on this connection, false to disablepublic final boolean isLoggingEnabled()
isLoggingEnabled
in interface PoolableConnection
public final boolean isValid()
isValid
in interface PoolableConnection
public final void disconnect()
disconnect
in interface PoolableConnection
public final boolean isConnected()
isConnected
in interface DatabaseConnection
public final Connection getConnection()
getConnection
in interface PoolableConnection
public final Database getDatabase()
getDatabase
in interface PoolableConnection
public final void beginTransaction()
beginTransaction
in interface PoolableConnection
public final void rollbackTransaction()
rollbackTransaction
in interface PoolableConnection
public final void commitTransaction()
commitTransaction
in interface PoolableConnection
public final boolean isTransactionOpen()
isTransactionOpen
in interface PoolableConnection
public final List query(String sql, ResultPacker resultPacker, int fetchCount) throws SQLException
query
in interface DatabaseConnection
sql
- the queryresultPacker
- a ResultPacker instance for creating the return ListfetchCount
- the number of records to retrieve, use -1 to retrieve all
SQLException
- thrown if anything goes wrong during the query executionpublic final List<String> queryStrings(String sql) throws SQLException
queryStrings
in interface DatabaseConnection
sql
- the query, it must select at least a single string column, any other
subsequent columns are disregarded
SQLException
- thrown if anything goes wrong during the executionpublic final int queryInteger(String sql) throws SQLException, DatabaseException
queryInteger
in interface DatabaseConnection
sql
- the query must select at least a single number column, any other
subsequent columns are disregarded
SQLException
- thrown if anything goes wrong during the execution
DatabaseException
- thrown if no record is foundpublic final List<Integer> queryIntegers(String sql) throws SQLException
queryIntegers
in interface DatabaseConnection
sql
- the query, it must select at least a single number column, any other
subsequent columns are disregarded
SQLException
- thrown if anything goes wrong during the executionpublic final List<List> queryObjects(String sql, int fetchCount) throws SQLException
queryObjects
in interface DatabaseConnection
sql
- the queryfetchCount
- the maximum number of records to return, -1 for all
SQLException
- thrown if anything goes wrong during the query executionpublic final byte[] readBlobField(String tableName, String columnName, String whereClause) throws SQLException
readBlobField
in interface DatabaseConnection
tableName
- the table namecolumnName
- the name of the blob columnwhereClause
- the where clause
SQLException
- thrown if anything goes wrong during the executionpublic final void writeBlobField(byte[] blobData, String tableName, String columnName, String whereClause) throws SQLException
writeBlobField
in interface DatabaseConnection
blobData
- the blob datatableName
- the table namecolumnName
- the blob column namewhereClause
- the where clause
SQLException
- thrown if anything goes wrong during the executionpublic final void commit() throws SQLException
commit
in interface PoolableConnection
SQLException
- thrown if anything goes wrong during the executionpublic final void rollback() throws SQLException
rollback
in interface PoolableConnection
SQLException
- thrown if anything goes wrong during the executionpublic final Object executeCallableStatement(String sqlStatement, int outParameterType) throws SQLException
executeCallableStatement
in interface DatabaseConnection
sqlStatement
- the statement to executeoutParameterType
- the type of the out parameter, -1 if no out parameter, java.sql.Types.*
SQLException
- thrown if anything goes wrong during executionpublic final void execute(String sql) throws SQLException
execute
in interface DatabaseConnection
sql
- the statement to execute
SQLException
- thrown if anything goes wrong during executionpublic final List<?> executeFunction(String functionID, Object... arguments) throws DatabaseException
executeFunction
in interface DatabaseConnection
functionID
- the function IDarguments
- the arguments, if any
DatabaseException
- in case anyhing goes wrong during the executionpublic final void executeProcedure(String procedureID, Object... arguments) throws DatabaseException
executeProcedure
in interface DatabaseConnection
procedureID
- the procedure IDarguments
- the arguments, if any
DatabaseException
- in case anyhing goes wrong during the executionpublic final void execute(List<String> statements) throws SQLException
execute
in interface DatabaseConnection
statements
- the statements to execute
SQLException
- thrown if anything goes wrong during executionpublic final List<LogEntry> getLogEntries()
getLogEntries
in interface PoolableConnection
public MethodLogger getMethodLogger()
getMethodLogger
in interface PoolableConnection
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |