Skip to content

Commit

Permalink
for apache#601, removed useless codes for integrate database type cod…
Browse files Browse the repository at this point in the history
…es from AbstractSQLTest
  • Loading branch information
haocao committed Aug 1, 2018
1 parent b08a93b commit 12cf09b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@

public abstract class AbstractSQLTest {

private static Map<DatabaseType, ShardingDataSource> shardingDataSources = new HashMap<>();
protected static ShardingDataSource shardingDataSource;

private static Set<DatabaseType> databaseTypes = Sets.newHashSet(DatabaseType.H2);

Expand All @@ -60,10 +60,6 @@ public abstract class AbstractSQLTest {
init();
}

protected static Map<DatabaseType, ShardingDataSource> getShardingDataSources() {
return shardingDataSources;
}

private static synchronized void init() {
try {
Properties prop = new Properties();
Expand Down Expand Up @@ -131,13 +127,12 @@ private static Connection initialConnection(final String dbName, final DatabaseT

@AfterClass
public static void clear() throws SQLException, ReflectiveOperationException {
if (!shardingDataSources.isEmpty()) {
for (ShardingDataSource each : shardingDataSources.values()) {
each.close();
closeDataSources(getDataSourceMap(each).values());
}
shardingDataSources.clear();
if (shardingDataSource == null) {
return;
}
shardingDataSource.close();
closeDataSources(getDataSourceMap(shardingDataSource).values());
shardingDataSource = null;
}

private void createDataSources(final String dbName, final DatabaseType type) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public void cleanAndInitTable() throws Exception {

@Before
public void initShardingDataSources() throws SQLException {
if (!getShardingDataSources().isEmpty()) {
if (null != shardingDataSource) {
return;
}

Expand Down Expand Up @@ -77,7 +77,7 @@ public void initShardingDataSources() throws SQLException {
shardingRuleConfig.setDefaultTableShardingStrategyConfig(new StandardShardingStrategyConfiguration("order_id", new PreciseOrderShardingAlgorithm(), new RangeOrderShardingAlgorithm()));
shardingRuleConfig.setDefaultDatabaseShardingStrategyConfig(new StandardShardingStrategyConfiguration("user_id", new PreciseOrderShardingAlgorithm(), new RangeOrderShardingAlgorithm()));
ShardingRule shardingRule = new ShardingRule(shardingRuleConfig, entry.getValue().keySet());
getShardingDataSources().put(entry.getKey(), new ShardingDataSource(entry.getValue(), shardingRule));
shardingDataSource = new ShardingDataSource(entry.getValue(), shardingRule);
}
}

Expand All @@ -87,6 +87,6 @@ protected List<String> getInitDataSetFiles() {
}

protected ShardingDataSource getShardingDataSource() {
return getShardingDataSources().get(DatabaseType.H2);
return shardingDataSource;
}
}

0 comments on commit 12cf09b

Please sign in to comment.