Package com.mysql.cj.jdbc.ha
Class ReplicationMySQLConnection
java.lang.Object
com.mysql.cj.jdbc.ha.MultiHostMySQLConnection
com.mysql.cj.jdbc.ha.ReplicationMySQLConnection
- All Implemented Interfaces:
ReplicationConnection
,JdbcConnection
,MysqlConnection
,TransactionEventHandler
,java.lang.AutoCloseable
,java.sql.Connection
,java.sql.Wrapper
public class ReplicationMySQLConnection extends MultiHostMySQLConnection implements ReplicationConnection
-
Field Summary
-
Constructor Summary
Constructors Constructor Description ReplicationMySQLConnection(MultiHostConnectionProxy proxy)
-
Method Summary
Modifier and Type Method Description void
abort(java.util.concurrent.Executor executor)
void
abortInternal()
Clobbers the physical network connection and marks this connection as closed.void
addReplicaHost(java.lang.String host)
void
changeUser(java.lang.String userName, java.lang.String newPassword)
Changes the user on this connection by performing a re-authentication.void
clearHasTriedMaster()
Deprecated.JdbcConnection
getActiveMySQLConnection()
long
getConnectionGroupId()
JdbcConnection
getCurrentConnection()
java.util.Properties
getProperties()
Returns the parsed and passed in properties for this connection.JdbcConnection
getReplicaConnection()
JdbcConnection
getSourceConnection()
ReplicationConnectionProxy
getThisAsProxy()
boolean
hasSameProperties(JdbcConnection c)
Does this connection have the same properties as another?boolean
isHostReplica(java.lang.String host)
boolean
isHostSource(java.lang.String host)
boolean
isReadOnly()
boolean
isWrapperFor(java.lang.Class<?> iface)
void
ping()
Detect if the connection is still good by sending a ping command to the server.void
promoteReplicaToSource(java.lang.String host)
void
removeReplica(java.lang.String host)
void
removeReplica(java.lang.String host, boolean closeGently)
void
removeSourceHost(java.lang.String host)
void
removeSourceHost(java.lang.String host, boolean waitUntilNotInUse)
void
setProxy(JdbcConnection proxy)
void
setReadOnly(boolean readOnlyFlag)
void
setStatementComment(java.lang.String comment)
Sets the comment that will be prepended to all statements sent to the server.<T> T
unwrap(java.lang.Class<T> iface)
Methods inherited from class com.mysql.cj.jdbc.ha.MultiHostMySQLConnection
checkClosed, cleanup, clearWarnings, clientPrepareStatement, clientPrepareStatement, clientPrepareStatement, clientPrepareStatement, clientPrepareStatement, clientPrepareStatement, close, commit, createArrayOf, createBlob, createClob, createNClob, createNewIO, createSQLXML, createStatement, createStatement, createStatement, createStruct, decachePreparedStatement, getActiveStatementCount, getAutoCommit, getAutoIncrementIncrement, getCachedMetaData, getCatalog, getCharacterSetMetadata, getClientInfo, getClientInfo, getClientInfoProviderImpl, getConnectionMutex, getDatabase, getExceptionInterceptor, getHoldability, getHost, getHostPortPair, getId, getIdleFor, getMetaData, getMetadataSafeStatement, getMultiHostParentProxy, getMultiHostSafeProxy, getNetworkTimeout, getPropertySet, getQueryInterceptorsInstances, getSchema, getServerVersion, getSession, getSessionMaxRows, getStatementComment, getTransactionIsolation, getTypeMap, getURL, getUser, getWarnings, hasTriedMaster, initializeResultsMetadataFromCache, initializeSafeQueryInterceptors, isClosed, isInGlobalTx, isProxySet, isReadOnly, isSameResource, isServerLocal, isSourceConnection, isValid, lowerCaseTableNames, nativeSQL, normalClose, pingInternal, prepareCall, prepareCall, prepareCall, prepareStatement, prepareStatement, prepareStatement, prepareStatement, prepareStatement, prepareStatement, realClose, recachePreparedStatement, registerStatement, releaseSavepoint, resetServerState, rollback, rollback, serverPrepareStatement, serverPrepareStatement, serverPrepareStatement, serverPrepareStatement, serverPrepareStatement, serverPrepareStatement, setAutoCommit, setCatalog, setClientInfo, setClientInfo, setDatabase, setFailedOver, setHoldability, setInGlobalTx, setNetworkTimeout, setReadOnlyInternal, setSavepoint, setSavepoint, setSchema, setSessionMaxRows, setTransactionIsolation, setTypeMap, shutdownServer, storesLowerCaseTableName, throwConnectionClosedException, transactionBegun, transactionCompleted, unregisterStatement, unSafeQueryInterceptors
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface java.sql.Connection
beginRequest, clearWarnings, close, commit, createArrayOf, createBlob, createClob, createNClob, createSQLXML, createStatement, createStatement, createStatement, createStruct, endRequest, getAutoCommit, getCatalog, getClientInfo, getClientInfo, getHoldability, getMetaData, getNetworkTimeout, getSchema, getTransactionIsolation, getTypeMap, getWarnings, isClosed, isValid, nativeSQL, prepareCall, prepareCall, prepareCall, prepareStatement, prepareStatement, prepareStatement, prepareStatement, prepareStatement, prepareStatement, releaseSavepoint, rollback, rollback, setAutoCommit, setCatalog, setClientInfo, setClientInfo, setHoldability, setNetworkTimeout, setSavepoint, setSavepoint, setSchema, setShardingKey, setShardingKey, setShardingKeyIfValid, setShardingKeyIfValid, setTransactionIsolation, setTypeMap
Methods inherited from interface com.mysql.cj.jdbc.JdbcConnection
clientPrepareStatement, clientPrepareStatement, clientPrepareStatement, clientPrepareStatement, clientPrepareStatement, clientPrepareStatement, decachePreparedStatement, getActiveStatementCount, getAutoIncrementIncrement, getCachedMetaData, getCharacterSetMetadata, getClientInfoProviderImpl, getDatabase, getHost, getHostPortPair, getIdleFor, getMetadataSafeStatement, getMultiHostParentProxy, getMultiHostSafeProxy, getPropertySet, getQueryInterceptorsInstances, getServerVersion, getSessionMaxRows, getStatementComment, hasTriedMaster, initializeResultsMetadataFromCache, initializeSafeQueryInterceptors, isInGlobalTx, isMasterConnection, isProxySet, isReadOnly, isSameResource, isServerLocal, isSourceConnection, lowerCaseTableNames, pingInternal, realClose, recachePreparedStatement, registerStatement, resetServerState, serverPrepareStatement, serverPrepareStatement, serverPrepareStatement, serverPrepareStatement, serverPrepareStatement, serverPrepareStatement, setDatabase, setFailedOver, setInGlobalTx, setReadOnlyInternal, setSessionMaxRows, shutdownServer, storesLowerCaseTableName, throwConnectionClosedException, unregisterStatement, unSafeQueryInterceptors
Methods inherited from interface com.mysql.cj.MysqlConnection
checkClosed, cleanup, createNewIO, getConnectionMutex, getExceptionInterceptor, getId, getSession, getURL, getUser, normalClose
Methods inherited from interface com.mysql.cj.jdbc.ha.ReplicationConnection
addSlaveHost, getMasterConnection, getSlavesConnection, isHostMaster, isHostSlave, promoteSlaveToMaster, removeMasterHost, removeMasterHost, removeSlave, removeSlave
Methods inherited from interface com.mysql.cj.TransactionEventHandler
transactionBegun, transactionCompleted
-
Constructor Details
-
Method Details
-
getThisAsProxy
- Overrides:
getThisAsProxy
in classMultiHostMySQLConnection
-
getActiveMySQLConnection
- Specified by:
getActiveMySQLConnection
in interfaceJdbcConnection
- Overrides:
getActiveMySQLConnection
in classMultiHostMySQLConnection
-
getCurrentConnection
- Specified by:
getCurrentConnection
in interfaceReplicationConnection
-
getConnectionGroupId
public long getConnectionGroupId()- Specified by:
getConnectionGroupId
in interfaceReplicationConnection
-
getSourceConnection
- Specified by:
getSourceConnection
in interfaceReplicationConnection
-
promoteReplicaToSource
public void promoteReplicaToSource(java.lang.String host) throws java.sql.SQLException- Specified by:
promoteReplicaToSource
in interfaceReplicationConnection
- Throws:
java.sql.SQLException
-
removeSourceHost
public void removeSourceHost(java.lang.String host) throws java.sql.SQLException- Specified by:
removeSourceHost
in interfaceReplicationConnection
- Throws:
java.sql.SQLException
-
removeSourceHost
public void removeSourceHost(java.lang.String host, boolean waitUntilNotInUse) throws java.sql.SQLException- Specified by:
removeSourceHost
in interfaceReplicationConnection
- Throws:
java.sql.SQLException
-
isHostSource
public boolean isHostSource(java.lang.String host)- Specified by:
isHostSource
in interfaceReplicationConnection
-
getReplicaConnection
- Specified by:
getReplicaConnection
in interfaceReplicationConnection
-
addReplicaHost
public void addReplicaHost(java.lang.String host) throws java.sql.SQLException- Specified by:
addReplicaHost
in interfaceReplicationConnection
- Throws:
java.sql.SQLException
-
removeReplica
public void removeReplica(java.lang.String host) throws java.sql.SQLException- Specified by:
removeReplica
in interfaceReplicationConnection
- Throws:
java.sql.SQLException
-
removeReplica
public void removeReplica(java.lang.String host, boolean closeGently) throws java.sql.SQLException- Specified by:
removeReplica
in interfaceReplicationConnection
- Throws:
java.sql.SQLException
-
isHostReplica
public boolean isHostReplica(java.lang.String host)- Specified by:
isHostReplica
in interfaceReplicationConnection
-
setReadOnly
public void setReadOnly(boolean readOnlyFlag) throws java.sql.SQLException- Specified by:
setReadOnly
in interfacejava.sql.Connection
- Overrides:
setReadOnly
in classMultiHostMySQLConnection
- Throws:
java.sql.SQLException
-
isReadOnly
public boolean isReadOnly() throws java.sql.SQLException- Specified by:
isReadOnly
in interfacejava.sql.Connection
- Overrides:
isReadOnly
in classMultiHostMySQLConnection
- Throws:
java.sql.SQLException
-
ping
public void ping() throws java.sql.SQLExceptionDescription copied from interface:JdbcConnection
Detect if the connection is still good by sending a ping command to the server.- Specified by:
ping
in interfaceJdbcConnection
- Overrides:
ping
in classMultiHostMySQLConnection
- Throws:
java.sql.SQLException
- if the ping fails
-
changeUser
public void changeUser(java.lang.String userName, java.lang.String newPassword) throws java.sql.SQLExceptionDescription copied from interface:JdbcConnection
Changes the user on this connection by performing a re-authentication. If authentication fails, the connection is failed.- Specified by:
changeUser
in interfaceJdbcConnection
- Overrides:
changeUser
in classMultiHostMySQLConnection
- Parameters:
userName
- the username to authenticate withnewPassword
- the password to authenticate with- Throws:
java.sql.SQLException
- if authentication fails, or some other error occurs while performing the command.
-
setStatementComment
public void setStatementComment(java.lang.String comment)Description copied from interface:JdbcConnection
Sets the comment that will be prepended to all statements sent to the server. Do not use slash-star or star-slash tokens in the comment as these will be added by the driver itself.- Specified by:
setStatementComment
in interfaceJdbcConnection
- Overrides:
setStatementComment
in classMultiHostMySQLConnection
- Parameters:
comment
- the comment that will be prepended to all statements sent to the server.
-
hasSameProperties
Description copied from interface:JdbcConnection
Does this connection have the same properties as another?- Specified by:
hasSameProperties
in interfaceJdbcConnection
- Overrides:
hasSameProperties
in classMultiHostMySQLConnection
- Parameters:
c
- connection- Returns:
- true if has the same properties
-
getProperties
public java.util.Properties getProperties()Description copied from interface:MysqlConnection
Returns the parsed and passed in properties for this connection.- Specified by:
getProperties
in interfaceMysqlConnection
- Overrides:
getProperties
in classMultiHostMySQLConnection
- Returns:
Properties
-
abort
public void abort(java.util.concurrent.Executor executor) throws java.sql.SQLException- Specified by:
abort
in interfacejava.sql.Connection
- Overrides:
abort
in classMultiHostMySQLConnection
- Throws:
java.sql.SQLException
-
abortInternal
public void abortInternal() throws java.sql.SQLExceptionDescription copied from interface:JdbcConnection
Clobbers the physical network connection and marks this connection as closed.- Specified by:
abortInternal
in interfaceJdbcConnection
- Overrides:
abortInternal
in classMultiHostMySQLConnection
- Throws:
java.sql.SQLException
- if an error occurs
-
setProxy
- Specified by:
setProxy
in interfaceJdbcConnection
- Overrides:
setProxy
in classMultiHostMySQLConnection
-
isWrapperFor
public boolean isWrapperFor(java.lang.Class<?> iface) throws java.sql.SQLException- Specified by:
isWrapperFor
in interfacejava.sql.Wrapper
- Overrides:
isWrapperFor
in classMultiHostMySQLConnection
- Throws:
java.sql.SQLException
-
unwrap
public <T> T unwrap(java.lang.Class<T> iface) throws java.sql.SQLException- Specified by:
unwrap
in interfacejava.sql.Wrapper
- Overrides:
unwrap
in classMultiHostMySQLConnection
- Throws:
java.sql.SQLException
-
clearHasTriedMaster
@Deprecated public void clearHasTriedMaster()Deprecated.- Specified by:
clearHasTriedMaster
in interfaceJdbcConnection
- Overrides:
clearHasTriedMaster
in classMultiHostMySQLConnection
-