Skip to content
This repository has been archived by the owner on Nov 24, 2022. It is now read-only.

Commit

Permalink
Merge pull request #30 from DevFactory/release/resource-should-be-clo…
Browse files Browse the repository at this point in the history
…sed-fix-1

[squid:S2095] Resources should be closed
  • Loading branch information
tedeling committed May 26, 2016
2 parents dc0fbab + cda01fc commit 3b6f98e
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.io.File;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.concurrent.TimeUnit;

public abstract class AbstractScenario {
Expand Down Expand Up @@ -92,7 +93,9 @@ protected final void updatePassword(String username, String password) throws SQL
Connection connection = dataSource.getConnection();
String sql = String.format("UPDATE USERS SET PASSWORD = '%s', SALT = %d WHERE USERNAME = '%s'", encodedPassword, salt, username);

connection.createStatement().execute(sql);
try (Statement statement = connection.createStatement()) {
statement.execute(sql);
}
}

@After
Expand Down
Original file line number Diff line number Diff line change
@@ -1,27 +1,41 @@
package net.rrm.ehour.it;

import javax.sql.DataSource;
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.SQLException;

public class DatabaseTruncater {
public static void truncate(DataSource dataSource) throws SQLException {
Connection connection = dataSource.getConnection();
try (Connection connection = dataSource.getConnection();

connection.prepareCall("DELETE FROM AUDIT").execute();
connection.prepareCall("DELETE FROM MAIL_LOG").execute();
connection.prepareCall("DELETE FROM TIMESHEET_COMMENT").execute();
connection.prepareCall("DELETE FROM TIMESHEET_ENTRY").execute();
connection.prepareCall("DELETE FROM TIMESHEET_LOCK_EXCLUSION").execute();
connection.prepareCall("DELETE FROM TIMESHEET_LOCK").execute();
CallableStatement c1 = connection.prepareCall("DELETE FROM AUDIT");
CallableStatement c2 = connection.prepareCall("DELETE FROM MAIL_LOG");
CallableStatement c3 = connection.prepareCall("DELETE FROM TIMESHEET_COMMENT");
CallableStatement c4 = connection.prepareCall("DELETE FROM TIMESHEET_ENTRY");
CallableStatement c5 = connection.prepareCall("DELETE FROM TIMESHEET_LOCK_EXCLUSION");
CallableStatement c6 = connection.prepareCall("DELETE FROM TIMESHEET_LOCK");

connection.prepareCall("DELETE FROM PROJECT_ASSIGNMENT").execute();
CallableStatement c7 = connection.prepareCall("DELETE FROM PROJECT_ASSIGNMENT");

connection.prepareCall("DELETE FROM PROJECT").execute();
connection.prepareCall("DELETE FROM CUSTOMER").execute();
connection.prepareCall("DELETE FROM USER_TO_USERROLE WHERE user_id != 1").execute();
connection.prepareCall("DELETE FROM USER_TO_DEPARTMENT WHERE user_id != 1").execute();
connection.prepareCall("DELETE FROM USERS WHERE user_id != 1").execute();
connection.close();
CallableStatement c8 = connection.prepareCall("DELETE FROM PROJECT");
CallableStatement c9 = connection.prepareCall("DELETE FROM CUSTOMER");
CallableStatement c10 = connection.prepareCall("DELETE FROM USER_TO_USERROLE WHERE user_id != 1");
CallableStatement c11 = connection.prepareCall("DELETE FROM USER_TO_DEPARTMENT WHERE user_id != 1");
CallableStatement c12 = connection.prepareCall("DELETE FROM USERS WHERE user_id != 1");
) {
c1.execute();
c2.execute();
c3.execute();
c4.execute();
c5.execute();
c6.execute();
c7.execute();
c8.execute();
c9.execute();
c10.execute();
c11.execute();
c12.execute();
}
}
}

0 comments on commit 3b6f98e

Please sign in to comment.