|
|||||||||||||||||||
30 day Evaluation Version distributed via the Maven Jar Repository. Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover | |||||||||||||||||||
Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
JdbcResourceRegistry.java | - | 0% | 0% | 0% |
|
1 |
package com.diasparsoftware.jdbc;
|
|
2 |
|
|
3 |
import java.sql.*;
|
|
4 |
import java.util.*;
|
|
5 |
|
|
6 |
import com.diasparsoftware.java.util.*;
|
|
7 |
|
|
8 |
/**
|
|
9 |
* Incorporate one of these registries anywhere you would
|
|
10 |
* like to ensure that JDBC resources are cleaned up.
|
|
11 |
*
|
|
12 |
* @author <a href="jbr@diasparsoftware.com>J. B. Rainsberger</a>
|
|
13 |
*/
|
|
14 |
public class JdbcResourceRegistry { |
|
15 |
private List connectionsToClose = new LinkedList(); |
|
16 |
private List statementsToClose = new LinkedList(); |
|
17 |
private List resultSetsToClose = new LinkedList(); |
|
18 |
|
|
19 | 0 |
public void registerStatement(Statement statement) { |
20 | 0 |
statementsToClose.add(statement); |
21 |
} |
|
22 |
|
|
23 | 0 |
public void registerResultSet(ResultSet resultSet) { |
24 | 0 |
resultSetsToClose.add(resultSet); |
25 |
} |
|
26 |
|
|
27 | 0 |
public void registerConnection(Connection connection) { |
28 | 0 |
connectionsToClose.add(connection); |
29 |
} |
|
30 |
|
|
31 | 0 |
public void cleanUp() { |
32 | 0 |
CollectionUtil |
33 |
.forEachDoIgnoreException( |
|
34 |
statementsToClose, |
|
35 |
new ExceptionalClosure() {
|
|
36 |
|
|
37 | 0 |
public Object execute(Object each) throws Exception { |
38 | 0 |
((Statement) each).close(); |
39 | 0 |
return null; |
40 |
} |
|
41 |
}); |
|
42 |
|
|
43 | 0 |
CollectionUtil |
44 |
.forEachDoIgnoreException( |
|
45 |
resultSetsToClose, |
|
46 |
new ExceptionalClosure() {
|
|
47 |
|
|
48 | 0 |
public Object execute(Object each) throws Exception { |
49 | 0 |
((ResultSet) each).close(); |
50 | 0 |
return null; |
51 |
} |
|
52 |
}); |
|
53 |
|
|
54 | 0 |
CollectionUtil |
55 |
.forEachDoIgnoreException( |
|
56 |
connectionsToClose, |
|
57 |
new ExceptionalClosure() {
|
|
58 |
|
|
59 | 0 |
public Object execute(Object each) throws Exception { |
60 | 0 |
((Connection) each).close(); |
61 | 0 |
return null; |
62 |
} |
|
63 |
}); |
|
64 |
|
|
65 |
} |
|
66 |
} |
|