Skip to content

Commit

Permalink
for #601: refactor InItCreateSchema
Browse files Browse the repository at this point in the history
  • Loading branch information
terrymanu committed May 3, 2018
1 parent 4c91538 commit bc7e6ad
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ public static Collection<String[]> getParameters() throws IOException, JAXBExcep
List<String> paths = FileUtil.getAllFilePaths(new File(assertPath), "assert-", "xml");
for (String each : paths) {
AssertsDefinition assertsDefinition = AnalyzeConfig.analyze(each);

if (StringUtils.isNotBlank(assertsDefinition.getBaseConfig())) {
String[] dbs = StringUtils.split(assertsDefinition.getBaseConfig(), ",");
for (String db : dbs) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,19 +53,10 @@ public final class InItCreateSchema {
*
* @param database database name
*/
public static void addDatabase(String database) {
public static void addDatabase(final String database) {
DATABASES.add(database);
}

/**
* Initialize the database table.
*/
public static synchronized void createTable() {
for (DatabaseType each : IntegrateTestEnvironment.getInstance().getDatabaseTypes()) {
createSchema(each);
}
}

/**
* Create a database.
*/
Expand Down Expand Up @@ -171,6 +162,15 @@ public static synchronized void dropDatabase() {
}
}

/**
* Initialize the database table.
*/
public static synchronized void createTable() {
for (DatabaseType each : IntegrateTestEnvironment.getInstance().getDatabaseTypes()) {
createSchema(each);
}
}

private static void createSchema(final DatabaseType dbType) {
createShardingSchema(dbType);
}
Expand All @@ -191,15 +191,12 @@ private static void createShardingSchema(final DatabaseType dbType) {
for (String tableSqlId : tableSqlIds) {
tableSqls.add(SQLCasesLoader.getInstance().getSchemaSQLCaseMap(tableSqlId));
}

sr = new StringReader(StringUtils.join(tableSqls, ";\n"));

resultSet = RunScript.execute(conn, sr);
}
}

} catch (SQLException | ParserConfigurationException | IOException | XPathExpressionException | SAXException e) {
e.printStackTrace();
} catch (final SQLException | ParserConfigurationException | IOException | XPathExpressionException | SAXException ex) {
ex.printStackTrace();
} finally {
if (sr != null) {
sr.close();
Expand Down Expand Up @@ -243,7 +240,7 @@ private static void createShardingSchema(final DatabaseType dbType, final String

for (String each : DATABASES) {
if (dbname != null) {
if (each != dbname) {
if (!each.equals(dbname)) {
continue;
}
}
Expand All @@ -253,15 +250,12 @@ private static void createShardingSchema(final DatabaseType dbType, final String
conn = initialConnection(database, dbType);
List<String> tableSqls = new ArrayList<>();
tableSqls.add(SQLCasesLoader.getInstance().getSchemaSQLCaseMap(sqlId));

sr = new StringReader(StringUtils.join(tableSqls, ";\n"));

resultSet = RunScript.execute(conn, sr);
}
}

} catch (SQLException | ParserConfigurationException | IOException | XPathExpressionException | SAXException e) {
e.printStackTrace();
} catch (final SQLException | ParserConfigurationException | IOException | XPathExpressionException | SAXException ex) {
ex.printStackTrace();
} finally {
if (sr != null) {
sr.close();
Expand Down Expand Up @@ -290,7 +284,7 @@ private static void dropShardingSchema(final DatabaseType dbType, final String s
try {
for (String each : DATABASES) {
if (dbname != null) {
if (each != dbname) {
if (!each.equals(dbname)) {
continue;
}
}
Expand Down Expand Up @@ -384,17 +378,16 @@ public static List<DatabaseType> getDatabaseTypes(final String typeStrs) {
if (StringUtils.isBlank(typeStrs)) {
return Arrays.asList(DatabaseType.values());
}

String[] types = StringUtils.split(typeStrs, ",");
List<DatabaseType> databaseTypes = new ArrayList<>();
List<DatabaseType> result = new ArrayList<>();
for (String eachType : types) {
DatabaseType[] databaseTypeSrcs = DatabaseType.values();
for (DatabaseType each : databaseTypeSrcs) {
if (eachType.equalsIgnoreCase(each.name())) {
databaseTypes.add(each);
result.add(each);
}
}
}
return databaseTypes;
return result;
}
}

0 comments on commit bc7e6ad

Please sign in to comment.