org.logicalcobwebs.proxool

Class ProxyConnection

Implemented Interfaces:
Comparable, ConnectionInfoIF, ProxyConnectionIF

public class ProxyConnection
extends java.lang.Object
implements ProxyConnectionIF

Manages a connection. This is wrapped up inside a...
Version:
$Revision: 1.37 $, $Date: 2006/01/18 14:40:02 $
Authors:
bill
$Author: billhorsman $ (current maintainer)
Since:
Proxool 0.10

Fields inherited from interface org.logicalcobwebs.proxool.ConnectionInfoIF

MARK_FOR_EXPIRY, MARK_FOR_USE, STATUS_ACTIVE, STATUS_AVAILABLE, STATUS_NULL, STATUS_OFFLINE

Constructor Summary

ProxyConnection(Connection connection, long id, String delegateUrl, org.logicalcobwebs.proxool.ConnectionPool connectionPool, ConnectionPoolDefinitionIF definition, int status)

Method Summary

protected void
addOpenStatement(Statement statement)
By calling this we can keep track of any statements that are left open when this connection is returned to the pool.
void
addSqlCall(String sqlCall)
void
close()
int
compareTo(Object o)
Compares using getId()
boolean
equals(Object obj)
Whether the underlying connections are equal
long
getAge()
Date
getBirthDate()
long
getBirthTime()
Connection
getConnection()
protected org.logicalcobwebs.proxool.ConnectionPool
getConnectionPool()
The ConnectionPool that this connection belongs to
ConnectionPoolDefinitionIF
getDefinition()
Get the definition that was used to create this connection
String
getDelegateHashcode()
String
getDelegateUrl()
long
getId()
A unique ID for this connection
String
getLastSqlCall()
Get the most recent of all the getSqlCalls()
int
getMark()
Sometimes we want do something to a connection but can't because it is still active and we don't want to disrupt its use.
String
getProxyHashcode()
String
getReasonForMark()
String
getRequester()
String[]
getSqlCalls()
A log of the last SQL used on this connection.
int
getStatus()
The status of the connection.
long
getTimeLastStartActive()
long
getTimeLastStopActive()
boolean
isActive()
boolean
isAvailable()
boolean
isClosed()
Whether this connection is available.
boolean
isMarkedForExpiry()
boolean
isNull()
boolean
isOffline()
boolean
isReallyClosed()
void
markForExpiry(String reason)
protected void
open()
This gets called /just/ before a connection is served.
void
reallyClose()
Close the connection for real
void
registerClosedStatement(Statement statement)
void
setBirthTime(long birthTime)
void
setId(long id)
protected void
setNeedToReset(boolean needToReset)
The subclass should call this to indicate that a change has been made to the connection that might mean it needs to be reset (like setting autoCommit to false or something).
void
setRequester(String requester)
boolean
setStatus(int newStatus)
boolean
setStatus(int oldStatus, int newStatus)
void
setTimeLastStartActive(long timeLastStartActive)
void
setTimeLastStopActive(long timeLastStopActive)
String
toString()

Constructor Details

ProxyConnection

protected ProxyConnection(Connection connection,
                          long id,
                          String delegateUrl,
                          org.logicalcobwebs.proxool.ConnectionPool connectionPool,
                          ConnectionPoolDefinitionIF definition,
                          int status)
            throws SQLException
Parameters:
connection - the real connection that is used
id - unique ID
delegateUrl -
connectionPool - the pool it is a member of
definition - the definition that was used to build it (could possibly be different from the one held in the connectionPool)
status - ConnectionInfoIF.STATUS_ACTIVE, ConnectionInfoIF.STATUS_AVAILABLE, STATUS_FORCE, ConnectionInfoIF.STATUS_NULL, or ConnectionInfoIF.STATUS_OFFLINE

Method Details

addOpenStatement

protected void addOpenStatement(Statement statement)
By calling this we can keep track of any statements that are left open when this connection is returned to the pool.
Parameters:
statement - the statement that we have just opened/created.

addSqlCall

public void addSqlCall(String sqlCall)

close

public void close()
            throws SQLException
Specified by:
close in interface ProxyConnectionIF

compareTo

public int compareTo(Object o)
Parameters:
o - must be another ConnectionInfoIF implementation
Returns:
the comparison
See Also:
Comparable.compareTo(Object)

equals

public boolean equals(Object obj)
Whether the underlying connections are equal
Parameters:
obj - the object (probably another connection) that we are being compared to
Returns:
whether they are the same

getAge

public long getAge()
Specified by:
getAge in interface ConnectionInfoIF

getBirthDate

public Date getBirthDate()
Specified by:
getBirthDate in interface ConnectionInfoIF

getBirthTime

public long getBirthTime()
Specified by:
getBirthTime in interface ConnectionInfoIF

getConnection

public Connection getConnection()
Specified by:
getConnection in interface ProxyConnectionIF

getConnectionPool

protected org.logicalcobwebs.proxool.ConnectionPool getConnectionPool()
The ConnectionPool that this connection belongs to
Returns:
connectionPool

getDefinition

public ConnectionPoolDefinitionIF getDefinition()
Get the definition that was used to create this connection
Specified by:
getDefinition in interface ProxyConnectionIF
Returns:
definition

getDelegateHashcode

public String getDelegateHashcode()
Specified by:
getDelegateHashcode in interface ConnectionInfoIF

getDelegateUrl

public String getDelegateUrl()
Specified by:
getDelegateUrl in interface ConnectionInfoIF

getId

public long getId()
A unique ID for this connection
Specified by:
getId in interface ConnectionInfoIF

getLastSqlCall

public String getLastSqlCall()
Get the most recent of all the getSqlCalls()
Specified by:
getLastSqlCall in interface ProxyConnectionIF
Returns:
the SQL (could be a batch of SQLs)

getMark

public int getMark()
Specified by:
getMark in interface ConnectionInfoIF

getProxyHashcode

public String getProxyHashcode()
Specified by:
getProxyHashcode in interface ConnectionInfoIF

getReasonForMark

public String getReasonForMark()
Specified by:
getReasonForMark in interface ProxyConnectionIF

getRequester

public String getRequester()
Specified by:
getRequester in interface ConnectionInfoIF

getSqlCalls

public String[] getSqlCalls()
Specified by:
getSqlCalls in interface ConnectionInfoIF
Returns:
the most recent SQL to be used

getStatus

public int getStatus()
Specified by:
getStatus in interface ConnectionInfoIF

getTimeLastStartActive

public long getTimeLastStartActive()
Specified by:
getTimeLastStartActive in interface ConnectionInfoIF

getTimeLastStopActive

public long getTimeLastStopActive()
Specified by:
getTimeLastStopActive in interface ConnectionInfoIF

isActive

public boolean isActive()
Specified by:
isActive in interface ProxyConnectionIF

isAvailable

public boolean isAvailable()
Specified by:
isAvailable in interface ProxyConnectionIF

isClosed

public boolean isClosed()
Whether this connection is available. (When you close the connection it doesn't really close, it just becomes available for others to use).
Returns:
true if the connection is not active

isMarkedForExpiry

public boolean isMarkedForExpiry()
Specified by:
isMarkedForExpiry in interface ProxyConnectionIF

isNull

public boolean isNull()
Specified by:
isNull in interface ProxyConnectionIF

isOffline

public boolean isOffline()
Specified by:
isOffline in interface ProxyConnectionIF

isReallyClosed

public boolean isReallyClosed()
            throws SQLException
Specified by:
isReallyClosed in interface ProxyConnectionIF

markForExpiry

public void markForExpiry(String reason)
Specified by:
markForExpiry in interface ProxyConnectionIF

open

protected void open()

reallyClose

public void reallyClose()
            throws SQLException
Close the connection for real
Specified by:
reallyClose in interface ProxyConnectionIF

registerClosedStatement

public void registerClosedStatement(Statement statement)
Specified by:
registerClosedStatement in interface ProxyConnectionIF

setBirthTime

public void setBirthTime(long birthTime)

setId

public void setId(long id)

setNeedToReset

protected void setNeedToReset(boolean needToReset)
The subclass should call this to indicate that a change has been made to the connection that might mean it needs to be reset (like setting autoCommit to false or something). We don't reset unless this has been called to avoid the overhead of unnecessary resetting.
Parameters:
needToReset - true if the connection might need resetting.

setRequester

public void setRequester(String requester)
Specified by:
setRequester in interface ProxyConnectionIF

setStatus

public boolean setStatus(int newStatus)
Specified by:
setStatus in interface ProxyConnectionIF

setStatus

public boolean setStatus(int oldStatus,
                         int newStatus)
Specified by:
setStatus in interface ProxyConnectionIF

setTimeLastStartActive

public void setTimeLastStartActive(long timeLastStartActive)

setTimeLastStopActive

public void setTimeLastStopActive(long timeLastStopActive)

toString

public String toString()
See Also:
Object.toString