public class PooledConnection
extends java.lang.Object
Connection
objectModifier and Type | Field and Description |
---|---|
protected ConnectionPool |
parent
The parent
|
protected PoolConfiguration |
poolProperties
The properties for the connection pool
|
static java.lang.String |
PROP_PASSWORD |
static java.lang.String |
PROP_USER |
static int |
VALIDATE_BORROW
Validate when connection is borrowed flag
|
static int |
VALIDATE_IDLE
Validate when connection is idle flag
|
static int |
VALIDATE_INIT
Validate when connection is initialized flag
|
static int |
VALIDATE_RETURN
Validate when connection is returned flag
|
protected javax.sql.XAConnection |
xaConnection
If using a XAConnection underneath.
|
Constructor and Description |
---|
PooledConnection(PoolConfiguration prop,
ConnectionPool parent)
Constructor
|
Modifier and Type | Method and Description |
---|---|
boolean |
checkUser(java.lang.String username,
java.lang.String password) |
void |
connect()
Connects the underlying connection to the database.
|
protected void |
connectUsingDataSource() |
protected void |
connectUsingDriver() |
long |
getAbandonTimeout()
Returns abandon timeout in milliseconds
|
java.util.HashMap<java.lang.Object,java.lang.Object> |
getAttributes() |
java.sql.Connection |
getConnection()
Returns the underlying connection
|
long |
getConnectionVersion() |
JdbcInterceptor |
getHandler()
Returns the first handler in the interceptor chain
|
long |
getLastConnected()
Returns the timestamp of when the connection was last connected to the database.
|
long |
getLastValidated()
Returns the timestamp of the last successful validation query execution.
|
PoolConfiguration |
getPoolProperties()
Returns the configuration for this connection and pool
|
long |
getReleaseTime()
The time limit for how long the object
can remain unused before it is released
|
java.lang.String |
getStackTrace()
Returns the stack trace from when this connection was borrowed.
|
long |
getTimestamp()
Return the timestamps of last pool action.
|
javax.sql.XAConnection |
getXAConnection()
Returns the underlying XA connection
|
boolean |
isDiscarded()
Returns the discarded flag.
|
boolean |
isInitialized() |
boolean |
isReleased()
Returns true if this connection has been released and wont be reused.
|
boolean |
isSuspect() |
void |
lock()
Locks the connection only if either
PoolConfiguration.isPoolSweeperEnabled() or
PoolConfiguration.getUseLock() return true. |
void |
reconnect()
Issues a call to
disconnect(boolean) with the argument false followed by a call to
connect() |
boolean |
release()
This method is called if (Now - timeCheckedIn > getReleaseTime())
This method disconnects the connection, logs an error in debug mode if it happens
then sets the
released flag to false. |
void |
setDiscarded(boolean discarded)
An interceptor can call this method with the value true, and the connection will be closed when it is returned to the pool.
|
void |
setHandler(JdbcInterceptor handler) |
void |
setLastValidated(long lastValidated)
Set the timestamp the connection was last validated.
|
void |
setPoolProperties(PoolConfiguration poolProperties)
Sets the pool configuration for this connection and connection pool.
|
void |
setStackTrace(java.lang.String trace)
The pool will set the stack trace when it is check out and
checked in
|
void |
setSuspect(boolean suspect) |
void |
setTimestamp(long timestamp)
Sets a timestamp on this connection.
|
java.lang.String |
toString() |
void |
unlock()
Unlocks the connection only if the sweeper is enabled
Otherwise this is a noop for performance
|
boolean |
validate(int validateAction)
Returns true if the object is still valid. if not
the pool will call the getExpiredAction() and follow up with one
of the four expired methods
|
boolean |
validate(int validateAction,
java.lang.String sql)
Validates a connection.
|
public static final java.lang.String PROP_USER
public static final java.lang.String PROP_PASSWORD
public static final int VALIDATE_BORROW
public static final int VALIDATE_RETURN
public static final int VALIDATE_IDLE
public static final int VALIDATE_INIT
protected PoolConfiguration poolProperties
protected volatile javax.sql.XAConnection xaConnection
protected ConnectionPool parent
public PooledConnection(PoolConfiguration prop, ConnectionPool parent)
prop
- - pool propertiesparent
- - the parent connection poolpublic long getConnectionVersion()
public boolean checkUser(java.lang.String username, java.lang.String password)
public void connect() throws java.sql.SQLException
java.sql.SQLException
- if the method release()
has been called.java.sql.SQLException
- if driver instantiation failsjava.sql.SQLException
- if a call to Driver.connect(String, java.util.Properties)
fails.java.sql.SQLException
- if default properties are configured and a call to
Connection.setAutoCommit(boolean)
, Connection.setCatalog(String)
,
Connection.setTransactionIsolation(int)
or Connection.setReadOnly(boolean)
fails.protected void connectUsingDataSource() throws java.sql.SQLException
java.sql.SQLException
protected void connectUsingDriver() throws java.sql.SQLException
java.sql.SQLException
public boolean isInitialized()
public void reconnect() throws java.sql.SQLException
disconnect(boolean)
with the argument false followed by a call to
connect()
java.sql.SQLException
- if the call to connect()
fails.public long getAbandonTimeout()
public boolean validate(int validateAction)
public boolean validate(int validateAction, java.lang.String sql)
validateAction
- the action used. One of VALIDATE_BORROW
, VALIDATE_IDLE
,
VALIDATE_INIT
or VALIDATE_RETURN
sql
- the SQL to be used during validation. If the PoolConfiguration.setInitSQL(String)
has been called with a non null
value and the action is VALIDATE_INIT
the init SQL will be used for validation.PoolConfiguration.setValidationInterval(long)
has been called with a positive value.
false if the validation failed. The caller should close the connection if false is returned since a session could have been left in an unknown state during initialization.
public long getReleaseTime()
public boolean release()
released
flag to false. Any attempts to connect this cached object again
will fail per connect()
The connection pool uses the atomic return value to decrement the pool size counter.public void setStackTrace(java.lang.String trace)
trace
- the stack trace for this connectionpublic java.lang.String getStackTrace()
public void setTimestamp(long timestamp)
timestamp
- the timestamp as defined by System.currentTimeMillis()
public boolean isSuspect()
public void setSuspect(boolean suspect)
public void setDiscarded(boolean discarded)
discarded
- - only valid value is truejava.lang.IllegalStateException
- if this method is called with the value false and the value true has already been set.public void setLastValidated(long lastValidated)
validation-interval
.lastValidated
- a timestamp as defined by System.currentTimeMillis()
public void setPoolProperties(PoolConfiguration poolProperties)
ConnectionPool
poolProperties
- public long getTimestamp()
abandon-timeouts
.
This timestamp can also be reset by the ResetAbandonedTimer.invoke(Object, java.lang.reflect.Method, Object[])
System.currentTimeMillis()
public boolean isDiscarded()
disconnect(boolean)
has been called or it will be called when the connection is returned to the pool.public long getLastValidated()
System.currentTimeMillis()
public PoolConfiguration getPoolProperties()
public void lock()
PoolConfiguration.isPoolSweeperEnabled()
or
PoolConfiguration.getUseLock()
return true. The per connection lock ensures thread safety is
multiple threads are performing operations on the connection.
Otherwise this is a noop for performancepublic void unlock()
public java.sql.Connection getConnection()
PooledConnection.getConnection()
public javax.sql.XAConnection getXAConnection()
public long getLastConnected()
Driver.connect(String, java.util.Properties)
.System.currentTimeMillis()
public JdbcInterceptor getHandler()
public void setHandler(JdbcInterceptor handler)
public java.lang.String toString()
toString
in class java.lang.Object
public boolean isReleased()
release()
has been calledpublic java.util.HashMap<java.lang.Object,java.lang.Object> getAttributes()
Copyright © 2000-2015 Apache Software Foundation. All Rights Reserved.