KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > jts > jta > UserTransactionImpl


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 /*
25  * Copyright 2004-2005 Sun Microsystems, Inc. All rights reserved.
26  * Use is subject to license terms.
27  */

28
29 package com.sun.jts.jta;
30
31 import javax.transaction.*;
32 import javax.naming.*;
33 import java.util.Properties JavaDoc;
34
35 import java.util.logging.Logger JavaDoc;
36 import java.util.logging.Level JavaDoc;
37 import com.sun.logging.LogDomains;
38 /**
39  * This class implements the javax.transaction.UserTransaction interface
40  * which defines methods that allow an application to explicitly manage
41  * transaction boundaries.
42  *
43  * @author Ram Jeyaraman
44  * @version 1.0 Feb 09, 1999
45  */

46 public class UserTransactionImpl implements javax.transaction.UserTransaction JavaDoc,
47     javax.naming.Referenceable JavaDoc, java.io.Serializable JavaDoc {
48
49     // Instance variables
50

51     private transient TransactionManager transactionManager;
52
53     /*
54         Logger to log transaction messages
55     */

56     static Logger JavaDoc _logger = LogDomains.getLogger(LogDomains.TRANSACTION_LOGGER);
57     // Constructor
58

59     public UserTransactionImpl() {}
60
61     // Implementation of javax.transaction.UserTransaction interface
62

63     /**
64      * Create a new transaction and associate it with the current thread.
65      *
66      * @exception IllegalStateException Thrown if the thread is already
67      * associated with a transaction.
68      *
69      * @exception SystemException Thrown if the transaction manager
70      * encounters an unexpected error condition
71      *
72      */

73     public void begin() throws NotSupportedException, SystemException {
74         if (transactionManager == null) init();
75         this.transactionManager.begin();
76     }
77
78     /**
79      * Complete the transaction associated with the current thread. When this
80      * method completes, the thread becomes associated with no transaction.
81      *
82      * @exception TransactionRolledbackException Thrown to indicate that
83      * the transaction has been rolled back rather than committed.
84      *
85      * @exception HeuristicMixedException Thrown to indicate that a heuristic
86      * decision was made and that some relevant updates have been committed
87      * while others have been rolled back.
88      *
89      * @exception HeuristicRollbackException Thrown to indicate that a
90      * heuristic decision was made and that all relevant updates have been
91      * rolled back.
92      *
93      * @exception SecurityException Thrown to indicate that the thread is
94      * not allowed to commit the transaction.
95      *
96      * @exception IllegalStateException Thrown if the current thread is
97      * not associated with a transaction.
98      *
99      * @exception SystemException Thrown if the transaction manager
100      * encounters an unexpected error condition
101     */

102     public void commit() throws RollbackException,
103     HeuristicMixedException, HeuristicRollbackException, SecurityException JavaDoc,
104     IllegalStateException JavaDoc, SystemException {
105         if (transactionManager == null) init();
106         this.transactionManager.commit();
107     }
108
109     /**
110      * Roll back the transaction associated with the current thread. When this
111      * method completes, the thread becomes associated with no transaction.
112      *
113      * @exception SecurityException Thrown to indicate that the thread is
114      * not allowed to roll back the transaction.
115      *
116      * @exception IllegalStateException Thrown if the current thread is
117      * not associated with a transaction.
118      *
119      * @exception SystemException Thrown if the transaction manager
120      * encounters an unexpected error condition
121      *
122      */

123     public void rollback() throws IllegalStateException JavaDoc, SecurityException JavaDoc,
124         SystemException {
125         if (transactionManager == null) init();
126         this.transactionManager.rollback();
127     }
128
129     /**
130      * Modify the transaction associated with the current thread such that
131      * the only possible outcome of the transaction is to roll back the
132      * transaction.
133      *
134      * @exception IllegalStateException Thrown if the current thread is
135      * not associated with a transaction.
136      *
137      * @exception SystemException Thrown if the transaction manager
138      * encounters an unexpected error condition
139      *
140      */

141     public void setRollbackOnly() throws IllegalStateException JavaDoc,
142         SystemException {
143         if (transactionManager == null) init();
144         this.transactionManager.setRollbackOnly();
145     }
146
147     /**
148      * Obtain the status of the transaction associated with the current thread.
149      *
150      * @return The transaction status. If no transaction is associated with
151      * the current thread, this method returns the Status.NoTransaction
152      * value.
153      *
154      * @exception SystemException Thrown if the transaction manager
155      * encounters an unexpected error condition
156      *
157      */

158     public int getStatus() throws SystemException {
159         if (transactionManager == null) init();
160         return this.transactionManager.getStatus();
161     }
162
163     /**
164      * Modify the timeout value that is associated with transactions started
165      * by subsequent invocations of the begin method.
166      *
167      * <p> If an application has not called this method, the transaction
168      * service uses some default value for the transaction timeout.
169      *
170      * @param seconds The value of the timeout in seconds. If the value is zero,
171      * the transaction service restores the default value. If the value
172      * is negative a SystemException is thrown.
173      *
174      * @exception SystemException Thrown if the transaction manager
175      * encounters an unexpected error condition.
176      *
177      */

178     public void setTransactionTimeout(int seconds) throws SystemException {
179         if (transactionManager == null) init();
180         this.transactionManager.setTransactionTimeout(seconds);
181     }
182
183     // Implementation of the javax.naming.Referenceable interface
184

185     /**
186      * This method is used by JNDI to store a referenceable object.
187      */

188     public Reference getReference() throws NamingException {
189         //_logger.log(Level.FINE,"Referenceable object invoked");
190
return new Reference(this.getClass().getName(),
191             UserTransactionFactory.class.getName(), null);
192     }
193
194     // serializable interface related
195

196
197     private void init() {
198         this.transactionManager =
199             TransactionManagerImpl.getTransactionManagerImpl();
200     }
201 }
202
203
Popular Tags