Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add DatabaseType#isSubtypeOfTrunkDatabase. #32606

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,16 @@ default Optional<DatabaseType> getTrunkDatabaseType() {
return Optional.empty();
}

/**
* Judge whether current database type is instance of trunk database type.
*
* @param databaseTypeClass database type class
* @return true if current database type is instance of trunk database type, otherwise false
*/
default boolean isSubtypeOfTrunkDatabase(Class<? extends DatabaseType> databaseTypeClass) {
return databaseTypeClass.isInstance(this) || getTrunkDatabaseType().map(databaseType -> databaseType.isSubtypeOfTrunkDatabase(databaseTypeClass)).orElse(false);
}

@Override
String getType();
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ public final class TableRefreshUtils {
* @return table name
*/
public static String getTableName(final DatabaseType databaseType, final IdentifierValue identifierValue) {
return databaseType instanceof OracleDatabaseType && QuoteCharacter.NONE == identifierValue.getQuoteCharacter() ? identifierValue.getValue().toUpperCase() : identifierValue.getValue();
return databaseType.isSubtypeOfTrunkDatabase(OracleDatabaseType.class) && QuoteCharacter.NONE == identifierValue.getQuoteCharacter() ? identifierValue.getValue().toUpperCase()
: identifierValue.getValue();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ private void cleanUpDataSource() {
return;
}
for (String each : Arrays.asList(DS_0, DS_1, DS_2, DS_3, DS_4)) {
String databaseName = databaseType instanceof OracleDatabaseType ? each.toUpperCase() : each;
String databaseName = databaseType.isSubtypeOfTrunkDatabase(OracleDatabaseType.class) ? each.toUpperCase() : each;
containerComposer.cleanUpDatabase(databaseName);
}
}
Expand Down Expand Up @@ -238,7 +238,7 @@ public String appendExtraParameter(final String jdbcUrl) {
* @throws SQLException SQL exception
*/
public void registerStorageUnit(final String storageUnitName) throws SQLException {
String username = databaseType instanceof OracleDatabaseType ? storageUnitName : getUsername();
String username = databaseType.isSubtypeOfTrunkDatabase(OracleDatabaseType.class) ? storageUnitName : getUsername();
String registerStorageUnitTemplate = "REGISTER STORAGE UNIT ${ds} ( URL='${url}', USER='${user}', PASSWORD='${password}')".replace("${ds}", storageUnitName)
.replace("${user}", username)
.replace("${password}", getPassword())
Expand Down Expand Up @@ -296,7 +296,7 @@ public String getActualJdbcUrlTemplate(final String databaseName, final boolean
* @return actual JDBC URL template
*/
public String getActualJdbcUrlTemplate(final String databaseName, final boolean isInContainer) {
if (databaseType instanceof OracleDatabaseType) {
if (databaseType.isSubtypeOfTrunkDatabase(OracleDatabaseType.class)) {
return getActualJdbcUrlTemplate(databaseName, isInContainer, 0);
}
return appendExtraParameter(getActualJdbcUrlTemplate(databaseName, isInContainer, 0));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public DockerContainerComposer(final DatabaseType databaseType, final String sto
storageContainers.add(storageContainer);
}
AdaptorContainerConfiguration containerConfig = PipelineProxyClusterContainerConfigurationFactory.newInstance(databaseType);
DatabaseType proxyDatabaseType = databaseType instanceof OracleDatabaseType ? TypedSPILoader.getService(DatabaseType.class, "MySQL") : databaseType;
DatabaseType proxyDatabaseType = databaseType.isSubtypeOfTrunkDatabase(OracleDatabaseType.class) ? TypedSPILoader.getService(DatabaseType.class, "MySQL") : databaseType;
ShardingSphereProxyClusterContainer proxyClusterContainer = (ShardingSphereProxyClusterContainer) AdapterContainerFactory.newInstance(
AdapterMode.CLUSTER, AdapterType.PROXY, proxyDatabaseType, "", containerConfig);
for (DockerStorageContainer each : storageContainers) {
Expand All @@ -84,7 +84,7 @@ public DockerContainerComposer(final DatabaseType databaseType, final String sto

@Override
public String getProxyJdbcUrl(final String databaseName) {
if (databaseType instanceof OracleDatabaseType) {
if (databaseType.isSubtypeOfTrunkDatabase(OracleDatabaseType.class)) {
return DataSourceEnvironment.getURL(TypedSPILoader.getService(DatabaseType.class, "MySQL"), proxyContainer.getHost(), proxyContainer.getFirstMappedPort(), databaseName);
}
return DataSourceEnvironment.getURL(databaseType, proxyContainer.getHost(), proxyContainer.getFirstMappedPort(), databaseName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ private void dropTableWithOracle(final Connection connection, final String schem

@Override
public String getProxyJdbcUrl(final String databaseName) {
if (databaseType instanceof OracleDatabaseType) {
if (databaseType.isSubtypeOfTrunkDatabase(OracleDatabaseType.class)) {
return String.format("jdbc:mysql://localhost:3307/%s?useSSL=false", databaseName);
}
return DataSourceEnvironment.getURL(databaseType, "localhost", 3307, databaseName);
Expand Down