Class MySqlJdbcContext
- java.lang.Object
-
- io.debezium.connector.mysql.legacy.MySqlJdbcContext
-
- All Implemented Interfaces:
AutoCloseable
public class MySqlJdbcContext extends Object implements AutoCloseable
A context for a JDBC connection to MySQL.- Author:
- Randall Hauch
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
MySqlJdbcContext.DatabaseLocales
-
Field Summary
Fields Modifier and Type Field Description protected Configuration
config
protected static JdbcConnection.ConnectionFactory
FACTORY
protected JdbcConnection
jdbc
protected static String
JDBC_PROPERTY_LEGACY_DATETIME
protected static org.slf4j.Logger
logger
protected static String
MYSQL_CONNECTION_URL
private Map<String,String>
originalSystemProperties
private static String
SQL_SHOW_SESSION_VARIABLE_SSL_VERSION
private static String
SQL_SHOW_SYSTEM_VARIABLES
private static String
SQL_SHOW_SYSTEM_VARIABLES_CHARACTER_SET
-
Constructor Summary
Constructors Constructor Description MySqlJdbcContext(MySqlConnectorConfig config)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
Configuration
config()
String
connectionString()
CommonConnectorConfig.EventProcessingFailureHandlingMode
eventProcessingFailureHandlingMode()
String
getSessionVariableForSslVersion()
Read the Ssl Version session variable.String
hostname()
CommonConnectorConfig.EventProcessingFailureHandlingMode
inconsistentSchemaHandlingMode()
boolean
isGtidModeEnabled()
Determine whether the MySQL server has GTIDs enabled.JdbcConnection
jdbc()
String
knownGtidSet()
Determine the executed GTID set for MySQL.org.slf4j.Logger
logger()
String
password()
int
port()
GtidSet
purgedGtidSet()
Get the purged GTID values from MySQL (gtid_purged value)private Map<String,String>
querySystemVariables(String statement)
protected Map<String,MySqlJdbcContext.DatabaseLocales>
readDatabaseCollations()
Read the MySQL default character sets for exisiting databases.protected Map<String,String>
readMySqlCharsetSystemVariables()
Read the MySQL charset-related system variables.Map<String,String>
readMySqlSystemVariables()
Read the MySQL system variables.protected String
setStatementFor(Map<String,String> variables)
protected void
setSystemProperty(String property, Field field, boolean showValueInError)
void
shutdown()
MySqlConnectorConfig.SecureConnectionMode
sslMode()
boolean
sslModeEnabled()
void
start()
GtidSet
subtractGtidSet(GtidSet set1, GtidSet set2)
Determine the difference between two sets.boolean
userHasPrivileges(String grantName)
Determine if the current user has the named privilege.String
username()
-
-
-
Field Detail
-
MYSQL_CONNECTION_URL
protected static final String MYSQL_CONNECTION_URL
- See Also:
- Constant Field Values
-
JDBC_PROPERTY_LEGACY_DATETIME
protected static final String JDBC_PROPERTY_LEGACY_DATETIME
- See Also:
- Constant Field Values
-
SQL_SHOW_SYSTEM_VARIABLES
private static final String SQL_SHOW_SYSTEM_VARIABLES
- See Also:
- Constant Field Values
-
SQL_SHOW_SYSTEM_VARIABLES_CHARACTER_SET
private static final String SQL_SHOW_SYSTEM_VARIABLES_CHARACTER_SET
- See Also:
- Constant Field Values
-
SQL_SHOW_SESSION_VARIABLE_SSL_VERSION
private static final String SQL_SHOW_SESSION_VARIABLE_SSL_VERSION
- See Also:
- Constant Field Values
-
FACTORY
protected static JdbcConnection.ConnectionFactory FACTORY
-
logger
protected static final org.slf4j.Logger logger
-
config
protected final Configuration config
-
jdbc
protected final JdbcConnection jdbc
-
-
Constructor Detail
-
MySqlJdbcContext
public MySqlJdbcContext(MySqlConnectorConfig config)
-
-
Method Detail
-
config
public Configuration config()
-
jdbc
public JdbcConnection jdbc()
-
logger
public org.slf4j.Logger logger()
-
username
public String username()
-
password
public String password()
-
hostname
public String hostname()
-
port
public int port()
-
sslMode
public MySqlConnectorConfig.SecureConnectionMode sslMode()
-
sslModeEnabled
public boolean sslModeEnabled()
-
eventProcessingFailureHandlingMode
public CommonConnectorConfig.EventProcessingFailureHandlingMode eventProcessingFailureHandlingMode()
-
inconsistentSchemaHandlingMode
public CommonConnectorConfig.EventProcessingFailureHandlingMode inconsistentSchemaHandlingMode()
-
start
public void start()
-
shutdown
public void shutdown()
-
close
public void close()
- Specified by:
close
in interfaceAutoCloseable
-
isGtidModeEnabled
public boolean isGtidModeEnabled()
Determine whether the MySQL server has GTIDs enabled.- Returns:
false
if the server'sgtid_mode
is set and isOFF
, ortrue
otherwise
-
knownGtidSet
public String knownGtidSet()
Determine the executed GTID set for MySQL.- Returns:
- the string representation of MySQL's GTID sets; never null but an empty string if the server does not use GTIDs
-
subtractGtidSet
public GtidSet subtractGtidSet(GtidSet set1, GtidSet set2)
Determine the difference between two sets.- Returns:
- a subtraction of two GTID sets; never null
-
purgedGtidSet
public GtidSet purgedGtidSet()
Get the purged GTID values from MySQL (gtid_purged value)- Returns:
- A GTID set; may be empty if not using GTIDs or none have been purged yet
-
userHasPrivileges
public boolean userHasPrivileges(String grantName)
Determine if the current user has the named privilege. Note that if the user has the "ALL" privilege this method returnstrue
.- Parameters:
grantName
- the name of the MySQL privilege; may not be null- Returns:
true
if the user has the named privilege, orfalse
otherwise
-
connectionString
public String connectionString()
-
readMySqlCharsetSystemVariables
protected Map<String,String> readMySqlCharsetSystemVariables()
Read the MySQL charset-related system variables.- Returns:
- the system variables that are related to server character sets; never null
-
readMySqlSystemVariables
public Map<String,String> readMySqlSystemVariables()
Read the MySQL system variables.- Returns:
- the system variables that are related to server character sets; never null
-
readDatabaseCollations
protected Map<String,MySqlJdbcContext.DatabaseLocales> readDatabaseCollations()
Read the MySQL default character sets for exisiting databases.- Returns:
- the map of database names with their default character sets; never null
-
setSystemProperty
protected void setSystemProperty(String property, Field field, boolean showValueInError)
-
getSessionVariableForSslVersion
public String getSessionVariableForSslVersion()
Read the Ssl Version session variable.- Returns:
- the session variables that are related to sessions ssl version
-
-