KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > cache > transaction > DummyUserTransaction


1 package org.jboss.cache.transaction;
2
3 import org.apache.commons.logging.Log;
4 import org.apache.commons.logging.LogFactory;
5
6 import javax.transaction.HeuristicMixedException JavaDoc;
7 import javax.transaction.HeuristicRollbackException JavaDoc;
8 import javax.transaction.NotSupportedException JavaDoc;
9 import javax.transaction.RollbackException JavaDoc;
10 import javax.transaction.Status JavaDoc;
11 import javax.transaction.Synchronization JavaDoc;
12 import javax.transaction.SystemException JavaDoc;
13 import javax.transaction.UserTransaction JavaDoc;
14 import java.util.ArrayList JavaDoc;
15 import java.util.List JavaDoc;
16
17 /**
18  * @author bela
19  * @version $Revision: 1.5 $
20  * Date: May 15, 2003
21  * Time: 4:20:17 PM
22  */

23 public class DummyUserTransaction implements UserTransaction JavaDoc, java.io.Serializable JavaDoc
24 {
25    int status = Status.STATUS_UNKNOWN;
26    static final Log logger_ = LogFactory.getLog(DummyUserTransaction.class);
27    DummyTransactionManager tm_;
28    private static final long serialVersionUID = -6568400755677046127L;
29
30    /**
31     * List<Synchronization>
32     */

33    List JavaDoc<Synchronization JavaDoc> l = new ArrayList JavaDoc<Synchronization JavaDoc>();
34
35    public DummyUserTransaction(DummyTransactionManager tm)
36    {
37       tm_ = tm;
38    }
39
40
41    /**
42     * Starts a new transaction, and associate it with the calling thread.
43     *
44     * @throws NotSupportedException If the calling thread is already
45     * associated with a transaction, and nested transactions are
46     * not supported.
47     * @throws SystemException If the transaction service fails in an
48     * unexpected way.
49     */

50    public void begin() throws NotSupportedException JavaDoc, SystemException JavaDoc
51    {
52       tm_.begin();
53       status = Status.STATUS_ACTIVE;
54    }
55
56    /**
57     * Attempt to commit this transaction.
58     *
59     * @throws RollbackException If the transaction was marked for rollback
60     * only, the transaction is rolled back and this exception is
61     * thrown.
62     * @throws SystemException If the transaction service fails in an
63     * unexpected way.
64     * @throws HeuristicMixedException If a heuristic decision was made and
65     * some some parts of the transaction have been committed while
66     * other parts have been rolled back.
67     * @throws HeuristicRollbackException If a heuristic decision to roll
68     * back the transaction was made.
69     * @throws SecurityException If the caller is not allowed to commit this
70     * transaction.
71     */

72    public void commit()
73            throws RollbackException JavaDoc, HeuristicMixedException JavaDoc,
74            HeuristicRollbackException JavaDoc, SecurityException JavaDoc, SystemException JavaDoc
75    {
76
77       tm_.commit();
78       status = Status.STATUS_COMMITTED;
79    }
80
81    /**
82     * Rolls back this transaction.
83     *
84     * @throws IllegalStateException If the transaction is in a state
85     * where it cannot be rolled back. This could be because the
86     * transaction is no longer active, or because it is in the
87     * {@link Status#STATUS_PREPARED prepared state}.
88     * @throws SystemException If the transaction service fails in an
89     * unexpected way.
90     */

91    public void rollback() throws IllegalStateException JavaDoc, SystemException JavaDoc
92    {
93       tm_.rollback();
94       status = Status.STATUS_ROLLEDBACK;
95    }
96
97    /**
98     * Mark the transaction so that the only possible outcome is a rollback.
99     *
100     * @throws IllegalStateException If the transaction is not in an active
101     * state.
102     * @throws SystemException If the transaction service fails in an
103     * unexpected way.
104     */

105    public void setRollbackOnly() throws IllegalStateException JavaDoc, SystemException JavaDoc
106    {
107       tm_.setRollbackOnly();
108    }
109
110    /**
111     * Get the status of the transaction.
112     *
113     * @return The status of the transaction. This is one of the
114     * {@link Status} constants.
115     * @throws SystemException If the transaction service fails in an
116     * unexpected way.
117     */

118    public int getStatus() throws SystemException JavaDoc
119    {
120       return tm_.getStatus();
121    }
122
123    /**
124     * Change the transaction timeout for transactions started by the calling
125     * thread with the {@link #begin()} method.
126     *
127     * @param seconds The new timeout value, in seconds. If this parameter
128     * is <code>0</code>, the timeout value is reset to the default
129     * value.
130     * @throws SystemException If the transaction service fails in an
131     * unexpected way.
132     */

133    public void setTransactionTimeout(int seconds) throws SystemException JavaDoc
134    {
135       throw new SystemException JavaDoc("not supported");
136    }
137
138 }
139
Popular Tags