001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common Development
008: * and Distribution License("CDDL") (collectively, the "License"). You
009: * may not use this file except in compliance with the License. You can obtain
010: * a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
011: * or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
012: * language governing permissions and limitations under the License.
013: *
014: * When distributing the software, include this License Header Notice in each
015: * file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
016: * Sun designates this particular file as subject to the "Classpath" exception
017: * as provided by Sun in the GPL Version 2 section of the License file that
018: * accompanied this code. If applicable, add the following below the License
019: * Header, with the fields enclosed by brackets [] replaced by your own
020: * identifying information: "Portions Copyrighted [year]
021: * [name of copyright owner]"
022: *
023: * Contributor(s):
024: *
025: * If you wish your version of this file to be governed by only the CDDL or
026: * only the GPL Version 2, indicate your decision by adding "[Contributor]
027: * elects to include this software in this distribution under the [CDDL or GPL
028: * Version 2] license." If you don't indicate a single choice of license, a
029: * recipient has the option to distribute your version of this file under
030: * either the CDDL, the GPL Version 2 or to extend the choice of license to
031: * its licensees as provided above. However, if you add GPL Version 2 code
032: * and therefore, elected the GPL Version 2 license, then the option applies
033: * only if the new code is made subject to such option by the copyright
034: * holder.
035: */
036:
037: package javax.transaction;
038:
039: import javax.transaction.xa.XAResource;
040: import java.lang.IllegalStateException;
041: import java.lang.SecurityException;
042:
043: /**
044: * The Transaction interface allows operations to be performed against
045: * the transaction in the target Transaction object. A Transaction
046: * object is created corresponding to each global transaction creation.
047: * The Transaction object can be used for resource enlistment,
048: * synchronization registration, transaction completion, and status
049: * query operations.
050: */
051:
052: public interface Transaction {
053:
054: /**
055: * Complete the transaction represented by this Transaction object.
056: *
057: * @exception RollbackException Thrown to indicate that
058: * the transaction has been rolled back rather than committed.
059: *
060: * @exception HeuristicMixedException Thrown to indicate that a heuristic
061: * decision was made and that some relevant updates have been committed
062: * while others have been rolled back.
063: *
064: * @exception HeuristicRollbackException Thrown to indicate that a
065: * heuristic decision was made and that all relevant updates have been
066: * rolled back.
067: *
068: * @exception SecurityException Thrown to indicate that the thread is
069: * not allowed to commit the transaction.
070: *
071: * @exception IllegalStateException Thrown if the transaction in the
072: * target object is inactive.
073: *
074: * @exception SystemException Thrown if the transaction manager
075: * encounters an unexpected error condition.
076: */
077: public void commit() throws RollbackException,
078: HeuristicMixedException, HeuristicRollbackException,
079: SecurityException, IllegalStateException, SystemException;
080:
081: /**
082: * Disassociate the resource specified from the transaction associated
083: * with the target Transaction object.
084: *
085: * @param xaRes The XAResource object associated with the resource
086: * (connection).
087: *
088: * @param flag One of the values of TMSUCCESS, TMSUSPEND, or TMFAIL.
089: *
090: * @exception IllegalStateException Thrown if the transaction in the
091: * target object is inactive.
092: *
093: * @exception SystemException Thrown if the transaction manager
094: * encounters an unexpected error condition.
095: *
096: * @return <i>true</i> if the resource was delisted successfully; otherwise
097: * <i>false</i>.
098: *
099: */
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,
179: SystemException;
180:
181: /**
182: * Modify the transaction associated with the target object such that
183: * the only possible outcome of the transaction is to roll back the
184: * transaction.
185: *
186: * @exception IllegalStateException Thrown if the target object is
187: * not associated with any transaction.
188: *
189: * @exception SystemException Thrown if the transaction manager
190: * encounters an unexpected error condition.
191: *
192: */
193: public void setRollbackOnly() throws IllegalStateException,
194: SystemException;
195:
196: }
|