Skip to content

Commit d58c773

Browse files
MuLeiSY2021imbajin
andauthored
refactor(loader): add a useSSL option for mysql (#650)
--------- Co-authored-by: imbajin <[email protected]>
1 parent e9cd336 commit d58c773

File tree

2 files changed

+14
-18
lines changed

2 files changed

+14
-18
lines changed

hugegraph-loader/src/test/java/org/apache/hugegraph/loader/test/functional/DBUtil.java

+10-15
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@
1717

1818
package org.apache.hugegraph.loader.test.functional;
1919

20+
import org.apache.hugegraph.loader.exception.LoadException;
21+
2022
import java.sql.Connection;
2123
import java.sql.DriverManager;
2224
import java.sql.SQLException;
2325
import java.sql.Statement;
2426

25-
import org.apache.hugegraph.loader.exception.LoadException;
26-
2727
public class DBUtil {
2828

2929
private final String driver;
@@ -40,33 +40,28 @@ public DBUtil(String driver, String url, String user, String pass) {
4040
this.pass = pass;
4141
}
4242

43-
public void connect() {
43+
public void connect(boolean useSSL) {
4444
try {
4545
Class.forName(this.driver);
46-
String url = String.format("%s?%s", this.url, "useSSL=false");
46+
String url = String.format("%s?useSSL=%s", this.url, useSSL);
4747
this.conn = DriverManager.getConnection(url, this.user, this.pass);
4848
} catch (ClassNotFoundException e) {
49-
throw new LoadException("Invalid driver class '%s'",
50-
e, this.driver);
49+
throw new LoadException("Invalid driver class '%s'", e, this.driver);
5150
} catch (SQLException e) {
52-
throw new LoadException("Failed to connect database via '%s'",
53-
e, this.url);
51+
throw new LoadException("Failed to connect database via '%s'", e, this.url);
5452
}
5553
}
5654

57-
public void connect(String database) {
55+
public void connect(String database, boolean useSSL) {
5856
this.close();
59-
String url = String.format("%s/%s?%s", this.url, database,
60-
"useSSL=false");
57+
String url = String.format("%s/%s?useSSL=%s", this.url, database, useSSL);
6158
try {
6259
Class.forName(this.driver);
6360
this.conn = DriverManager.getConnection(url, this.user, this.pass);
6461
} catch (ClassNotFoundException e) {
65-
throw new LoadException("Invalid driver class '%s'",
66-
e, this.driver);
62+
throw new LoadException("Invalid driver class '%s'", e, this.driver);
6763
} catch (SQLException e) {
68-
throw new LoadException("Failed to connect database via '%s'",
69-
e, this.url);
64+
throw new LoadException("Failed to connect database via '%s'", e, this.url);
7065
}
7166
}
7267

hugegraph-loader/src/test/java/org/apache/hugegraph/loader/test/functional/JDBCLoadTest.java

+4-3
Original file line numberDiff line numberDiff line change
@@ -48,16 +48,17 @@ public class JDBCLoadTest extends LoadTest {
4848
private static final String PASS = "root";
4949

5050
private static final DBUtil dbUtil = new DBUtil(DRIVER, DB_URL, USER, PASS);
51+
private static final boolean USE_SSL = false;
5152

5253
@BeforeClass
5354
public static void setUp() {
5455
clearServerData();
5556

56-
dbUtil.connect();
57-
// create the database
57+
dbUtil.connect(USE_SSL);
58+
// create database
5859
dbUtil.execute(String.format("CREATE DATABASE IF NOT EXISTS `%s`;", DATABASE));
5960
// create tables
60-
dbUtil.connect(DATABASE);
61+
dbUtil.connect(DATABASE, USE_SSL);
6162
// vertex person
6263
dbUtil.execute("CREATE TABLE IF NOT EXISTS `person` (" +
6364
"`id` int(10) unsigned NOT NULL," +

0 commit comments

Comments
 (0)