net.xoetrope.optional.data.sql
Class ConnectionObject

java.lang.Object
  extended by net.xoetrope.optional.pool.PoolObject
      extended by net.xoetrope.optional.data.sql.ConnectionObject
Direct Known Subclasses:
NamedConnectionObject

public class ConnectionObject
extends PoolObject

A wrapper for a connection for use by a ConnectionManager

Copyright (c) Xoetrope Ltd. 2001-2003

$Revision: 2.3 $ License: see license.txt


Constructor Summary
ConnectionObject(java.sql.Connection conn, PoolManager pool)
          Constructs a new connection object
 
Method Summary
 void close()
          Return the connection to the connection manager
 java.sql.Statement createStatement()
          Create a statement
 java.sql.Statement createStatement(int resultSetType, int resultSetConcurrency)
          Create a statement
 java.sql.Statement createStatement(int resultSetType, int resultSetConcurrency, int resultSetHoldability)
          Create a statement
 java.sql.Connection getConnection()
          Get a reference to the Connection.
 boolean isClosed()
          Check to see that the connection to the database is still active.
 java.sql.PreparedStatement prepareStatement(java.lang.String sql)
          Creates a PreparedStatement object for sending parameterized SQL statements to the database.
 java.sql.PreparedStatement prepareStatement(java.lang.String sql, int resultSetType, int resultSetConcurrency)
          Creates a PreparedStatement object for sending parameterized SQL statements to the database.
 java.sql.PreparedStatement prepareStatement(java.lang.String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability)
          Creates a PreparedStatement object for sending parameterized SQL statements to the database.
 void returnPreparedStatement()
          Create a prepared statement.
 void returnStatement()
          Create a prepared statement.
 boolean validate()
          Check to see if a connection can be made and is still in a working state
 
Methods inherited from class net.xoetrope.optional.pool.PoolObject
expireLease, getInUse, getLastUse, lease
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ConnectionObject

public ConnectionObject(java.sql.Connection conn,
                        PoolManager pool)
Constructs a new connection object

Parameters:
conn - a JDBC connection
pool - the pool manager
Method Detail

isClosed

public boolean isClosed()
Check to see that the connection to the database is still active.

Returns:
true if the connection is closed

validate

public boolean validate()
Check to see if a connection can be made and is still in a working state

Specified by:
validate in class PoolObject
Returns:
true if the connection is still working

close

public void close()
           throws java.lang.Exception
Return the connection to the connection manager

Specified by:
close in class PoolObject
Throws:
java.lang.Exception - possible exceptions while trying to close the JDBC connection object

createStatement

public java.sql.Statement createStatement()
                                   throws java.sql.SQLException
Create a statement

Returns:
the new statement or null if there is already an open statement
Throws:
java.sql.SQLException

createStatement

public java.sql.Statement createStatement(int resultSetType,
                                          int resultSetConcurrency)
                                   throws java.sql.SQLException
Create a statement

Parameters:
resultSetType - a result set type; one of ResultSet.TYPE_FORWARD_ONLY, ResultSet.TYPE_SCROLL_INSENSITIVE, or ResultSet.TYPE_SCROLL_SENSITIVE
resultSetConcurrency - - a concurrency type; one of ResultSet.CONCUR_READ_ONLY or ResultSet.CONCUR_UPDATABLE
Returns:
the new statement or null if there is already an open statement
Throws:
java.sql.SQLException

createStatement

public java.sql.Statement createStatement(int resultSetType,
                                          int resultSetConcurrency,
                                          int resultSetHoldability)
                                   throws java.sql.SQLException
Create a statement

Parameters:
resultSetType - a result set type; one of ResultSet.TYPE_FORWARD_ONLY, ResultSet.TYPE_SCROLL_INSENSITIVE, or ResultSet.TYPE_SCROLL_SENSITIVE
resultSetConcurrency - - a concurrency type; one of ResultSet.CONCUR_READ_ONLY or ResultSet.CONCUR_UPDATABLE
resultSetHoldability - - one of the following ResultSet constants: ResultSet.HOLD_CURSORS_OVER_COMMIT or ResultSet.CLOSE_CURSORS_AT_COMMIT
Returns:
the new statement or null if there is already an open statement
Throws:
java.sql.SQLException

returnStatement

public void returnStatement()
Create a prepared statement. Note that you MUST release the PreparedStatement by calling returnPreparedStatement when finished with the

Parameters:
ps - the PreparedStatement to be retrived

prepareStatement

public java.sql.PreparedStatement prepareStatement(java.lang.String sql)
                                            throws java.sql.SQLException
Creates a PreparedStatement object for sending parameterized SQL statements to the database.

Parameters:
sql - - an SQL statement that may contain one or more '?' IN parameter placeholders
Throws:
java.sql.SQLException

prepareStatement

public java.sql.PreparedStatement prepareStatement(java.lang.String sql,
                                                   int resultSetType,
                                                   int resultSetConcurrency)
                                            throws java.sql.SQLException
Creates a PreparedStatement object for sending parameterized SQL statements to the database.

Parameters:
sql - - an SQL statement that may contain one or more '?' IN parameter placeholders
resultSetType - a result set type; one of ResultSet.TYPE_FORWARD_ONLY, ResultSet.TYPE_SCROLL_INSENSITIVE, or ResultSet.TYPE_SCROLL_SENSITIVE
resultSetConcurrency - - a concurrency type; one of ResultSet.CONCUR_READ_ONLY or ResultSet.CONCUR_UPDATABLE
Throws:
java.sql.SQLException

prepareStatement

public java.sql.PreparedStatement prepareStatement(java.lang.String sql,
                                                   int resultSetType,
                                                   int resultSetConcurrency,
                                                   int resultSetHoldability)
                                            throws java.sql.SQLException
Creates a PreparedStatement object for sending parameterized SQL statements to the database.

Parameters:
sql - - an SQL statement that may contain one or more '?' IN parameter placeholders
resultSetType - a result set type; one of ResultSet.TYPE_FORWARD_ONLY, ResultSet.TYPE_SCROLL_INSENSITIVE, or ResultSet.TYPE_SCROLL_SENSITIVE
resultSetConcurrency - - a concurrency type; one of ResultSet.CONCUR_READ_ONLY or ResultSet.CONCUR_UPDATABLE
resultSetHoldability - - one of the following ResultSet constants: ResultSet.HOLD_CURSORS_OVER_COMMIT or ResultSet.CLOSE_CURSORS_AT_COMMIT
Throws:
java.sql.SQLException

returnPreparedStatement

public void returnPreparedStatement()
Create a prepared statement. Note that you MUST release the PreparedStatement by calling returnPreparedStatement when finished with the

Parameters:
ps - the PreparedStatement to be retrived

getConnection

public java.sql.Connection getConnection()
Get a reference to the Connection.
If attempting to create a statement or a PreparedStatment, please use this methods values instead of calling the connection's methods directly. DO NOT RETAIN A REFERENCE TO THE RETURNED OBJECT

Returns:
possible JDBC exceptions while attempting to establish a connection