From 6f7fdc14c0a875e6a0f493fd0e555c445a164057 Mon Sep 17 00:00:00 2001 From: terrymanu Date: Fri, 4 May 2018 18:43:46 +0800 Subject: [PATCH] for #601: remove initialConnection --- .../dbtest/asserts/AssertEngine.java | 2 +- .../init/DatabaseEnvironmentManager.java | 23 ++++++------------- 2 files changed, 8 insertions(+), 17 deletions(-) diff --git a/sharding-jdbc-core/src/test/java/io/shardingjdbc/dbtest/asserts/AssertEngine.java b/sharding-jdbc-core/src/test/java/io/shardingjdbc/dbtest/asserts/AssertEngine.java index c333a727642c7..265651f97b179 100644 --- a/sharding-jdbc-core/src/test/java/io/shardingjdbc/dbtest/asserts/AssertEngine.java +++ b/sharding-jdbc-core/src/test/java/io/shardingjdbc/dbtest/asserts/AssertEngine.java @@ -106,7 +106,7 @@ private static void onlyDatabaseRun(final String dbName, final String path, fina for (DatabaseType each : IntegrateTestEnvironment.getInstance().getDatabaseTypes()) { Map dataSourceMaps = new HashMap<>(); for (String db : dbs) { - DataSource subDataSource = DatabaseEnvironmentManager.buildDataSource(db, each); + DataSource subDataSource = DatabaseEnvironmentManager.createDataSource(db, each); dataSourceMaps.put(db, subDataSource); } if ("true".equals(assertsDefinition.getMasterslave())) { diff --git a/sharding-jdbc-core/src/test/java/io/shardingjdbc/dbtest/init/DatabaseEnvironmentManager.java b/sharding-jdbc-core/src/test/java/io/shardingjdbc/dbtest/init/DatabaseEnvironmentManager.java index 797f472138dc0..babb32464ec6f 100644 --- a/sharding-jdbc-core/src/test/java/io/shardingjdbc/dbtest/init/DatabaseEnvironmentManager.java +++ b/sharding-jdbc-core/src/test/java/io/shardingjdbc/dbtest/init/DatabaseEnvironmentManager.java @@ -85,7 +85,7 @@ public static void createDatabase() throws JAXBException, SQLException, IOExcept continue; } try ( - Connection conn = initialConnection(null, each); + Connection conn = createDataSource(null, each).getConnection(); StringReader stringReader = new StringReader(Joiner.on("\n").skipNulls().join(generateCreateDatabaseSQLs(each, databaseInitialization.getDatabases())))) { ResultSet resultSet = RunScript.execute(conn, stringReader); resultSet.close(); @@ -110,11 +110,7 @@ private static Collection generateCreateDatabaseSQLs(final DatabaseType return result; } - private static Connection initialConnection(final String dbName, final DatabaseType type) throws SQLException { - return buildDataSource(dbName, type).getConnection(); - } - - public static DataSource buildDataSource(final String dbName, final DatabaseType type) { + public static DataSource createDataSource(final String dbName, final DatabaseType type) { BasicDataSource result = new BasicDataSource(); DatabaseEnvironment dbEnv = new DatabaseEnvironment(type); result.setDriverClassName(dbEnv.getDriverClassName()); @@ -147,14 +143,12 @@ public static synchronized void dropDatabase() { String oracleSql = getDropTableSql(DatabaseType.Oracle, AnalyzeDatabase.analyze(DatabaseEnvironmentManager.class.getClassLoader() .getResource("integrate/dbtest").getPath() + "/" + database + "/database.xml")); sr = new StringReader(oracleSql); - conn = initialConnection(null, each); - + conn = createDataSource(null, each).getConnection(); resultSet = RunScript.execute(conn, sr); } else { sr = new StringReader(sql); - conn = initialConnection(null, each); - + conn = createDataSource(null, each).getConnection(); resultSet = RunScript.execute(conn, sr); } } @@ -204,7 +198,7 @@ private static void createShardingSchema(final DatabaseType dbType) { List databases = AnalyzeDatabase.analyze(DatabaseEnvironmentManager.class.getClassLoader() .getResource("integrate/dbtest").getPath() + "/" + each + "/database.xml"); for (String database : databases) { - conn = initialConnection(database, dbType); + conn = createDataSource(database, dbType).getConnection(); List tableSqlIds = AnalyzeSql.analyze(DatabaseEnvironmentManager.class.getClassLoader() .getResource("integrate/dbtest").getPath() + "/" + each + "/table/create-table.xml"); List tableSqls = new ArrayList<>(); @@ -257,7 +251,6 @@ private static void createShardingSchema(final DatabaseType dbType, final String ResultSet resultSet = null; StringReader sr = null; try { - for (String each : DATABASES) { if (dbname != null) { if (!each.equals(dbname)) { @@ -267,7 +260,7 @@ private static void createShardingSchema(final DatabaseType dbType, final String List databases = AnalyzeDatabase.analyze(DatabaseEnvironmentManager.class.getClassLoader() .getResource("integrate/dbtest").getPath() + "/" + each + "/database.xml"); for (String database : databases) { - conn = initialConnection(database, dbType); + conn = createDataSource(database, dbType).getConnection(); List tableSqls = new ArrayList<>(); tableSqls.add(SQLCasesLoader.getInstance().getSchemaSQLCaseMap(sqlId)); sr = new StringReader(StringUtils.join(tableSqls, ";\n")); @@ -311,12 +304,10 @@ private static void dropShardingSchema(final DatabaseType dbType, final String s List databases = AnalyzeDatabase.analyze(DatabaseEnvironmentManager.class.getClassLoader() .getResource("integrate/dbtest").getPath() + "/" + each + "/database.xml"); for (String database : databases) { - conn = initialConnection(database, dbType); + conn = createDataSource(database, dbType).getConnection(); List tableSqls = new ArrayList<>(); tableSqls.add(SQLCasesLoader.getInstance().getSchemaSQLCaseMap(sqlId)); - sr = new StringReader(StringUtils.join(tableSqls, ";\n")); - resultSet = RunScript.execute(conn, sr); } }