|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.logicalcobwebs.proxool.ProxyConnection
public class ProxyConnection
Manages a connection. This is wrapped up inside a...
Field Summary | |
---|---|
private java.util.Date |
birthDate
|
private java.sql.Connection |
connection
|
private ConnectionPool |
connectionPool
|
private ConnectionPoolDefinitionIF |
definition
|
private java.lang.String |
delegateUrl
|
private long |
id
|
private java.text.DecimalFormat |
idFormat
|
private static Log |
LOG
|
private int |
mark
|
private boolean |
needToReset
Whether we have invoked a method that requires us to reset |
private java.util.Set |
openStatements
|
private java.lang.String |
reasonForMark
|
private java.lang.String |
requester
|
private java.util.List |
sqlCalls
|
private int |
status
|
(package private) static int |
STATUS_FORCE
|
private WriterPreferenceReadWriteLock |
statusReadWriteLock
|
private long |
timeLastStartActive
|
private long |
timeLastStopActive
|
Fields inherited from interface org.logicalcobwebs.proxool.ConnectionInfoIF |
---|
MARK_FOR_EXPIRY, MARK_FOR_USE, STATUS_ACTIVE, STATUS_AVAILABLE, STATUS_NULL, STATUS_OFFLINE |
Constructor Summary | |
---|---|
protected |
ProxyConnection(java.sql.Connection connection,
long id,
java.lang.String delegateUrl,
ConnectionPool connectionPool,
ConnectionPoolDefinitionIF definition,
int status)
|
Method Summary | |
---|---|
protected void |
addOpenStatement(java.sql.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(java.lang.String sqlCall)
|
void |
close()
Doesn't really close the connection, just puts it back in the pool. |
int |
compareTo(java.lang.Object o)
Compares using getId() |
boolean |
equals(java.lang.Object obj)
Whether the underlying connections are equal |
long |
getAge()
The age in millseconds since this connection was built |
java.util.Date |
getBirthDate()
Like ConnectionInfoIF.getBirthTime() but in Date format |
long |
getBirthTime()
The time that this connection was created. |
java.sql.Connection |
getConnection()
The real, delegate connection that we are using |
protected ConnectionPool |
getConnectionPool()
The ConnectionPool that this connection belongs to |
ConnectionPoolDefinitionIF |
getDefinition()
Get the definition that was used to create this connection |
java.lang.String |
getDelegateHashcode()
The hashcode (in hex) of the delegate connection object. |
java.lang.String |
getDelegateUrl()
The URL that this connection is using (the definition might have changed since this connection was built). |
long |
getId()
A unique ID for this connection |
java.lang.String |
getLastSqlCall()
Get the most recent of all the ConnectionInfoIF.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. |
java.lang.String |
getProxyHashcode()
The hashcode (in hex) of the ProxyConnection object. |
java.lang.String |
getReasonForMark()
Why this connection is marked (for instance, if a thread has marked it for expiry then it's nice to know why) |
java.lang.String |
getRequester()
The name of the thread that asked for this connection. |
java.lang.String[] |
getSqlCalls()
A log of the last SQL used on this connection. |
int |
getStatus()
The status of the connection. |
long |
getTimeLastStartActive()
When this connection was last given out. |
long |
getTimeLastStopActive()
When this connection was last given back (or zero if it is still active). |
boolean |
isActive()
|
boolean |
isAvailable()
|
boolean |
isClosed()
Whether this connection is available. |
boolean |
isMarkedForExpiry()
Whether this connection is due for expiry |
boolean |
isNull()
|
boolean |
isOffline()
|
boolean |
isReallyClosed()
Find out if the delegated connection is close. |
void |
markForExpiry(java.lang.String reason)
Mark this connection for expiry (destruction) as soon as it stops being active. |
protected void |
open()
This gets called /just/ before a connection is served. |
void |
reallyClose()
Close the connection for real |
void |
registerClosedStatement(java.sql.Statement statement)
Notify that a statement has been closed and won't need closing when the connection is returned to the poo. |
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(java.lang.String requester)
|
boolean |
setStatus(int newStatus)
Forces the new status regardless of the old state |
boolean |
setStatus(int oldStatus,
int newStatus)
Changes the status and lets the ConnectionPool know so that it can keep count of how many connections are at each status. |
void |
setTimeLastStartActive(long timeLastStartActive)
|
void |
setTimeLastStopActive(long timeLastStopActive)
|
java.lang.String |
toString()
|
Methods inherited from class java.lang.Object |
---|
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
static final int STATUS_FORCE
private WriterPreferenceReadWriteLock statusReadWriteLock
private static final Log LOG
private java.sql.Connection connection
private java.lang.String delegateUrl
private int mark
private java.lang.String reasonForMark
private int status
private long id
private java.util.Date birthDate
private long timeLastStartActive
private long timeLastStopActive
private ConnectionPool connectionPool
private ConnectionPoolDefinitionIF definition
private java.lang.String requester
private java.util.Set openStatements
private java.text.DecimalFormat idFormat
private java.util.List sqlCalls
private boolean needToReset
Constructor Detail |
---|
protected ProxyConnection(java.sql.Connection connection, long id, java.lang.String delegateUrl, ConnectionPool connectionPool, ConnectionPoolDefinitionIF definition, int status) throws java.sql.SQLException
connection
- the real connection that is usedid
- unique IDdelegateUrl
- connectionPool
- the pool it is a member ofdefinition
- 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
java.sql.SQLException
Method Detail |
---|
public boolean equals(java.lang.Object obj)
equals
in class java.lang.Object
obj
- the object (probably another connection) that we
are being compared to
public boolean isClosed()
protected void setNeedToReset(boolean needToReset)
needToReset
- true if the connection might need resetting.protected ConnectionPool getConnectionPool()
public ConnectionPoolDefinitionIF getDefinition()
getDefinition
in interface ProxyConnectionIF
protected void addOpenStatement(java.sql.Statement statement)
statement
- the statement that we have just opened/created.registerClosedStatement(java.sql.Statement)
public void registerClosedStatement(java.sql.Statement statement)
ProxyConnectionIF
registerClosedStatement
in interface ProxyConnectionIF
statement
- the statement that has just been closedProxyConnectionIF.registerClosedStatement(java.sql.Statement)
public void reallyClose() throws java.sql.SQLException
reallyClose
in interface ProxyConnectionIF
java.sql.SQLException
- if anything goes wrongpublic boolean isReallyClosed() throws java.sql.SQLException
ProxyConnectionIF
isReallyClosed
in interface ProxyConnectionIF
java.sql.SQLException
- if anything went wrongProxyConnectionIF.isReallyClosed()
public void close() throws java.sql.SQLException
ProxyConnectionIF
close
in interface ProxyConnectionIF
java.sql.SQLException
ProxyConnectionIF.close()
protected void open()
open()
then close()
public int getMark()
ConnectionInfoIF
expire
the
connection (if it is too old for instance). And this will happen if the
housekeeper decides it should but the connection is still active.
getMark
in interface ConnectionInfoIF
public int getStatus()
ConnectionInfoIF
null
,
available
,
active
or
offline
.
getStatus
in interface ConnectionInfoIF
public boolean setStatus(int newStatus)
ProxyConnectionIF
setStatus
in interface ProxyConnectionIF
newStatus
- the status to change to
ProxyConnectionIF.setStatus(int)
public boolean setStatus(int oldStatus, int newStatus)
ProxyConnectionIF
setStatus
in interface ProxyConnectionIF
oldStatus
- the expected existing status. if the existing
status is not this value then no change is made and false is returned.newStatus
- the status to change to
ProxyConnectionIF.setStatus(int, int)
public long getId()
ConnectionInfoIF
getId
in interface ConnectionInfoIF
public void setId(long id)
public long getBirthTime()
ConnectionInfoIF
getBirthTime
in interface ConnectionInfoIF
ConnectionInfoIF.getBirthTime()
public java.util.Date getBirthDate()
ConnectionInfoIF
ConnectionInfoIF.getBirthTime()
but in Date format
getBirthDate
in interface ConnectionInfoIF
ConnectionInfoIF.getBirthDate()
public long getAge()
ConnectionInfoIF
getAge
in interface ConnectionInfoIF
ConnectionInfoIF.getAge()
public void setBirthTime(long birthTime)
ConnectionInfoIF.getBirthTime()
public long getTimeLastStartActive()
ConnectionInfoIF
getTimeLastStartActive
in interface ConnectionInfoIF
ConnectionInfoIF.getTimeLastStartActive()
public void setTimeLastStartActive(long timeLastStartActive)
ConnectionInfoIF.getTimeLastStartActive()
public long getTimeLastStopActive()
ConnectionInfoIF
getTimeLastStopActive
in interface ConnectionInfoIF
ConnectionInfoIF.getTimeLastStopActive()
public void setTimeLastStopActive(long timeLastStopActive)
ConnectionInfoIF.getTimeLastStopActive()
public java.lang.String getRequester()
ConnectionInfoIF
getRequester
in interface ConnectionInfoIF
ConnectionInfoIF.getRequester()
public void setRequester(java.lang.String requester)
setRequester
in interface ProxyConnectionIF
ConnectionInfoIF.getRequester()
public boolean isNull()
isNull
in interface ProxyConnectionIF
ProxyConnectionIF.isNull()
public boolean isAvailable()
isAvailable
in interface ProxyConnectionIF
ProxyConnectionIF.isAvailable()
public boolean isActive()
isActive
in interface ProxyConnectionIF
ProxyConnectionIF.isActive()
public boolean isOffline()
isOffline
in interface ProxyConnectionIF
ProxyConnectionIF.isOffline()
public void markForExpiry(java.lang.String reason)
ProxyConnectionIF
markForExpiry
in interface ProxyConnectionIF
reason
- why we are marking this connectionProxyConnectionIF.markForExpiry(java.lang.String)
public boolean isMarkedForExpiry()
ProxyConnectionIF
isMarkedForExpiry
in interface ProxyConnectionIF
ProxyConnectionIF.isMarkedForExpiry()
public java.lang.String getReasonForMark()
ProxyConnectionIF
getReasonForMark
in interface ProxyConnectionIF
ProxyConnectionIF.getReasonForMark()
public java.sql.Connection getConnection()
ProxyConnectionIF
getConnection
in interface ProxyConnectionIF
ProxyConnectionIF.getConnection()
public java.lang.String toString()
toString
in class java.lang.Object
Object.toString()
public java.lang.String getDelegateUrl()
ConnectionInfoIF
getDelegateUrl
in interface ConnectionInfoIF
ConnectionInfoIF.getDelegateUrl()
public java.lang.String getProxyHashcode()
ConnectionInfoIF
getProxyHashcode
in interface ConnectionInfoIF
ConnectionInfoIF.getProxyHashcode()
public java.lang.String getDelegateHashcode()
ConnectionInfoIF
getDelegateHashcode
in interface ConnectionInfoIF
ConnectionInfoIF.getDelegateHashcode()
public int compareTo(java.lang.Object o)
getId()
compareTo
in interface java.lang.Comparable
o
- must be another ConnectionInfoIF
implementation
Comparable.compareTo(Object)
public java.lang.String[] getSqlCalls()
ConnectionInfoIF
ConnectionPoolDefinitionIF.isTrace()
is enabled.
getSqlCalls
in interface ConnectionInfoIF
public java.lang.String getLastSqlCall()
ProxyConnectionIF
ConnectionInfoIF.getSqlCalls()
getLastSqlCall
in interface ProxyConnectionIF
public void addSqlCall(java.lang.String sqlCall)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |