Skip to content

Commit

Permalink
for #601: Remove useless codes
Browse files Browse the repository at this point in the history
  • Loading branch information
terrymanu committed May 3, 2018
1 parent a7c60ba commit 306ffe2
Show file tree
Hide file tree
Showing 7 changed files with 86 additions and 416 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,16 +78,12 @@ public static Collection<String[]> getParameters() {
InItCreateSchema.addDatabase(db);
}
}

List<AssertDQLDefinition> assertDQLs = assertsDefinition.getAssertDQL();
collateData(RESULT_ASSERT, each, assertDQLs);

List<AssertDMLDefinition> assertDMLs = assertsDefinition.getAssertDML();
collateData(RESULT_ASSERT, each, assertDMLs);

List<AssertDDLDefinition> assertDDLs = assertsDefinition.getAssertDDL();
collateData(RESULT_ASSERT, each, assertDDLs);

AssertEngine.addAssertDefinition(each, assertsDefinition);
}
} catch (JAXBException | IOException e) {
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -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<DatabaseType, String> each : DRIVER_CLASS_NAME.entrySet()) {
if (type.equals(each.getValue())) {
return each.getKey();
}
}
return DatabaseType.H2;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 {

Expand Down Expand Up @@ -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.
*
Expand Down Expand Up @@ -605,7 +594,7 @@ private static void sqlPreparedStatement(final List<ParameterValueDefinition> 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";
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -68,16 +60,8 @@ public static void addDatabase(String database) {
}

static {
String assertPath = IntegrateTestRunningEnvironment.getInstance().getAssertPath();
assertPath = PathUtil.getPath(assertPath);
List<String> paths = FileUtil.getAllFilePaths(new File(assertPath), "t", "yaml");
try {
Set<DatabaseType> databaseSchemas = InItCreateSchema.getDatabaseSchema();
InItCreateSchema.setDatabaseSchemas(databaseSchemas);
} catch (IOException e) {
e.printStackTrace();
}

Set<DatabaseType> databaseSchemas = InItCreateSchema.getDatabaseSchema();
InItCreateSchema.setDatabaseSchemas(databaseSchemas);
}

public static Set<DatabaseType> getDatabaseSchemas() {
Expand All @@ -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.
*/
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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<String> databases = AnalyzeDatabase.analyze(InItCreateSchema.class.getClassLoader()
.getResource("integrate/dbtest").getPath() + "/" + each + "/database.xml");
for (String database : databases) {
conn = initialConnection(database, dbType);
List<String> tableSqlIds = AnalyzeSql.analyze(InItCreateSchema.class.getClassLoader()
.getResource("integrate/dbtest").getPath() + "/" + each + "/table/drop-table.xml");
List<String> 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;
Expand Down Expand Up @@ -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));
}
Expand All @@ -474,10 +365,7 @@ private static Connection initialConnection(final String dbName, final DatabaseT
return buildDataSource(dbName, type).getConnection();
}

/**
* @return
*/
public static Set<DatabaseType> getDatabaseSchema() throws IOException {
public static Set<DatabaseType> getDatabaseSchema() {
Set<DatabaseType> dbset = new HashSet<>();
for (String each : IntegrateTestRunningEnvironment.getInstance().getDatabaseTypes()) {
DatabaseType databaseType = getDatabaseType(each);
Expand All @@ -486,15 +374,6 @@ public static Set<DatabaseType> 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<String> databases) {
String basesql = "CREATE DATABASE ";
if (DatabaseType.Oracle == databaseType) {
Expand Down Expand Up @@ -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())) {
Expand Down

0 comments on commit 306ffe2

Please sign in to comment.