Skip to content

Commit 0fc5f26

Browse files
committed
Replace MySQL deprecated loading class
1 parent 83acf6c commit 0fc5f26

File tree

3 files changed

+31
-37
lines changed

3 files changed

+31
-37
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package com.databasepreservation.modules.mysql;
2+
3+
public class Constants {
4+
5+
public static final String MYSQL_DRIVER_CLASS_NAME = "com.mysql.cj.jdbc.Driver";
6+
7+
private Constants() {
8+
// private constructor
9+
}
10+
}

dbptk-modules/dbptk-module-mysql/src/main/java/com/databasepreservation/modules/mysql/in/MySQLJDBCImportModule.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@
3939
import com.databasepreservation.modules.mysql.MySQLModuleFactory;
4040
import com.databasepreservation.utils.MapUtils;
4141

42+
import static com.databasepreservation.modules.mysql.Constants.MYSQL_DRIVER_CLASS_NAME;
43+
4244
/**
4345
* @author Luis Faria <[email protected]>
4446
* @author Bruno Ferreira <[email protected]>
@@ -65,7 +67,7 @@ public class MySQLJDBCImportModule extends JDBCImportModule {
6567
*/
6668
public MySQLJDBCImportModule(String moduleName, String hostname, int port, String database, String username,
6769
String password, boolean encrypt) {
68-
super("com.mysql.jdbc.Driver",
70+
super(MYSQL_DRIVER_CLASS_NAME,
6971
"jdbc:mysql://" + hostname + ":" + port + "/" + database + (encrypt ? "?useSSL=true" : ""), new MySQLHelper(),
7072
new MySQLDatatypeImporter(), moduleName,
7173
MapUtils.buildMapFromObjects(MySQLModuleFactory.PARAMETER_HOSTNAME, hostname,
@@ -80,7 +82,7 @@ public MySQLJDBCImportModule(String moduleName, String hostname, int port, Strin
8082
public MySQLJDBCImportModule(String moduleName, String hostname, int port, String database, String username,
8183
String password, boolean encrypt, String sshHost, String sshUser, String sshPassword, String sshPortNumber)
8284
throws ModuleException {
83-
super("com.mysql.jdbc.Driver",
85+
super(MYSQL_DRIVER_CLASS_NAME,
8486
"jdbc:mysql://" + hostname + ":" + port + "/" + database + (encrypt ? "?useSSL=true" : ""), new MySQLHelper(),
8587
new MySQLDatatypeImporter(), moduleName,
8688
MapUtils.buildMapFromObjects(MySQLModuleFactory.PARAMETER_HOSTNAME, hostname,
@@ -182,8 +184,8 @@ protected TableStructure getTableStructure(SchemaStructure schema, String tableN
182184
}
183185
}
184186
} catch (Exception e) {
185-
LOGGER.debug(
186-
"Exception while trying to obtain MySQL table '" + tableIndex + "' description (comment). with query ", e);
187+
LOGGER.debug("Exception while trying to obtain MySQL table '{}' description (comment). with query ", tableIndex,
188+
e);
187189
}
188190
}
189191

dbptk-modules/dbptk-module-mysql/src/main/java/com/databasepreservation/modules/mysql/out/MySQLJDBCExportModule.java

Lines changed: 15 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* The contents of this file are subject to the license and copyright
33
* detailed in the LICENSE file at the root of the source
44
* tree and available online at
5-
*
5+
* <p>
66
* https://github.com/keeps/db-preservation-toolkit
77
*/
88
/**
@@ -30,6 +30,8 @@
3030
import com.databasepreservation.modules.mysql.MySQLHelper;
3131
import com.databasepreservation.utils.RemoteConnectionUtils;
3232

33+
import static com.databasepreservation.modules.mysql.Constants.MYSQL_DRIVER_CLASS_NAME;
34+
3335
/**
3436
* @author Luis Faria
3537
*/
@@ -53,30 +55,6 @@ public class MySQLJDBCExportModule extends JDBCExportModule {
5355

5456
private final boolean ssh;
5557

56-
/**
57-
* MySQL JDBC export module constructor
58-
*
59-
* @param hostname
60-
* the hostname of the MySQL server
61-
* @param database
62-
* the name of the database to import from
63-
* @param username
64-
* the name of the user to use in connection
65-
* @param password
66-
* the password of the user to use in connection
67-
68-
public MySQLJDBCExportModule(String hostname, String database, String username, String password, boolean encrypt) {
69-
super("com.mysql.jdbc.Driver", createConnectionURL(hostname, -1, database, username, password, encrypt), new MySQLHelper());
70-
this.hostname = hostname;
71-
this.port = -1;
72-
this.database = database;
73-
this.username = username;
74-
this.password = password;
75-
this.encrypt = encrypt;
76-
this.ignoredSchemas = new TreeSet<String>(Arrays.asList(IGNORED_SCHEMAS));
77-
}
78-
*/
79-
8058
/**
8159
* MySQL JDBC export module constructor
8260
*
@@ -91,8 +69,9 @@ public MySQLJDBCExportModule(String hostname, String database, String username,
9169
* @param password
9270
* the password of the user to use in connection
9371
*/
94-
public MySQLJDBCExportModule(String hostname, int port, String database, String username, String password, boolean encrypt) {
95-
super("com.mysql.jdbc.Driver", createConnectionURL(hostname, port, database, username, password, encrypt),
72+
public MySQLJDBCExportModule(String hostname, int port, String database, String username, String password,
73+
boolean encrypt) {
74+
super(MYSQL_DRIVER_CLASS_NAME, createConnectionURL(hostname, port, database, username, password, encrypt),
9675
new MySQLHelper());
9776
this.hostname = hostname;
9877
this.port = port;
@@ -104,9 +83,11 @@ public MySQLJDBCExportModule(String hostname, int port, String database, String
10483
this.ssh = false;
10584
}
10685

107-
public MySQLJDBCExportModule(String hostname, int port, String database, String username, String password, boolean encrypt, boolean ssh, String sshHost, String sshUser, String sshPassword, String sshPortNumber) throws ModuleException {
108-
super("com.mysql.jdbc.Driver", createConnectionURL(hostname, port, database, username, password, encrypt),
109-
new MySQLHelper(), ssh, sshHost, sshUser, sshPassword, sshPortNumber);
86+
public MySQLJDBCExportModule(String hostname, int port, String database, String username, String password,
87+
boolean encrypt, boolean ssh, String sshHost, String sshUser, String sshPassword, String sshPortNumber)
88+
throws ModuleException {
89+
super(MYSQL_DRIVER_CLASS_NAME, createConnectionURL(hostname, port, database, username, password, encrypt),
90+
new MySQLHelper(), ssh, sshHost, sshUser, sshPassword, sshPortNumber);
11091
this.hostname = hostname;
11192
this.port = port;
11293
this.database = database;
@@ -117,15 +98,16 @@ public MySQLJDBCExportModule(String hostname, int port, String database, String
11798
this.ssh = ssh;
11899
}
119100

120-
public static String createConnectionURL(String hostname, int port, String database, String username,
121-
String password, boolean encrypt) {
101+
public static String createConnectionURL(String hostname, int port, String database, String username, String password,
102+
boolean encrypt) {
122103
return "jdbc:mysql://" + hostname + (port >= 0 ? ":" + port : "") + "/" + database + "?" + "user=" + username
123104
+ "&password=" + password + "&useSSL=" + encrypt + "&rewriteBatchedStatements=true";
124105
}
125106

126107
public String createConnectionURL(String databaseName) {
127108
if (ssh) {
128-
return createConnectionURL(hostname, RemoteConnectionUtils.getLocalPort(), databaseName, username, password, encrypt);
109+
return createConnectionURL(hostname, RemoteConnectionUtils.getLocalPort(), databaseName, username, password,
110+
encrypt);
129111
} else {
130112
return createConnectionURL(hostname, port, databaseName, username, password, encrypt);
131113
}

0 commit comments

Comments
 (0)