001: /*
002: * Enhydra Java Application Server Project
003: *
004: * The contents of this file are subject to the Enhydra Public License
005: * Version 1.1 (the "License"); you may not use this file except in
006: * compliance with the License. You may obtain a copy of the License on
007: * the Enhydra web site ( http://www.enhydra.org/ ).
008: *
009: * Software distributed under the License is distributed on an "AS IS"
010: * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
011: * the License for the specific terms governing rights and limitations
012: * under the License.
013: *
014: * The Initial Developer of the Enhydra Application Server is Lutris
015: * Technologies, Inc. The Enhydra Application Server and portions created
016: * by Lutris Technologies, Inc. are Copyright Lutris Technologies, Inc.
017: * All Rights Reserved.
018: *
019: * Contributor(s):
020: *
021: * $Id: DBTransaction.java,v 1.1 2007-01-24 16:59:09 sinisa Exp $
022: *
023: * formatted with JxBeauty (c) johann.langhofer@nextra.at
024: */
025: package com.lutris.appserver.server.sql;
026:
027: import java.sql.SQLException;
028:
029: /**
030: * Used to perform database transactions.
031: *
032: * <P>Example - adding a new user:
033: * <PRE>
034: * import org.enhydra.dods.DODS;
035: * import com.lutris.appserver.server.sql.*;
036: *
037: * DBTransaction transaction =
038: * DODS.getDatabaseManager().createTransaction(DATABASE_NAME);
039: *
040: * // NOTE: class CustomerDO implements Transaction { ... }
041: * // NOTE: An Object ID is automatically calculated by the constructor.
042: * CustomerDO customer = new CustomerDO();
043: * customer.setFirstName("Santa");
044: * customer.setLastName("Claus");
045: *
046: * // ... set all other CustomerFields ...
047: *
048: * //
049: * // Now add the new object to the database.
050: * //
051: * try {
052: * transaction.insert(customer);
053: * transaction.commit();
054: * System.out.println("Object ID is " + customer.get_OId());
055: * }
056: * catch (SQLException e) {
057: * transaction.rollback();
058: * throw e;
059: * }
060: * finally {
061: * transaction.release();
062: * }
063: * </PRE>
064: *
065: * @author Kyle Clark
066: * @since LBS1.8
067: * @version $Revision: 1.1 $
068: */
069: public interface DBTransaction {
070:
071: /**
072: * Method to update an object in the database.
073: *
074: * @param transaction
075: * Object that implements transaction interface.
076: */
077: public void update(Transaction transaction);
078:
079: /**
080: * Method to delete an object in the database.
081: *
082: * @param transaction
083: * Object that implements transaction interface.
084: */
085: public void delete(Transaction transaction);
086:
087: /**
088: * Method to insert an object in the database.
089: *
090: * @param transaction
091: * Object that implements transaction interface.
092: */
093: public void insert(Transaction transaction);
094:
095: /**
096: * Method to commit upates.
097: *
098: * @exception java.sql.SQLException If a database access error occurs.
099: */
100: public void commit() throws SQLException;
101:
102: /**
103: * Method to rollback changes.
104: *
105: * @exception java.sql.SQLException
106: * If a database access error occurs.
107: */
108: public void rollback() throws SQLException;
109:
110: /**
111: * Frees all resources consumed by this transaction
112: * Connections are returned to the connection pool.
113: * Subsequent transactions via this object,
114: * will allocate a new set of resources (i.e. connection).
115: */
116: public void release();
117:
118: /**
119: * Exception handeler. This object is should not be
120: * used for subsequent queries if this method returns
121: * false.
122: *
123: * @return boolean True if the exception can be handeled
124: * and the object is still valid, false otherwise.
125: */
126: public boolean handleException(SQLException e);
127:
128: // compliance with WEBDOCWF begin
129: /**
130: * Method find a DO in the transaction
131: *
132: * @param transaction
133: * Object that implements transaction interface.
134: * @return DO if the oid was in the transaction, null if it was not
135: *
136: * WebDocWf extension
137: */
138: public Transaction getDO(Transaction transaction);
139:
140: /**
141: * Method find a DO in the transaction
142: *
143: * @param transaction
144: * Object that implements transaction interface.
145: * @param action
146: * if not NONE=0, the DO is found only woth the matching action
147: * @return DO if the oid was in the transaction, null if it was not
148: *
149: * WebDocWf extension
150: */
151: public Transaction getDO(Transaction transaction, int action);
152:
153: // original line
154: //
155: // compliance with WEBDOCWF end
156:
157: /**
158: * Method return name of used database
159: *
160: * @return name of used database
161: */
162: public String getDatabaseName();
163:
164: /**
165: * Method set name of used database
166: *
167: * @param dbName name of used database
168: */
169: public void setDatabaseName(String dbName);
170:
171: /**
172: *
173: */
174: public void write() throws SQLException;
175:
176: /**
177: *
178: */
179: public void lockDO(Transaction cdo) throws SQLException;
180:
181: /**
182: * Return a query for use with this TRANSACTION please!!!
183: *
184: * @return The query object.
185: * @exception SQLException
186: * if a SQL error occurs.
187: */
188: public DBQuery createQuery() throws SQLException;
189:
190: /**
191: *
192: */
193: public boolean preventCacheQueries();
194: }
|