anvil.database
Class PooledConnection

java.lang.Object
  |
  +--anvil.database.PooledConnection
Direct Known Subclasses:
JDBCConnection, JNDIConnection

public abstract class PooledConnection
extends java.lang.Object

Abstract class wrapping connection objects.

Version:
$Revision: 1.2 $
Author:
Jani Lehtimäki

Field Summary
protected  long closedAt
          Closing timestamp.
protected  java.lang.Object connection
          Connection object
protected  long createdAt
          Creation timestamp.
protected  ConnectionPool myPool
          Pool where this connections belongs into.
protected  java.lang.String name
          Name of connection "[name_of_pool]-[count]".
protected  long releasedAt
          Timestamp for last release.
protected  boolean reserved
          Being reserved?
protected  long reservedAt
          Timestamp for last reserve.
protected  int timeout
          Timeout
 
Constructor Summary
PooledConnection(ConnectionPool myPool, java.lang.String name, java.lang.Object connection)
          Creates the connection.
 
Method Summary
protected abstract  void closeConnection()
           
 boolean equals(java.lang.Object o)
           
 long getClosingTime()
          Timestamp of last close.
 java.lang.Object getConnection()
          Gets the connection object.
 long getCreationTime()
          Timestamp of creation time.
 java.lang.String getName()
          Gets the name of connection.
 ConnectionPool getPool()
          Gets the pool where connection belongs into.
 long getReleaseTime()
          Timestamp of last release.
 long getReserveTime()
          Timestamp of last reservation.
 boolean hasTimedOut()
          Checks if the connection has timed out.
 boolean isAlive()
          Checks if the connection is still alive.
protected abstract  boolean isConnectionClosed()
           
 boolean isReserved()
          Is this connection reserved?
 void release()
          Releases the connection
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

myPool

protected ConnectionPool myPool
Pool where this connections belongs into.


name

protected java.lang.String name
Name of connection "[name_of_pool]-[count]".


connection

protected java.lang.Object connection
Connection object


timeout

protected int timeout
Timeout


createdAt

protected long createdAt
Creation timestamp.


closedAt

protected long closedAt
Closing timestamp.


reservedAt

protected long reservedAt
Timestamp for last reserve.


releasedAt

protected long releasedAt
Timestamp for last release.


reserved

protected boolean reserved
Being reserved?

Constructor Detail

PooledConnection

public PooledConnection(ConnectionPool myPool,
                        java.lang.String name,
                        java.lang.Object connection)
Creates the connection.

Parameters:
myPool - Connection pool
name - Name of connection
connection - java.sql.Connection
Method Detail

getName

public java.lang.String getName()
Gets the name of connection.

Returns:
Name of connection

getPool

public ConnectionPool getPool()
Gets the pool where connection belongs into.

Returns:
Connection pool

isReserved

public boolean isReserved()
Is this connection reserved?

Returns:
true if reserved, false otherwise.

getCreationTime

public long getCreationTime()
Timestamp of creation time.

Returns:
Timestamp

getClosingTime

public long getClosingTime()
Timestamp of last close.

Returns:
Timestamp

getReserveTime

public long getReserveTime()
Timestamp of last reservation.

Returns:
Timestamp

getReleaseTime

public long getReleaseTime()
Timestamp of last release.

Returns:
Timestamp

getConnection

public java.lang.Object getConnection()
Gets the connection object.

Returns:
Connection

isConnectionClosed

protected abstract boolean isConnectionClosed()
                                       throws java.lang.Exception
java.lang.Exception

closeConnection

protected abstract void closeConnection()
                                 throws java.lang.Exception
java.lang.Exception

isAlive

public boolean isAlive()
Checks if the connection is still alive. Connection is considered alive if java.sql.Connection has not yet been closed, and maximum lifetime is not exceeded. However, lifetime can be exceeded if connection is reserved.

Returns:
true if alive, false otherwise.

hasTimedOut

public boolean hasTimedOut()
Checks if the connection has timed out. It is considered timed out if it is reserved and maximum reservation time has been exceeded.

Returns:
true if timed out, false otherwise.

release

public void release()
Releases the connection


equals

public boolean equals(java.lang.Object o)
Overrides:
equals in class java.lang.Object

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object