Loading sharding-jdbc/src/test/java/io/shardingsphere/dbtest/engine/DDLIntegrateTest.java +1 −1 Original line number Diff line number Diff line Loading @@ -92,7 +92,7 @@ public final class DDLIntegrateTest extends BaseIntegrateTest { @Before public void insertData() throws SQLException, ParseException { if (getDatabaseTypeEnvironment().isEnabled()) { getDataSetEnvironmentManager().initialize(false); getDataSetEnvironmentManager().initialize(); } } Loading sharding-jdbc/src/test/java/io/shardingsphere/dbtest/engine/DMLIntegrateTest.java +1 −1 Original line number Diff line number Diff line Loading @@ -100,7 +100,7 @@ public final class DMLIntegrateTest extends BaseIntegrateTest { @Before public void insertData() throws SQLException, ParseException { if (getDatabaseTypeEnvironment().isEnabled()) { getDataSetEnvironmentManager().initialize(true); getDataSetEnvironmentManager().initialize(); } } Loading sharding-jdbc/src/test/java/io/shardingsphere/dbtest/engine/DQLIntegrateTest.java +1 −1 Original line number Diff line number Diff line Loading @@ -108,7 +108,7 @@ public final class DQLIntegrateTest extends BaseIntegrateTest { continue; } for (String shardingRuleType : integrateTestCasesLoader.getShardingRuleTypes()) { new DataSetEnvironmentManager(EnvironmentPath.getDataInitializeResourceFile(shardingRuleType), createDataSourceMap(each, shardingRuleType)).initialize(false); new DataSetEnvironmentManager(EnvironmentPath.getDataInitializeResourceFile(shardingRuleType), createDataSourceMap(each, shardingRuleType)).initialize(); } } } Loading sharding-jdbc/src/test/java/io/shardingsphere/dbtest/env/dataset/DataSetEnvironmentManager.java +3 −22 Original line number Diff line number Diff line Loading @@ -34,7 +34,6 @@ import java.io.FileReader; import java.io.IOException; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.text.ParseException; import java.util.Collection; Loading Loading @@ -65,14 +64,11 @@ public final class DataSetEnvironmentManager { /** * Initialize data. * * @param forceInsert force insert * @throws SQLException SQL exception * @throws ParseException parse exception */ public void initialize(final boolean forceInsert) throws SQLException, ParseException { if (forceInsert) { public void initialize() throws SQLException, ParseException { clear(); } Map<DataNode, List<DataSetRow>> dataNodeListMap = getDataSetRowMap(); for (Entry<DataNode, List<DataSetRow>> entry : dataNodeListMap.entrySet()) { DataNode dataNode = entry.getKey(); Loading @@ -84,12 +80,10 @@ public final class DataSetEnvironmentManager { sqlValueGroups.add(new SQLValueGroup(dataSetMetadata, row.getValues())); } try (Connection connection = dataSourceMap.get(dataNode.getDataSourceName()).getConnection()) { if (forceInsert || !isExisted(dataNode, connection)) { executeBatch(connection, insertSQL, sqlValueGroups); } } } } private Map<DataNode, List<DataSetRow>> getDataSetRowMap() { Map<DataNode, List<DataSetRow>> result = new LinkedHashMap<>(); Loading @@ -113,19 +107,6 @@ public final class DataSetEnvironmentManager { return String.format("INSERT INTO %s (%s) VALUES (%s)", tableName, Joiner.on(",").join(columnNames), Joiner.on(",").join(placeholders)); } private boolean isExisted(final DataNode dataNode, final Connection connection) throws SQLException { int count = 0; try ( PreparedStatement preparedStatement = connection.prepareStatement(String.format("SELECT COUNT(*) FROM %s", dataNode.getTableName())); ResultSet resultSet = preparedStatement.executeQuery()) { if (resultSet.next()) { count = resultSet.getInt(1); } } return 0 != count; } private void executeBatch(final Connection connection, final String sql, final List<SQLValueGroup> sqlValueGroups) throws SQLException { try (PreparedStatement preparedStatement = connection.prepareStatement(sql)) { for (SQLValueGroup each : sqlValueGroups) { Loading Loading
sharding-jdbc/src/test/java/io/shardingsphere/dbtest/engine/DDLIntegrateTest.java +1 −1 Original line number Diff line number Diff line Loading @@ -92,7 +92,7 @@ public final class DDLIntegrateTest extends BaseIntegrateTest { @Before public void insertData() throws SQLException, ParseException { if (getDatabaseTypeEnvironment().isEnabled()) { getDataSetEnvironmentManager().initialize(false); getDataSetEnvironmentManager().initialize(); } } Loading
sharding-jdbc/src/test/java/io/shardingsphere/dbtest/engine/DMLIntegrateTest.java +1 −1 Original line number Diff line number Diff line Loading @@ -100,7 +100,7 @@ public final class DMLIntegrateTest extends BaseIntegrateTest { @Before public void insertData() throws SQLException, ParseException { if (getDatabaseTypeEnvironment().isEnabled()) { getDataSetEnvironmentManager().initialize(true); getDataSetEnvironmentManager().initialize(); } } Loading
sharding-jdbc/src/test/java/io/shardingsphere/dbtest/engine/DQLIntegrateTest.java +1 −1 Original line number Diff line number Diff line Loading @@ -108,7 +108,7 @@ public final class DQLIntegrateTest extends BaseIntegrateTest { continue; } for (String shardingRuleType : integrateTestCasesLoader.getShardingRuleTypes()) { new DataSetEnvironmentManager(EnvironmentPath.getDataInitializeResourceFile(shardingRuleType), createDataSourceMap(each, shardingRuleType)).initialize(false); new DataSetEnvironmentManager(EnvironmentPath.getDataInitializeResourceFile(shardingRuleType), createDataSourceMap(each, shardingRuleType)).initialize(); } } } Loading
sharding-jdbc/src/test/java/io/shardingsphere/dbtest/env/dataset/DataSetEnvironmentManager.java +3 −22 Original line number Diff line number Diff line Loading @@ -34,7 +34,6 @@ import java.io.FileReader; import java.io.IOException; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.text.ParseException; import java.util.Collection; Loading Loading @@ -65,14 +64,11 @@ public final class DataSetEnvironmentManager { /** * Initialize data. * * @param forceInsert force insert * @throws SQLException SQL exception * @throws ParseException parse exception */ public void initialize(final boolean forceInsert) throws SQLException, ParseException { if (forceInsert) { public void initialize() throws SQLException, ParseException { clear(); } Map<DataNode, List<DataSetRow>> dataNodeListMap = getDataSetRowMap(); for (Entry<DataNode, List<DataSetRow>> entry : dataNodeListMap.entrySet()) { DataNode dataNode = entry.getKey(); Loading @@ -84,12 +80,10 @@ public final class DataSetEnvironmentManager { sqlValueGroups.add(new SQLValueGroup(dataSetMetadata, row.getValues())); } try (Connection connection = dataSourceMap.get(dataNode.getDataSourceName()).getConnection()) { if (forceInsert || !isExisted(dataNode, connection)) { executeBatch(connection, insertSQL, sqlValueGroups); } } } } private Map<DataNode, List<DataSetRow>> getDataSetRowMap() { Map<DataNode, List<DataSetRow>> result = new LinkedHashMap<>(); Loading @@ -113,19 +107,6 @@ public final class DataSetEnvironmentManager { return String.format("INSERT INTO %s (%s) VALUES (%s)", tableName, Joiner.on(",").join(columnNames), Joiner.on(",").join(placeholders)); } private boolean isExisted(final DataNode dataNode, final Connection connection) throws SQLException { int count = 0; try ( PreparedStatement preparedStatement = connection.prepareStatement(String.format("SELECT COUNT(*) FROM %s", dataNode.getTableName())); ResultSet resultSet = preparedStatement.executeQuery()) { if (resultSet.next()) { count = resultSet.getInt(1); } } return 0 != count; } private void executeBatch(final Connection connection, final String sql, final List<SQLValueGroup> sqlValueGroups) throws SQLException { try (PreparedStatement preparedStatement = connection.prepareStatement(sql)) { for (SQLValueGroup each : sqlValueGroups) { Loading