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 class
Hash key forPreparedStatement
initialization args. -
Constructor Summary
ConstructorsConstructorDescriptionIuPooledConnection
(Instant initTime, PooledConnection physicalConnection, UnsafeFunction<Connection, Connection> connectionInitializer, Duration abandonedConnectionTimeout, Consumer<IuPooledConnection> onClose) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionvoid
void
void
close()
void
connectionClosed
(ConnectionEvent event) void
(package private) Throwable
error()
Gets the error that invalidated this connection, if invalid due to an error.Gets the averageDuration
of the transaction segments completed via this physical connection.Gets theInstant
the connection factory initiated this physical connection.Gets theInstant
the connection factory opened this physical connection.Gets the endInstant
of the last transaction segment completed on this physical connection.Gets the startInstant
of the last transaction segment completed on this physical connection.Gets theInstant
the logical connection associated with this physical connection was opened.Gets the averageDuration
of the transaction segments completed via this physical connection.long
Gets the number of times this connection has been used.boolean
isClosed()
Determines whether or not the physical connection is closed.void
void
void
statementClosed
(StatementEvent event) void
toString()
(package private) void
Pre-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
-Instant
the physical connection was initiatedphysicalConnection
-PooledConnection
downstream physical connectionconnectionInitializer
- FromIuCommonDataSource.setConnectionInitializer(UnsafeFunction)
abandonedConnectionTimeout
-Duration
aftergetConnection()
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:
getConnection
in interfacePooledConnection
- Throws:
SQLException
-
addConnectionEventListener
- Specified by:
addConnectionEventListener
in interfacePooledConnection
-
connectionClosed
- Specified by:
connectionClosed
in interfaceConnectionEventListener
-
connectionErrorOccurred
- Specified by:
connectionErrorOccurred
in interfaceConnectionEventListener
-
removeConnectionEventListener
- Specified by:
removeConnectionEventListener
in interfacePooledConnection
-
addStatementEventListener
- Specified by:
addStatementEventListener
in interfacePooledConnection
-
statementClosed
- Specified by:
statementClosed
in interfaceStatementEventListener
-
statementErrorOccurred
- Specified by:
statementErrorOccurred
in interfaceStatementEventListener
-
removeStatementEventListener
- Specified by:
removeStatementEventListener
in interfacePooledConnection
-
close
- Specified by:
close
in interfacePooledConnection
- Throws:
SQLException
-
toString
-
getConnectionInitiated
Gets theInstant
the connection factory initiated this physical connection.- Returns:
Instant
-
getConnectionOpened
Gets theInstant
the connection factory opened this physical connection.- Returns:
Instant
-
getLogicalConnectionOpened
Gets theInstant
the logical connection associated with this physical connection was opened.- Returns:
Instant
-
getLastTransactionSegmentStarted
Gets the startInstant
of the last transaction segment completed on this physical connection.- Returns:
Instant
-
getLastTransactionSegmentEnded
Gets the endInstant
of the last transaction segment completed on this physical connection.- Returns:
Instant
-
getAverageTransactionSegmentDuration
Gets the averageDuration
of the transaction segments completed via this physical connection.- Returns:
Duration
-
getMaxTransactionSegmentDuration
Gets the averageDuration
of 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
-