jacquard 1.12.0 by The Web Engineering Factory and Toolworks

uk.co.weft.dbutil
Class ConnectionFish

java.lang.Object
  extended byuk.co.weft.dbutil.ConnectionFish
All Implemented Interfaces:
java.sql.Connection

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

A fish is something that swims in a pool, obviously. This is a connection which knows a bit about itself, enabling it to be reissued on request from a pool. The idea is that you should not create instances of this class directly, and you should not know that you've got one. Instead, you'll ask for connections from the pool, and when you've finished with them, release them back into the pool. You'll treat them as vanilla-flavoured java.sql.Connections. The pool won't tell you it's really giving you a fish.

A fish which is not returned to the pool will eventually be cleaned up by the SuckerFish; however, it's unwise to rely on this in situations where connections may be being requested in quick succession. For every call you make to ConnectionPool.getConnection() you should make a call to ConnectionPool.releaseConnection().

The Connection interface is implemented through a series of wrappers. Most of these are very simple for speed, but the key ones update the lastRequested date of the fish so that it stays alive.

Version:
$Revision: 1.12.4.1 $ This revision: $Author: simon $
Author:
Simon Brooke
See Also:
ConnectionPool.getConnection(java.lang.String, java.lang.String, java.lang.String), ConnectionPool.releaseConnection(java.sql.Connection)

Field Summary
protected  java.util.Date lastRequested
          the time when I was last asked to do anything
protected  java.util.Stack statements
          My (potentially open) statements
protected static int ttl
          the time a fish is allowed to live after it was last used, in milliseconds.
 
Fields inherited from interface java.sql.Connection
TRANSACTION_NONE, TRANSACTION_READ_COMMITTED, TRANSACTION_READ_UNCOMMITTED, TRANSACTION_REPEATABLE_READ, TRANSACTION_SERIALIZABLE
 
Constructor Summary
protected ConnectionFish(java.lang.String db_url, java.lang.String username, java.lang.String password, java.lang.Integer hash)
          Spawn a new fish.
 
Method Summary
 void clearWarnings()
          a simple wrapper round clearWarnings
 void close()
          close my real connection and remove me from the pool.
 void commit()
          a simple wrapper round commit
 java.sql.Statement createStatement()
          a wrapper round createStatement, simply to remind me I'm still alive
 java.sql.Statement createStatement(int resultSetType, int resultSetConcurrency)
          a wrapper round createStatement, simply to remind me I'm still alive
 java.sql.Statement createStatement(int resultSetType, int resultSetConcurrency, int resultSetHoldability)
          jdbc 3 methods; don't yet really know what they do so I'm just passing them through blindly.
 boolean getAutoCommit()
          just pass it on ...
 java.lang.String getCatalog()
          just pass it on ...
 int getHoldability()
          jdbc 3 methods; don't yet really know what they do so I'm just passing them through blindly.
 java.sql.DatabaseMetaData getMetaData()
          just pass it on ...
 int getTransactionIsolation()
          just pass it on ...
 java.util.Map getTypeMap()
          DOCUMENT ME!
 java.sql.SQLWarning getWarnings()
          just pass it on ...
 boolean isClosed()
          Whoops! Need to watch this one...
 boolean isReadOnly()
          just pass it on ...
 java.lang.String nativeSQL(java.lang.String sql)
          just pass it on ...
 java.sql.CallableStatement prepareCall(java.lang.String sql)
          just pass it on ...
 java.sql.CallableStatement prepareCall(java.lang.String sql, int resultSetType, int resultSetConcurrency)
          just pass it on ...
 java.sql.CallableStatement prepareCall(java.lang.String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability)
          jdbc 3 methods; don't yet really know what they do so I'm just passing them through blindly.
 java.sql.PreparedStatement prepareStatement(java.lang.String sql)
          just pass it on ...
 java.sql.PreparedStatement prepareStatement(java.lang.String sql, int autoGeneratedKeys)
          jdbc 3 methods; don't yet really know what they do so I'm just passing them through blindly.
 java.sql.PreparedStatement prepareStatement(java.lang.String sql, int[] columnIndexes)
          jdbc 3 methods; don't yet really know what they do so I'm just passing them through blindly.
 java.sql.PreparedStatement prepareStatement(java.lang.String sql, int resultSetType, int resultSetConcurrency)
          just pass it on ...
 java.sql.PreparedStatement prepareStatement(java.lang.String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability)
          jdbc 3 methods; don't yet really know what they do so I'm just passing them through blindly.
 java.sql.PreparedStatement prepareStatement(java.lang.String sql, java.lang.String[] columnNames)
          jdbc 3 methods; don't yet really know what they do so I'm just passing them through blindly.
 void releaseSavepoint(java.sql.Savepoint savepoint)
          jdbc 3 methods; don't yet really know what they do so I'm just passing them through blindly.
 void rollback()
          just pass it on ...
 void rollback(java.sql.Savepoint savepoint)
          jdbc 3 methods; don't yet really know what they do so I'm just passing them through blindly.
 void setAutoCommit(boolean autoCommit)
          just pass it on ...
 void setCatalog(java.lang.String catalog)
          just pass it on ...
 void setHoldability(int holdability)
          jdbc 3 methods; don't yet really know what they do so I'm just passing them through blindly.
 void setReadOnly(boolean readOnly)
          just pass it on ...
 java.sql.Savepoint setSavepoint()
          jdbc 3 methods; don't yet really know what they do so I'm just passing them through blindly.
 java.sql.Savepoint setSavepoint(java.lang.String savepoint)
          jdbc 3 methods; don't yet really know what they do so I'm just passing them through blindly.
 void setTransactionIsolation(int level)
          Set transaction isolation; thanks to David Orr for this code
 void setTypeMap(java.util.Map map)
          just pass it on ...
protected  int unused()
          how many milliseconds is it since I was last used?
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ttl

protected static final int ttl
the time a fish is allowed to live after it was last used, in milliseconds. TODO: Make this configurable

See Also:
Constant Field Values

lastRequested

protected java.util.Date lastRequested
the time when I was last asked to do anything


statements

protected java.util.Stack statements
My (potentially open) statements

Constructor Detail

ConnectionFish

protected ConnectionFish(java.lang.String db_url,
                         java.lang.String username,
                         java.lang.String password,
                         java.lang.Integer hash)
                  throws DataStoreException
Spawn a new fish.

Method Detail

setAutoCommit

public void setAutoCommit(boolean autoCommit)
                   throws java.sql.SQLException
just pass it on ...

Specified by:
setAutoCommit in interface java.sql.Connection
Throws:
java.sql.SQLException

getAutoCommit

public boolean getAutoCommit()
                      throws java.sql.SQLException
just pass it on ...

Specified by:
getAutoCommit in interface java.sql.Connection
Throws:
java.sql.SQLException

setCatalog

public void setCatalog(java.lang.String catalog)
                throws java.sql.SQLException
just pass it on ...

Specified by:
setCatalog in interface java.sql.Connection
Throws:
java.sql.SQLException

getCatalog

public java.lang.String getCatalog()
                            throws java.sql.SQLException
just pass it on ...

Specified by:
getCatalog in interface java.sql.Connection
Throws:
java.sql.SQLException

isClosed

public boolean isClosed()
                 throws java.sql.SQLException
Whoops! Need to watch this one...

Specified by:
isClosed in interface java.sql.Connection
Throws:
java.sql.SQLException

setHoldability

public void setHoldability(int holdability)
                    throws java.sql.SQLException
jdbc 3 methods; don't yet really know what they do so I'm just passing them through blindly.

Specified by:
setHoldability in interface java.sql.Connection
Throws:
java.sql.SQLException

getHoldability

public int getHoldability()
                   throws java.sql.SQLException
jdbc 3 methods; don't yet really know what they do so I'm just passing them through blindly.

Specified by:
getHoldability in interface java.sql.Connection
Throws:
java.sql.SQLException

getMetaData

public java.sql.DatabaseMetaData getMetaData()
                                      throws java.sql.SQLException
just pass it on ...

Specified by:
getMetaData in interface java.sql.Connection
Throws:
java.sql.SQLException

setReadOnly

public void setReadOnly(boolean readOnly)
                 throws java.sql.SQLException
just pass it on ...

Specified by:
setReadOnly in interface java.sql.Connection
Throws:
java.sql.SQLException

isReadOnly

public boolean isReadOnly()
                   throws java.sql.SQLException
just pass it on ...

Specified by:
isReadOnly in interface java.sql.Connection
Throws:
java.sql.SQLException

setSavepoint

public java.sql.Savepoint setSavepoint()
                                throws java.sql.SQLException
jdbc 3 methods; don't yet really know what they do so I'm just passing them through blindly.

Specified by:
setSavepoint in interface java.sql.Connection
Throws:
java.sql.SQLException

setSavepoint

public java.sql.Savepoint setSavepoint(java.lang.String savepoint)
                                throws java.sql.SQLException
jdbc 3 methods; don't yet really know what they do so I'm just passing them through blindly.

Specified by:
setSavepoint in interface java.sql.Connection
Throws:
java.sql.SQLException

setTransactionIsolation

public void setTransactionIsolation(int level)
                             throws java.sql.SQLException
Set transaction isolation; thanks to David Orr for this code

Specified by:
setTransactionIsolation in interface java.sql.Connection
Throws:
java.sql.SQLException

getTransactionIsolation

public int getTransactionIsolation()
                            throws java.sql.SQLException
just pass it on ...

Specified by:
getTransactionIsolation in interface java.sql.Connection
Throws:
java.sql.SQLException

setTypeMap

public void setTypeMap(java.util.Map map)
                throws java.sql.SQLException
just pass it on ...

Specified by:
setTypeMap in interface java.sql.Connection
Throws:
java.sql.SQLException

getTypeMap

public java.util.Map getTypeMap()
                         throws java.sql.SQLException
DOCUMENT ME!

Specified by:
getTypeMap in interface java.sql.Connection
Returns:
DOCUMENT ME!
Throws:
java.sql.SQLException - DOCUMENT ME!

getWarnings

public java.sql.SQLWarning getWarnings()
                                throws java.sql.SQLException
just pass it on ...

Specified by:
getWarnings in interface java.sql.Connection
Throws:
java.sql.SQLException

clearWarnings

public void clearWarnings()
                   throws java.sql.SQLException
a simple wrapper round clearWarnings

Specified by:
clearWarnings in interface java.sql.Connection
Throws:
java.sql.SQLException

close

public void close()
           throws java.sql.SQLException
close my real connection and remove me from the pool.

Specified by:
close in interface java.sql.Connection
Throws:
java.sql.SQLException

commit

public void commit()
            throws java.sql.SQLException
a simple wrapper round commit

Specified by:
commit in interface java.sql.Connection
Throws:
java.sql.SQLException

createStatement

public java.sql.Statement createStatement()
                                   throws java.sql.SQLException
a wrapper round createStatement, simply to remind me I'm still alive

Specified by:
createStatement in interface java.sql.Connection
Throws:
java.sql.SQLException
See Also:
Connection.createStatement()

createStatement

public java.sql.Statement createStatement(int resultSetType,
                                          int resultSetConcurrency)
                                   throws java.sql.SQLException
a wrapper round createStatement, simply to remind me I'm still alive

Specified by:
createStatement in interface java.sql.Connection
Throws:
java.sql.SQLException
See Also:
Connection.createStatement(int, int)

createStatement

public java.sql.Statement createStatement(int resultSetType,
                                          int resultSetConcurrency,
                                          int resultSetHoldability)
                                   throws java.sql.SQLException
jdbc 3 methods; don't yet really know what they do so I'm just passing them through blindly.

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
just pass it on ...

Specified by:
nativeSQL in interface java.sql.Connection
Throws:
java.sql.SQLException

prepareCall

public java.sql.CallableStatement prepareCall(java.lang.String sql)
                                       throws java.sql.SQLException
just pass it on ...

Specified by:
prepareCall in interface java.sql.Connection
Throws:
java.sql.SQLException

prepareCall

public java.sql.CallableStatement prepareCall(java.lang.String sql,
                                              int resultSetType,
                                              int resultSetConcurrency)
                                       throws java.sql.SQLException
just pass it on ...

Specified by:
prepareCall in interface java.sql.Connection
Throws:
java.sql.SQLException

prepareCall

public java.sql.CallableStatement prepareCall(java.lang.String sql,
                                              int resultSetType,
                                              int resultSetConcurrency,
                                              int resultSetHoldability)
                                       throws java.sql.SQLException
jdbc 3 methods; don't yet really know what they do so I'm just passing them through blindly.

Specified by:
prepareCall in interface java.sql.Connection
Throws:
java.sql.SQLException

prepareStatement

public java.sql.PreparedStatement prepareStatement(java.lang.String sql)
                                            throws java.sql.SQLException
just pass it on ...

Specified by:
prepareStatement in interface java.sql.Connection
Throws:
java.sql.SQLException

prepareStatement

public java.sql.PreparedStatement prepareStatement(java.lang.String sql,
                                                   int resultSetType,
                                                   int resultSetConcurrency)
                                            throws java.sql.SQLException
just pass it on ...

Specified by:
prepareStatement in interface java.sql.Connection
Throws:
java.sql.SQLException

prepareStatement

public java.sql.PreparedStatement prepareStatement(java.lang.String sql,
                                                   int resultSetType,
                                                   int resultSetConcurrency,
                                                   int resultSetHoldability)
                                            throws java.sql.SQLException
jdbc 3 methods; don't yet really know what they do so I'm just passing them through blindly.

Specified by:
prepareStatement in interface java.sql.Connection
Throws:
java.sql.SQLException

prepareStatement

public java.sql.PreparedStatement prepareStatement(java.lang.String sql,
                                                   int autoGeneratedKeys)
                                            throws java.sql.SQLException
jdbc 3 methods; don't yet really know what they do so I'm just passing them through blindly.

Specified by:
prepareStatement in interface java.sql.Connection
Throws:
java.sql.SQLException

prepareStatement

public java.sql.PreparedStatement prepareStatement(java.lang.String sql,
                                                   int[] columnIndexes)
                                            throws java.sql.SQLException
jdbc 3 methods; don't yet really know what they do so I'm just passing them through blindly.

Specified by:
prepareStatement in interface java.sql.Connection
Throws:
java.sql.SQLException

prepareStatement

public java.sql.PreparedStatement prepareStatement(java.lang.String sql,
                                                   java.lang.String[] columnNames)
                                            throws java.sql.SQLException
jdbc 3 methods; don't yet really know what they do so I'm just passing them through blindly.

Specified by:
prepareStatement in interface java.sql.Connection
Throws:
java.sql.SQLException

releaseSavepoint

public void releaseSavepoint(java.sql.Savepoint savepoint)
                      throws java.sql.SQLException
jdbc 3 methods; don't yet really know what they do so I'm just passing them through blindly.

Specified by:
releaseSavepoint in interface java.sql.Connection
Throws:
java.sql.SQLException

rollback

public void rollback()
              throws java.sql.SQLException
just pass it on ...

Specified by:
rollback in interface java.sql.Connection
Throws:
java.sql.SQLException

rollback

public void rollback(java.sql.Savepoint savepoint)
              throws java.sql.SQLException
jdbc 3 methods; don't yet really know what they do so I'm just passing them through blindly.

Specified by:
rollback in interface java.sql.Connection
Throws:
java.sql.SQLException

unused

protected int unused()
how many milliseconds is it since I was last used?


jacquard 1.12.0 by The Web Engineering Factory and Toolworks