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

Quick Search    Search Deep

Source code: ojb/odmg/TransactionAware.java


1   /*
2    * ObJectRelationalBridge - Bridging Java Objects and Relational Databases
3    * http://objectbridge.sourceforge.net
4    * Copyright (C) 2000, 2001 Thomas Mahler, et al.
5    *
6    * This library is free software; you can redistribute it and/or
7    * modify it under the terms of the GNU Lesser General Public
8    * License as published by the Free Software Foundation; either
9    * version 2.1 of the License, or (at your option) any later version.
10   *
11   * This library is distributed in the hope that it will be useful,
12   * but WITHOUT ANY WARRANTY; without even the implied warranty of
13   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14   * Lesser General Public License for more details.
15   *
16   * You should have received a copy of the GNU Lesser General Public
17   * License along with this library; if not, write to the Free Software
18   * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19   */
20  
21  
22  package ojb.odmg;
23  
24  import java.io.Serializable;
25  
26  /**
27   *
28   * TransactionAware is an interface that can be implemented
29   * to provide hooks into the Transaction interface provided
30   * by ObJectRelationalBridge.
31  
32   * Only objects which have a write lock acquired on them can
33   * participate in a transaction.
34  
35   * To kill a transaction, implement beforeCommit() and throw
36   * a TransactionAbortedException.  This will force the entire
37   * transaction to rollback.
38   *
39   * To rebuild an object after a rollback use the afterAbort()
40   * call.  This is a good place to populate transient or other
41   * variables.
42   *
43   * beforeAbort and afterCommit are there for informational
44   * purposes.
45   *
46   * Here are some common ways you can expect this interface
47   * to be called:
48   *
49   * Sucessful commit:
50   * beforeCommit()
51   * afterCommit()
52   *
53   * Transaction Failure (1):
54   * beforeCommit()
55   * beforeAbort()
56   * afterAbort()
57   *
58   * Transaction Failure (2):
59   * beforeAbort()
60   * afterAbort()
61   *
62   * Commits and Aborts aren't directly provided to TransactionAware classes.
63   * The idea is that Transactions are difficult to handle, and most of it
64   * will be handled by ObjectSnapshot.  However, you use TransactionAware
65   * to do one of two things, kill a transaction from happening, and clean
66   * up after a rollback.
67   *
68   */
69  public interface TransactionAware extends Serializable
70  {
71      /**
72       *
73       * beforeCommit will give an object a chance to kill a
74       * transaction before it is committed.
75       * To kill a transaction, throw a new TransactionAbortedException.
76       *
77       */
78      public void beforeCommit() throws org.odmg.TransactionAbortedException;
79  
80      /**
81       *
82       * afterCommit is called only after a successful commit has taken
83       * place.
84       *
85       */
86      public void afterCommit();
87  
88      /**
89       *
90       * beforeAbort is called before a transaction is aborted.
91       *
92       */
93      public void beforeAbort();
94  
95      /**
96       *
97       * afterAbort will be called after a transaction has been aborted.
98       * The values of fields which get persisted will have changed to
99       * what they were at the begining of the transaction.  This method
100      * should be overridden to reset any transient or non-persistent
101      * fields.
102      *
103      */
104     public void afterAbort();
105 }