Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: com/lutris/appserver/server/sql/DBTransaction.java


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.17.12.1 2000/10/19 17:59:05 jasona Exp $
22   */
23  
24  
25  
26  
27  
28  package  com.lutris.appserver.server.sql;
29  
30  import java.sql.*;
31  
32  /**
33   * Used to perform database transactions.
34   *
35   * <P>Example - adding a new user:
36   * <PRE>
37   *    import com.lutris.appserver.server.LBS;
38   *    import com.lutris.appserver.server.sql.*;
39   *
40   *       DBTransaction transaction =
41   *         LBS.getDatabaseManager().createTransaction(DATABASE_NAME);
42   *
43   *       // NOTE: class CustomerDO implements Transaction { ... }
44   *       // NOTE: An Object ID is automatically calculated by the constructor.
45   *       CustomerDO customer = new CustomerDO();
46   *       customer.setFirstName("Santa");
47   *       customer.setLastName("Claus");
48   *
49   *       // ... set all other CustomerFields ...
50   *
51   *       //
52   *       // Now add the new object to the database.
53   *       //
54   *       try {
55   *           transaction.insert(customer);
56   *           transaction.commit();
57   *           System.out.println("Object ID is " + customer.getOId());
58   *       }
59   *       catch (SQLException e) {
60   *           transaction.rollback();
61   *           throw e;
62   *       }
63   *       finally {
64   *           transaction.release();
65   *       }
66   * </PRE>
67   *
68   * @author  Kyle Clark
69   * @since  LBS1.8
70   * @version  $Revision: 1.17.12.1 $
71   */
72  public interface DBTransaction {
73  
74      /**
75       * Method to update an object in the database.
76       *
77       * @param transaction
78       *   Object that implements transaction interface.
79       */
80      public void update(Transaction transaction);
81  
82  
83      /**
84       * Method to delete an object in the database.
85       *
86       * @param transaction
87       *   Object that implements transaction interface.
88       */
89      public void delete(Transaction transaction);
90  
91  
92      /**
93       * Method to insert an object in the database.
94       *
95       * @param transaction
96       *   Object that implements transaction interface.
97       */
98      public void insert(Transaction transaction);
99  
100 
101     /**
102      * Method to commit upates.
103      *
104      * @exception java.sql.SQLException If a database access error occurs. 
105      * @exception DBRowUpdateException If a version error occurs.
106      */
107     public void commit() throws SQLException, DBRowUpdateException;     
108 
109 
110     /**
111      * Method to rollback changes.
112      *
113      * @exception java.sql.SQLException
114      *   If a database access error occurs. 
115      */
116     public void rollback() throws SQLException;
117 
118 
119     /**
120      * Frees all resources consumed by this transaction
121      * Connections are returned to the connection pool.
122      * Subsequent transactions via this object,
123      * will allocate a new set of resources (i.e. connection).
124      */
125     public void release();
126 
127 
128     /**
129      * Exception handeler.  This object is should not be
130      * used for subsequent queries if this method returns
131      * false.
132      *
133      * @return boolean True if the exception can be handeled
134      *   and the object is still valid, false otherwise.
135      */
136     public boolean handleException(SQLException e);
137 }