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:
09: /**
10: * <p>An Executable allows queries and execution of statements
11: * on an existing connection. It is up to the Connection supplier to
12: * manage all transactional properties, if any. This should generally
13: * only be used for container managed transactions and
14: * similar type external transaction management.
15: * </p>
16: * <p>An Executable can also be passed to other methods that
17: * needs to take part in a transaction, but without exposing the
18: * commit and rollback capabilities of the
19: * {@link net.sourceforge.orbroker.Transaction} object.
20: * </p>
21: *
22: * @author Nils Kilden-Pedersen
23: * @see Broker#obtainExecutable(Connection)
24: * @see Transaction#obtainExecutable()
25: */
26: public final class Executable extends ExecutableConnection {
27:
28: private final Transaction transaction;
29:
30: Executable(Broker owner, Connection connection)
31: throws BrokerException {
32: super (owner, connection);
33: this .transaction = null;
34: }
35:
36: Executable(Broker owner, Transaction transaction)
37: throws BrokerException {
38: super (owner, transaction.getActiveConnection());
39: this .transaction = transaction;
40: }
41:
42: /**
43: * @see net.sourceforge.orbroker.QueryableConnection#getClosedConnectionMessage()
44: */
45: protected String getClosedConnectionMessage() {
46: return "Executable has been released and is no longer valid.";
47: }
48:
49: /**
50: * @see net.sourceforge.orbroker.QueryableConnection#getFinalizeWarning()
51: */
52: protected String getFinalizeWarning() {
53: return "Executable was not released. "
54: + "This can cause connection cross usage with unpredictable results.";
55: }
56:
57: /**
58: * @inheritDoc
59: * @see net.sourceforge.orbroker.ExecutableConnection#markTransactionStarted()
60: */
61: protected void markTransactionStarted() {
62: if (this .transaction != null) {
63: this .transaction.markTransactionStarted();
64: }
65: }
66:
67: protected boolean retryFailedStatement(SQLException e) {
68: // Don't retry because it's an outside supplied connection.
69: return false;
70: }
71:
72: /**
73: * @see net.sourceforge.orbroker.QueryableConnection#setConnectionProperties()
74: */
75: protected void setConnectionProperties() throws SQLException {
76: // Do not touch connection.
77: return;
78: }
79:
80: /**
81: * @see net.sourceforge.orbroker.BrokerConnection#shouldConnectionClose()
82: */
83: protected boolean shouldConnectionClose() {
84: // Connection handled externally, so never close.
85: return false;
86: }
87:
88: /**
89: * Invalidate this Executable.
90: */
91: void release() {
92: dropConnection();
93: }
94: }
|