|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--org.apache.turbine.util.db.pool.DBConnection
This class wraps the JDBC Connection
class, providing
built-in exception logging to stderr and a timestamp which
indicates how old the Connection
is.
DBConnection
's timestamp is used by the
ConnectionPool
to expire connections when they get too
old. Do not use this class as a shared resource (it is not thread-safe).
Field Summary | |
private java.sql.Connection |
connection
The JDBC database connection. |
private java.util.Vector |
eventListeners
ConnectionEventListeners |
private ConnectionPool |
pool
The ConnectionPool that this DBConnection came from. |
private javax.sql.PooledConnection |
pooledConnection
The JDBC PooledConnection (if supported by the JDBC driver). |
private long |
timestamp
The time in milliseconds at which the connection was created. |
private java.lang.String |
url
The URL of this connection. |
private java.lang.String |
username
The user name for this connection. |
Constructor Summary | |
protected |
DBConnection(java.sql.Connection connection)
Creates a Turbine DBConnection specifying
nothing but a single database Connection. |
protected |
DBConnection(java.sql.Connection connection,
java.lang.String url)
Creates a Turbine DBConnection with the specified
attributes. |
protected |
DBConnection(java.sql.Connection connection,
java.lang.String url,
java.lang.String username)
Creates a Turbine DBConnection with the specified
attributes. |
protected |
DBConnection(java.sql.Connection connection,
java.lang.String url,
java.lang.String username,
ConnectionPool pool)
Creates a Turbine DBConnection that is part of
a pool. |
protected |
DBConnection(javax.sql.PooledConnection pooledConnection,
java.lang.String url,
java.lang.String username,
ConnectionPool pool)
Creates a Turbine DBConnection that is part of
a pool. |
Method Summary | |
void |
addConnectionEventListener(javax.sql.ConnectionEventListener listener)
Add an event listener. |
void |
close()
Force the close of this database connection. |
void |
commit()
Commit the connection. |
void |
connectionClosed(javax.sql.ConnectionEvent event)
This will be called if the Connection returned by the getConnection method came from a PooledConnection, and the user calls the close() method of this connection object. |
void |
connectionErrorOccurred(javax.sql.ConnectionEvent e)
If a fatal error occurs, close the undelying physical connection so as not to be returned in the future |
java.sql.Statement |
createStatement()
Create a Java SQL statement for this connection. |
protected void |
finalize()
The finalizer helps prevent ConnectionPool leakage. |
java.sql.Connection |
getConnection()
Returns a JDBC connection. |
ConnectionPool |
getPool()
Returns the pool this DBConnection came from, or null if it is not linked to any pool |
long |
getTimestamp()
Returns a long representing the time this connection was created. |
java.lang.String |
getUrl()
Returns the connection URL. |
java.lang.String |
getUsername()
Returns the connection user name. |
protected void |
link(ConnectionPool pool)
Links this DBConnection with a ConnectionPool. |
java.sql.PreparedStatement |
prepareStatement(java.lang.String sql)
Create a prepared Java SQL statement for this connection. |
void |
removeConnectionEventListener(javax.sql.ConnectionEventListener listener)
Remove an event listener. |
void |
rollback()
Roll back the connection. |
void |
setAutoCommit(boolean b)
Set the autocommit flag for the connection. |
protected void |
unlink(ConnectionPool pool)
Unlink the DBConnection from it's pool. |
Methods inherited from class java.lang.Object |
|
Field Detail |
private ConnectionPool pool
private java.sql.Connection connection
private javax.sql.PooledConnection pooledConnection
private java.lang.String url
private java.lang.String username
private long timestamp
private java.util.Vector eventListeners
Constructor Detail |
protected DBConnection(java.sql.Connection connection)
DBConnection
specifying
nothing but a single database Connection.connection
- The JDBC connection to wrap.protected DBConnection(java.sql.Connection connection, java.lang.String url)
DBConnection
with the specified
attributes.connection
- The JDBC connection to wrap.url
- The URL we're connecting to.protected DBConnection(java.sql.Connection connection, java.lang.String url, java.lang.String username)
DBConnection
with the specified
attributes.connection
- The JDBC connection to wrap.url
- The URL we're connecting to.username
- The user name we are connecting asprotected DBConnection(java.sql.Connection connection, java.lang.String url, java.lang.String username, ConnectionPool pool)
DBConnection
that is part of
a pool.connection
- The JDBC connection to wrap.url
- The URL we're connecting to.username
- The user name we are connecting aspool
- The ConnectionPool that this DBConnection belongs toprotected DBConnection(javax.sql.PooledConnection pooledConnection, java.lang.String url, java.lang.String username, ConnectionPool pool)
DBConnection
that is part of
a pool.connection
- The JDBC connection to wrap.url
- The URL we're connecting to.username
- The user name we are connecting aspool
- The ConnectionPool that this DBConnection belongs toMethod Detail |
protected void finalize() throws java.lang.Throwable
ConnectionPool
leakage.finalize
in class java.lang.Object
protected void link(ConnectionPool pool)
The
- pool to link to.protected void unlink(ConnectionPool pool) throws java.lang.Exception
pool
- The pool to unlink from.java.lang.Exception
- Attempt to unlink from another pool.public ConnectionPool getPool()
public void addConnectionEventListener(javax.sql.ConnectionEventListener listener)
public void removeConnectionEventListener(javax.sql.ConnectionEventListener listener)
public java.sql.Connection getConnection() throws java.sql.SQLException
public long getTimestamp()
public java.lang.String getUrl()
public java.lang.String getUsername()
public void commit()
public void rollback()
public void setAutoCommit(boolean b)
b
- True if autocommit should be set to true.public java.sql.Statement createStatement()
Statement
.public java.sql.PreparedStatement prepareStatement(java.lang.String sql)
sql
- The SQL statement to prepare.PreparedStatement
.public void close() throws java.sql.SQLException
java.sql.SQLException
- The database connection couldn't be closed.public void connectionClosed(javax.sql.ConnectionEvent event)
connectionClosed
in interface javax.sql.ConnectionEventListener
public void connectionErrorOccurred(javax.sql.ConnectionEvent e)
connectionErrorOccurred
in interface javax.sql.ConnectionEventListener
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |