com.peter.db
Class DBConHandler

java.lang.Object
  |
  +--com.peter.db.DBConHandler

public class DBConHandler
extends java.lang.Object

This class handles the queries to the database. It uses the a pool of connections in order to set up the needed connection.

Version:
$Revision: 1.0.2, 2003-11-04 $
Author:
Peter Larsson

Constructor Summary
DBConHandler(DBConPool pool, java.sql.Connection con)
          Constructor for this class
 
Method Summary
 void closeConnection()
          Closes this handler's database connection.
 void countDown()
          Starts counting down until the maximum time threashold is reached
 DBMatrix[] executeNQueries(java.lang.String[] queries)
          Executes a selection of N queries in the database
 DBMatrix executePreparedStatement(java.lang.String query, java.lang.Object[] obj)
          Executes a selection query in the database.
 DBMatrix executeQuery(java.lang.String query)
          Executes a selection query in the database.
 java.sql.ResultSet executeQueryRS(java.lang.String query)
          Executes a selection query in the database.
 int executeUpdate(java.lang.String query)
          Excutes an update query in the database.
 int executeUpdatePS(java.lang.String query, java.lang.Object[] obj)
          Excutes an update query in the database.
 java.sql.Connection getConnection()
          This method is used when it's necessary to retrieve the Connection and handle it by yourself.
 void setReleased()
          Sets the released flag indicating that this handler is released
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DBConHandler

public DBConHandler(DBConPool pool,
                    java.sql.Connection con)
Constructor for this class
Parameters:
pool - The pool that contains this Handler.
con - The connection for this Handler.
Method Detail

executeUpdate

public int executeUpdate(java.lang.String query)
                  throws java.sql.SQLException
Excutes an update query in the database. Returns the number of rows affected by the update. Return -1 if no rows were found.
Parameters:
query - The query to execute
Returns:
The number of rows affected by the update
Throws:
java.sql.SQLException - If a SQLException was thrown

executeUpdatePS

public int executeUpdatePS(java.lang.String query,
                           java.lang.Object[] obj)
                    throws java.sql.SQLException
Excutes an update query in the database. Returns the number of rows affected by the update. Return -1 if no rows were found.
Parameters:
query - The query to execute
obj - An Array of Objects to be inserted in the SQL-query
Returns:
The number of rows affected by the update
Throws:
java.sql.SQLException - If a SQLException was thrown

executeQuery

public DBMatrix executeQuery(java.lang.String query)
                      throws java.sql.SQLException
Executes a selection query in the database.
Parameters:
query - The query to execute
Returns:
A ResultSet translated into a DBMatrix
Throws:
java.sql.SQLException - If a SQLException was thrown

executeQueryRS

public java.sql.ResultSet executeQueryRS(java.lang.String query)
                                  throws java.sql.SQLException
Executes a selection query in the database.
Parameters:
query - The query to execute
Returns:
A ResultSet
Throws:
java.sql.SQLException - If a SQLException was thrown

executePreparedStatement

public DBMatrix executePreparedStatement(java.lang.String query,
                                         java.lang.Object[] obj)
                                  throws java.sql.SQLException
Executes a selection query in the database.
Parameters:
query - The query to execute
obj - An Array of Objects to be inserted in the SQL-query
Returns:
A ResultSet translated into a DBMatrix
Throws:
java.sql.SQLException - If a SQLException was thrown

executeNQueries

public DBMatrix[] executeNQueries(java.lang.String[] queries)
                           throws java.sql.SQLException
Executes a selection of N queries in the database
Parameters:
queries - The queries to execute
Returns:
A ResultSet translated into a DBMatrix
Throws:
java.sql.SQLException - If a SQLException was thrown

getConnection

public java.sql.Connection getConnection()

This method is used when it's necessary to retrieve the Connection and handle it by yourself.

Returns:
The Connection instance.

closeConnection

public void closeConnection()
                     throws java.sql.SQLException
Closes this handler's database connection.
Throws:
java.sql.SQLException - If a SQLException was thrown

countDown

public void countDown()
Starts counting down until the maximum time threashold is reached
See Also:
DBConHandler.WaitAndRelease

setReleased

public void setReleased()
Sets the released flag indicating that this handler is released