Package org.postgresql.ds
Class PGPooledConnection
java.lang.Object
org.postgresql.ds.PGPooledConnection
- All Implemented Interfaces:
PooledConnection
- Direct Known Subclasses:
PGXAConnection
PostgreSQL implementation of the PooledConnection interface. This shouldn't be used directly, as
the pooling client should just interact with the ConnectionPool instead.
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate class
Instead of declaring a class implementing Connection, which would have to be updated for every JDK rev, use a dynamic proxy to handle all calls through the Connection interface.private class
Instead of declaring classes implementing Statement, PreparedStatement, and CallableStatement, which would have to be updated for every JDK rev, use a dynamic proxy to handle all calls through the Statement interfaces. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final boolean
private Connection
private static final String[]
private final boolean
private final List<ConnectionEventListener>
-
Constructor Summary
ConstructorsConstructorDescriptionPGPooledConnection
(Connection con, boolean autoCommit) PGPooledConnection
(Connection con, boolean autoCommit, boolean isXA) Creates a new PooledConnection representing the specified physical connection. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addConnectionEventListener
(ConnectionEventListener connectionEventListener) Adds a listener for close or fatal error events on the connection handed out to a client.void
void
close()
Closes the physical database connection represented by this PooledConnection.protected ConnectionEvent
(package private) void
Used to fire a connection closed event to all listeners.private void
Fires a connection error event, but only if we think the exception is fatal.(package private) void
Used to fire a connection error event to all listeners.Gets a handle for a client to use.private static boolean
isFatalState
(String state) void
removeConnectionEventListener
(ConnectionEventListener connectionEventListener) Removes a listener for close or fatal error events on the connection handed out to a client.void
-
Field Details
-
listeners
-
con
-
last
-
autoCommit
private final boolean autoCommit -
isXA
private final boolean isXA -
fatalClasses
-
-
Constructor Details
-
PGPooledConnection
Creates a new PooledConnection representing the specified physical connection.- Parameters:
con
- connectionautoCommit
- whether to autocommitisXA
- whether connection is a XA connection
-
PGPooledConnection
-
-
Method Details
-
addConnectionEventListener
Adds a listener for close or fatal error events on the connection handed out to a client.- Specified by:
addConnectionEventListener
in interfacePooledConnection
-
removeConnectionEventListener
Removes a listener for close or fatal error events on the connection handed out to a client.- Specified by:
removeConnectionEventListener
in interfacePooledConnection
-
close
Closes the physical database connection represented by this PooledConnection. If any client has a connection based on this PooledConnection, it is forcibly closed as well.- Specified by:
close
in interfacePooledConnection
- Throws:
SQLException
-
getConnection
Gets a handle for a client to use. This is a wrapper around the physical connection, so the client can call close and it will just return the connection to the pool without really closing the pgysical connection.According to the JDBC 2.0 Optional Package spec (6.2.3), only one client may have an active handle to the connection at a time, so if there is a previous handle active when this is called, the previous one is forcibly closed and its work rolled back.
- Specified by:
getConnection
in interfacePooledConnection
- Throws:
SQLException
-
fireConnectionClosed
void fireConnectionClosed()Used to fire a connection closed event to all listeners. -
fireConnectionFatalError
Used to fire a connection error event to all listeners. -
createConnectionEvent
-
isFatalState
-
fireConnectionError
Fires a connection error event, but only if we think the exception is fatal.- Parameters:
e
- the SQLException to consider
-
removeStatementEventListener
- Specified by:
removeStatementEventListener
in interfacePooledConnection
-
addStatementEventListener
- Specified by:
addStatementEventListener
in interfacePooledConnection
-