Skip to content

Commit

Permalink
Refactor StorageResourceCreator
Browse files Browse the repository at this point in the history
  • Loading branch information
terrymanu committed Sep 25, 2023
1 parent 7c0b07f commit 3bc3d37
Showing 1 changed file with 4 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import org.apache.shardingsphere.infra.database.core.connector.url.JdbcUrl;
import org.apache.shardingsphere.infra.database.core.connector.url.StandardJdbcUrlParser;
import org.apache.shardingsphere.infra.database.core.connector.url.UnrecognizedDatabaseURLException;
import org.apache.shardingsphere.infra.database.core.type.DatabaseType;
import org.apache.shardingsphere.infra.database.core.type.DatabaseTypeFactory;
import org.apache.shardingsphere.infra.database.core.type.DatabaseTypeRegistry;
import org.apache.shardingsphere.infra.datasource.pool.creator.DataSourcePoolCreator;
Expand Down Expand Up @@ -54,10 +53,8 @@ public static StorageResource createStorageResource(final Map<String, DataSource
String storageUnitName = entry.getKey();
Map<String, Object> standardProps = entry.getValue().getConnectionPropertySynonyms().getStandardProperties();
String url = standardProps.get("url").toString();
String username = standardProps.get("username").toString();
DatabaseType databaseType = DatabaseTypeFactory.get(url);
boolean isInstanceConnectionAvailable = new DatabaseTypeRegistry(databaseType).getDialectDatabaseMetaData().isInstanceConnectionAvailable();
StorageNode storageNode = new StorageNode(getStorageNodeName(storageUnitName, url, username, isInstanceConnectionAvailable));
boolean isInstanceConnectionAvailable = new DatabaseTypeRegistry(DatabaseTypeFactory.get(url)).getDialectDatabaseMetaData().isInstanceConnectionAvailable();
StorageNode storageNode = new StorageNode(getStorageNodeName(storageUnitName, url, standardProps.get("username").toString(), isInstanceConnectionAvailable));
if (!storageNodes.containsKey(storageNode)) {
storageNodes.put(storageNode, DataSourcePoolCreator.create(storageUnitName, entry.getValue(), true, storageNodes.values()));
}
Expand Down Expand Up @@ -99,10 +96,8 @@ public static StorageResource createStorageResourceWithoutDataSource(final Map<S
String storageUnitName = entry.getKey();
Map<String, Object> standardProps = entry.getValue().getConnectionPropertySynonyms().getStandardProperties();
String url = standardProps.get("url").toString();
String username = standardProps.get("username").toString();
DatabaseType databaseType = DatabaseTypeFactory.get(url);
boolean isInstanceConnectionAvailable = new DatabaseTypeRegistry(databaseType).getDialectDatabaseMetaData().isInstanceConnectionAvailable();
StorageNode storageNode = new StorageNode(getStorageNodeName(entry.getKey(), url, username, isInstanceConnectionAvailable));
boolean isInstanceConnectionAvailable = new DatabaseTypeRegistry(DatabaseTypeFactory.get(url)).getDialectDatabaseMetaData().isInstanceConnectionAvailable();
StorageNode storageNode = new StorageNode(getStorageNodeName(storageUnitName, url, standardProps.get("username").toString(), isInstanceConnectionAvailable));
if (!storageNodes.containsKey(storageNode)) {
storageNodes.put(storageNode, null);
newPropsMap.put(storageNode.getName(), entry.getValue());
Expand Down

0 comments on commit 3bc3d37

Please sign in to comment.