KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > ejb3 > embedded > UserTransactionImpl


1 /*
2   * JBoss, Home of Professional Open Source
3   * Copyright 2005, JBoss Inc., and individual contributors as indicated
4   * by the @authors tag. See the copyright.txt in the distribution for a
5   * full listing of individual contributors.
6   *
7   * This is free software; you can redistribute it and/or modify it
8   * under the terms of the GNU Lesser General Public License as
9   * published by the Free Software Foundation; either version 2.1 of
10   * the License, or (at your option) any later version.
11   *
12   * This software is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15   * Lesser General Public License for more details.
16   *
17   * You should have received a copy of the GNU Lesser General Public
18   * License along with this software; if not, write to the Free
19   * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20   * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21   */

22 package org.jboss.ejb3.embedded;
23
24 import java.io.IOException JavaDoc;
25 import java.io.ObjectInput JavaDoc;
26 import java.io.ObjectOutput JavaDoc;
27 import javax.transaction.HeuristicMixedException JavaDoc;
28 import javax.transaction.HeuristicRollbackException JavaDoc;
29 import javax.transaction.NotSupportedException JavaDoc;
30 import javax.transaction.RollbackException JavaDoc;
31 import javax.transaction.SystemException JavaDoc;
32 import javax.transaction.Transaction JavaDoc;
33 import javax.transaction.TransactionManager JavaDoc;
34 import javax.transaction.UserTransaction JavaDoc;
35 import org.jboss.logging.Logger;
36 import org.jboss.ejb3.tx.TxUtil;
37
38 /**
39  * Comment
40  *
41  * @author <a HREF="mailto:bill@jboss.org">Bill Burke</a>
42  * @version $Revision: 40050 $
43  */

44 public final class UserTransactionImpl implements UserTransaction JavaDoc, java.io.Externalizable JavaDoc
45 {
46    protected static Logger log = Logger.getLogger(UserTransactionImpl.class);
47
48    /**
49     * Timeout value in seconds for new transactions started
50     * by this bean instance.
51     */

52    private TransactionManager JavaDoc tm;
53
54    public UserTransactionImpl()
55    {
56    }
57
58    public void start()
59    {
60       if (log.isDebugEnabled())
61          log.debug("new UserTx: " + this);
62       this.tm = TxUtil.getTransactionManager();
63    }
64
65    public void stop()
66    {
67       this.tm = null;
68    }
69
70    public void begin()
71            throws NotSupportedException JavaDoc, SystemException JavaDoc
72    {
73       // Start the transaction
74
tm.begin();
75
76       Transaction JavaDoc tx = tm.getTransaction();
77       if (log.isDebugEnabled())
78          log.debug("UserTx begin: " + tx);
79
80    }
81
82    public void commit()
83            throws RollbackException JavaDoc, HeuristicMixedException JavaDoc, HeuristicRollbackException JavaDoc,
84                   SecurityException JavaDoc, IllegalStateException JavaDoc, SystemException JavaDoc
85    {
86       Transaction JavaDoc tx = tm.getTransaction();
87       if (log.isDebugEnabled())
88          log.debug("UserTx commit: " + tx);
89
90       tm.commit();
91    }
92
93    public void rollback()
94            throws IllegalStateException JavaDoc, SecurityException JavaDoc, SystemException JavaDoc
95    {
96       Transaction JavaDoc tx = tm.getTransaction();
97       if (log.isDebugEnabled())
98          log.debug("UserTx rollback: " + tx);
99       tm.rollback();
100    }
101
102    public void setRollbackOnly()
103            throws IllegalStateException JavaDoc, SystemException JavaDoc
104    {
105       Transaction JavaDoc tx = tm.getTransaction();
106       if (log.isDebugEnabled())
107          log.debug("UserTx setRollbackOnly: " + tx);
108
109       tm.setRollbackOnly();
110    }
111
112    public int getStatus()
113            throws SystemException JavaDoc
114    {
115       return tm.getStatus();
116    }
117
118    /**
119     * Set the transaction timeout value for new transactions
120     * started by this instance.
121     */

122    public void setTransactionTimeout(int seconds)
123            throws SystemException JavaDoc
124    {
125       tm.setTransactionTimeout(seconds);
126    }
127
128    public void writeExternal(ObjectOutput JavaDoc out) throws IOException JavaDoc
129    {
130       //To change body of implemented methods use File | Settings | File Templates.
131
}
132
133    public void readExternal(ObjectInput JavaDoc in) throws IOException JavaDoc, ClassNotFoundException JavaDoc
134    {
135       this.tm = TxUtil.getTransactionManager();
136    }
137
138 }
139
Popular Tags