Skip to content

Commit

Permalink
Merge pull request #520 from cheenamalhotra/JavaImprovements
Browse files Browse the repository at this point in the history
Try with resources implementation in JUnit FW - Part 1
  • Loading branch information
cheenamalhotra authored Oct 10, 2017
2 parents b8daa42 + eb7efe3 commit e7b68fd
Show file tree
Hide file tree
Showing 23 changed files with 2,288 additions and 2,834 deletions.
2,227 changes: 1,110 additions & 1,117 deletions src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/AESetup.java

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -512,68 +512,46 @@ public void testNumericNormalization() throws SQLException {
private void testChar(SQLServerStatement stmt,
String[] values) throws SQLException {
String sql = "select * from " + charTable;
SQLServerPreparedStatement pstmt = (SQLServerPreparedStatement) Util.getPreparedStmt(con, sql, stmtColEncSetting);
ResultSet rs = null;
if (stmt == null) {
rs = pstmt.executeQuery();
try(SQLServerPreparedStatement pstmt = (SQLServerPreparedStatement) Util.getPreparedStmt(con, sql, stmtColEncSetting)) {
try(ResultSet rs = (stmt == null) ? pstmt.executeQuery() : stmt.executeQuery(sql)) {
int numberOfColumns = rs.getMetaData().getColumnCount();
while (rs.next()) {
testGetString(rs, numberOfColumns, values);
testGetObject(rs, numberOfColumns, values);
}
}
}
else {
rs = stmt.executeQuery(sql);
}
int numberOfColumns = rs.getMetaData().getColumnCount();

while (rs.next()) {
testGetString(rs, numberOfColumns, values);
testGetObject(rs, numberOfColumns, values);
}

Util.close(rs, pstmt, null);
}

private void testBinary(SQLServerStatement stmt,
LinkedList<byte[]> values) throws SQLException {
String sql = "select * from " + binaryTable;
SQLServerPreparedStatement pstmt = (SQLServerPreparedStatement) Util.getPreparedStmt(con, sql, stmtColEncSetting);
ResultSet rs = null;
if (stmt == null) {
rs = pstmt.executeQuery();
}
else {
rs = stmt.executeQuery(sql);
try(SQLServerPreparedStatement pstmt = (SQLServerPreparedStatement) Util.getPreparedStmt(con, sql, stmtColEncSetting)) {
try(ResultSet rs = (stmt == null) ? pstmt.executeQuery() : stmt.executeQuery(sql)) {
int numberOfColumns = rs.getMetaData().getColumnCount();
while (rs.next()) {
testGetStringForBinary(rs, numberOfColumns, values);
testGetBytes(rs, numberOfColumns, values);
testGetObjectForBinary(rs, numberOfColumns, values);
}
}
}
int numberOfColumns = rs.getMetaData().getColumnCount();

while (rs.next()) {
testGetStringForBinary(rs, numberOfColumns, values);
testGetBytes(rs, numberOfColumns, values);
testGetObjectForBinary(rs, numberOfColumns, values);
}

Util.close(rs, pstmt, null);
}

private void testDate(SQLServerStatement stmt,
LinkedList<Object> values1) throws SQLException {

String sql = "select * from " + dateTable;
SQLServerPreparedStatement pstmt = (SQLServerPreparedStatement) Util.getPreparedStmt(con, sql, stmtColEncSetting);
ResultSet rs = null;
if (stmt == null) {
rs = pstmt.executeQuery();
try(SQLServerPreparedStatement pstmt = (SQLServerPreparedStatement) Util.getPreparedStmt(con, sql, stmtColEncSetting)) {
try(ResultSet rs = (stmt == null) ? pstmt.executeQuery() : stmt.executeQuery(sql)) {
int numberOfColumns = rs.getMetaData().getColumnCount();
while (rs.next()) {
// testGetStringForDate(rs, numberOfColumns, values1); //TODO: Disabling, since getString throws verification error for zero temporal
// types
testGetObjectForTemporal(rs, numberOfColumns, values1);
testGetDate(rs, numberOfColumns, values1);
}
}
}
else {
rs = stmt.executeQuery(sql);
}
int numberOfColumns = rs.getMetaData().getColumnCount();

while (rs.next()) {
// testGetStringForDate(rs, numberOfColumns, values1); //TODO: Disabling, since getString throws verification error for zero temporal
// types
testGetObjectForTemporal(rs, numberOfColumns, values1);
testGetDate(rs, numberOfColumns, values1);
}

Util.close(rs, pstmt, null);
}

private void testGetObject(ResultSet rs,
Expand Down Expand Up @@ -948,29 +926,22 @@ private void testNumeric(Statement stmt,
String[] numericValues,
boolean isNull) throws SQLException {
String sql = "select * from " + numericTable;
SQLServerPreparedStatement pstmt = (SQLServerPreparedStatement) Util.getPreparedStmt(con, sql, stmtColEncSetting);
SQLServerResultSet rs = null;
if (stmt == null) {
rs = (SQLServerResultSet) pstmt.executeQuery();
}
else {
rs = (SQLServerResultSet) stmt.executeQuery(sql);
try(SQLServerPreparedStatement pstmt = (SQLServerPreparedStatement) Util.getPreparedStmt(con, sql, stmtColEncSetting)) {
try(SQLServerResultSet rs = (stmt == null) ? (SQLServerResultSet) pstmt.executeQuery() : (SQLServerResultSet) stmt.executeQuery(sql)) {
int numberOfColumns = rs.getMetaData().getColumnCount();
while (rs.next()) {
testGetString(rs, numberOfColumns, numericValues);
testGetObject(rs, numberOfColumns, numericValues);
testGetBigDecimal(rs, numberOfColumns, numericValues);
if (!isNull)
testWithSpecifiedtype(rs, numberOfColumns, numericValues);
else {
String[] nullNumericValues = {"false", "0", "0", "0", "0", "0.0", "0.0", "0.0", null, null, null, null, null, null, null, null};
testWithSpecifiedtype(rs, numberOfColumns, nullNumericValues);
}
}
}
}
int numberOfColumns = rs.getMetaData().getColumnCount();

while (rs.next()) {
testGetString(rs, numberOfColumns, numericValues);
testGetObject(rs, numberOfColumns, numericValues);
testGetBigDecimal(rs, numberOfColumns, numericValues);
if (!isNull)
testWithSpecifiedtype(rs, numberOfColumns, numericValues);
else {
String[] nullNumericValues = {"false", "0", "0", "0", "0", "0.0", "0.0", "0.0", null, null, null, null, null, null, null, null};
testWithSpecifiedtype(rs, numberOfColumns, nullNumericValues);
}
}

Util.close(rs, pstmt, null);
}

private void testWithSpecifiedtype(SQLServerResultSet rs,
Expand Down
Loading

0 comments on commit e7b68fd

Please sign in to comment.