Skip to content

Commit

Permalink
Fix problem with connections in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
seanf committed Aug 24, 2017
1 parent a1df119 commit ae1e8fb
Showing 1 changed file with 14 additions and 14 deletions.
Expand Up @@ -27,6 +27,7 @@
import java.net.URL;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

Expand Down Expand Up @@ -110,24 +111,23 @@ private void clearCache() {
}

protected void executeOperations(List<DataSetOperation> list) {
IDatabaseConnection con = null;
IDatabaseConnection con = getConnection();
try {
con = getConnection();
editConfig(con.getConfig());
disableReferentialIntegrity(con);
disableReferentialIntegrity(con.getConnection());
for (DataSetOperation op : list) {
prepareExecution(con, op);
op.execute(con);
afterExecution(con, op);
}
enableReferentialIntegrity(con);
enableReferentialIntegrity(con.getConnection());
} catch (SQLException e) {
throw new RuntimeException(e);
} finally {
if (con != null) {
try {
con.close();
} catch (Exception ex) {
ex.printStackTrace(System.err);
}
try {
con.close();
} catch (SQLException ignore) {
// ignore
}
}
}
Expand Down Expand Up @@ -272,8 +272,8 @@ public String toString() {
* A DBUnit connection wrapper, which is used afterwards for
* dataset operations
*/
protected void disableReferentialIntegrity(IDatabaseConnection con) {
try (Connection c = con.getConnection(); PreparedStatement s = c
protected void disableReferentialIntegrity(Connection conn) {
try (PreparedStatement s = conn
.prepareStatement("set referential_integrity FALSE")) {
s.execute();
} catch (Exception ex) {
Expand All @@ -289,8 +289,8 @@ protected void disableReferentialIntegrity(IDatabaseConnection con) {
* A DBUnit connection wrapper, before it is used by the
* application again
*/
protected void enableReferentialIntegrity(IDatabaseConnection con) {
try (Connection c = con.getConnection(); PreparedStatement s = c
protected void enableReferentialIntegrity(Connection conn) {
try (PreparedStatement s = conn
.prepareStatement("set referential_integrity TRUE")) {
s.execute();
} catch (Exception ex) {
Expand Down

0 comments on commit ae1e8fb

Please sign in to comment.