1 /*
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3 *
4 * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
5 *
6 * The contents of this file are subject to the terms of either the GNU
7 * General Public License Version 2 only ("GPL") or the Common Development
8 * and Distribution License("CDDL") (collectively, the "License"). You
9 * may not use this file except in compliance with the License. You can obtain
10 * a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
11 * or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
12 * language governing permissions and limitations under the License.
13 *
14 * When distributing the software, include this License Header Notice in each
15 * file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
16 * Sun designates this particular file as subject to the "Classpath" exception
17 * as provided by Sun in the GPL Version 2 section of the License file that
18 * accompanied this code. If applicable, add the following below the License
19 * Header, with the fields enclosed by brackets [] replaced by your own
20 * identifying information: "Portions Copyrighted [year]
21 * [name of copyright owner]"
22 *
23 * Contributor(s):
24 *
25 * If you wish your version of this file to be governed by only the CDDL or
26 * only the GPL Version 2, indicate your decision by adding "[Contributor]
27 * elects to include this software in this distribution under the [CDDL or GPL
28 * Version 2] license." If you don't indicate a single choice of license, a
29 * recipient has the option to distribute your version of this file under
30 * either the CDDL, the GPL Version 2 or to extend the choice of license to
31 * its licensees as provided above. However, if you add GPL Version 2 code
32 * and therefore, elected the GPL Version 2 license, then the option applies
33 * only if the new code is made subject to such option by the copyright
34 * holder.
35 */
36
37 package javax.transaction;
38
39 import javax.transaction.xa.XAResource;
40 import java.lang.IllegalStateException;
41 import java.lang.SecurityException;
42
43 /**
44 * The Transaction interface allows operations to be performed against
45 * the transaction in the target Transaction object. A Transaction
46 * object is created corresponding to each global transaction creation.
47 * The Transaction object can be used for resource enlistment,
48 * synchronization registration, transaction completion, and status
49 * query operations.
50 */
51
52 public interface Transaction {
53
54 /**
55 * Complete the transaction represented by this Transaction object.
56 *
57 * @exception RollbackException Thrown to indicate that
58 * the transaction has been rolled back rather than committed.
59 *
60 * @exception HeuristicMixedException Thrown to indicate that a heuristic
61 * decision was made and that some relevant updates have been committed
62 * while others have been rolled back.
63 *
64 * @exception HeuristicRollbackException Thrown to indicate that a
65 * heuristic decision was made and that all relevant updates have been
66 * rolled back.
67 *
68 * @exception SecurityException Thrown to indicate that the thread is
69 * not allowed to commit the transaction.
70 *
71 * @exception IllegalStateException Thrown if the transaction in the
72 * target object is inactive.
73 *
74 * @exception SystemException Thrown if the transaction manager
75 * encounters an unexpected error condition.
76 */
77 public void commit() throws RollbackException,
78 HeuristicMixedException, HeuristicRollbackException,
79 SecurityException, IllegalStateException, SystemException;
80
81 /**
82 * Disassociate the resource specified from the transaction associated
83 * with the target Transaction object.
84 *
85 * @param xaRes The XAResource object associated with the resource
86 * (connection).
87 *
88 * @param flag One of the values of TMSUCCESS, TMSUSPEND, or TMFAIL.
89 *
90 * @exception IllegalStateException Thrown if the transaction in the
91 * target object is inactive.
92 *
93 * @exception SystemException Thrown if the transaction manager
94 * encounters an unexpected error condition.
95 *
96 * @return <i>true</i> if the resource was delisted successfully; otherwise
97 * <i>false</i>.
98 *
99 */
100 public boolean delistResource(XAResource xaRes, int flag)
101 throws IllegalStateException, SystemException;
102
103 /**
104 * Enlist the resource specified with the transaction associated with the
105 * target Transaction object.
106 *
107 * @param xaRes The XAResource object associated with the resource
108 * (connection).
109 *
110 * @return <i>true</i> if the resource was enlisted successfully; otherwise
111 * <i>false</i>.
112 *
113 * @exception RollbackException Thrown to indicate that
114 * the transaction has been marked for rollback only.
115 *
116 * @exception IllegalStateException Thrown if the transaction in the
117 * target object is in the prepared state or the transaction is
118 * inactive.
119 *
120 * @exception SystemException Thrown if the transaction manager
121 * encounters an unexpected error condition.
122 *
123 */
124 public boolean enlistResource(XAResource xaRes)
125 throws RollbackException, IllegalStateException,
126 SystemException;
127
128 /**
129 * Obtain the status of the transaction associated with the target
130 * Transaction object.
131 *
132 * @return The transaction status. If no transaction is associated with
133 * the target object, this method returns the
134 * Status.NoTransaction value.
135 *
136 * @exception SystemException Thrown if the transaction manager
137 * encounters an unexpected error condition.
138 *
139 */
140 public int getStatus() throws SystemException;
141
142 /**
143 * Register a synchronization object for the transaction currently
144 * associated with the target object. The transction manager invokes
145 * the beforeCompletion method prior to starting the two-phase transaction
146 * commit process. After the transaction is completed, the transaction
147 * manager invokes the afterCompletion method.
148 *
149 * @param sync The Synchronization object for the transaction associated
150 * with the target object.
151 *
152 * @exception RollbackException Thrown to indicate that
153 * the transaction has been marked for rollback only.
154 *
155 * @exception IllegalStateException Thrown if the transaction in the
156 * target object is in the prepared state or the transaction is
157 * inactive.
158 *
159 * @exception SystemException Thrown if the transaction manager
160 * encounters an unexpected error condition.
161 *
162 */
163 public void registerSynchronization(Synchronization sync)
164 throws RollbackException, IllegalStateException,
165 SystemException;
166
167 /**
168 * Rollback the transaction represented by this Transaction object.
169 *
170 * @exception IllegalStateException Thrown if the transaction in the
171 * target object is in the prepared state or the transaction is
172 * inactive.
173 *
174 * @exception SystemException Thrown if the transaction manager
175 * encounters an unexpected error condition.
176 *
177 */
178 public void rollback() throws IllegalStateException, SystemException;
179
180 /**
181 * Modify the transaction associated with the target object such that
182 * the only possible outcome of the transaction is to roll back the
183 * transaction.
184 *
185 * @exception IllegalStateException Thrown if the target object is
186 * not associated with any transaction.
187 *
188 * @exception SystemException Thrown if the transaction manager
189 * encounters an unexpected error condition.
190 *
191 */
192 public void setRollbackOnly() throws IllegalStateException,
193 SystemException;
194
195 }