KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > portal > core > impl > tree > tm > TransactionObservation


1 /*****************************************
2  * *
3  * JBoss Portal: The OpenSource Portal *
4  * *
5  * Distributable under LGPL license. *
6  * See terms of license at gnu.org. *
7  * *
8  *****************************************/

9 package org.jboss.portal.core.impl.tree.tm;
10
11 import javax.transaction.Transaction JavaDoc;
12 import javax.transaction.RollbackException JavaDoc;
13 import javax.transaction.HeuristicMixedException JavaDoc;
14 import javax.transaction.HeuristicRollbackException JavaDoc;
15 import javax.transaction.SystemException JavaDoc;
16 import javax.transaction.Synchronization JavaDoc;
17 import javax.transaction.xa.XAResource JavaDoc;
18 import java.util.List JavaDoc;
19 import java.util.ArrayList JavaDoc;
20 import java.util.Iterator JavaDoc;
21
22 /**
23  * Symbolize an on going current JTA transaction. It supports attachment of listeners that wants to know the outcome
24  * of the transaction that is being observed. It also implements the <code>javax.transaction.Transaction</code>
25  * interface that delegates to the <code>TransactionManagerObserver</code>.
26  *
27  * @author <a HREF="mailto:julien@jboss.org">Julien Viet</a>
28  * @version $Revision: 1.1 $
29  */

30 public class TransactionObservation implements Transaction JavaDoc
31 {
32
33    /** The set of listeners. */
34    private final List JavaDoc listeners;
35
36    /** . */
37    private final TransactionManagerObserver observer;
38
39    /** . */
40    final Transaction JavaDoc tx;
41
42    public TransactionObservation(TransactionManagerObserver observer, Transaction JavaDoc tx)
43    {
44       this.listeners = new ArrayList JavaDoc();
45       this.tx = tx;
46       this.observer = observer;
47    }
48
49    /**
50     * Add a listener.
51     *
52     * @param listener the listener to add
53     */

54    public void addListener(TransactionListener listener)
55    {
56       listeners.add(listener);
57    }
58
59    void afterCommit()
60    {
61       for (Iterator JavaDoc i = listeners.iterator(); i.hasNext();)
62       {
63          TransactionListener listener = (TransactionListener)i.next();
64          listener.afterCommit();
65       }
66    }
67
68    void afterRollback()
69    {
70       for (Iterator JavaDoc i = listeners.iterator(); i.hasNext();)
71       {
72          TransactionListener listener = (TransactionListener)i.next();
73          listener.afterRollack();
74       }
75    }
76
77    public void commit() throws RollbackException JavaDoc, HeuristicMixedException JavaDoc, HeuristicRollbackException JavaDoc, SecurityException JavaDoc, SystemException JavaDoc
78    {
79       observer.commit();
80    }
81
82    public void rollback() throws IllegalStateException JavaDoc, SystemException JavaDoc
83    {
84       observer.rollback();
85    }
86
87    public void setRollbackOnly() throws IllegalStateException JavaDoc, SystemException JavaDoc
88    {
89       tx.setRollbackOnly();
90    }
91
92    public int getStatus() throws SystemException JavaDoc
93    {
94       return tx.getStatus();
95    }
96
97    public boolean enlistResource(XAResource JavaDoc xares) throws RollbackException JavaDoc, IllegalStateException JavaDoc, SystemException JavaDoc
98    {
99       return tx.enlistResource(xares);
100    }
101
102    public boolean delistResource(XAResource JavaDoc xares, int value) throws IllegalStateException JavaDoc, SystemException JavaDoc
103    {
104       return tx.delistResource(xares, value);
105    }
106
107    public void registerSynchronization(Synchronization JavaDoc synch) throws RollbackException JavaDoc, IllegalStateException JavaDoc, SystemException JavaDoc
108    {
109       tx.registerSynchronization(synch);
110    }
111
112    public int hashCode()
113    {
114       return tx.hashCode();
115    }
116
117    public boolean equals(Object JavaDoc obj)
118    {
119       return ((TransactionObservation)obj).tx.equals(tx);
120    }
121 }
122
Popular Tags