Package com.mysql.cj.jdbc.ha.ca
Class ClusterAwareConnectionLifecycleInterceptor
java.lang.Object
com.mysql.cj.jdbc.ha.ca.ClusterAwareConnectionLifecycleInterceptor
- All Implemented Interfaces:
ConnectionLifecycleInterceptor
public class ClusterAwareConnectionLifecycleInterceptor extends java.lang.Object implements ConnectionLifecycleInterceptor
This basic implementation of ConnectionLifecycleInterceptor allows the
ClusterAwareConnectionProxy class to be aware of certain events occurring against the database
connection. The main goal is to track the transaction state of the connection.
-
Constructor Summary
Constructors Constructor Description ClusterAwareConnectionLifecycleInterceptor(ClusterAwareConnectionProxy proxy)Creates a new instance of ClusterAwareConnectionLifecycleInterceptor and initialize it with an instance of connection proxy. -
Method Summary
Modifier and Type Method Description voidclose()Called when an application calls Connection.close(), before the driver processes its own internal logic for close.booleancommit()Called when an application calls Connection.commit(), before the driver processes its own internal logic for commit().voiddestroy()Called by the driver when this extension should release any resources it is holding and cleanup internally before the connection is closed.ConnectionLifecycleInterceptorinit(MysqlConnection conn, java.util.Properties props, Log log)Called once per connection that wants to use the extension The properties are the same ones passed in in the URL or arguments to Driver.connect() or DriverManager.getConnection().booleanrollback()Called when an application calls Connection.rollback(), before the driver processes its own internal logic for rollback().booleanrollback(java.sql.Savepoint s)Called when an application calls Connection.rollback(), before the driver processes its own internal logic for rollback().booleansetAutoCommit(boolean flag)Called when an application calls Connection.setAutoCommit(), before the driver processes its own internal logic for setAutoCommit().booleansetDatabase(java.lang.String db)Called when an application calls Connection.setCatalog() or Connection.setSchema(), before the driver processes its own internal logic for these methods.booleantransactionBegun()Called when the driver has been told by the server that a transaction is now in progress (when one has not been currently in progress).booleantransactionCompleted()Called when the driver has been told by the server that a transaction has completed, and no transaction is currently in progress.
-
Constructor Details
-
ClusterAwareConnectionLifecycleInterceptor
Creates a new instance of ClusterAwareConnectionLifecycleInterceptor and initialize it with an instance of connection proxy. This interceptor may change internal state of a connection proxy.- Parameters:
proxy- A connection proxy representing a logical connection. This proxy's internal state may be changed by this class.
-
-
Method Details
-
init
public ConnectionLifecycleInterceptor init(MysqlConnection conn, java.util.Properties props, Log log)Description copied from interface:ConnectionLifecycleInterceptorCalled once per connection that wants to use the extension The properties are the same ones passed in in the URL or arguments to Driver.connect() or DriverManager.getConnection().- Specified by:
initin interfaceConnectionLifecycleInterceptor- Parameters:
conn- the connection for which this extension is being createdprops- configuration values as passed to the connection. Note that in order to support javax.sql.DataSources, configuration properties specific to an interceptor must be passed via setURL() on the DataSource. Extension properties are not exposed via accessor/mutator methods on DataSources.log- logger instance- Returns:
- interceptor
-
destroy
public void destroy()Description copied from interface:ConnectionLifecycleInterceptorCalled by the driver when this extension should release any resources it is holding and cleanup internally before the connection is closed.- Specified by:
destroyin interfaceConnectionLifecycleInterceptor
-
close
public void close() throws java.sql.SQLExceptionDescription copied from interface:ConnectionLifecycleInterceptorCalled when an application calls Connection.close(), before the driver processes its own internal logic for close.- Specified by:
closein interfaceConnectionLifecycleInterceptor- Throws:
java.sql.SQLException- if an error occurs
-
commit
public boolean commit()Description copied from interface:ConnectionLifecycleInterceptorCalled when an application calls Connection.commit(), before the driver processes its own internal logic for commit(). Interceptors should return "true" if the driver should perform its own internal logic for commit(), or "false" if not.- Specified by:
commitin interfaceConnectionLifecycleInterceptor- Returns:
- "true" if the driver should perform its own internal logic for commit(), or "false" if not.
-
rollback
public boolean rollback()Description copied from interface:ConnectionLifecycleInterceptorCalled when an application calls Connection.rollback(), before the driver processes its own internal logic for rollback(). Interceptors should return "true" if the driver should perform its own internal logic for rollback(), or "false" if not.- Specified by:
rollbackin interfaceConnectionLifecycleInterceptor- Returns:
- "true" if the driver should perform its own internal logic for rollback(), or "false" if not.
-
rollback
public boolean rollback(java.sql.Savepoint s)Description copied from interface:ConnectionLifecycleInterceptorCalled when an application calls Connection.rollback(), before the driver processes its own internal logic for rollback(). Interceptors should return "true" if the driver should perform its own internal logic for rollback(), or "false" if not.- Specified by:
rollbackin interfaceConnectionLifecycleInterceptor- Parameters:
s- savepoint- Returns:
- "true" if the driver should perform its own internal logic for rollback(), or "false" if not.
-
setAutoCommit
public boolean setAutoCommit(boolean flag)Description copied from interface:ConnectionLifecycleInterceptorCalled when an application calls Connection.setAutoCommit(), before the driver processes its own internal logic for setAutoCommit(). Interceptors should return "true" if the driver should perform its own internal logic for setAutoCommit(), or "false" if not.- Specified by:
setAutoCommitin interfaceConnectionLifecycleInterceptor- Parameters:
flag- autocommit flag- Returns:
- "true" if the driver should perform its own internal logic for setAutoCommit(), or "false" if not.
-
setDatabase
public boolean setDatabase(java.lang.String db)Description copied from interface:ConnectionLifecycleInterceptorCalled when an application calls Connection.setCatalog() or Connection.setSchema(), before the driver processes its own internal logic for these methods. Interceptors should return "true" if the driver should perform its own internal logic for setCatalog() or setSchema(), or "false" if not.- Specified by:
setDatabasein interfaceConnectionLifecycleInterceptor- Parameters:
db- database name- Returns:
- "true" if the driver should perform its own internal logic for setCatalog() or setSchema(), or "false" if not.
-
transactionBegun
public boolean transactionBegun()Called when the driver has been told by the server that a transaction is now in progress (when one has not been currently in progress).- Specified by:
transactionBegunin interfaceConnectionLifecycleInterceptor- Returns:
- true if transaction is in progress.
-
transactionCompleted
public boolean transactionCompleted()Called when the driver has been told by the server that a transaction has completed, and no transaction is currently in progress.- Specified by:
transactionCompletedin interfaceConnectionLifecycleInterceptor- Returns:
- true if transaction is completed.
-