java.lang.Object
edu.iu.jdbc.pool.IuPooledConnection
- All Implemented Interfaces:
EventListener,ConnectionEventListener,PooledConnection,StatementEventListener
public class IuPooledConnection
extends Object
implements PooledConnection, ConnectionEventListener, StatementEventListener
Generic
PooledConnection implementation.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescription(package private) static classHash key forPreparedStatementinitialization args. -
Constructor Summary
ConstructorsConstructorDescriptionIuPooledConnection(Instant initTime, PooledConnection physicalConnection, UnsafeFunction<Connection, Connection> connectionInitializer, Duration abandonedConnectionTimeout, Consumer<IuPooledConnection> onClose) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionvoidvoidvoidclose()voidconnectionClosed(ConnectionEvent event) void(package private) Throwableerror()Gets the error that invalidated this connection, if invalid due to an error.Gets the averageDurationof the transaction segments completed via this physical connection.Gets theInstantthe connection factory initiated this physical connection.Gets theInstantthe connection factory opened this physical connection.Gets the endInstantof the last transaction segment completed on this physical connection.Gets the startInstantof the last transaction segment completed on this physical connection.Gets theInstantthe logical connection associated with this physical connection was opened.Gets the averageDurationof the transaction segments completed via this physical connection.longGets the number of times this connection has been used.booleanisClosed()Determines whether or not the physical connection is closed.voidvoidvoidstatementClosed(StatementEvent event) voidtoString()(package private) voidPre-emptively establishes and validates the logical connection.
-
Constructor Details
-
IuPooledConnection
public IuPooledConnection(Instant initTime, PooledConnection physicalConnection, UnsafeFunction<Connection, Connection> connectionInitializer, Duration abandonedConnectionTimeout, Consumer<IuPooledConnection> onClose) Constructor.- Parameters:
initTime-Instantthe physical connection was initiatedphysicalConnection-PooledConnectiondownstream physical connectionconnectionInitializer- FromIuCommonDataSource.setConnectionInitializer(UnsafeFunction)abandonedConnectionTimeout-DurationaftergetConnection()is invoked when the connection will be considered abandoned and removed from the poolonClose- receives a handle to this pooled connection decorator whenclose()is invoked
-
-
Method Details
-
getConnection
- Specified by:
getConnectionin interfacePooledConnection- Throws:
SQLException
-
addConnectionEventListener
- Specified by:
addConnectionEventListenerin interfacePooledConnection
-
connectionClosed
- Specified by:
connectionClosedin interfaceConnectionEventListener
-
connectionErrorOccurred
- Specified by:
connectionErrorOccurredin interfaceConnectionEventListener
-
removeConnectionEventListener
- Specified by:
removeConnectionEventListenerin interfacePooledConnection
-
addStatementEventListener
- Specified by:
addStatementEventListenerin interfacePooledConnection
-
statementClosed
- Specified by:
statementClosedin interfaceStatementEventListener
-
statementErrorOccurred
- Specified by:
statementErrorOccurredin interfaceStatementEventListener
-
removeStatementEventListener
- Specified by:
removeStatementEventListenerin interfacePooledConnection
-
close
- Specified by:
closein interfacePooledConnection- Throws:
SQLException
-
toString
-
getConnectionInitiated
Gets theInstantthe connection factory initiated this physical connection.- Returns:
Instant
-
getConnectionOpened
Gets theInstantthe connection factory opened this physical connection.- Returns:
Instant
-
getLogicalConnectionOpened
Gets theInstantthe logical connection associated with this physical connection was opened.- Returns:
Instant
-
getLastTransactionSegmentStarted
Gets the startInstantof the last transaction segment completed on this physical connection.- Returns:
Instant
-
getLastTransactionSegmentEnded
Gets the endInstantof the last transaction segment completed on this physical connection.- Returns:
Instant
-
getAverageTransactionSegmentDuration
Gets the averageDurationof the transaction segments completed via this physical connection.- Returns:
Duration
-
getMaxTransactionSegmentDuration
Gets the averageDurationof the transaction segments completed via this physical connection.- Returns:
Duration
-
getTransactionSegmentCount
public long getTransactionSegmentCount()Gets the number of times this connection has been used.- Returns:
-
invalid reference
long
-
isClosed
public boolean isClosed()Determines whether or not the physical connection is closed.- Returns:
- true if the physical connection is closed; else false
-
error
Throwable error()Gets the error that invalidated this connection, if invalid due to an error.- Returns:
SQLException; null if the connection has not experienced a error
-
validate
Pre-emptively establishes and validates the logical connection.- Parameters:
validationQuery- SQL to execute on the connection, should produce at least one row with a non-null value in the first column- Throws:
SQLException- if the logical connection cannot be established or the validation query fails
-