Skip to content

Commit

Permalink
jdbc url parser: refactor DataSourcePropertyManager
Browse files Browse the repository at this point in the history
  • Loading branch information
terrymanu committed Jul 12, 2018
1 parent d3375aa commit 681b183
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@ public final class DataSourceMetaData {
private final String schemeName;

/**
* Judge whether two of data source properties point at the same instance.
* Judge whether two of data sources are in the same database instance.
*
* @param dataSourceProperty data source property.
* @return pointing at the same instance or not.
* @param dataSourceMetaData data source meta data
* @return data sources are in the same database instance or not
*/
public boolean isPointAtSameInstance(final DataSourceMetaData dataSourceProperty) {
return hostName.equals(dataSourceProperty.getHostName()) && port.equals(dataSourceProperty.getPort());
public boolean isInSameDatabaseInstance(final DataSourceMetaData dataSourceMetaData) {
return hostName.equals(dataSourceMetaData.getHostName()) && port.equals(dataSourceMetaData.getPort());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@
*/
public class DataSourcePropertyManager {

private final Map<String, DataSourceMetaData> dataSourcePropertyMap;
private final Map<String, DataSourceMetaData> dataSourceMetaDataMap;

public DataSourcePropertyManager(final Map<String, DataSource> dataSourceMap, final DatabaseType databaseType) {
dataSourcePropertyMap = initDataSourcePropertyMap(dataSourceMap, databaseType);
dataSourceMetaDataMap = getDataSourceMetaDataMap(dataSourceMap, databaseType);
}

private Map<String, DataSourceMetaData> initDataSourcePropertyMap(final Map<String, DataSource> dataSourceMap, final DatabaseType databaseType) {
private Map<String, DataSourceMetaData> getDataSourceMetaDataMap(final Map<String, DataSource> dataSourceMap, final DatabaseType databaseType) {
Map<String, DataSourceMetaData> result = new LinkedHashMap<>();
for (Entry<String, DataSource> entry : dataSourceMap.entrySet()) {
result.put(entry.getKey(), DataSourceMetaDataFactory.getDataSourceMetaData(databaseType, entry.getValue()));
Expand All @@ -54,7 +54,7 @@ private Map<String, DataSourceMetaData> initDataSourcePropertyMap(final Map<Stri
*/
public List<String> getAllInstanceDataSourceNames() {
List<String> result = new LinkedList<>();
for (Entry<String, DataSourceMetaData> entry : dataSourcePropertyMap.entrySet()) {
for (Entry<String, DataSourceMetaData> entry : dataSourceMetaDataMap.entrySet()) {
if (!isExisted(entry.getKey(), result)) {
result.add(entry.getKey());
}
Expand All @@ -64,7 +64,7 @@ public List<String> getAllInstanceDataSourceNames() {

private boolean isExisted(final String dataSourceName, final List<String> existedDataSourceNames) {
for (String each : existedDataSourceNames) {
if (dataSourcePropertyMap.get(each).isPointAtSameInstance(dataSourcePropertyMap.get(dataSourceName))) {
if (dataSourceMetaDataMap.get(each).isInSameDatabaseInstance(dataSourceMetaDataMap.get(dataSourceName))) {
return true;
}
}
Expand All @@ -78,6 +78,6 @@ private boolean isExisted(final String dataSourceName, final List<String> existe
* @return actual schema name
*/
public String getActualSchemaName(final String actualDataSourceName) {
return dataSourcePropertyMap.get(actualDataSourceName).getSchemeName();
return dataSourceMetaDataMap.get(actualDataSourceName).getSchemeName();
}
}

0 comments on commit 681b183

Please sign in to comment.