Methods Summary |
---|
public void | addConnectionEventListener(javax.sql.ConnectionEventListener lstnr)Adds new listeners to connection events. This method is part
of the pooled connection's contract with its pooling environment
so that the pooling environment knows when connections occur
and unrecoverable errors occur.
synchronized( listeners ) {
listeners.add(lstnr);
}
|
public void | clearWarnings()Delegates to the underlying JDBC connection.
database.clearWarnings();
|
public void | close()Delegates to the underlying JDBC connection.
synchronized( listeners ) {
if( database != null ) {
database.close();
}
}
logical = null;
|
public void | commit()Delegates to the underlying JDBC connection.
database.commit();
|
public void | connectionClosed()Called by the current logical connection to let the physical
connection know that the application has closed the logical
connection. This method will thus trigger a connection event
notifying the pooling environment that this physical connection
is now available for reuse.
synchronized( listeners ) {
Iterator it = listeners.iterator();
while( it.hasNext() ) {
ConnectionEventListener lstnr;
lstnr = (ConnectionEventListener)it.next();
lstnr.connectionClosed(new ConnectionEvent(this));
}
logical = null;
listeners.notifyAll();
}
|
public void | connectionErrored(java.sql.SQLException e)Called by the current logical connection to let the physical
connection know that an error has occured indicating a need
to discard this physical connection. This method will thus
trigger a connection event notifying the pooling environment
that this physical connection should be permanently out of use.
synchronized( listeners ) {
Iterator it = listeners.iterator();
while( it.hasNext() ) {
ConnectionEventListener lstnr;
lstnr = (ConnectionEventListener)it.next();
lstnr.connectionErrorOccurred(new ConnectionEvent(this, e));
}
}
|
public java.sql.Statement | createStatement(int rst, int rsc)Delegates to the underlying JDBC connection.
return database.createStatement(rst, rsc);
|
public java.sql.Statement | createStatement()Delegates to the underlying JDBC connection.
return database.createStatement();
|
public boolean | getAutoCommit()Delegates to the underlying JDBC connection.
return database.getAutoCommit();
|
public java.lang.String | getCatalog()Delegates to the underlying JDBC connection.
return database.getCatalog();
|
public java.sql.Connection | getConnection()Provides the connection pooling environment with a logical
connection that references this physical connection.
synchronized( listeners ) {
logical = new LogicalConnection(this);
return logical;
}
|
public java.sql.DatabaseMetaData | getMetaData()Delegates to the underlying JDBC connection.
return database.getMetaData();
|
public int | getTransactionIsolation()Delegates to the underlying JDBC connection.
return database.getTransactionIsolation();
|
public java.util.Map | getTypeMap()Delegates to the underlying JDBC connection.
return database.getTypeMap();
|
public java.sql.SQLWarning | getWarnings()Delegates to the underlying JDBC connection.
return database.getWarnings();
|
public boolean | isClosed()Delegates to the underlying JDBC connection, if any.
return (database != null && database.isClosed());
|
public boolean | isReadOnly()Delegates to the underlying JDBC connection.
return database.isReadOnly();
|
private void | keepAlive()This method sits in a loop and keeps the underlying connection
alive while the connection is in a pool. It keeps the connection
alive by periodically sending:
SELECT 1
to the underlying database.
synchronized( listeners ) {
boolean closed = false;
do {
try { listeners.wait(60000); }
catch( InterruptedException e ) { }
// only do this if the connection is in the pool
if( logical == null ) {
// if an error occurs while testing
// this connection will be removed from the pool
if( !test() ) {
try { database.close(); }
catch( SQLException e ) { }
database = null;
logical = null;
return;
}
}
try {
closed = isClosed();
}
catch( SQLException e ) {
closed = true;
}
} while( !closed );
}
|
public java.lang.String | nativeSQL(java.lang.String sql)Delegates to the underlying JDBC connection.
return database.nativeSQL(sql);
|
public java.sql.CallableStatement | prepareCall(java.lang.String sql)Delegates to the underlying JDBC connection.
return database.prepareCall(sql);
|
public java.sql.CallableStatement | prepareCall(java.lang.String sql, int rst, int rsc)Delegates to the underlying JDBC connection.
return database.prepareCall(sql, rst, rsc);
|
public java.sql.PreparedStatement | prepareStatement(java.lang.String sql)Looks in the prepared statement pool for matching SQL and if
no match is found prepares a new one.
PreparedStatement stmt;
PooledStatement ps;
synchronized( pool ) {
if( pool.contains(sql) ) {
stmt = pool.pop(sql);
}
else {
stmt = database.prepareStatement(sql);
}
}
ps = new PooledStatement(logical, sql, stmt);
ps.addStatementEventListener(this);
return ps;
|
public java.sql.PreparedStatement | prepareStatement(java.lang.String sql, int rst, int rsc)Prepares a statement for the specified SQL. If the statement
pool contains the specified statement and the result sets
should be ResultSet.TYPE_FORWARD_ONLY and
ResultSet.CONCUR_READ_ONLY , then the statement
is pulled from the pool. A new statement is prepared for
all other statements. Scrollable and updateable result
sets are not supported in this pooling mechanism.
if( rst == ResultSet.TYPE_FORWARD_ONLY ) {
if( rsc == ResultSet.CONCUR_READ_ONLY ) {
return prepareStatement(sql);
}
}
return database.prepareStatement(sql);
|
public void | removeConnectionEventListener(javax.sql.ConnectionEventListener lstnr)Removes a listener from the list of listeners in accordance
with this pooled connection's contract with the pooling
environment.
synchronized( listeners ) {
listeners.remove(lstnr);
}
|
public void | rollback()Delegates to the underlying JDBC connection.
database.rollback();
|
public void | setAutoCommit(boolean ac)Delegates to the underlying JDBC connection.
database.setAutoCommit(ac);
|
public void | setCatalog(java.lang.String cat)Delegates to the underlying JDBC connection.
database.setCatalog(cat);
|
public void | setReadOnly(boolean ro)Delegates to the underlying JDBC connection.
database.setReadOnly(ro);
|
public void | setTransactionIsolation(int lvl)Delegates to the underlying JDBC connection.
database.setTransactionIsolation(lvl);
|
public void | setTypeMap(java.util.Map map)Delegates to the underlying JDBC connection.
database.setTypeMap(map);
|
public void | statementClosed(StatementEvent evt)Triggered by a statement when the application closes it so that
this connection may return the statement to the statement pool.
synchronized( pool ) {
pool.push(evt.getSQL(), evt.getStatement());
}
|
private boolean | test()Tests the connection to see if it is still up. If not, it
notifies the pooling environment that this connection is no longer
valid.
Statement stmt = null;
try {
stmt = database.createStatement();
stmt.executeQuery("SELECT 1");
return true;
}
catch( SQLException e ) {
connectionErrored(e);
return false;
}
finally {
if( stmt != null ) {
try { stmt.close(); }
catch( SQLException e ) { }
}
}
|
public java.lang.String | toString()
if( database != null ) {
return super.toString() + " [" + database.toString() + "]";
}
else {
return super.toString();
}
|