01: /*
02: * Created on Feb 22, 2004
03: */
04: package net.sourceforge.orbroker;
05:
06: import java.sql.Connection;
07: import java.sql.SQLException;
08: import java.util.logging.Level;
09:
10: /**
11: * The query class. Read-only queries can use a Query object.
12: * It wraps a {@link java.sql.Connection Connection}
13: * object, and {@link #close()} should be called after use, to avoid
14: * open connections, or connection pool leaks.
15: * @author Nils Kilden-Pedersen
16: * @see net.sourceforge.orbroker.Broker#startQuery()
17: * @see net.sourceforge.orbroker.Broker#startQuery(int)
18: */
19: public final class Query extends QueryableConnection {
20:
21: Query(Broker owner, Integer isolationLevel) throws BrokerException {
22: super (owner, isolationLevel);
23: }
24:
25: /**
26: * @see net.sourceforge.orbroker.QueryableConnection#getClosedConnectionMessage()
27: */
28: protected String getClosedConnectionMessage() {
29: return "Query has been closed";
30: }
31:
32: /**
33: * @see net.sourceforge.orbroker.QueryableConnection#getFinalizeWarning()
34: */
35: protected String getFinalizeWarning() {
36: return "A Query was not closed. Temporary connection pool leak now closed.";
37: }
38:
39: protected void setConnectionProperties() throws SQLException {
40: Connection con = getActiveConnection();
41: if (!con.isReadOnly()) {
42: con.setReadOnly(true);
43: }
44: }
45:
46: /**
47: * @see net.sourceforge.orbroker.BrokerConnection#shouldConnectionClose()
48: */
49: protected boolean shouldConnectionClose() {
50: return true;
51: }
52:
53: /**
54: * Close query. Subsequent closes will be ignored.
55: */
56: public void close() {
57: if (!isAutoCommit()) {
58: try {
59: // Call commit to release any resource locks
60: getActiveConnection().commit();
61: } catch (SQLException e) {
62: Broker.log(Level.WARNING, "Commit on Query caused "
63: + e.toString());
64: }
65: }
66: dropConnection();
67: }
68:
69: }
|