001: /**
002: * Objective Database Abstraction Layer (ODAL)
003: * Copyright (c) 2004, The ODAL Development Group
004: * All rights reserved.
005: * For definition of the ODAL Development Group please refer to LICENCE.txt file
006: *
007: * Distributable under LGPL license.
008: * See terms of license at gnu.org.
009: */package com.completex.objective.components.persistency.transact;
010:
011: import java.sql.CallableStatement;
012: import java.sql.Connection;
013: import java.sql.PreparedStatement;
014: import java.sql.SQLException;
015: import java.sql.Statement;
016: import java.util.List;
017:
018: /**
019: * @author Gennady Krizhevsky
020: */
021: public interface Transaction {
022:
023: NullTransaction NULL_TRANSACTION = new NullTransaction();
024:
025: /**
026: *
027: * @param sql
028: * @return PreparedStatement
029: * @throws SQLException
030: */
031: PreparedStatement prepareStatement(String sql) throws SQLException;
032:
033: /**
034: * Release statement if cached
035: *
036: * @param statement
037: * @throws SQLException
038: */
039: void releaseStatement(PreparedStatement statement)
040: throws SQLException;
041:
042: /**
043: *
044: * @return Connection
045: */
046: Connection getConnection();
047:
048: /**
049: * Commit transaction
050: *
051: * @throws SQLException
052: */
053: void commit() throws SQLException;
054:
055: /**
056: * Rollback transaction
057: *
058: * @throws SQLException
059: */
060: void rollback() throws SQLException;
061:
062: public void commitUnchecked();
063:
064: public void rollbackUnchecked();
065:
066: /**
067: * Rollback transaction and suppress exceptions
068: *
069: */
070: void rollbackSilently();
071:
072: /**
073: * Flush all batch updates
074: *
075: * @return List of arrays of return codes produced by executeBatch()
076: * @throws SQLException
077: */
078: List flush() throws SQLException;
079:
080: /**
081: * Proxy for connection.createStatement()
082: *
083: * @return created statement
084: * @throws SQLException
085: */
086: Statement createStatement() throws SQLException;
087:
088: /**
089: *
090: * @return String representation of connection
091: */
092: String connectionToString();
093:
094: /**
095: * Add listener to transaction events
096: *
097: * @param key
098: * @param listener
099: */
100: void addListerner(Object key, TransactionListener listener);
101:
102: /**
103: * Returns listener associated with key
104: *
105: * @param key
106: * @return listener associated with key
107: */
108: TransactionListener getListener(Object key);
109:
110: /**
111: * Returns true if there is listener associated with key
112: *
113: * @param key
114: * @return true if there is listener associated with key
115: */
116: boolean containsListener(Object key);
117:
118: /**
119: * Remove listener associated with key
120: *
121: * @param key
122: */
123: void removeListerner(Object key);
124:
125: /**
126: *
127: * @return number of registered listeners
128: */
129: int listenersSize();
130:
131: /**
132: * Unregister all listeners
133: */
134: void clearListerners();
135:
136: /**
137: *
138: * @param sql
139: * @return prepared CallableStatement
140: * @throws SQLException
141: */
142: CallableStatement prepareCall(String sql) throws SQLException;
143:
144: //
145: //
146: // NullTransaction
147: //
148: //
149: static class NullTransaction implements Transaction {
150: public PreparedStatement prepareStatement(String sql)
151: throws SQLException {
152: return null;
153: }
154:
155: public void releaseStatement(PreparedStatement statement)
156: throws SQLException {
157:
158: }
159:
160: public Connection getConnection() {
161: return null;
162: }
163:
164: public void commit() throws SQLException {
165:
166: }
167:
168: public void rollback() throws SQLException {
169:
170: }
171:
172: public void commitUnchecked() {
173:
174: }
175:
176: public void rollbackUnchecked() {
177:
178: }
179:
180: public void rollbackSilently() {
181:
182: }
183:
184: public List flush() throws SQLException {
185: return null;
186: }
187:
188: public Statement createStatement() throws SQLException {
189: return null;
190: }
191:
192: public String connectionToString() {
193: return null;
194: }
195:
196: public void addListerner(Object key,
197: TransactionListener listener) {
198: }
199:
200: public TransactionListener getListener(Object key) {
201: return null;
202: }
203:
204: public boolean containsListener(Object key) {
205: return false;
206: }
207:
208: public void removeListerner(Object key) {
209:
210: }
211:
212: public int listenersSize() {
213: return 0;
214: }
215:
216: public void clearListerners() {
217:
218: }
219:
220: public CallableStatement prepareCall(String sql)
221: throws SQLException {
222: return null;
223: }
224: }
225:
226: }
|