KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > lutris > appserver > server > sql > DBTransaction


1 /*
2  * Enhydra Java Application Server Project
3  *
4  * The contents of this file are subject to the Enhydra Public License
5  * Version 1.1 (the "License"); you may not use this file except in
6  * compliance with the License. You may obtain a copy of the License on
7  * the Enhydra web site ( http://www.enhydra.org/ ).
8  *
9  * Software distributed under the License is distributed on an "AS IS"
10  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
11  * the License for the specific terms governing rights and limitations
12  * under the License.
13  *
14  * The Initial Developer of the Enhydra Application Server is Lutris
15  * Technologies, Inc. The Enhydra Application Server and portions created
16  * by Lutris Technologies, Inc. are Copyright Lutris Technologies, Inc.
17  * All Rights Reserved.
18  *
19  * Contributor(s):
20  *
21  * $Id: DBTransaction.java,v 1.1 2004/09/03 13:42:37 sinisa Exp $
22  *
23  * formatted with JxBeauty (c) johann.langhofer@nextra.at
24  */

25 package com.lutris.appserver.server.sql;
26
27 import java.sql.SQLException JavaDoc;
28
29 /**
30  * Used to perform database transactions.
31  *
32  * <P>Example - adding a new user:
33  * <PRE>
34  * import org.enhydra.dods.DODS;
35  * import com.lutris.appserver.server.sql.*;
36  *
37  * DBTransaction transaction =
38  * DODS.getDatabaseManager().createTransaction(DATABASE_NAME);
39  *
40  * // NOTE: class CustomerDO implements Transaction { ... }
41  * // NOTE: An Object ID is automatically calculated by the constructor.
42  * CustomerDO customer = new CustomerDO();
43  * customer.setFirstName("Santa");
44  * customer.setLastName("Claus");
45  *
46  * // ... set all other CustomerFields ...
47  *
48  * //
49  * // Now add the new object to the database.
50  * //
51  * try {
52  * transaction.insert(customer);
53  * transaction.commit();
54  * System.out.println("Object ID is " + customer.get_OId());
55  * }
56  * catch (SQLException e) {
57  * transaction.rollback();
58  * throw e;
59  * }
60  * finally {
61  * transaction.release();
62  * }
63  * </PRE>
64  *
65  * @author Kyle Clark
66  * @since LBS1.8
67  * @version $Revision: 1.1 $
68  */

69 public interface DBTransaction {
70
71     /**
72      * Method to update an object in the database.
73      *
74      * @param transaction
75      * Object that implements transaction interface.
76      */

77     public void update(Transaction transaction);
78
79     /**
80      * Method to delete an object in the database.
81      *
82      * @param transaction
83      * Object that implements transaction interface.
84      */

85     public void delete(Transaction transaction);
86
87     /**
88      * Method to insert an object in the database.
89      *
90      * @param transaction
91      * Object that implements transaction interface.
92      */

93     public void insert(Transaction transaction);
94
95     /**
96      * Method to commit upates.
97      *
98      * @exception java.sql.SQLException If a database access error occurs.
99      */

100     public void commit() throws SQLException JavaDoc;
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 JavaDoc;
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 JavaDoc 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 JavaDoc getDatabaseName();
163   
164     /**
165      * Method set name of used database
166      *
167      * @param dbName name of used database
168      */

169     public void setDatabaseName(String JavaDoc dbName);
170
171     /**
172      *
173      */

174     public void write() throws SQLException JavaDoc;
175
176     /**
177      *
178      */

179     public void lockDO(Transaction cdo) throws SQLException JavaDoc;
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 JavaDoc;
189     
190     /**
191      *
192      */

193     public boolean preventCacheQueries();
194 }
195
Popular Tags