Top Description Fields Constructors Methods
com.mysql.cj.jdbc

public Class MysqlPooledConnection

extends Object
implements PooledConnection
Class Inheritance
All Implemented Interfaces
javax.sql.PooledConnection
Known Direct Subclasses
com.mysql.cj.jdbc.MysqlXAConnection, com.mysql.cj.jdbc.SuspendableXAConnection
Imports
java.sql.Connection, .SQLException, java.util.HashMap, .Iterator, .Map, java.util.concurrent.locks.Lock, .ReentrantLock, javax.sql.ConnectionEvent, .ConnectionEventListener, .PooledConnection, .StatementEvent, .StatementEventListener, com.mysql.cj.Messages, com.mysql.cj.exceptions.ExceptionInterceptor, com.mysql.cj.jdbc.exceptions.SQLError

This class is used to wrap and return a physical connection within a logical handle. It also registers and notifies ConnectionEventListeners of any ConnectionEvents

Field Summary

Modifier and TypeField and Description
public static final int
CONNECTION_CLOSED_EVENT

The flag for a connection being closed.

public static final int
CONNECTION_ERROR_EVENT

The flag for an exception being thrown.

private Map<ConnectionEventListener, ConnectionEventListener>
private ExceptionInterceptor
protected final Lock
private Connection
private JdbcConnection
private final Map<StatementEventListener, StatementEventListener>
private final Lock

Constructor Summary

AccessConstructor and Description
public
MysqlPooledConnection(JdbcConnection
physical connection to db
connection
)

Construct a new MysqlPooledConnection and set instance variables

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.

Registers the given event listener so that it will be notified when an event occurs on this PooledConnection object.

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.

protected void
callConnectionEventListeners(int
value indicating whether connectionClosed or connectionErrorOccurred called
eventType
,
SQLException
the exception being thrown
sqlException
)

Notifies all registered ConnectionEventListeners of ConnectionEvents.

public void
close()

Implements javax.sql.PooledConnection.close.

Invoked by the container (not the client), and should close the physical connection.

pack-priv void
public Connection
getConnection()

Implements javax.sql.PooledConnection.getConnection.

Creates and returns a Connection object that is a handle for the physical connection that this PooledConnection object represents.

protected Connection
getConnection(boolean resetServerState, boolean forXa)

protected ExceptionInterceptor
protected static MysqlPooledConnection
public Lock
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 the given event listener from the list of components that will be notified when an event occurs on this PooledConnection object.

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

CONNECTION_CLOSED_EVENTback to summary
public static final int CONNECTION_CLOSED_EVENT

The flag for a connection being closed.

CONNECTION_ERROR_EVENTback to summary
public static final int CONNECTION_ERROR_EVENT

The flag for an exception being thrown.

connectionEventListenersback to summary
private Map<ConnectionEventListener, ConnectionEventListener> connectionEventListeners
exceptionInterceptorback to summary
private ExceptionInterceptor exceptionInterceptor
lockback to summary
protected final Lock lock
logicalHandleback to summary
private Connection logicalHandle
physicalConnback to summary
private JdbcConnection physicalConn
statementEventListenersback to summary
private final Map<StatementEventListener, StatementEventListener> statementEventListeners
statementEventListenersLockback to summary
private final Lock statementEventListenersLock

Constructor Detail

MysqlPooledConnectionback to summary
public MysqlPooledConnection(JdbcConnection connection)

Construct a new MysqlPooledConnection and set instance variables

Parameters
connection:JdbcConnection

physical connection to db

Method Detail

addConnectionEventListenerback to summary
public void addConnectionEventListener(ConnectionEventListener connectioneventlistener)

Implements javax.sql.PooledConnection.addConnectionEventListener.

Doc from javax.sql.PooledConnection.addConnectionEventListener.

Registers the given event listener so that it will be notified when an event occurs on this PooledConnection object.

Parameters
connectioneventlistener: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

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
callConnectionEventListenersback to summary
protected void callConnectionEventListeners(int eventType, SQLException sqlException)

Notifies all registered ConnectionEventListeners of ConnectionEvents. Instantiates a new ConnectionEvent which wraps sqlException and invokes either connectionClose or connectionErrorOccurred on listener as appropriate.

Parameters
eventType:int

value indicating whether connectionClosed or connectionErrorOccurred called

sqlException:SQLException

the exception being thrown

closeback to summary
public void close() throws SQLException

Implements javax.sql.PooledConnection.close.

Invoked by the container (not the client), and should close the physical connection. This will be called if the pool is destroyed or the connectionEventListener receives a connectionErrorOccurred event.

Annotations
@Override
Exceptions
SQLException:

Doc from javax.sql.PooledConnection.close.

if a database access error occurs

fireStatementEventback to summary
pack-priv void fireStatementEvent(StatementEvent event) throws SQLException
getConnectionback to summary
public Connection getConnection() throws SQLException

Implements javax.sql.PooledConnection.getConnection.

Doc from javax.sql.PooledConnection.getConnection.

Creates and returns a Connection object that is a handle for the physical connection that this PooledConnection object represents. The connection pool manager calls this method when an application has called the method DataSource.getConnection and there are no PooledConnection objects available. See the interface description for more information.

Returns:Connection

a Connection object that is a handle to this PooledConnection object

Annotations
@Override
Exceptions
SQLException:
if a database access error occurs
getConnectionback to summary
protected Connection getConnection(boolean resetServerState, boolean forXa) throws SQLException
getExceptionInterceptorback to summary
protected ExceptionInterceptor getExceptionInterceptor()
getInstanceback to summary
protected static MysqlPooledConnection getInstance(JdbcConnection connection) throws SQLException
getLockback to summary
public Lock getLock()
removeConnectionEventListenerback to summary
public void removeConnectionEventListener(ConnectionEventListener connectioneventlistener)

Implements javax.sql.PooledConnection.removeConnectionEventListener.

Doc from javax.sql.PooledConnection.removeConnectionEventListener.

Removes the given event listener from the list of components that will be notified when an event occurs on this PooledConnection object.

Parameters
connectioneventlistener:ConnectionEventListener

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