This repository has been archived by the owner on Nov 24, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #30 from DevFactory/release/resource-should-be-clo…
…sed-fix-1 [squid:S2095] Resources should be closed
- Loading branch information
Showing
2 changed files
with
32 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 28 additions & 14 deletions
42
eHour-selenium/src/test/java/net/rrm/ehour/it/DatabaseTruncater.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} | ||
} |