diff --git a/sharding-jdbc-core/src/test/java/io/shardingjdbc/dbtest/StartTest.java b/sharding-jdbc-core/src/test/java/io/shardingjdbc/dbtest/StartTest.java index 63e1a7ee74234..c09caea41c96d 100644 --- a/sharding-jdbc-core/src/test/java/io/shardingjdbc/dbtest/StartTest.java +++ b/sharding-jdbc-core/src/test/java/io/shardingjdbc/dbtest/StartTest.java @@ -78,16 +78,12 @@ public static Collection getParameters() { InItCreateSchema.addDatabase(db); } } - List assertDQLs = assertsDefinition.getAssertDQL(); collateData(RESULT_ASSERT, each, assertDQLs); - List assertDMLs = assertsDefinition.getAssertDML(); collateData(RESULT_ASSERT, each, assertDMLs); - List assertDDLs = assertsDefinition.getAssertDDL(); collateData(RESULT_ASSERT, each, assertDDLs); - AssertEngine.addAssertDefinition(each, assertsDefinition); } } catch (JAXBException | IOException e) { 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 201bbf97bb731..ba85d7d0f67ec 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 @@ -20,9 +20,7 @@ import io.shardingjdbc.core.api.MasterSlaveDataSourceFactory; import io.shardingjdbc.core.api.ShardingDataSourceFactory; import io.shardingjdbc.core.constant.DatabaseType; -import io.shardingjdbc.core.jdbc.core.ShardingContext; import io.shardingjdbc.core.jdbc.core.datasource.ShardingDataSource; -import io.shardingjdbc.core.rule.ShardingRule; import io.shardingjdbc.dbtest.common.DatabaseUtil; import io.shardingjdbc.dbtest.common.PathUtil; import io.shardingjdbc.dbtest.config.AnalyzeDataset; @@ -47,7 +45,6 @@ import javax.xml.xpath.XPathExpressionException; import java.io.File; import java.io.IOException; -import java.lang.reflect.Field; import java.sql.Connection; import java.sql.SQLException; import java.text.ParseException; @@ -196,27 +193,18 @@ private static void ddlRun(final DatabaseType databaseType, final String id, fin if (anAssert.getParameter().getValues().isEmpty() && anAssert.getParameter().getValueReplaces().isEmpty()) { List subAsserts = anAssert.getSubAsserts(); if (subAsserts.isEmpty()) { - doUpdateUseStatementToExecuteUpdateDDL(rootPath, databaseType, dbName, expectedDataFile, dataSource, anAssert, rootsql, msg); - - doUpdateUseStatementToExecuteDDL(rootPath, databaseType, dbName, expectedDataFile, dataSource, anAssert, rootsql, msg); - - doUpdateUsePreparedStatementToExecuteUpdateDDL(rootPath, databaseType, dbName, expectedDataFile, dataSource, anAssert, rootsql, msg); - - doUpdateUsePreparedStatementToExecuteDDL(rootPath, databaseType, dbName, expectedDataFile, dataSource, anAssert, rootsql, msg); + doUpdateUseStatementToExecuteUpdateDDL(databaseType, dbName, expectedDataFile, dataSource, anAssert, rootsql, msg); + doUpdateUseStatementToExecuteDDL(databaseType, dbName, expectedDataFile, dataSource, anAssert, rootsql, msg); + doUpdateUsePreparedStatementToExecuteUpdateDDL(databaseType, dbName, expectedDataFile, dataSource, anAssert, rootsql, msg); + doUpdateUsePreparedStatementToExecuteDDL(databaseType, dbName, expectedDataFile, dataSource, anAssert, rootsql, msg); } else { - ddlSubRun(databaseType, dbName, rootPath, msg, dataSource, anAssert, rootsql, expectedDataFile, subAsserts); } - } else { - doUpdateUseStatementToExecuteUpdateDDL(rootPath, databaseType, dbName, expectedDataFile, dataSource, anAssert, rootsql, msg); - - doUpdateUseStatementToExecuteDDL(rootPath, databaseType, dbName, expectedDataFile, dataSource, anAssert, rootsql, msg); - - doUpdateUsePreparedStatementToExecuteUpdateDDL(rootPath, databaseType, dbName, expectedDataFile, dataSource, anAssert, rootsql, msg); - - doUpdateUsePreparedStatementToExecuteDDL(rootPath, databaseType, dbName, expectedDataFile, dataSource, anAssert, rootsql, msg); - + doUpdateUseStatementToExecuteUpdateDDL(databaseType, dbName, expectedDataFile, dataSource, anAssert, rootsql, msg); + doUpdateUseStatementToExecuteDDL(databaseType, dbName, expectedDataFile, dataSource, anAssert, rootsql, msg); + doUpdateUsePreparedStatementToExecuteUpdateDDL(databaseType, dbName, expectedDataFile, dataSource, anAssert, rootsql, msg); + doUpdateUsePreparedStatementToExecuteDDL(databaseType, dbName, expectedDataFile, dataSource, anAssert, rootsql, msg); List subAsserts = anAssert.getSubAsserts(); if (!subAsserts.isEmpty()) { ddlSubRun(databaseType, dbName, rootPath, msg, dataSource, anAssert, rootsql, expectedDataFile, subAsserts); @@ -268,14 +256,10 @@ private static void ddlSubRun(final DatabaseType databaseType, final String dbNa anAssert.getBaseConfig(), anAssert.getCleanSql(), expectedDataFileSub, anAssert.getDatabaseConfig(), anAssert.getSql(), anAssert.getTable(), parameter, anAssert.getSubAsserts()); - - doUpdateUseStatementToExecuteUpdateDDL(rootPath, databaseType, dbName, expectedDataFileTmp, dataSource, anAssertSub, rootsql, msg); - - doUpdateUseStatementToExecuteDDL(rootPath, databaseType, dbName, expectedDataFileTmp, dataSource, anAssertSub, rootsql, msg); - - doUpdateUsePreparedStatementToExecuteUpdateDDL(rootPath, databaseType, dbName, expectedDataFileTmp, dataSource, anAssertSub, rootsql, msg); - - doUpdateUsePreparedStatementToExecuteDDL(rootPath, databaseType, dbName, expectedDataFileTmp, dataSource, anAssertSub, rootsql, msg); + doUpdateUseStatementToExecuteUpdateDDL(databaseType, dbName, expectedDataFileTmp, dataSource, anAssertSub, rootsql, msg); + doUpdateUseStatementToExecuteDDL(databaseType, dbName, expectedDataFileTmp, dataSource, anAssertSub, rootsql, msg); + doUpdateUsePreparedStatementToExecuteUpdateDDL(databaseType, dbName, expectedDataFileTmp, dataSource, anAssertSub, rootsql, msg); + doUpdateUsePreparedStatementToExecuteDDL(databaseType, dbName, expectedDataFileTmp, dataSource, anAssertSub, rootsql, msg); } } @@ -286,7 +270,6 @@ private static void dmlRun(final DatabaseType databaseType, final String initDat if (!databaseTypes.contains(databaseType)) { break; } - AssertDMLDefinition anAssert = each; String baseConfig = anAssert.getBaseConfig(); if (StringUtils.isNotBlank(baseConfig)) { @@ -327,19 +310,13 @@ private static void dmlRun(final DatabaseType databaseType, final String initDat if (anAssert.getParameter().getValues().isEmpty() && anAssert.getParameter().getValueReplaces().isEmpty()) { List subAsserts = anAssert.getSubAsserts(); if (subAsserts.isEmpty()) { - resultDoUpdateUseStatementToExecuteUpdate = resultDoUpdateUseStatementToExecuteUpdate + doUpdateUseStatementToExecuteUpdate(rootPath, expectedDataFile, dataSource, dataSourceMaps, anAssert, rootsql, mapDatasetDefinition, sqls, msg); - - resultDoUpdateUseStatementToExecute = resultDoUpdateUseStatementToExecute + doUpdateUseStatementToExecute(rootPath, expectedDataFile, dataSource, dataSourceMaps, anAssert, rootsql, mapDatasetDefinition, sqls, msg); - - resultDoUpdateUsePreparedStatementToExecuteUpdate = resultDoUpdateUsePreparedStatementToExecuteUpdate + doUpdateUsePreparedStatementToExecuteUpdate(rootPath, expectedDataFile, dataSource, dataSourceMaps, anAssert, rootsql, mapDatasetDefinition, sqls, msg); - - resultDoUpdateUsePreparedStatementToExecute = resultDoUpdateUsePreparedStatementToExecute + doUpdateUsePreparedStatementToExecute(rootPath, expectedDataFile, dataSource, dataSourceMaps, anAssert, rootsql, mapDatasetDefinition, sqls, msg); - - + resultDoUpdateUseStatementToExecuteUpdate = resultDoUpdateUseStatementToExecuteUpdate + doUpdateUseStatementToExecuteUpdate(expectedDataFile, dataSource, dataSourceMaps, anAssert, rootsql, mapDatasetDefinition, sqls, msg); + resultDoUpdateUseStatementToExecute = resultDoUpdateUseStatementToExecute + doUpdateUseStatementToExecute(expectedDataFile, dataSource, dataSourceMaps, anAssert, rootsql, mapDatasetDefinition, sqls, msg); + resultDoUpdateUsePreparedStatementToExecuteUpdate = resultDoUpdateUsePreparedStatementToExecuteUpdate + doUpdateUsePreparedStatementToExecuteUpdate(expectedDataFile, dataSource, dataSourceMaps, anAssert, rootsql, mapDatasetDefinition, sqls, msg); + resultDoUpdateUsePreparedStatementToExecute = resultDoUpdateUsePreparedStatementToExecute + doUpdateUsePreparedStatementToExecute(expectedDataFile, dataSource, dataSourceMaps, anAssert, rootsql, mapDatasetDefinition, sqls, msg); } else { for (AssertSubDefinition subAssert : subAsserts) { List databaseSubTypes = InItCreateSchema.getDatabaseTypes(subAssert.getDatabaseConfig()); - if (!databaseSubTypes.contains(databaseType)) { break; } @@ -379,31 +356,21 @@ private static void dmlRun(final DatabaseType databaseType, final String initDat AssertDMLDefinition anAssertSub = new AssertDMLDefinition(anAssert.getId(), expectedDataFileSub, anAssert.getBaseConfig(), subAssert.getExpectedUpdate(), anAssert.getDatabaseConfig(), anAssert.getSql(), anAssert.getExpectedSql(), parameter, expectedParameter, anAssert.getSubAsserts()); - - resultDoUpdateUseStatementToExecuteUpdate = resultDoUpdateUseStatementToExecuteUpdate + doUpdateUseStatementToExecuteUpdate(rootPath, expectedDataFileTmp, dataSource, dataSourceMaps, anAssertSub, rootsql, mapDatasetDefinition, sqls, msg); - - resultDoUpdateUseStatementToExecute = resultDoUpdateUseStatementToExecute + doUpdateUseStatementToExecute(rootPath, expectedDataFileTmp, dataSource, dataSourceMaps, anAssertSub, rootsql, mapDatasetDefinition, sqls, msg); - - resultDoUpdateUsePreparedStatementToExecuteUpdate = resultDoUpdateUsePreparedStatementToExecuteUpdate + doUpdateUsePreparedStatementToExecuteUpdate(rootPath, expectedDataFileTmp, dataSource, dataSourceMaps, anAssertSub, rootsql, mapDatasetDefinition, sqls, msg); - - resultDoUpdateUsePreparedStatementToExecute = resultDoUpdateUsePreparedStatementToExecute + doUpdateUsePreparedStatementToExecute(rootPath, expectedDataFileTmp, dataSource, dataSourceMaps, anAssertSub, rootsql, mapDatasetDefinition, sqls, msg); + resultDoUpdateUseStatementToExecuteUpdate = resultDoUpdateUseStatementToExecuteUpdate + doUpdateUseStatementToExecuteUpdate(expectedDataFileTmp, dataSource, dataSourceMaps, anAssertSub, rootsql, mapDatasetDefinition, sqls, msg); + resultDoUpdateUseStatementToExecute = resultDoUpdateUseStatementToExecute + doUpdateUseStatementToExecute(expectedDataFileTmp, dataSource, dataSourceMaps, anAssertSub, rootsql, mapDatasetDefinition, sqls, msg); + resultDoUpdateUsePreparedStatementToExecuteUpdate = resultDoUpdateUsePreparedStatementToExecuteUpdate + doUpdateUsePreparedStatementToExecuteUpdate(expectedDataFileTmp, dataSource, dataSourceMaps, anAssertSub, rootsql, mapDatasetDefinition, sqls, msg); + resultDoUpdateUsePreparedStatementToExecute = resultDoUpdateUsePreparedStatementToExecute + doUpdateUsePreparedStatementToExecute(expectedDataFileTmp, dataSource, dataSourceMaps, anAssertSub, rootsql, mapDatasetDefinition, sqls, msg); } } - } else { - resultDoUpdateUseStatementToExecuteUpdate = resultDoUpdateUseStatementToExecuteUpdate + doUpdateUseStatementToExecuteUpdate(rootPath, expectedDataFile, dataSource, dataSourceMaps, anAssert, rootsql, mapDatasetDefinition, sqls, msg); - - resultDoUpdateUseStatementToExecute = resultDoUpdateUseStatementToExecute + doUpdateUseStatementToExecute(rootPath, expectedDataFile, dataSource, dataSourceMaps, anAssert, rootsql, mapDatasetDefinition, sqls, msg); - - resultDoUpdateUsePreparedStatementToExecuteUpdate = resultDoUpdateUsePreparedStatementToExecuteUpdate + doUpdateUsePreparedStatementToExecuteUpdate(rootPath, expectedDataFile, dataSource, dataSourceMaps, anAssert, rootsql, mapDatasetDefinition, sqls, msg); - - resultDoUpdateUsePreparedStatementToExecute = resultDoUpdateUsePreparedStatementToExecute + doUpdateUsePreparedStatementToExecute(rootPath, expectedDataFile, dataSource, dataSourceMaps, anAssert, rootsql, mapDatasetDefinition, sqls, msg); - + resultDoUpdateUseStatementToExecuteUpdate = resultDoUpdateUseStatementToExecuteUpdate + doUpdateUseStatementToExecuteUpdate(expectedDataFile, dataSource, dataSourceMaps, anAssert, rootsql, mapDatasetDefinition, sqls, msg); + resultDoUpdateUseStatementToExecute = resultDoUpdateUseStatementToExecute + doUpdateUseStatementToExecute(expectedDataFile, dataSource, dataSourceMaps, anAssert, rootsql, mapDatasetDefinition, sqls, msg); + resultDoUpdateUsePreparedStatementToExecuteUpdate = resultDoUpdateUsePreparedStatementToExecuteUpdate + doUpdateUsePreparedStatementToExecuteUpdate(expectedDataFile, dataSource, dataSourceMaps, anAssert, rootsql, mapDatasetDefinition, sqls, msg); + resultDoUpdateUsePreparedStatementToExecute = resultDoUpdateUsePreparedStatementToExecute + doUpdateUsePreparedStatementToExecute(expectedDataFile, dataSource, dataSourceMaps, anAssert, rootsql, mapDatasetDefinition, sqls, msg); List subAsserts = anAssert.getSubAsserts(); if (!subAsserts.isEmpty()) { for (AssertSubDefinition subAssert : subAsserts) { List databaseSubTypes = InItCreateSchema.getDatabaseTypes(subAssert.getDatabaseConfig()); - if (!databaseSubTypes.contains(databaseType)) { break; } @@ -443,14 +410,10 @@ private static void dmlRun(final DatabaseType databaseType, final String initDat AssertDMLDefinition anAssertSub = new AssertDMLDefinition(anAssert.getId(), expectedDataFileSub, anAssert.getBaseConfig(), subAssert.getExpectedUpdate(), anAssert.getDatabaseConfig(), anAssert.getSql(), anAssert.getExpectedSql(), parameter, expectedParameter, anAssert.getSubAsserts()); - - resultDoUpdateUseStatementToExecuteUpdate = resultDoUpdateUseStatementToExecuteUpdate + doUpdateUseStatementToExecuteUpdate(rootPath, expectedDataFileTmp, dataSource, dataSourceMaps, anAssertSub, rootsql, mapDatasetDefinition, sqls, msg); - - resultDoUpdateUseStatementToExecute = resultDoUpdateUseStatementToExecute + doUpdateUseStatementToExecute(rootPath, expectedDataFileTmp, dataSource, dataSourceMaps, anAssertSub, rootsql, mapDatasetDefinition, sqls, msg); - - resultDoUpdateUsePreparedStatementToExecuteUpdate = resultDoUpdateUsePreparedStatementToExecuteUpdate + doUpdateUsePreparedStatementToExecuteUpdate(rootPath, expectedDataFileTmp, dataSource, dataSourceMaps, anAssertSub, rootsql, mapDatasetDefinition, sqls, msg); - - resultDoUpdateUsePreparedStatementToExecute = resultDoUpdateUsePreparedStatementToExecute + doUpdateUsePreparedStatementToExecute(rootPath, expectedDataFileTmp, dataSource, dataSourceMaps, anAssertSub, rootsql, mapDatasetDefinition, sqls, msg); + resultDoUpdateUseStatementToExecuteUpdate = resultDoUpdateUseStatementToExecuteUpdate + doUpdateUseStatementToExecuteUpdate(expectedDataFileTmp, dataSource, dataSourceMaps, anAssertSub, rootsql, mapDatasetDefinition, sqls, msg); + resultDoUpdateUseStatementToExecute = resultDoUpdateUseStatementToExecute + doUpdateUseStatementToExecute(expectedDataFileTmp, dataSource, dataSourceMaps, anAssertSub, rootsql, mapDatasetDefinition, sqls, msg); + resultDoUpdateUsePreparedStatementToExecuteUpdate = resultDoUpdateUsePreparedStatementToExecuteUpdate + doUpdateUsePreparedStatementToExecuteUpdate(expectedDataFileTmp, dataSource, dataSourceMaps, anAssertSub, rootsql, mapDatasetDefinition, sqls, msg); + resultDoUpdateUsePreparedStatementToExecute = resultDoUpdateUsePreparedStatementToExecute + doUpdateUsePreparedStatementToExecute(expectedDataFileTmp, dataSource, dataSourceMaps, anAssertSub, rootsql, mapDatasetDefinition, sqls, msg); } } } @@ -461,7 +424,6 @@ private static void dmlRun(final DatabaseType databaseType, final String initDat Assert.assertEquals("Update row number error UpdateUsePreparedStatementToExecute" + msg, anAssert.getExpectedUpdate().intValue(), resultDoUpdateUsePreparedStatementToExecute); } break; - } } } @@ -516,19 +478,19 @@ private static void dqlRun(final DatabaseType databaseType, final String initDat if (anAssert.getParameter().getValues().isEmpty() && anAssert.getParameter().getValueReplaces().isEmpty()) { List subAsserts = anAssert.getSubAsserts(); if (subAsserts.isEmpty()) { - doSelectUsePreparedStatement(rootPath, expectedDataFile, dataSource, anAssert, rootsql, msg); - doSelectUsePreparedStatementToExecuteSelect(rootPath, expectedDataFile, dataSource, anAssert, rootsql, msg); - doSelectUseStatement(rootPath, expectedDataFile, dataSource, anAssert, rootsql, msg); - doSelectUseStatementToExecuteSelect(rootPath, expectedDataFile, dataSource, anAssert, rootsql, msg); + doSelectUsePreparedStatement(expectedDataFile, dataSource, anAssert, rootsql, msg); + doSelectUsePreparedStatementToExecuteSelect(expectedDataFile, dataSource, anAssert, rootsql, msg); + doSelectUseStatement(expectedDataFile, dataSource, anAssert, rootsql, msg); + doSelectUseStatementToExecuteSelect(expectedDataFile, dataSource, anAssert, rootsql, msg); } else { dqlSubRun(databaseType, dbName, rootPath, msg, dataSource, anAssert, rootsql, expectedDataFile, subAsserts); } } else { - doSelectUsePreparedStatement(rootPath, expectedDataFile, dataSource, anAssert, rootsql, msg); - doSelectUsePreparedStatementToExecuteSelect(rootPath, expectedDataFile, dataSource, anAssert, rootsql, msg); - doSelectUseStatement(rootPath, expectedDataFile, dataSource, anAssert, rootsql, msg); - doSelectUseStatementToExecuteSelect(rootPath, expectedDataFile, dataSource, anAssert, rootsql, msg); + doSelectUsePreparedStatement(expectedDataFile, dataSource, anAssert, rootsql, msg); + doSelectUsePreparedStatementToExecuteSelect(expectedDataFile, dataSource, anAssert, rootsql, msg); + doSelectUseStatement(expectedDataFile, dataSource, anAssert, rootsql, msg); + doSelectUseStatementToExecuteSelect(expectedDataFile, dataSource, anAssert, rootsql, msg); List subAsserts = anAssert.getSubAsserts(); if (!subAsserts.isEmpty()) { @@ -584,26 +546,24 @@ private static void dqlSubRun(final DatabaseType databaseType, final String dbNa anAssert.getDatabaseConfig(), anAssert.getSql(), parameter, anAssert.getSubAsserts()); - doSelectUsePreparedStatement(rootPath, expectedDataFileTmp, dataSource, anAssertSub, rootsql, msg); - doSelectUsePreparedStatementToExecuteSelect(rootPath, expectedDataFileTmp, dataSource, anAssertSub, rootsql, msg); - doSelectUseStatement(rootPath, expectedDataFileTmp, dataSource, anAssertSub, rootsql, msg); - doSelectUseStatementToExecuteSelect(rootPath, expectedDataFileTmp, dataSource, anAssertSub, rootsql, msg); + doSelectUsePreparedStatement(expectedDataFileTmp, dataSource, anAssertSub, rootsql, msg); + doSelectUsePreparedStatementToExecuteSelect(expectedDataFileTmp, dataSource, anAssertSub, rootsql, msg); + doSelectUseStatement(expectedDataFileTmp, dataSource, anAssertSub, rootsql, msg); + doSelectUseStatementToExecuteSelect(expectedDataFileTmp, dataSource, anAssertSub, rootsql, msg); } } - private static int doUpdateUsePreparedStatementToExecute(final String rootPath, final String expectedDataFile, final DataSource dataSource, final Map dataSourceMaps, final AssertDMLDefinition anAssert, final String rootsql, final Map mapDatasetDefinition, final Map sqls, final String msg) throws SQLException, ParseException, IOException, SAXException, ParserConfigurationException, XPathExpressionException { + private static int doUpdateUsePreparedStatementToExecute(final String expectedDataFile, final DataSource dataSource, final Map dataSourceMaps, final AssertDMLDefinition anAssert, final String rootsql, final Map mapDatasetDefinition, final Map sqls, final String msg) throws SQLException, ParseException, IOException, SAXException, ParserConfigurationException, XPathExpressionException { try { initTableData(dataSourceMaps, sqls, mapDatasetDefinition); try (Connection con = dataSource.getConnection();) { int actual = DatabaseUtil.updateUsePreparedStatementToExecute(con, rootsql, anAssert.getParameter()); - //String expectedDataFile = PathUtil.getPath(anAssert.getExpectedDataFile(), rootPath); DatasetDefinition checkDataset = AnalyzeDataset.analyze(new File(expectedDataFile), "data"); if (anAssert.getExpectedUpdate() != null) { Assert.assertEquals("Update row number error", anAssert.getExpectedUpdate().intValue(), actual); } - String checksql = anAssert.getExpectedSql(); checksql = SQLCasesLoader.getInstance().getSupportedSQL(checksql); DatasetDatabase ddPreparedStatement = DatabaseUtil.selectUsePreparedStatement(con, checksql, @@ -616,7 +576,7 @@ private static int doUpdateUsePreparedStatementToExecute(final String rootPath, } } - private static void doUpdateUsePreparedStatementToExecuteDDL(final String rootPath, final DatabaseType databaseType, final String dbName, final String expectedDataFile, final DataSource dataSource, final AssertDDLDefinition anAssert, final String rootsql, final String msg) throws SQLException, ParseException, IOException, SAXException, ParserConfigurationException, XPathExpressionException { + private static void doUpdateUsePreparedStatementToExecuteDDL(final DatabaseType databaseType, final String dbName, final String expectedDataFile, final DataSource dataSource, final AssertDDLDefinition anAssert, final String rootsql, final String msg) throws SQLException, ParseException, IOException, SAXException, ParserConfigurationException, XPathExpressionException { try { try (Connection con = dataSource.getConnection()) { if (StringUtils.isNotBlank(anAssert.getCleanSql())) { @@ -627,7 +587,6 @@ private static void doUpdateUsePreparedStatementToExecuteDDL(final String rootPa } DatabaseUtil.updateUsePreparedStatementToExecute(con, rootsql, anAssert.getParameter()); - //String expectedDataFile = PathUtil.getPath(anAssert.getExpectedDataFile(), rootPath); DatasetDefinition checkDataset = AnalyzeDataset.analyze(new File(expectedDataFile), "data"); String table = anAssert.getTable(); @@ -644,13 +603,12 @@ private static void doUpdateUsePreparedStatementToExecuteDDL(final String rootPa } } - private static int doUpdateUsePreparedStatementToExecuteUpdate(final String rootPath, final String expectedDataFile, final DataSource dataSource, final Map dataSourceMaps, final AssertDMLDefinition anAssert, final String rootsql, final Map mapDatasetDefinition, final Map sqls, final String msg) throws SQLException, ParseException, IOException, SAXException, ParserConfigurationException, XPathExpressionException { + private static int doUpdateUsePreparedStatementToExecuteUpdate(final String expectedDataFile, final DataSource dataSource, final Map dataSourceMaps, final AssertDMLDefinition anAssert, final String rootsql, final Map mapDatasetDefinition, final Map sqls, final String msg) throws SQLException, ParseException, IOException, SAXException, ParserConfigurationException, XPathExpressionException { try { initTableData(dataSourceMaps, sqls, mapDatasetDefinition); try (Connection con = dataSource.getConnection();) { int actual = DatabaseUtil.updateUsePreparedStatementToExecuteUpdate(con, rootsql, anAssert.getParameter()); - //String expectedDataFile = PathUtil.getPath(anAssert.getExpectedDataFile(), rootPath); DatasetDefinition checkDataset = AnalyzeDataset.analyze(new File(expectedDataFile), "data"); if (anAssert.getExpectedUpdate() != null) { @@ -670,7 +628,7 @@ private static int doUpdateUsePreparedStatementToExecuteUpdate(final String root } } - private static void doUpdateUsePreparedStatementToExecuteUpdateDDL(final String rootPath, final DatabaseType databaseType, final String dbName, final String expectedDataFile, final DataSource dataSource, final AssertDDLDefinition anAssert, final String rootsql, final String msg) throws SQLException, ParseException, IOException, SAXException, ParserConfigurationException, XPathExpressionException { + private static void doUpdateUsePreparedStatementToExecuteUpdateDDL(final DatabaseType databaseType, final String dbName, final String expectedDataFile, final DataSource dataSource, final AssertDDLDefinition anAssert, final String rootsql, final String msg) throws SQLException, ParseException, IOException, SAXException, ParserConfigurationException, XPathExpressionException { try { try (Connection con = dataSource.getConnection()) { if (StringUtils.isNotBlank(anAssert.getCleanSql())) { @@ -681,10 +639,7 @@ private static void doUpdateUsePreparedStatementToExecuteUpdateDDL(final String } DatabaseUtil.updateUsePreparedStatementToExecuteUpdate(con, rootsql, anAssert.getParameter()); - //String expectedDataFile = PathUtil.getPath(anAssert.getExpectedDataFile(), rootPath); DatasetDefinition checkDataset = AnalyzeDataset.analyze(new File(expectedDataFile), "data"); - - String table = anAssert.getTable(); List columnDefinitions = DatabaseUtil.getColumnDefinitions(con, table); DatabaseUtil.assertConfigs(checkDataset, columnDefinitions, table, msg); @@ -699,20 +654,15 @@ private static void doUpdateUsePreparedStatementToExecuteUpdateDDL(final String } } - private static int doUpdateUseStatementToExecute(final String rootPath, final String expectedDataFile, final DataSource dataSource, final Map dataSourceMaps, final AssertDMLDefinition anAssert, final String rootsql, final Map mapDatasetDefinition, final Map sqls, final String msg) throws SQLException, ParseException, IOException, SAXException, ParserConfigurationException, XPathExpressionException { + private static int doUpdateUseStatementToExecute(final String expectedDataFile, final DataSource dataSource, final Map dataSourceMaps, final AssertDMLDefinition anAssert, final String rootsql, final Map mapDatasetDefinition, final Map sqls, final String msg) throws SQLException, ParseException, IOException, SAXException, ParserConfigurationException, XPathExpressionException { try { initTableData(dataSourceMaps, sqls, mapDatasetDefinition); try (Connection con = dataSource.getConnection();) { int actual = DatabaseUtil.updateUseStatementToExecute(con, rootsql, anAssert.getParameter()); - - //String expectedDataFile = PathUtil.getPath(anAssert.getExpectedDataFile(), rootPath); DatasetDefinition checkDataset = AnalyzeDataset.analyze(new File(expectedDataFile), "data"); - if (anAssert.getExpectedUpdate() != null) { Assert.assertEquals("Update row number error", anAssert.getExpectedUpdate().intValue(), actual); } - - String checksql = anAssert.getExpectedSql(); checksql = SQLCasesLoader.getInstance().getSupportedSQL(checksql); DatasetDatabase ddPreparedStatement = DatabaseUtil.selectUsePreparedStatement(con, checksql, @@ -725,7 +675,7 @@ private static int doUpdateUseStatementToExecute(final String rootPath, final St } } - private static void doUpdateUseStatementToExecuteDDL(final String rootPath, final DatabaseType databaseType, final String dbName, final String expectedDataFile, final DataSource dataSource, final AssertDDLDefinition anAssert, final String rootsql, final String msg) throws SQLException, ParseException, IOException, SAXException, ParserConfigurationException, XPathExpressionException { + private static void doUpdateUseStatementToExecuteDDL(final DatabaseType databaseType, final String dbName, final String expectedDataFile, final DataSource dataSource, final AssertDDLDefinition anAssert, final String rootsql, final String msg) throws SQLException, ParseException, IOException, SAXException, ParserConfigurationException, XPathExpressionException { try { try (Connection con = dataSource.getConnection()) { if (StringUtils.isNotBlank(anAssert.getCleanSql())) { @@ -735,10 +685,7 @@ private static void doUpdateUseStatementToExecuteDDL(final String rootPath, fina InItCreateSchema.createTable(databaseType, anAssert.getInitSql(), dbName); } DatabaseUtil.updateUseStatementToExecute(con, rootsql, anAssert.getParameter()); - - //String expectedDataFile = PathUtil.getPath(anAssert.getExpectedDataFile(), rootPath); DatasetDefinition checkDataset = AnalyzeDataset.analyze(new File(expectedDataFile), "data"); - String table = anAssert.getTable(); List columnDefinitions = DatabaseUtil.getColumnDefinitions(con, table); DatabaseUtil.assertConfigs(checkDataset, columnDefinitions, table, msg); @@ -753,19 +700,15 @@ private static void doUpdateUseStatementToExecuteDDL(final String rootPath, fina } } - private static int doUpdateUseStatementToExecuteUpdate(final String rootPath, final String expectedDataFile, final DataSource dataSource, final Map dataSourceMaps, final AssertDMLDefinition anAssert, final String rootsql, final Map mapDatasetDefinition, final Map sqls, final String msg) throws SQLException, ParseException, IOException, SAXException, ParserConfigurationException, XPathExpressionException { + private static int doUpdateUseStatementToExecuteUpdate(final String expectedDataFile, final DataSource dataSource, final Map dataSourceMaps, final AssertDMLDefinition anAssert, final String rootsql, final Map mapDatasetDefinition, final Map sqls, final String msg) throws SQLException, ParseException, IOException, SAXException, ParserConfigurationException, XPathExpressionException { try { initTableData(dataSourceMaps, sqls, mapDatasetDefinition); try (Connection con = dataSource.getConnection();) { int actual = DatabaseUtil.updateUseStatementToExecuteUpdate(con, rootsql, anAssert.getParameter()); - //String expectedDataFile = PathUtil.getPath(anAssert.getExpectedDataFile(), rootPath); DatasetDefinition checkDataset = AnalyzeDataset.analyze(new File(expectedDataFile), "data"); - - if (anAssert.getExpectedUpdate() != null) { + if (null != anAssert.getExpectedUpdate()) { Assert.assertEquals("Update row number error" + msg, anAssert.getExpectedUpdate().intValue(), actual); } - - String checksql = anAssert.getExpectedSql(); checksql = SQLCasesLoader.getInstance().getSupportedSQL(checksql); DatasetDatabase ddPreparedStatement = DatabaseUtil.selectUsePreparedStatement(con, checksql, @@ -778,7 +721,7 @@ private static int doUpdateUseStatementToExecuteUpdate(final String rootPath, fi } } - private static void doUpdateUseStatementToExecuteUpdateDDL(final String rootPath, final DatabaseType databaseType, final String dbName, final String expectedDataFile, final DataSource dataSource, final AssertDDLDefinition anAssert, final String rootsql, final String msg) throws SQLException, ParseException, IOException, SAXException, ParserConfigurationException, XPathExpressionException { + private static void doUpdateUseStatementToExecuteUpdateDDL(final DatabaseType databaseType, final String dbName, final String expectedDataFile, final DataSource dataSource, final AssertDDLDefinition anAssert, final String rootsql, final String msg) throws SQLException, ParseException, IOException, SAXException, ParserConfigurationException, XPathExpressionException { try { try (Connection con = dataSource.getConnection()) { if (StringUtils.isNotBlank(anAssert.getCleanSql())) { @@ -788,7 +731,6 @@ private static void doUpdateUseStatementToExecuteUpdateDDL(final String rootPath InItCreateSchema.createTable(databaseType, anAssert.getInitSql(), dbName); } DatabaseUtil.updateUseStatementToExecuteUpdate(con, rootsql, anAssert.getParameter()); - //String expectedDataFile = PathUtil.getPath(anAssert.getExpectedDataFile(), rootPath); DatasetDefinition checkDataset = AnalyzeDataset.analyze(new File(expectedDataFile), "data"); String table = anAssert.getTable(); @@ -805,54 +747,40 @@ private static void doUpdateUseStatementToExecuteUpdateDDL(final String rootPath } } - private static void doSelectUseStatement(final String rootPath, final String expectedDataFile, final DataSource dataSource, final AssertDQLDefinition anAssert, final String rootsql, final String msg) throws SQLException, IOException, SAXException, ParserConfigurationException, XPathExpressionException { - try (Connection con = dataSource.getConnection();) { - DatasetDatabase ddStatement = DatabaseUtil.selectUseStatement(con, rootsql, - anAssert.getParameter()); - //String expectedDataFile = PathUtil.getPath(anAssert.getExpectedDataFile(), rootPath); + private static void doSelectUseStatement(final String expectedDataFile, final DataSource dataSource, final AssertDQLDefinition anAssert, final String rootsql, final String msg) throws SQLException, IOException, SAXException, ParserConfigurationException, XPathExpressionException { + try (Connection con = dataSource.getConnection()) { + DatasetDatabase ddStatement = DatabaseUtil.selectUseStatement(con, rootsql, anAssert.getParameter()); DatasetDefinition checkDataset = AnalyzeDataset.analyze(new File(expectedDataFile), "data"); DatabaseUtil.assertDatas(checkDataset, ddStatement, msg); } } - private static void doSelectUseStatementToExecuteSelect(final String rootPath, final String expectedDataFile, final DataSource dataSource, final AssertDQLDefinition anAssert, final String rootsql, final String msg) throws SQLException, IOException, SAXException, ParserConfigurationException, XPathExpressionException { + private static void doSelectUseStatementToExecuteSelect(final String expectedDataFile, final DataSource dataSource, final AssertDQLDefinition anAssert, final String rootsql, final String msg) throws SQLException, IOException, SAXException, ParserConfigurationException, XPathExpressionException { try (Connection con = dataSource.getConnection();) { - DatasetDatabase ddStatement = DatabaseUtil.selectUseStatementToExecuteSelect(con, rootsql, - anAssert.getParameter()); - //String expectedDataFile = PathUtil.getPath(anAssert.getExpectedDataFile(), rootPath); + DatasetDatabase ddStatement = DatabaseUtil.selectUseStatementToExecuteSelect(con, rootsql, anAssert.getParameter()); DatasetDefinition checkDataset = AnalyzeDataset.analyze(new File(expectedDataFile), "data"); - DatabaseUtil.assertDatas(checkDataset, ddStatement, msg); } } - private static void doSelectUsePreparedStatement(final String rootPath, final String expectedDataFile, final DataSource dataSource, final AssertDQLDefinition anAssert, final String rootsql, final String msg) throws SQLException, ParseException, IOException, SAXException, ParserConfigurationException, XPathExpressionException { - try (Connection con = dataSource.getConnection();) { - DatasetDatabase ddPreparedStatement = DatabaseUtil.selectUsePreparedStatement(con, rootsql, - anAssert.getParameter()); - - //String expectedDataFile = PathUtil.getPath(anAssert.getExpectedDataFile(), rootPath); + private static void doSelectUsePreparedStatement(final String expectedDataFile, final DataSource dataSource, final AssertDQLDefinition anAssert, final String rootsql, final String msg) throws SQLException, ParseException, IOException, SAXException, ParserConfigurationException, XPathExpressionException { + try (Connection con = dataSource.getConnection()) { + DatasetDatabase ddPreparedStatement = DatabaseUtil.selectUsePreparedStatement(con, rootsql, anAssert.getParameter()); DatasetDefinition checkDataset = AnalyzeDataset.analyze(new File(expectedDataFile), "data"); - DatabaseUtil.assertDatas(checkDataset, ddPreparedStatement, msg); } } - private static void doSelectUsePreparedStatementToExecuteSelect(final String rootPath, final String expectedDataFile, final DataSource dataSource, final AssertDQLDefinition anAssert, final String rootsql, final String msg) throws SQLException, ParseException, IOException, SAXException, ParserConfigurationException, XPathExpressionException { + private static void doSelectUsePreparedStatementToExecuteSelect(final String expectedDataFile, final DataSource dataSource, final AssertDQLDefinition anAssert, final String rootsql, final String msg) throws SQLException, ParseException, IOException, SAXException, ParserConfigurationException, XPathExpressionException { try (Connection con = dataSource.getConnection();) { - DatasetDatabase ddPreparedStatement = DatabaseUtil.selectUsePreparedStatementToExecuteSelect(con, rootsql, - anAssert.getParameter()); - - //String expectedDataFile = PathUtil.getPath(anAssert.getExpectedDataFile(), rootPath); + DatasetDatabase ddPreparedStatement = DatabaseUtil.selectUsePreparedStatementToExecuteSelect(con, rootsql, anAssert.getParameter()); DatasetDefinition checkDataset = AnalyzeDataset.analyze(new File(expectedDataFile), "data"); - DatabaseUtil.assertDatas(checkDataset, ddPreparedStatement, msg); } } - private static void getInitDatas(final List dbs, final String initDataFile, - final Map mapDatasetDefinition, final Map sqls) + private static void getInitDatas(final List dbs, final String initDataFile, final Map mapDatasetDefinition, final Map sqls) throws IOException, SAXException, ParserConfigurationException, XPathExpressionException { for (String each : dbs) { String tempPath = initDataFile + "/" + each + ".xml"; @@ -870,33 +798,26 @@ private static void getInitDatas(final List dbs, final String initDataFi } } - - private static void clearTableData(final Map dataSourceMaps, - final Map mapDatasetDefinition) throws SQLException { + private static void clearTableData(final Map dataSourceMaps, final Map mapDatasetDefinition) throws SQLException { for (Map.Entry eachEntry : dataSourceMaps.entrySet()) { - DataSource dataSource1 = eachEntry.getValue(); DatasetDefinition datasetDefinition = mapDatasetDefinition.get(eachEntry.getKey()); Map>> datas = datasetDefinition.getDatas(); - for (Map.Entry>> eachListEntry : datas.entrySet()) { try (Connection conn = dataSource1.getConnection()) { DatabaseUtil.cleanAllUsePreparedStatement(conn, eachListEntry.getKey()); } } - } } - private static void initTableData(final Map dataSourceMaps, final Map sqls, - final Map mapDatasetDefinition) throws SQLException, ParseException { + private static void initTableData(final Map dataSourceMaps, final Map sqls, final Map mapDatasetDefinition) throws SQLException, ParseException { clearTableData(dataSourceMaps, mapDatasetDefinition); for (Map.Entry eachDataSourceEntry : dataSourceMaps.entrySet()) { DataSource dataSource1 = eachDataSourceEntry.getValue(); DatasetDefinition datasetDefinition = mapDatasetDefinition.get(eachDataSourceEntry.getKey()); Map> configs = datasetDefinition.getMetadatas(); Map>> datas = datasetDefinition.getDatas(); - for (Map.Entry>> eachListEntry : datas.entrySet()) { try (Connection conn = dataSource1.getConnection()) { DatabaseUtil.insertUsePreparedStatement(conn, sqls.get(eachListEntry.getKey()), @@ -906,20 +827,6 @@ private static void initTableData(final Map dataSourceMaps, } } - - /** - * Generating DataSource from yaml. - * - * @param path path - * @return DataSource - * @throws IOException IOException - * @throws SQLException SQLException - */ - public static DataSource getDataSource(final String path) throws IOException, SQLException { - return ShardingDataSourceFactory.createDataSource(new File(path)); - } - - public static DataSource getDataSource(final Map dataSourceMap, final String path) throws IOException, SQLException { return ShardingDataSourceFactory.createDataSource(dataSourceMap, new File(path)); } @@ -927,55 +834,4 @@ public static DataSource getDataSource(final Map dataSourceM public static DataSource getMasterSlaveDataSource(final Map dataSourceMap, final String path) throws IOException, SQLException { return MasterSlaveDataSourceFactory.createDataSource(dataSourceMap, new File(path)); } - - /** - * According to the sub DataSource set of shardingDataSource. - * - * @param shardingDataSource shardingDataSource - * @return DataSource map - * @throws NoSuchFieldException NoSuchFieldException - * @throws SecurityException SecurityException - * @throws IllegalArgumentException IllegalArgumentException - * @throws IllegalAccessException IllegalAccessException - */ - public static Map getDataSourceMap(final ShardingDataSource shardingDataSource) - throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException { - ShardingContext shardingContext = getShardingContext(shardingDataSource); - return shardingContext.getDataSourceMap(); - } - - /** - * According to ShardingRule in shardingDataSource. - * - * @param shardingDataSource shardingDataSource - * @return ShardingRule - * @throws NoSuchFieldException NoSuchFieldException - * @throws SecurityException SecurityException - * @throws IllegalArgumentException IllegalArgumentException - * @throws IllegalAccessException IllegalAccessException - */ - public static ShardingRule getShardingRule(final ShardingDataSource shardingDataSource) - throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException { - ShardingContext shardingContext = getShardingContext(shardingDataSource); - return shardingContext.getShardingRule(); - } - - /** - * According to ShardingContext in shardingDataSource. - * - * @param shardingDataSource shardingDataSource - * @return ShardingContext - * @throws NoSuchFieldException NoSuchFieldException - * @throws SecurityException SecurityException - * @throws IllegalArgumentException IllegalArgumentException - * @throws IllegalAccessException IllegalAccessException - */ - public static ShardingContext getShardingContext(final ShardingDataSource shardingDataSource) - throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException { - Field field = shardingDataSource.getClass().getDeclaredField("shardingContext"); - field.setAccessible(true); - return (ShardingContext) field.get(shardingDataSource); - } - - } diff --git a/sharding-jdbc-core/src/test/java/io/shardingjdbc/dbtest/common/DatabaseEnvironment.java b/sharding-jdbc-core/src/test/java/io/shardingjdbc/dbtest/common/DatabaseEnvironment.java index 4cc51848d12c8..1559fa7382100 100644 --- a/sharding-jdbc-core/src/test/java/io/shardingjdbc/dbtest/common/DatabaseEnvironment.java +++ b/sharding-jdbc-core/src/test/java/io/shardingjdbc/dbtest/common/DatabaseEnvironment.java @@ -124,29 +124,4 @@ public String getUsername() { public String getPassword() { return PASSWORD.get(databaseType); } - - /** - * Get table. - * - * @param dbName database name - * @return table - */ - public String getSchema(final String dbName) { - return null == SCHEMA.get(databaseType) ? null : String.format(SCHEMA.get(databaseType), dbName); - } - - /** - * Get the database type enumeration. - * - * @param type String database type - * @return database enumeration - */ - public DatabaseType getDatabaseTypeByJdbcDriver(final String type) { - for (Map.Entry each : DRIVER_CLASS_NAME.entrySet()) { - if (type.equals(each.getValue())) { - return each.getKey(); - } - } - return DatabaseType.H2; - } } diff --git a/sharding-jdbc-core/src/test/java/io/shardingjdbc/dbtest/common/DatabaseUtil.java b/sharding-jdbc-core/src/test/java/io/shardingjdbc/dbtest/common/DatabaseUtil.java index 48dac202625a9..d155fddbb51fc 100644 --- a/sharding-jdbc-core/src/test/java/io/shardingjdbc/dbtest/common/DatabaseUtil.java +++ b/sharding-jdbc-core/src/test/java/io/shardingjdbc/dbtest/common/DatabaseUtil.java @@ -17,9 +17,26 @@ package io.shardingjdbc.dbtest.common; -import static org.junit.Assert.assertTrue; +import io.shardingjdbc.dbtest.config.bean.ColumnDefinition; +import io.shardingjdbc.dbtest.config.bean.DatasetDatabase; +import io.shardingjdbc.dbtest.config.bean.DatasetDefinition; +import io.shardingjdbc.dbtest.config.bean.ParameterDefinition; +import io.shardingjdbc.dbtest.config.bean.ParameterValueDefinition; +import io.shardingjdbc.dbtest.exception.DbTestException; +import org.apache.commons.lang3.StringUtils; +import org.apache.commons.lang3.time.DateFormatUtils; +import org.apache.commons.lang3.time.FastDateFormat; +import org.junit.Assert; -import java.sql.*; +import java.sql.Connection; +import java.sql.DatabaseMetaData; +import java.sql.Date; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.ResultSetMetaData; +import java.sql.SQLException; +import java.sql.Statement; +import java.sql.Types; import java.text.ParseException; import java.util.ArrayList; import java.util.HashMap; @@ -28,13 +45,7 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; -import io.shardingjdbc.dbtest.config.bean.*; -import org.apache.commons.lang3.StringUtils; -import org.apache.commons.lang3.time.DateFormatUtils; -import org.apache.commons.lang3.time.FastDateFormat; - -import io.shardingjdbc.dbtest.exception.DbTestException; -import org.junit.Assert; +import static org.junit.Assert.assertTrue; public class DatabaseUtil { @@ -152,28 +163,6 @@ public static void cleanAllUsePreparedStatement(final Connection conn, final Str } } - /** - * To determine if it is a query statement. - * - * @param sql sql - * @return true select - */ - public static boolean isSelect(final String sql) { - String newSql = sql.trim(); - return newSql.startsWith("select"); - } - - /** - * To determine whether the statement is an update. - * - * @param sql sql - * @return true update - */ - public static boolean isInsertOrUpdateOrDelete(final String sql) { - String newSql = sql.trim(); - return newSql.startsWith("insert") || newSql.startsWith("update") || newSql.startsWith("delete"); - } - /** * Use Statement Test data update. * @@ -605,7 +594,7 @@ private static void sqlPreparedStatement(final List pa * @return java type */ private static String getDataType(final int type, final int scale) { - String result = null; + String result; switch (type) { case Types.INTEGER: result = "int"; diff --git a/sharding-jdbc-core/src/test/java/io/shardingjdbc/dbtest/core/common/util/SQLPlaceholderUtil.java b/sharding-jdbc-core/src/test/java/io/shardingjdbc/dbtest/core/common/util/SQLPlaceholderUtil.java deleted file mode 100644 index cfc80a64ccb42..0000000000000 --- a/sharding-jdbc-core/src/test/java/io/shardingjdbc/dbtest/core/common/util/SQLPlaceholderUtil.java +++ /dev/null @@ -1,20 +0,0 @@ -package io.shardingjdbc.dbtest.core.common.util; - -import io.shardingjdbc.core.parsing.lexer.token.Symbol; -import lombok.AccessLevel; -import lombok.NoArgsConstructor; - -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public final class SQLPlaceholderUtil { - - public static String replaceStatement(final String str, final Object[] args) { - if (args.length == 0) { - return str; - } - return String.format(str, args).replace("%%", "%"); - } - - public static String replacePreparedStatement(final String str) { - return str.replace("%s", Symbol.QUESTION.getLiterals()).replace("%%", "%"); - } -} \ No newline at end of file diff --git a/sharding-jdbc-core/src/test/java/io/shardingjdbc/dbtest/exception/DbTestException.java b/sharding-jdbc-core/src/test/java/io/shardingjdbc/dbtest/exception/DbTestException.java index ef43a85fc0fa6..fd01b52822c3a 100644 --- a/sharding-jdbc-core/src/test/java/io/shardingjdbc/dbtest/exception/DbTestException.java +++ b/sharding-jdbc-core/src/test/java/io/shardingjdbc/dbtest/exception/DbTestException.java @@ -25,10 +25,6 @@ public DbTestException(final String message) { super(message); } - public DbTestException(final String message, final Throwable cause) { - super(message, cause); - } - public DbTestException(final Throwable cause) { super(cause); } diff --git a/sharding-jdbc-core/src/test/java/io/shardingjdbc/dbtest/init/InItCreateSchema.java b/sharding-jdbc-core/src/test/java/io/shardingjdbc/dbtest/init/InItCreateSchema.java index 1d747f5d08233..31e541a4d96e3 100644 --- a/sharding-jdbc-core/src/test/java/io/shardingjdbc/dbtest/init/InItCreateSchema.java +++ b/sharding-jdbc-core/src/test/java/io/shardingjdbc/dbtest/init/InItCreateSchema.java @@ -18,11 +18,8 @@ package io.shardingjdbc.dbtest.init; import io.shardingjdbc.core.constant.DatabaseType; -import io.shardingjdbc.core.yaml.sharding.YamlShardingConfiguration; import io.shardingjdbc.dbtest.IntegrateTestRunningEnvironment; import io.shardingjdbc.dbtest.common.DatabaseEnvironment; -import io.shardingjdbc.dbtest.common.FileUtil; -import io.shardingjdbc.dbtest.common.PathUtil; import io.shardingjdbc.dbtest.config.AnalyzeDatabase; import io.shardingjdbc.dbtest.config.AnalyzeSql; import io.shardingjdbc.test.sql.SQLCasesLoader; @@ -31,15 +28,10 @@ import org.apache.commons.lang3.StringUtils; import org.h2.tools.RunScript; import org.xml.sax.SAXException; -import org.yaml.snakeyaml.Yaml; -import org.yaml.snakeyaml.constructor.Constructor; import javax.xml.parsers.ParserConfigurationException; import javax.xml.xpath.XPathExpressionException; -import java.io.File; -import java.io.FileInputStream; import java.io.IOException; -import java.io.InputStreamReader; import java.io.StringReader; import java.sql.Connection; import java.sql.ResultSet; @@ -68,16 +60,8 @@ public static void addDatabase(String database) { } static { - String assertPath = IntegrateTestRunningEnvironment.getInstance().getAssertPath(); - assertPath = PathUtil.getPath(assertPath); - List paths = FileUtil.getAllFilePaths(new File(assertPath), "t", "yaml"); - try { - Set databaseSchemas = InItCreateSchema.getDatabaseSchema(); - InItCreateSchema.setDatabaseSchemas(databaseSchemas); - } catch (IOException e) { - e.printStackTrace(); - } - + Set databaseSchemas = InItCreateSchema.getDatabaseSchema(); + InItCreateSchema.setDatabaseSchemas(databaseSchemas); } public static Set getDatabaseSchemas() { @@ -97,33 +81,6 @@ public static synchronized void createTable() { } } - /** - * Initialize the database table. - */ - public static synchronized void createTable(final String sqlId) { - for (DatabaseType db : DATABASE_SCHEMAS) { - createSchema(db, sqlId); - } - } - - /** - * Initialize the database table. - */ - public static synchronized void dropTable() { - for (DatabaseType db : DATABASE_SCHEMAS) { - dropSchema(db); - } - } - - /** - * Initialize the database table. - */ - public static synchronized void dropTable(final String sqlId) { - for (DatabaseType db : DATABASE_SCHEMAS) { - dropSchema(db, sqlId); - } - } - /** * Create a database. */ @@ -233,18 +190,6 @@ private static void createSchema(final DatabaseType dbType) { createShardingSchema(dbType); } - private static void createSchema(final DatabaseType dbType, final String sqlId) { - createShardingSchema(dbType, sqlId, null); - } - - private static void dropSchema(final DatabaseType dbType) { - dropShardingSchema(dbType, null); - } - - private static void dropSchema(final DatabaseType dbType, final String sqlId) { - dropShardingSchema(dbType, sqlId); - } - private static void createShardingSchema(final DatabaseType dbType) { Connection conn = null; ResultSet resultSet = null; @@ -305,7 +250,6 @@ public static void createTable(final DatabaseType dbType, final String sqlId, fi createShardingSchema(dbType, sqlId, dbname); } - private static void createShardingSchema(final DatabaseType dbType, final String sqlId, final String dbname) { Connection conn = null; ResultSet resultSet = null; @@ -354,57 +298,6 @@ private static void createShardingSchema(final DatabaseType dbType, final String } } - private static void dropShardingSchema(final DatabaseType dbType, final String dbname) { - Connection conn = null; - ResultSet resultSet = null; - StringReader sr = null; - try { - for (String each : DATABASES) { - if (dbname != null) { - if (each != dbname) { - continue; - } - } - List databases = AnalyzeDatabase.analyze(InItCreateSchema.class.getClassLoader() - .getResource("integrate/dbtest").getPath() + "/" + each + "/database.xml"); - for (String database : databases) { - conn = initialConnection(database, dbType); - List tableSqlIds = AnalyzeSql.analyze(InItCreateSchema.class.getClassLoader() - .getResource("integrate/dbtest").getPath() + "/" + each + "/table/drop-table.xml"); - List tableSqls = new ArrayList<>(); - 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) { - // The table may not exist at the time of deletion(删除时可能表不存在) - //e.printStackTrace(); - } finally { - if (sr != null) { - sr.close(); - } - if (resultSet != null) { - try { - resultSet.close(); - } catch (SQLException e) { - e.printStackTrace(); - } - } - if (conn != null) { - try { - conn.close(); - } catch (SQLException e) { - e.printStackTrace(); - } - } - } - } - private static void dropShardingSchema(final DatabaseType dbType, final String sqlId, final String dbname) { Connection conn = null; ResultSet resultSet = null; @@ -462,8 +355,6 @@ public static BasicDataSource buildDataSource(final String dbName, final Databas result.setUrl(dbEnv.getURL(dbName)); result.setUsername(dbEnv.getUsername()); result.setPassword(dbEnv.getPassword()); - - //result.setMaxActive(1); if (DatabaseType.Oracle == type) { result.setConnectionInitSqls(Collections.singleton("ALTER SESSION SET CURRENT_SCHEMA = " + dbName)); } @@ -474,10 +365,7 @@ private static Connection initialConnection(final String dbName, final DatabaseT return buildDataSource(dbName, type).getConnection(); } - /** - * @return - */ - public static Set getDatabaseSchema() throws IOException { + public static Set getDatabaseSchema() { Set dbset = new HashSet<>(); for (String each : IntegrateTestRunningEnvironment.getInstance().getDatabaseTypes()) { DatabaseType databaseType = getDatabaseType(each); @@ -486,15 +374,6 @@ public static Set getDatabaseSchema() throws IOException { return dbset; } - private static YamlShardingConfiguration unmarshal(final File yamlFile) throws IOException { - try ( - FileInputStream fileInputStream = new FileInputStream(yamlFile); - InputStreamReader inputStreamReader = new InputStreamReader(fileInputStream, "UTF-8") - ) { - return new Yaml(new Constructor(YamlShardingConfiguration.class)).loadAs(inputStreamReader, YamlShardingConfiguration.class); - } - } - private static String getCreateTableSql(final DatabaseType databaseType, final List databases) { String basesql = "CREATE DATABASE "; if (DatabaseType.Oracle == databaseType) { @@ -526,7 +405,6 @@ private static String getDropTableSql(final DatabaseType databaseType, final Lis * @return database enumeration */ public static DatabaseType getDatabaseType(final String type) { - DatabaseType[] databaseTypes = DatabaseType.values(); for (DatabaseType each : databaseTypes) { if (type.equalsIgnoreCase(each.name())) {