com.cometway.jdbc
Class JDBCConnection

java.lang.Object
  extended by com.cometway.jdbc.JDBCConnection
All Implemented Interfaces:
java.sql.Connection

public class JDBCConnection
extends java.lang.Object
implements java.sql.Connection

This class implements a pool-able JDBCConnection.


Field Summary
protected static int DEFAULT_MAX_ROW_SIZE
           
protected  ReporterInterface reporter
           
protected static int uniqueIndex
           
 
Fields inherited from interface java.sql.Connection
TRANSACTION_NONE, TRANSACTION_READ_COMMITTED, TRANSACTION_READ_UNCOMMITTED, TRANSACTION_REPEATABLE_READ, TRANSACTION_SERIALIZABLE
 
Constructor Summary
JDBCConnection(java.lang.String jdbcURL, java.sql.Connection connection, JDBCConnectionPool ownerPool, ReporterInterface reporter)
          Users will probably not need to call the constructor directly; the connection is typically created by a ConnectionPoolManager.
JDBCConnection(java.lang.String jdbcDriver, java.lang.String jdbcURL, java.lang.String username, java.lang.String password)
           
 
Method Summary
 void buildDataTypeInfo()
          Builds a type information list specific to this driver connection.
 void clearWarnings()
           
 void close()
          It is really important to call close when you are done using a pooled JDBCConnection because un-closed connections will be unusable until the ConnectionReaper gets around to freeing them.
 void commit()
           
 java.sql.Statement createStatement()
           
 java.sql.Statement createStatement(int parm1, int parm2)
           
 java.sql.Statement createStatement(int parm1, int parm2, int parm3)
           
 void debug(java.lang.String message)
          Prints a debug message tagged with this Connection's identity to the output stream.
 void error(java.lang.String message)
          Prints an error message tagged with this Connection's identity to the error stream.
 void error(java.lang.String message, java.lang.Exception e)
          Prints an error message tagged with this Connection's identity followed by a stack trace of the passed Exception to the error stream.
 java.lang.String executeQuery(java.lang.String sql)
          Executes the query contained in the argument, returning results as a String.
 java.lang.String executeUpdate(java.lang.String sql)
          Executes the update contained in the argument, returning results as a String.
protected  void expireLease()
          Called by the ConnectionReaper to forcibly expire this lease.
 boolean getAutoCommit()
           
 java.lang.String getCatalog()
           
 java.sql.Connection getConnection()
          Returns the actual java.sql.Connection object used by this JDBCConnection.
 java.sql.Driver getDriver()
          Returns the String used to load the JDBC driver.
 int getHoldability()
           
 long getLastUse()
          Returns a long containing the timestamp when this connection was leased.
 int getMaxRowSize()
          Should return the maximum row size supported by the current database but JDBC drivers have problems reporting MAX_ROW_SIZE accurately so MAX_ROW_SIZE is hard-coded to be 255.
 java.sql.DatabaseMetaData getMetaData()
           
 java.lang.String getStatus()
          Returns the current status information and performance data for this connection.
 int getTransactionIsolation()
           
 java.util.Map getTypeMap()
           
 java.lang.String getTypeName(int dataType)
          Get the String name for the DataType with this ID.
 java.sql.SQLWarning getWarnings()
           
 boolean inUse()
          Returns true if the JDBCConnection is currently in use; false otherwise.
 boolean isClosed()
           
 boolean isReadOnly()
           
 boolean lease()
          Called by the JDBCConnectionPool.
 java.lang.String nativeSQL(java.lang.String sql)
           
 java.sql.CallableStatement prepareCall(java.lang.String sql)
           
 java.sql.CallableStatement prepareCall(java.lang.String sql, int parm2, int parm3)
           
 java.sql.CallableStatement prepareCall(java.lang.String sql, int parm2, int parm3, int parm4)
           
 java.sql.PreparedStatement prepareStatement(java.lang.String sql)
           
 java.sql.PreparedStatement prepareStatement(java.lang.String sql, int parm2)
           
 java.sql.PreparedStatement prepareStatement(java.lang.String sql, int[] parm2)
           
 java.sql.PreparedStatement prepareStatement(java.lang.String sql, int parm2, int parm3)
           
 java.sql.PreparedStatement prepareStatement(java.lang.String sql, int parm2, int parm3, int parm4)
           
 java.sql.PreparedStatement prepareStatement(java.lang.String sql, java.lang.String[] parm2)
           
 void println(java.lang.String message)
          Prints a message tagged with this connection's identity to the output stream.
 void releaseSavepoint(java.sql.Savepoint savepnt)
           
 void rollback()
           
 void rollback(java.sql.Savepoint sp)
           
 void setAutoCommit(boolean autoCommit)
           
 void setCatalog(java.lang.String catalog)
           
protected  void setConnection(java.sql.Connection connection)
          Sets the JDBC Connection and initializes the database MetaData used by this class.
 void setHoldability(int parm1)
           
 void setReadOnly(boolean readOnly)
           
 void setReporter(ReporterInterface reporter)
          Sets the reporter for this Connection.
 java.sql.Savepoint setSavepoint()
           
 java.sql.Savepoint setSavepoint(java.lang.String savepnt)
           
 void setTransactionIsolation(int level)
           
 void setTypeMap(java.util.Map map)
           
 java.lang.String toString()
          Returns this connection as a String.
 boolean validate()
          Called by the ConnectionReaper to determine if this connection should be freed.
 void warning(java.lang.String message)
          Prints a warning message tagged with this Connection's identity to the error stream.
 void warning(java.lang.String message, java.lang.Exception e)
          Prints an warning message tagged with this Connection's identity followed by a stack trace of the passed Exception to error stream.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

uniqueIndex

protected static int uniqueIndex

DEFAULT_MAX_ROW_SIZE

protected static final int DEFAULT_MAX_ROW_SIZE
See Also:
Constant Field Values

reporter

protected ReporterInterface reporter
Constructor Detail

JDBCConnection

public JDBCConnection(java.lang.String jdbcURL,
                      java.sql.Connection connection,
                      JDBCConnectionPool ownerPool,
                      ReporterInterface reporter)
Users will probably not need to call the constructor directly; the connection is typically created by a ConnectionPoolManager.

Parameters:
con - The JDBC Connection to use
ownerPool - The ThreadPool to use when performing lazy database modifications

JDBCConnection

public JDBCConnection(java.lang.String jdbcDriver,
                      java.lang.String jdbcURL,
                      java.lang.String username,
                      java.lang.String password)
Parameters:
jdbcDriver - The JDBC Driver to use
jdbcURL - The JDBC URL to use
username - The username to use for DB access
password - The password to use for DB access
Method Detail

lease

public boolean lease()
Called by the JDBCConnectionPool.


validate

public boolean validate()
Called by the ConnectionReaper to determine if this connection should be freed.


inUse

public boolean inUse()
Returns true if the JDBCConnection is currently in use; false otherwise.


getLastUse

public long getLastUse()
Returns a long containing the timestamp when this connection was leased.


close

public void close()
           throws java.sql.SQLException
It is really important to call close when you are done using a pooled JDBCConnection because un-closed connections will be unusable until the ConnectionReaper gets around to freeing them.

Specified by:
close in interface java.sql.Connection
Throws:
java.sql.SQLException - if there was a problem closing the connection

expireLease

protected void expireLease()
Called by the ConnectionReaper to forcibly expire this lease.


getMaxRowSize

public int getMaxRowSize()
Should return the maximum row size supported by the current database but JDBC drivers have problems reporting MAX_ROW_SIZE accurately so MAX_ROW_SIZE is hard-coded to be 255.


buildDataTypeInfo

public void buildDataTypeInfo()
Builds a type information list specific to this driver connection. The type information is used internally to construct dynamic queries. This method only needs to be called once. See: DatabaseMetaData.getTypeInfo()


executeQuery

public java.lang.String executeQuery(java.lang.String sql)
Executes the query contained in the argument, returning results as a String.

Parameters:
sql - The query to execute.

executeUpdate

public java.lang.String executeUpdate(java.lang.String sql)
Executes the update contained in the argument, returning results as a String.

Parameters:
sql - The update to execute.

getConnection

public java.sql.Connection getConnection()
Returns the actual java.sql.Connection object used by this JDBCConnection.


getDriver

public java.sql.Driver getDriver()
Returns the String used to load the JDBC driver.


getStatus

public java.lang.String getStatus()
Returns the current status information and performance data for this connection.


getTypeName

public java.lang.String getTypeName(int dataType)
Get the String name for the DataType with this ID.

Parameters:
dataType -

setConnection

protected void setConnection(java.sql.Connection connection)
Sets the JDBC Connection and initializes the database MetaData used by this class.


debug

public void debug(java.lang.String message)
Prints a debug message tagged with this Connection's identity to the output stream.


warning

public void warning(java.lang.String message)
Prints a warning message tagged with this Connection's identity to the error stream. If the Exception is type java.lang.reflect.InvocationTargetException that exception's target exception is also stack traced.


warning

public void warning(java.lang.String message,
                    java.lang.Exception e)
Prints an warning message tagged with this Connection's identity followed by a stack trace of the passed Exception to error stream. If the Exception is type java.lang.reflect.InvocationTargetException that exception's target exception is also stack traced.


error

public void error(java.lang.String message)
Prints an error message tagged with this Connection's identity to the error stream. If the Exception is type java.lang.reflect.InvocationTargetException that exception's target exception is also stack traced.


error

public void error(java.lang.String message,
                  java.lang.Exception e)
Prints an error message tagged with this Connection's identity followed by a stack trace of the passed Exception to the error stream. If the Exception is type java.lang.reflect.InvocationTargetException that exception's target exception is also stack traced.


println

public void println(java.lang.String message)
Prints a message tagged with this connection's identity to the output stream.


setReporter

public void setReporter(ReporterInterface reporter)
Sets the reporter for this Connection.


toString

public java.lang.String toString()
Returns this connection as a String.

Overrides:
toString in class java.lang.Object

prepareStatement

public java.sql.PreparedStatement prepareStatement(java.lang.String sql)
                                            throws java.sql.SQLException
Specified by:
prepareStatement in interface java.sql.Connection
Throws:
java.sql.SQLException

prepareStatement

public java.sql.PreparedStatement prepareStatement(java.lang.String sql,
                                                   int parm2,
                                                   int parm3)
                                            throws java.sql.SQLException
Specified by:
prepareStatement in interface java.sql.Connection
Throws:
java.sql.SQLException

prepareCall

public java.sql.CallableStatement prepareCall(java.lang.String sql)
                                       throws java.sql.SQLException
Specified by:
prepareCall in interface java.sql.Connection
Throws:
java.sql.SQLException

prepareCall

public java.sql.CallableStatement prepareCall(java.lang.String sql,
                                              int parm2,
                                              int parm3)
                                       throws java.sql.SQLException
Specified by:
prepareCall in interface java.sql.Connection
Throws:
java.sql.SQLException

createStatement

public java.sql.Statement createStatement()
                                   throws java.sql.SQLException
Specified by:
createStatement in interface java.sql.Connection
Throws:
java.sql.SQLException

createStatement

public java.sql.Statement createStatement(int parm1,
                                          int parm2)
                                   throws java.sql.SQLException
Specified by:
createStatement in interface java.sql.Connection
Throws:
java.sql.SQLException

nativeSQL

public java.lang.String nativeSQL(java.lang.String sql)
                           throws java.sql.SQLException
Specified by:
nativeSQL in interface java.sql.Connection
Throws:
java.sql.SQLException

getTypeMap

public java.util.Map getTypeMap()
                         throws java.sql.SQLException
Specified by:
getTypeMap in interface java.sql.Connection
Throws:
java.sql.SQLException

setTypeMap

public void setTypeMap(java.util.Map map)
                throws java.sql.SQLException
Specified by:
setTypeMap in interface java.sql.Connection
Throws:
java.sql.SQLException

setAutoCommit

public void setAutoCommit(boolean autoCommit)
                   throws java.sql.SQLException
Specified by:
setAutoCommit in interface java.sql.Connection
Throws:
java.sql.SQLException

getAutoCommit

public boolean getAutoCommit()
                      throws java.sql.SQLException
Specified by:
getAutoCommit in interface java.sql.Connection
Throws:
java.sql.SQLException

commit

public void commit()
            throws java.sql.SQLException
Specified by:
commit in interface java.sql.Connection
Throws:
java.sql.SQLException

rollback

public void rollback()
              throws java.sql.SQLException
Specified by:
rollback in interface java.sql.Connection
Throws:
java.sql.SQLException

isClosed

public boolean isClosed()
                 throws java.sql.SQLException
Specified by:
isClosed in interface java.sql.Connection
Throws:
java.sql.SQLException

getMetaData

public java.sql.DatabaseMetaData getMetaData()
                                      throws java.sql.SQLException
Specified by:
getMetaData in interface java.sql.Connection
Throws:
java.sql.SQLException

setReadOnly

public void setReadOnly(boolean readOnly)
                 throws java.sql.SQLException
Specified by:
setReadOnly in interface java.sql.Connection
Throws:
java.sql.SQLException

isReadOnly

public boolean isReadOnly()
                   throws java.sql.SQLException
Specified by:
isReadOnly in interface java.sql.Connection
Throws:
java.sql.SQLException

setCatalog

public void setCatalog(java.lang.String catalog)
                throws java.sql.SQLException
Specified by:
setCatalog in interface java.sql.Connection
Throws:
java.sql.SQLException

getCatalog

public java.lang.String getCatalog()
                            throws java.sql.SQLException
Specified by:
getCatalog in interface java.sql.Connection
Throws:
java.sql.SQLException

setTransactionIsolation

public void setTransactionIsolation(int level)
                             throws java.sql.SQLException
Specified by:
setTransactionIsolation in interface java.sql.Connection
Throws:
java.sql.SQLException

getTransactionIsolation

public int getTransactionIsolation()
                            throws java.sql.SQLException
Specified by:
getTransactionIsolation in interface java.sql.Connection
Throws:
java.sql.SQLException

getWarnings

public java.sql.SQLWarning getWarnings()
                                throws java.sql.SQLException
Specified by:
getWarnings in interface java.sql.Connection
Throws:
java.sql.SQLException

clearWarnings

public void clearWarnings()
                   throws java.sql.SQLException
Specified by:
clearWarnings in interface java.sql.Connection
Throws:
java.sql.SQLException

prepareCall

public java.sql.CallableStatement prepareCall(java.lang.String sql,
                                              int parm2,
                                              int parm3,
                                              int parm4)
                                       throws java.sql.SQLException
Specified by:
prepareCall in interface java.sql.Connection
Throws:
java.sql.SQLException

prepareStatement

public java.sql.PreparedStatement prepareStatement(java.lang.String sql,
                                                   java.lang.String[] parm2)
                                            throws java.sql.SQLException
Specified by:
prepareStatement in interface java.sql.Connection
Throws:
java.sql.SQLException

prepareStatement

public java.sql.PreparedStatement prepareStatement(java.lang.String sql,
                                                   int parm2)
                                            throws java.sql.SQLException
Specified by:
prepareStatement in interface java.sql.Connection
Throws:
java.sql.SQLException

prepareStatement

public java.sql.PreparedStatement prepareStatement(java.lang.String sql,
                                                   int[] parm2)
                                            throws java.sql.SQLException
Specified by:
prepareStatement in interface java.sql.Connection
Throws:
java.sql.SQLException

prepareStatement

public java.sql.PreparedStatement prepareStatement(java.lang.String sql,
                                                   int parm2,
                                                   int parm3,
                                                   int parm4)
                                            throws java.sql.SQLException
Specified by:
prepareStatement in interface java.sql.Connection
Throws:
java.sql.SQLException

createStatement

public java.sql.Statement createStatement(int parm1,
                                          int parm2,
                                          int parm3)
                                   throws java.sql.SQLException
Specified by:
createStatement in interface java.sql.Connection
Throws:
java.sql.SQLException

getHoldability

public int getHoldability()
                   throws java.sql.SQLException
Specified by:
getHoldability in interface java.sql.Connection
Throws:
java.sql.SQLException

setHoldability

public void setHoldability(int parm1)
                    throws java.sql.SQLException
Specified by:
setHoldability in interface java.sql.Connection
Throws:
java.sql.SQLException

setSavepoint

public java.sql.Savepoint setSavepoint()
                                throws java.sql.SQLException
Specified by:
setSavepoint in interface java.sql.Connection
Throws:
java.sql.SQLException

setSavepoint

public java.sql.Savepoint setSavepoint(java.lang.String savepnt)
                                throws java.sql.SQLException
Specified by:
setSavepoint in interface java.sql.Connection
Throws:
java.sql.SQLException

releaseSavepoint

public void releaseSavepoint(java.sql.Savepoint savepnt)
                      throws java.sql.SQLException
Specified by:
releaseSavepoint in interface java.sql.Connection
Throws:
java.sql.SQLException

rollback

public void rollback(java.sql.Savepoint sp)
              throws java.sql.SQLException
Specified by:
rollback in interface java.sql.Connection
Throws:
java.sql.SQLException