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

Quick Search    Search Deep

Source code: ojb/server/TransactionAware.java


1   
2   /**
3    * Title:        ObJectBridge<p>
4    * Description:  Relational - Object Bridge<p>
5    * Copyright:    Copyright (c)2000 Thomas Mahler, David Dixon-Peugh<p>
6    * Company:      <p>
7    * @author David Dixon-Peugh
8    * @version 1.0
9    */
10  package ojb.server;
11  
12  import org.odmg.TransactionAbortedException;
13  
14  /**
15   * TransactionAware is an interface that can be implemented
16   * to provide hooks into the Transaction interface provided
17   * by ObJectBridge.
18   *
19   * Only objects which have a write lock acquired on them can
20   * participate in a transaction.
21   *
22   * To kill a transaction, implement beforeCommit() and throw
23   * a TransactionAbortedException.  This will force the entire
24   * transaction to rollback.
25   *
26   * To rebuild an object after a rollback use the afterAbort()
27   * call.  This is a good place to populate transient or other
28   * variables.
29   *
30   * beforeAbort and afterCommit are there for informational
31   * purposes.
32   *
33   * Here are some common ways you can expect this interface
34   * to be called:
35   *
36   * Sucessful commit:
37   *   beforeCommit()
38   *   afterCommit()
39   *
40   * Transaction Failure (1):
41   *   beforeCommit()
42   *   beforeAbort()
43   *   afterAbort()
44   *
45   * Transaction Failure (2):
46   *   beforeAbort()
47   *   afterAbort()
48   *
49   * Commits and Aborts aren't directly provided to TransactionAware classes.
50   * The idea is that Transactions are difficult to handle, and most of it
51   * will be handled by ObjectSnapshot.  However, you use TransactionAware
52   * to do one of two things, kill a transaction from happening, and clean
53   * up after a rollback.
54   *
55   */
56  public interface TransactionAware {
57    /**
58     * beforeCommit will give an object a chance to kill a
59     * transaction before it is committed.
60     *
61     * To kill a transaction, throw a new TransactionAbortedException.
62     */
63    public void beforeCommit()
64    throws org.odmg.TransactionAbortedException;
65  
66    /**
67     * afterCommit is called only after a successful commit has taken
68     * place.
69     */
70    public void afterCommit();  
71  
72    /**
73     * beforeAbort is called before a transaction is aborted.
74     */
75    public void beforeAbort();  
76  
77    /**
78     * afterAbort will be called after a transaction has been aborted.
79     * The values of fields which get persisted will have changed to
80     * what they were at the begining of the transaction.  This method
81     * should be overridden to reset any transient or non-persistent
82     * fields.
83     */
84    public void afterAbort();  
85  
86  }