Skip to content

Commit b7a07db

Browse files
committed
fix(Jdbc Connector): Fix JdbcCatalogOptions BASE builder will be changed by call required()
JdbcCatalogOptions BASE builder will be changed by call `required()` because it just a static variable and Builder inner list will be changed if you are using code like this: ```java OceanBaseCatalogFactory factory = new OceanBaseCatalogFactory(); factory.optionRule(); factory.optionRule(); ``` So change the BASE variable to a function, when we call the `base()` function, it will create a new Builder, so it will be new every call;
1 parent 4d9287f commit b7a07db

File tree

9 files changed

+23
-19
lines changed

9 files changed

+23
-19
lines changed

Diff for: seatunnel-connectors-v2/connector-jdbc/src/main/java/org/apache/seatunnel/connectors/seatunnel/jdbc/catalog/JdbcCatalogOptions.java

+15-11
Original file line numberDiff line numberDiff line change
@@ -21,57 +21,61 @@
2121
import org.apache.seatunnel.api.configuration.Options;
2222
import org.apache.seatunnel.api.configuration.util.OptionRule;
2323

24-
public interface JdbcCatalogOptions {
25-
Option<String> BASE_URL =
24+
public class JdbcCatalogOptions {
25+
public static final Option<String> BASE_URL =
2626
Options.key("base-url")
2727
.stringType()
2828
.noDefaultValue()
2929
.withDescription(
3030
"URL has to be with database, like \"jdbc:mysql://localhost:5432/db\" or"
3131
+ "\"jdbc:mysql://localhost:5432/db?useSSL=true\".");
3232

33-
Option<String> USERNAME =
33+
public static final Option<String> USERNAME =
3434
Options.key("username")
3535
.stringType()
3636
.noDefaultValue()
3737
.withDescription(
3838
"Name of the database to use when connecting to the database server.");
3939

40-
Option<String> PASSWORD =
40+
public static final Option<String> PASSWORD =
4141
Options.key("password")
4242
.stringType()
4343
.noDefaultValue()
4444
.withDescription("Password to use when connecting to the database server.");
4545

46-
Option<String> SCHEMA =
46+
public static final Option<String> SCHEMA =
4747
Options.key("schema")
4848
.stringType()
4949
.noDefaultValue()
5050
.withDescription(
5151
"for databases that support the schema parameter, give it priority.");
5252

53-
Option<String> COMPATIBLE_MODE =
53+
public static final Option<String> COMPATIBLE_MODE =
5454
Options.key("compatibleMode")
5555
.stringType()
5656
.noDefaultValue()
5757
.withDescription(
5858
"The compatible mode of database, required when the database supports multiple compatible modes. "
5959
+ "For example, when using OceanBase database, you need to set it to 'mysql' or 'oracle'.");
6060

61-
OptionRule.Builder BASE_RULE =
62-
OptionRule.builder().required(BASE_URL).required(USERNAME, PASSWORD).optional(SCHEMA);
63-
64-
Option<String> TABLE_PREFIX =
61+
public static final Option<String> TABLE_PREFIX =
6562
Options.key("tablePrefix")
6663
.stringType()
6764
.noDefaultValue()
6865
.withDescription(
6966
"The table prefix name added when the table is automatically created");
7067

71-
Option<String> TABLE_SUFFIX =
68+
public static final Option<String> TABLE_SUFFIX =
7269
Options.key("tableSuffix")
7370
.stringType()
7471
.noDefaultValue()
7572
.withDescription(
7673
"The table suffix name added when the table is automatically created");
74+
75+
public static OptionRule.Builder base() {
76+
return OptionRule.builder()
77+
.required(BASE_URL)
78+
.required(USERNAME, PASSWORD)
79+
.optional(SCHEMA);
80+
}
7781
}

Diff for: seatunnel-connectors-v2/connector-jdbc/src/main/java/org/apache/seatunnel/connectors/seatunnel/jdbc/catalog/dm/DamengCatalogFactory.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,6 @@ public Catalog createCatalog(String catalogName, ReadonlyConfig options) {
5757

5858
@Override
5959
public OptionRule optionRule() {
60-
return JdbcCatalogOptions.BASE_RULE.build();
60+
return JdbcCatalogOptions.base().build();
6161
}
6262
}

Diff for: seatunnel-connectors-v2/connector-jdbc/src/main/java/org/apache/seatunnel/connectors/seatunnel/jdbc/catalog/mysql/MySqlCatalogFactory.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,6 @@ public Catalog createCatalog(String catalogName, ReadonlyConfig options) {
5656

5757
@Override
5858
public OptionRule optionRule() {
59-
return JdbcCatalogOptions.BASE_RULE.build();
59+
return JdbcCatalogOptions.base().build();
6060
}
6161
}

Diff for: seatunnel-connectors-v2/connector-jdbc/src/main/java/org/apache/seatunnel/connectors/seatunnel/jdbc/catalog/oceanbase/OceanBaseCatalogFactory.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,6 @@ public Catalog createCatalog(String catalogName, ReadonlyConfig options) {
7777

7878
@Override
7979
public OptionRule optionRule() {
80-
return JdbcCatalogOptions.BASE_RULE.required(JdbcCatalogOptions.COMPATIBLE_MODE).build();
80+
return JdbcCatalogOptions.base().required(JdbcCatalogOptions.COMPATIBLE_MODE).build();
8181
}
8282
}

Diff for: seatunnel-connectors-v2/connector-jdbc/src/main/java/org/apache/seatunnel/connectors/seatunnel/jdbc/catalog/oracle/OracleCatalogFactory.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,6 @@ public Catalog createCatalog(String catalogName, ReadonlyConfig options) {
5757

5858
@Override
5959
public OptionRule optionRule() {
60-
return JdbcCatalogOptions.BASE_RULE.build();
60+
return JdbcCatalogOptions.base().build();
6161
}
6262
}

Diff for: seatunnel-connectors-v2/connector-jdbc/src/main/java/org/apache/seatunnel/connectors/seatunnel/jdbc/catalog/psql/PostgresCatalogFactory.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,6 @@ public Catalog createCatalog(String catalogName, ReadonlyConfig options) {
5757

5858
@Override
5959
public OptionRule optionRule() {
60-
return JdbcCatalogOptions.BASE_RULE.build();
60+
return JdbcCatalogOptions.base().build();
6161
}
6262
}

Diff for: seatunnel-connectors-v2/connector-jdbc/src/main/java/org/apache/seatunnel/connectors/seatunnel/jdbc/catalog/sqlserver/SqlServerCatalogFactory.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,6 @@ public Catalog createCatalog(String catalogName, ReadonlyConfig options) {
5050

5151
@Override
5252
public OptionRule optionRule() {
53-
return JdbcCatalogOptions.BASE_RULE.build();
53+
return JdbcCatalogOptions.base().build();
5454
}
5555
}

Diff for: seatunnel-connectors-v2/connector-jdbc/src/main/java/org/apache/seatunnel/connectors/seatunnel/jdbc/catalog/tidb/TiDBCatalogFactory.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,6 @@ public Catalog createCatalog(String catalogName, ReadonlyConfig options) {
5656

5757
@Override
5858
public OptionRule optionRule() {
59-
return JdbcCatalogOptions.BASE_RULE.build();
59+
return JdbcCatalogOptions.base().build();
6060
}
6161
}

Diff for: seatunnel-connectors-v2/connector-jdbc/src/main/java/org/apache/seatunnel/connectors/seatunnel/jdbc/catalog/xugu/XuguCatalogFactory.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,6 @@ public Catalog createCatalog(String catalogName, ReadonlyConfig options) {
5858

5959
@Override
6060
public OptionRule optionRule() {
61-
return JdbcCatalogOptions.BASE_RULE.build();
61+
return JdbcCatalogOptions.base().build();
6262
}
6363
}

0 commit comments

Comments
 (0)