org.jminor.common.db
Interface DatabaseConnection

All Superinterfaces:
PoolableConnection
All Known Implementing Classes:
DatabaseConnectionImpl

public interface DatabaseConnection
extends PoolableConnection

Specifies a database connection, providing basic transaction control and helper functions for querying and manipulating data.


Nested Class Summary
static interface DatabaseConnection.Function
          A database function
static interface DatabaseConnection.Operation
          A database operation
static interface DatabaseConnection.Procedure
          A database procedure
 
Method Summary
 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
 boolean isConnected()
           
 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 writeBlobField(byte[] blobData, String tableName, String columnName, String whereClause)
          Writes the given blob data into the given column.
 
Methods inherited from interface org.jminor.common.db.PoolableConnection
beginTransaction, commit, commitTransaction, disconnect, getConnection, getDatabase, getLogEntries, getMethodLogger, getPoolTime, getRetryCount, getUser, isLoggingEnabled, isTransactionOpen, isValid, rollback, rollbackTransaction, setLoggingEnabled, setPoolTime, setRetryCount
 

Method Detail

query

List query(String sql,
           ResultPacker resultPacker,
           int fetchCount)
           throws SQLException
Performs the given sql query and returns the result in a List

Parameters:
sql - the query
resultPacker - a ResultPacker instance for creating the return List
fetchCount - the number of records to retrieve, use -1 to retrieve all
Returns:
the query result in a List
Throws:
SQLException - thrown if anything goes wrong during the query execution

isConnected

boolean isConnected()
Returns:
true if the connection is connected

queryObjects

List<List> queryObjects(String sql,
                        int fetchCount)
                        throws SQLException
Parameters:
sql - the query
fetchCount - the maximum number of records to return, -1 for all
Returns:
the result of this query, in a List of rows represented as Lists
Throws:
SQLException - thrown if anything goes wrong during the query execution

queryInteger

int queryInteger(String sql)
                 throws SQLException,
                        DatabaseException
Performs the given query and returns the result as an integer

Parameters:
sql - the query must select at least a single number column, any other subsequent columns are disregarded
Returns:
the first record in the result as a integer
Throws:
SQLException - thrown if anything goes wrong during the execution
DatabaseException - thrown if no record is found

queryIntegers

List<Integer> queryIntegers(String sql)
                            throws SQLException
Performs the given query and returns the result as a List of Integers

Parameters:
sql - the query, it must select at least a single number column, any other subsequent columns are disregarded
Returns:
a List of Integers representing the query result
Throws:
SQLException - thrown if anything goes wrong during the execution

queryStrings

List<String> queryStrings(String sql)
                          throws SQLException
Performs the given query and returns the result as a List of Strings

Parameters:
sql - the query, it must select at least a single string column, any other subsequent columns are disregarded
Returns:
a List of Strings representing the query result
Throws:
SQLException - thrown if anything goes wrong during the execution

readBlobField

byte[] readBlobField(String tableName,
                     String columnName,
                     String whereClause)
                     throws SQLException
Returns the contents of the given blob field.

Parameters:
tableName - the table name
columnName - the name of the blob column
whereClause - the where clause
Returns:
the blob contents
Throws:
SQLException - thrown if anything goes wrong during the execution

writeBlobField

void writeBlobField(byte[] blobData,
                    String tableName,
                    String columnName,
                    String whereClause)
                    throws SQLException
Writes the given blob data into the given column.

Parameters:
blobData - the blob data
tableName - the table name
columnName - the blob column name
whereClause - the where clause
Throws:
SQLException - thrown if anything goes wrong during the execution

execute

void execute(String sql)
             throws SQLException
Executes the given statement, which can be anything except a select query.

Parameters:
sql - the statement to execute
Throws:
SQLException - thrown if anything goes wrong during execution

executeCallableStatement

Object executeCallableStatement(String sqlStatement,
                                int outParameterType)
                                throws SQLException
Executes the statement.

Parameters:
sqlStatement - the statement to execute
outParameterType - the type of the out parameter, -1 if no out parameter, java.sql.Types.*
Returns:
the out parameter, null if none is specified
Throws:
SQLException - thrown if anything goes wrong during execution

execute

void execute(List<String> statements)
             throws SQLException
Executes the given statements, in a batch if possible, which can be anything except a select query.

Parameters:
statements - the statements to execute
Throws:
SQLException - thrown if anything goes wrong during execution

executeFunction

List<?> executeFunction(String functionID,
                        Object... arguments)
                        throws DatabaseException
Executes the function with the given id

Parameters:
functionID - the function ID
arguments - the arguments, if any
Returns:
the procedure return arguments, if any
Throws:
DatabaseException - in case anyhing goes wrong during the execution

executeProcedure

void executeProcedure(String procedureID,
                      Object... arguments)
                      throws DatabaseException
Executes the procedure with the given id

Parameters:
procedureID - the procedure ID
arguments - the arguments, if any
Throws:
DatabaseException - in case anyhing goes wrong during the execution