KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > ejb3 > tx > 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.tx;
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
37 /**
38  * Comment
39  *
40  * @author <a HREF="mailto:bill@jboss.org">Bill Burke</a>
41  * @version $Revision: 42321 $
42  */

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

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

112    public void setTransactionTimeout(int seconds)
113            throws SystemException JavaDoc
114    {
115       tm.setTransactionTimeout(seconds);
116    }
117
118    public void writeExternal(ObjectOutput JavaDoc out) throws IOException JavaDoc
119    {
120       //To change body of implemented methods use File | Settings | File Templates.
121
}
122
123    public void readExternal(ObjectInput JavaDoc in) throws IOException JavaDoc, ClassNotFoundException JavaDoc
124    {
125       this.tm = TxUtil.getTransactionManager();
126    }
127
128 }
129
Popular Tags