Top Description Inners Fields Constructors Methods
org.postgresql.ds

public Class PGPooledConnection

extends Object
implements PooledConnection
Class Inheritance
All Implemented Interfaces
javax.sql.PooledConnection
Known Direct Subclasses
org.postgresql.xa.PGXAConnection
Static Imports
org.postgresql.util.internal.Nullness.castNonNull

PostgreSQL implementation of the PooledConnection interface. This shouldn't be used directly, as the pooling client should just interact with the ConnectionPool instead.
Authors
Aaron Mulder ([email protected]), Csaba Nagy ([email protected])
See Also
org.postgresql.ds.PGConnectionPoolDataSource

Nested and Inner Type Summary

Modifier and TypeClass and Description
private class
PGPooledConnection.ConnectionHandler

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
PGPooledConnection.StatementHandler

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

Modifier and TypeField and Description
private final boolean
private @Nullable Connection
private static final String[]
private final boolean
private @Nullable PGPooledConnection.ConnectionHandler
private final List<ConnectionEventListener>

Constructor Summary

AccessConstructor and Description
public
PGPooledConnection(Connection
connection
con
,
boolean
whether to autocommit
autoCommit
,
boolean
whether connection is a XA connection
isXA
)

Creates a new PooledConnection representing the specified physical connection.

public
PGPooledConnection(Connection con, boolean autoCommit)

Method Summary

Modifier and TypeMethod and Description
public void
addConnectionEventListener(ConnectionEventListener
a component, usually the connection pool manager, that has implemented the ConnectionEventListener interface and wants to be notified when the connection is closed or has an error
connectionEventListener
)

Implements javax.sql.PooledConnection.addConnectionEventListener.

Adds a listener for close or fatal error events on the connection handed out to a client.

public void
addStatementEventListener(StatementEventListener
an component which implements the StatementEventListener interface that is to be registered with this PooledConnection object
listener
)

Implements javax.sql.PooledConnection.addStatementEventListener.

Registers a StatementEventListener with this PooledConnection object.

public void
close()

Implements javax.sql.PooledConnection.close.

Closes the physical database connection represented by this PooledConnection.

protected ConnectionEvent
pack-priv void
fireConnectionClosed()

Used to fire a connection closed event to all listeners.

private void
fireConnectionError(SQLException
the SQLException to consider
e
)

Fires a connection error event, but only if we think the exception is fatal.

pack-priv void
fireConnectionFatalError(SQLException e)

Used to fire a connection error event to all listeners.

public Connection
getConnection()

Implements javax.sql.PooledConnection.getConnection.

Gets a handle for a client to use.

private static boolean
public void
removeConnectionEventListener(ConnectionEventListener
a component, usually the connection pool manager, that has implemented the ConnectionEventListener interface and been registered with this PooledConnection object as a listener
connectionEventListener
)

Implements javax.sql.PooledConnection.removeConnectionEventListener.

Removes a listener for close or fatal error events on the connection handed out to a client.

public void
removeStatementEventListener(StatementEventListener
the component which implements the StatementEventListener interface that was previously registered with this PooledConnection object
listener
)

Implements javax.sql.PooledConnection.removeStatementEventListener.

Removes the specified StatementEventListener from the list of components that will be notified when the driver detects that a PreparedStatement has been closed or is invalid.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

autoCommitback to summary
private final boolean autoCommit
conback to summary
private @Nullable Connection con
fatalClassesback to summary
private static final String[] fatalClasses
isXAback to summary
private final boolean isXA
lastback to summary
private @Nullable PGPooledConnection.ConnectionHandler last
listenersback to summary
private final List<ConnectionEventListener> listeners

Constructor Detail

PGPooledConnectionback to summary
public PGPooledConnection(Connection con, boolean autoCommit, boolean isXA)

Creates a new PooledConnection representing the specified physical connection.

Parameters
con:Connection

connection

autoCommit:boolean

whether to autocommit

isXA:boolean

whether connection is a XA connection

PGPooledConnectionback to summary
public PGPooledConnection(Connection con, boolean autoCommit)

Method Detail

addConnectionEventListenerback to summary
public void addConnectionEventListener(ConnectionEventListener connectionEventListener)

Implements javax.sql.PooledConnection.addConnectionEventListener.

Adds a listener for close or fatal error events on the connection handed out to a client.

Parameters
connectionEventListener:ConnectionEventListener

Doc from javax.sql.PooledConnection.addConnectionEventListener.

a component, usually the connection pool manager, that has implemented the ConnectionEventListener interface and wants to be notified when the connection is closed or has an error

Annotations
@Override
addStatementEventListenerback to summary
public void addStatementEventListener(StatementEventListener listener)

Implements javax.sql.PooledConnection.addStatementEventListener.

Doc from javax.sql.PooledConnection.addStatementEventListener.

Registers a StatementEventListener with this PooledConnection object. Components that wish to be notified when PreparedStatements created by the connection are closed or are detected to be invalid may use this method to register a StatementEventListener with this PooledConnection object.

Parameters
listener:StatementEventListener

an component which implements the StatementEventListener interface that is to be registered with this PooledConnection object

Annotations
@Override
closeback to summary
public void close() throws SQLException

Implements javax.sql.PooledConnection.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.

Annotations
@Override
Exceptions
SQLException:

Doc from javax.sql.PooledConnection.close.

if a database access error occurs

createConnectionEventback to summary
protected ConnectionEvent createConnectionEvent(@Nullable SQLException e)
fireConnectionClosedback to summary
pack-priv void fireConnectionClosed()

Used to fire a connection closed event to all listeners.

fireConnectionErrorback to summary
private void fireConnectionError(SQLException e)

Fires a connection error event, but only if we think the exception is fatal.

Parameters
e:SQLException

the SQLException to consider

fireConnectionFatalErrorback to summary
pack-priv void fireConnectionFatalError(SQLException e)

Used to fire a connection error event to all listeners.

getConnectionback to summary
public Connection getConnection() throws SQLException

Implements javax.sql.PooledConnection.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 physical 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.

Returns:Connection

Doc from javax.sql.PooledConnection.getConnection.

a Connection object that is a handle to this PooledConnection object

Annotations
@Override
Exceptions
SQLException:

Doc from javax.sql.PooledConnection.getConnection.

if a database access error occurs

isFatalStateback to summary
private static boolean isFatalState(@Nullable String state)
removeConnectionEventListenerback to summary
public void removeConnectionEventListener(ConnectionEventListener connectionEventListener)

Implements javax.sql.PooledConnection.removeConnectionEventListener.

Removes a listener for close or fatal error events on the connection handed out to a client.

Parameters
connectionEventListener:ConnectionEventListener

Doc from javax.sql.PooledConnection.removeConnectionEventListener.

a component, usually the connection pool manager, that has implemented the ConnectionEventListener interface and been registered with this PooledConnection object as a listener

Annotations
@Override
removeStatementEventListenerback to summary
public void removeStatementEventListener(StatementEventListener listener)

Implements javax.sql.PooledConnection.removeStatementEventListener.

Doc from javax.sql.PooledConnection.removeStatementEventListener.

Removes the specified StatementEventListener from the list of components that will be notified when the driver detects that a PreparedStatement has been closed or is invalid.

Parameters
listener:StatementEventListener

the component which implements the StatementEventListener interface that was previously registered with this PooledConnection object

Annotations
@Override
org.postgresql.ds back to summary

private Class PGPooledConnection.ConnectionHandler

extends Object
implements InvocationHandler
Class Inheritance
All Implemented Interfaces
java.lang.reflect.InvocationHandler

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. This is the part that requires JDK 1.3 or higher, though JDK 1.2 could be supported with a 3rd-party proxy package.

Field Summary

Modifier and TypeField and Description
private boolean
private @Nullable Connection
private @Nullable Connection

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public void
pack-priv Connection
public @Nullable Object
invoke(Object
the proxy instance that the method was invoked on
proxy
,
Method
the Method instance corresponding to the interface method invoked on the proxy instance. The declaring class of the Method object will be the interface that the method was declared in, which may be a superinterface of the proxy interface that the proxy class inherits the method through.
method
,
@Nullable Object[]
an array of objects containing the values of the arguments passed in the method invocation on the proxy instance, or null if interface method takes no arguments. Arguments of primitive types are wrapped in instances of the appropriate primitive wrapper class, such as java.lang.Integer or java.lang.Boolean.
args
)

Implements java.lang.reflect.InvocationHandler.invoke.

Processes a method invocation on a proxy instance and returns the result.

public boolean
pack-priv void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

automaticback to summary
private boolean automatic
conback to summary
private @Nullable Connection con
proxyback to summary
private @Nullable Connection proxy

Constructor Detail

ConnectionHandlerback to summary
pack-priv ConnectionHandler(Connection con)

Method Detail

closeback to summary
public void close()
getProxyback to summary
pack-priv Connection getProxy()
invokeback to summary
public @Nullable Object invoke(Object proxy, Method method, @Nullable Object[] args) throws Throwable

Implements java.lang.reflect.InvocationHandler.invoke.

Doc from java.lang.reflect.InvocationHandler.invoke.

Processes a method invocation on a proxy instance and returns the result. This method will be invoked on an invocation handler when a method is invoked on a proxy instance that it is associated with.

Parameters
proxy:Object

the proxy instance that the method was invoked on

method:Method

the Method instance corresponding to the interface method invoked on the proxy instance. The declaring class of the Method object will be the interface that the method was declared in, which may be a superinterface of the proxy interface that the proxy class inherits the method through.

args:@Nullable Object[]

an array of objects containing the values of the arguments passed in the method invocation on the proxy instance, or null if interface method takes no arguments. Arguments of primitive types are wrapped in instances of the appropriate primitive wrapper class, such as java.lang.Integer or java.lang.Boolean.

Returns:@Nullable Object

the value to return from the method invocation on the proxy instance. If the declared return type of the interface method is a primitive type, then the value returned by this method must be an instance of the corresponding primitive wrapper class; otherwise, it must be a type assignable to the declared return type. If the value returned by this method is null and the interface method's return type is primitive, then a NullPointerException will be thrown by the method invocation on the proxy instance. If the value returned by this method is otherwise not compatible with the interface method's declared return type as described above, a ClassCastException will be thrown by the method invocation on the proxy instance.

Annotations
@Override
@SuppressWarnings:throwing.nullable
Exceptions
Throwable:
the exception to throw from the method invocation on the proxy instance. The exception's type must be assignable either to any of the exception types declared in the throws clause of the interface method or to the unchecked exception types java.lang.RuntimeException or java.lang.Error. If a checked exception is thrown by this method that is not assignable to any of the exception types declared in the throws clause of the interface method, then an UndeclaredThrowableException containing the exception that was thrown by this method will be thrown by the method invocation on the proxy instance.
isClosedback to summary
public boolean isClosed()
setProxyback to summary
pack-priv void setProxy(Connection proxy)
org.postgresql.ds back to summary

private Class PGPooledConnection.StatementHandler

extends Object
implements InvocationHandler
Class Inheritance
All Implemented Interfaces
java.lang.reflect.InvocationHandler

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. This is the part that requires JDK 1.3 or higher, though JDK 1.2 could be supported with a 3rd-party proxy package.

The StatementHandler is required in order to return the proper Connection proxy for the getConnection method.

Field Summary

Modifier and TypeField and Description
private @Nullable PGPooledConnection.ConnectionHandler
private @Nullable Statement

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public @Nullable Object
invoke(Object
the proxy instance that the method was invoked on
proxy
,
Method
the Method instance corresponding to the interface method invoked on the proxy instance. The declaring class of the Method object will be the interface that the method was declared in, which may be a superinterface of the proxy interface that the proxy class inherits the method through.
method
,
@Nullable Object[]
an array of objects containing the values of the arguments passed in the method invocation on the proxy instance, or null if interface method takes no arguments. Arguments of primitive types are wrapped in instances of the appropriate primitive wrapper class, such as java.lang.Integer or java.lang.Boolean.
args
)

Implements java.lang.reflect.InvocationHandler.invoke.

Processes a method invocation on a proxy instance and returns the result.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

conback to summary
private @Nullable PGPooledConnection.ConnectionHandler con
stback to summary
private @Nullable Statement st

Constructor Detail

StatementHandlerback to summary
pack-priv StatementHandler(PGPooledConnection.ConnectionHandler con, Statement st)

Method Detail

invokeback to summary
public @Nullable Object invoke(Object proxy, Method method, @Nullable Object[] args) throws Throwable

Implements java.lang.reflect.InvocationHandler.invoke.

Doc from java.lang.reflect.InvocationHandler.invoke.

Processes a method invocation on a proxy instance and returns the result. This method will be invoked on an invocation handler when a method is invoked on a proxy instance that it is associated with.

Parameters
proxy:Object

the proxy instance that the method was invoked on

method:Method

the Method instance corresponding to the interface method invoked on the proxy instance. The declaring class of the Method object will be the interface that the method was declared in, which may be a superinterface of the proxy interface that the proxy class inherits the method through.

args:@Nullable Object[]

an array of objects containing the values of the arguments passed in the method invocation on the proxy instance, or null if interface method takes no arguments. Arguments of primitive types are wrapped in instances of the appropriate primitive wrapper class, such as java.lang.Integer or java.lang.Boolean.

Returns:@Nullable Object

the value to return from the method invocation on the proxy instance. If the declared return type of the interface method is a primitive type, then the value returned by this method must be an instance of the corresponding primitive wrapper class; otherwise, it must be a type assignable to the declared return type. If the value returned by this method is null and the interface method's return type is primitive, then a NullPointerException will be thrown by the method invocation on the proxy instance. If the value returned by this method is otherwise not compatible with the interface method's declared return type as described above, a ClassCastException will be thrown by the method invocation on the proxy instance.

Annotations
@Override
@SuppressWarnings:throwing.nullable
Exceptions
Throwable:
the exception to throw from the method invocation on the proxy instance. The exception's type must be assignable either to any of the exception types declared in the throws clause of the interface method or to the unchecked exception types java.lang.RuntimeException or java.lang.Error. If a checked exception is thrown by this method that is not assignable to any of the exception types declared in the throws clause of the interface method, then an UndeclaredThrowableException containing the exception that was thrown by this method will be thrown by the method invocation on the proxy instance.