Skip to content

Commit 13f147c

Browse files
committed
simplify code
1 parent 30d2965 commit 13f147c

File tree

2 files changed

+8
-20
lines changed

2 files changed

+8
-20
lines changed

src/main/java/com/geckotechnology/mySqlDataCompare/MySQLSchemaRetriever.java

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
public class MySQLSchemaRetriever {
99

10-
private static final int FETCH_SIZE = 1024;
10+
private static final int SELECT_FETCH_SIZE = 1024;
1111
private static final String SQL_SELECT_SCHEMA = "select schema()";
1212
private static final String SQL_SELECT_ALL_TABLES = "select columns.table_name, columns.column_name, columns.column_type, columns.ordinal_position, columns.column_key, columns.is_nullable from information_schema.columns, information_schema.tables where tables.table_schema=schema() and columns.table_name = tables.table_name and columns.table_schema = tables.table_schema and tables.table_type='BASE TABLE' order by columns.table_name, columns.column_name";
1313
private static final String SQL_SELECT_ALL_PKS = "select key_column_usage.table_name, key_column_usage.column_name, key_column_usage.ordinal_position from information_schema.key_column_usage where key_column_usage.table_schema=schema() and key_column_usage.constraint_name = 'PRIMARY' order by key_column_usage.table_name, key_column_usage.ordinal_position";
@@ -31,12 +31,12 @@ public void closeConnection() {
3131
}
3232
}
3333

34-
public Statement getStatement() throws Exception {
34+
public Statement createStatement() throws Exception {
3535
Statement stmt = conn.createStatement(
3636
ResultSet.TYPE_FORWARD_ONLY,
3737
ResultSet.CONCUR_READ_ONLY,
3838
ResultSet.CLOSE_CURSORS_AT_COMMIT);
39-
stmt.setFetchSize(FETCH_SIZE);
39+
stmt.setFetchSize(SELECT_FETCH_SIZE);
4040
return stmt;
4141
}
4242

@@ -48,11 +48,7 @@ public Schema retrieveMetaData() throws Exception {
4848
ResultSet rs = null;
4949
//-----------------------------------------------------------
5050
//check that current schema is not null
51-
stmt = conn.createStatement(
52-
ResultSet.TYPE_FORWARD_ONLY,
53-
ResultSet.CONCUR_READ_ONLY,
54-
ResultSet.CLOSE_CURSORS_AT_COMMIT);
55-
stmt.setFetchSize(FETCH_SIZE);
51+
stmt = createStatement();
5652
rs = stmt.executeQuery(SQL_SELECT_SCHEMA);
5753
while(rs.next()) {
5854
schema.setSchemaName(rs.getString(1));
@@ -65,11 +61,7 @@ public Schema retrieveMetaData() throws Exception {
6561
stmt.close();
6662
//-----------------------------------------------------------
6763
//get all tables
68-
stmt = conn.createStatement(
69-
ResultSet.TYPE_FORWARD_ONLY,
70-
ResultSet.CONCUR_READ_ONLY,
71-
ResultSet.CLOSE_CURSORS_AT_COMMIT);
72-
stmt.setFetchSize(FETCH_SIZE);
64+
stmt = createStatement();
7365
rs = stmt.executeQuery(SQL_SELECT_ALL_TABLES);
7466
String currentTableName = null;
7567
Table currentTable = null;
@@ -96,11 +88,7 @@ public Schema retrieveMetaData() throws Exception {
9688
stmt.close();
9789
//-----------------------------------------------------------
9890
//get all PKs
99-
stmt = conn.createStatement(
100-
ResultSet.TYPE_FORWARD_ONLY,
101-
ResultSet.CONCUR_READ_ONLY,
102-
ResultSet.CLOSE_CURSORS_AT_COMMIT);
103-
stmt.setFetchSize(FETCH_SIZE);
91+
stmt = createStatement();
10492
rs = stmt.executeQuery(SQL_SELECT_ALL_PKS);
10593
currentTable = null;
10694
while(rs.next()) {

src/main/java/com/geckotechnology/mySqlDataCompare/MySQLTableDataComparer.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ public void compareTable(Table table) throws Exception {
2222
//note that only 1 SQL statement is used for both tables, even if column or PK columns are not in the same order
2323
StringBuilder selectSQL = table.createSQLToGetAllRows();
2424
String pkColumnsTuple = table.createPKColumnsTuple().toString();
25-
Statement masterStatement = masterSchemaReader.getStatement();
25+
Statement masterStatement = masterSchemaReader.createStatement();
2626
ResultSet masterResultSet = masterStatement.executeQuery(selectSQL.toString());
27-
Statement slaveStatement = slaveSchemaReader.getStatement();
27+
Statement slaveStatement = slaveSchemaReader.createStatement();
2828
ResultSet slaveResultSet = slaveStatement.executeQuery(selectSQL.toString());
2929
ArrayList<OneRow> masterRows = new ArrayList<OneRow>();
3030
ArrayList<OneRow> slaveRows = new ArrayList<OneRow>();

0 commit comments

Comments
 (0)