Package com.mysql.cj.jdbc
Class MysqlPooledConnection
java.lang.Object
com.mysql.cj.jdbc.MysqlPooledConnection
- All Implemented Interfaces:
javax.sql.PooledConnection
- Direct Known Subclasses:
MysqlXAConnection,SuspendableXAConnection
public class MysqlPooledConnection
extends java.lang.Object
implements javax.sql.PooledConnection
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
Fields Modifier and Type Field Description static intCONNECTION_CLOSED_EVENTThe flag for a connection being closed.static intCONNECTION_ERROR_EVENTThe flag for an exception being thrown. -
Constructor Summary
Constructors Constructor Description MysqlPooledConnection(JdbcConnection connection)Construct a new MysqlPooledConnection and set instance variables -
Method Summary
Modifier and Type Method Description voidaddConnectionEventListener(javax.sql.ConnectionEventListener connectioneventlistener)voidaddStatementEventListener(javax.sql.StatementEventListener listener)protected voidcallConnectionEventListeners(int eventType, java.sql.SQLException sqlException)Notifies all registered ConnectionEventListeners of ConnectionEvents.voidclose()Invoked by the container (not the client), and should close the physical connection.java.sql.ConnectiongetConnection()protected java.sql.ConnectiongetConnection(boolean resetServerState, boolean forXa)protected ExceptionInterceptorgetExceptionInterceptor()protected static MysqlPooledConnectiongetInstance(JdbcConnection connection)voidremoveConnectionEventListener(javax.sql.ConnectionEventListener connectioneventlistener)voidremoveStatementEventListener(javax.sql.StatementEventListener listener)
-
Field Details
-
CONNECTION_ERROR_EVENT
public static final int CONNECTION_ERROR_EVENTThe flag for an exception being thrown.- See Also:
- Constant Field Values
-
CONNECTION_CLOSED_EVENT
public static final int CONNECTION_CLOSED_EVENTThe flag for a connection being closed.- See Also:
- Constant Field Values
-
-
Constructor Details
-
MysqlPooledConnection
Construct a new MysqlPooledConnection and set instance variables- Parameters:
connection- physical connection to db
-
-
Method Details
-
getInstance
protected static MysqlPooledConnection getInstance(JdbcConnection connection) throws java.sql.SQLException- Throws:
java.sql.SQLException
-
addConnectionEventListener
public void addConnectionEventListener(javax.sql.ConnectionEventListener connectioneventlistener)- Specified by:
addConnectionEventListenerin interfacejavax.sql.PooledConnection
-
removeConnectionEventListener
public void removeConnectionEventListener(javax.sql.ConnectionEventListener connectioneventlistener)- Specified by:
removeConnectionEventListenerin interfacejavax.sql.PooledConnection
-
getConnection
public java.sql.Connection getConnection() throws java.sql.SQLException- Specified by:
getConnectionin interfacejavax.sql.PooledConnection- Throws:
java.sql.SQLException
-
getConnection
protected java.sql.Connection getConnection(boolean resetServerState, boolean forXa) throws java.sql.SQLException- Throws:
java.sql.SQLException
-
close
public void close() throws java.sql.SQLExceptionInvoked 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.- Specified by:
closein interfacejavax.sql.PooledConnection- Throws:
java.sql.SQLException
-
callConnectionEventListeners
protected void callConnectionEventListeners(int eventType, java.sql.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- value indicating whether connectionClosed or connectionErrorOccurred calledsqlException- the exception being thrown
-
getExceptionInterceptor
-
addStatementEventListener
public void addStatementEventListener(javax.sql.StatementEventListener listener)- Specified by:
addStatementEventListenerin interfacejavax.sql.PooledConnection
-
removeStatementEventListener
public void removeStatementEventListener(javax.sql.StatementEventListener listener)- Specified by:
removeStatementEventListenerin interfacejavax.sql.PooledConnection
-