Wed, 26 Feb 2014 14:43:56 -0800
Added tag jdk8u20-b03 for changeset 9059a1c85704
duke@1 | 1 | /* |
ohair@158 | 2 | * Copyright (c) 2000, 2001, Oracle and/or its affiliates. All rights reserved. |
duke@1 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
duke@1 | 4 | * |
duke@1 | 5 | * This code is free software; you can redistribute it and/or modify it |
duke@1 | 6 | * under the terms of the GNU General Public License version 2 only, as |
ohair@158 | 7 | * published by the Free Software Foundation. Oracle designates this |
duke@1 | 8 | * particular file as subject to the "Classpath" exception as provided |
ohair@158 | 9 | * by Oracle in the LICENSE file that accompanied this code. |
duke@1 | 10 | * |
duke@1 | 11 | * This code is distributed in the hope that it will be useful, but WITHOUT |
duke@1 | 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
duke@1 | 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
duke@1 | 14 | * version 2 for more details (a copy is included in the LICENSE file that |
duke@1 | 15 | * accompanied this code). |
duke@1 | 16 | * |
duke@1 | 17 | * You should have received a copy of the GNU General Public License version |
duke@1 | 18 | * 2 along with this work; if not, write to the Free Software Foundation, |
duke@1 | 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
duke@1 | 20 | * |
ohair@158 | 21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
ohair@158 | 22 | * or visit www.oracle.com if you need additional information or have any |
ohair@158 | 23 | * questions. |
duke@1 | 24 | */ |
duke@1 | 25 | |
duke@1 | 26 | package javax.transaction.xa; |
duke@1 | 27 | |
duke@1 | 28 | /** <p>The XAResource interface is a Java mapping of the industry standard |
duke@1 | 29 | * XA interface based on the X/Open CAE Specification (Distributed |
duke@1 | 30 | * Transaction Processing: The XA Specification). |
duke@1 | 31 | * |
duke@1 | 32 | * <p>The XA interface defines the contract between a Resource Manager |
duke@1 | 33 | * and a Transaction Manager in a distributed transaction processing |
duke@1 | 34 | * (DTP) environment. A JDBC driver or a JMS provider implements |
duke@1 | 35 | * this interface to support the association between a global transaction |
duke@1 | 36 | * and a database or message service connection. |
duke@1 | 37 | * |
duke@1 | 38 | * <p>The XAResource interface can be supported by any transactional |
duke@1 | 39 | * resource that is intended to be used by application programs in an |
duke@1 | 40 | * environment where transactions are controlled by an external |
duke@1 | 41 | * transaction manager. An example of such a resource is a database |
duke@1 | 42 | * management system. An application may access data through multiple |
duke@1 | 43 | * database connections. Each database connection is enlisted with |
duke@1 | 44 | * the transaction manager as a transactional resource. The transaction |
duke@1 | 45 | * manager obtains an XAResource for each connection participating |
duke@1 | 46 | * in a global transaction. The transaction manager uses the |
duke@1 | 47 | * <code>start</code> method |
duke@1 | 48 | * to associate the global transaction with the resource, and it uses the |
duke@1 | 49 | * <code>end</code> method to disassociate the transaction from |
duke@1 | 50 | * the resource. The resource |
duke@1 | 51 | * manager is responsible for associating the global transaction to all |
duke@1 | 52 | * work performed on its data between the start and end method invocations. |
duke@1 | 53 | * |
duke@1 | 54 | * <p>At transaction commit time, the resource managers are informed by |
duke@1 | 55 | * the transaction manager to prepare, commit, or rollback a transaction |
duke@1 | 56 | * according to the two-phase commit protocol.</p> |
duke@1 | 57 | * |
duke@1 | 58 | */ |
duke@1 | 59 | |
duke@1 | 60 | public interface XAResource |
duke@1 | 61 | { |
duke@1 | 62 | /** Commits the global transaction specified by xid. |
duke@1 | 63 | * |
duke@1 | 64 | * @param xid A global transaction identifier |
duke@1 | 65 | * |
duke@1 | 66 | * @param onePhase If true, the resource manager should use a one-phase |
duke@1 | 67 | * commit protocol to commit the work done on behalf of xid. |
duke@1 | 68 | * |
duke@1 | 69 | * @exception XAException An error has occurred. Possible XAExceptions |
duke@1 | 70 | * are XA_HEURHAZ, XA_HEURCOM, XA_HEURRB, XA_HEURMIX, XAER_RMERR, |
duke@1 | 71 | * XAER_RMFAIL, XAER_NOTA, XAER_INVAL, or XAER_PROTO. |
duke@1 | 72 | * |
duke@1 | 73 | * <P>If the resource manager did not commit the transaction and the |
duke@1 | 74 | * paramether onePhase is set to true, the resource manager may throw |
duke@1 | 75 | * one of the XA_RB* exceptions. Upon return, the resource manager has |
duke@1 | 76 | * rolled back the branch's work and has released all held resources. |
duke@1 | 77 | */ |
duke@1 | 78 | |
duke@1 | 79 | void commit(Xid xid, boolean onePhase) throws XAException; |
duke@1 | 80 | |
duke@1 | 81 | |
duke@1 | 82 | /** Ends the work performed on behalf of a transaction branch. |
duke@1 | 83 | * The resource manager disassociates the XA resource from the |
duke@1 | 84 | * transaction branch specified and lets the transaction |
duke@1 | 85 | * complete. |
duke@1 | 86 | * |
duke@1 | 87 | * <p>If TMSUSPEND is specified in the flags, the transaction branch |
duke@1 | 88 | * is temporarily suspended in an incomplete state. The transaction |
duke@1 | 89 | * context is in a suspended state and must be resumed via the |
duke@1 | 90 | * <code>start</code> method with TMRESUME specified.</p> |
duke@1 | 91 | * |
duke@1 | 92 | * <p>If TMFAIL is specified, the portion of work has failed. |
duke@1 | 93 | * The resource manager may mark the transaction as rollback-only</p> |
duke@1 | 94 | * |
duke@1 | 95 | * <p>If TMSUCCESS is specified, the portion of work has completed |
duke@1 | 96 | * successfully.</p> |
duke@1 | 97 | * |
duke@1 | 98 | * @param xid A global transaction identifier that is the same as |
duke@1 | 99 | * the identifier used previously in the <code>start</code> method. |
duke@1 | 100 | * |
duke@1 | 101 | * @param flags One of TMSUCCESS, TMFAIL, or TMSUSPEND. |
duke@1 | 102 | * |
duke@1 | 103 | * @exception XAException An error has occurred. Possible XAException |
duke@1 | 104 | * values are XAER_RMERR, XAER_RMFAILED, XAER_NOTA, XAER_INVAL, |
duke@1 | 105 | * XAER_PROTO, or XA_RB*. |
duke@1 | 106 | */ |
duke@1 | 107 | |
duke@1 | 108 | void end(Xid xid, int flags) throws XAException; |
duke@1 | 109 | |
duke@1 | 110 | |
duke@1 | 111 | /** Tells the resource manager to forget about a heuristically |
duke@1 | 112 | * completed transaction branch. |
duke@1 | 113 | * |
duke@1 | 114 | * @param xid A global transaction identifier. |
duke@1 | 115 | * |
duke@1 | 116 | * @exception XAException An error has occurred. Possible exception |
duke@1 | 117 | * values are XAER_RMERR, XAER_RMFAIL, XAER_NOTA, XAER_INVAL, or |
duke@1 | 118 | * XAER_PROTO. |
duke@1 | 119 | */ |
duke@1 | 120 | |
duke@1 | 121 | void forget(Xid xid) throws XAException; |
duke@1 | 122 | |
duke@1 | 123 | /** Obtains the current transaction timeout value set for this |
duke@1 | 124 | * XAResource instance. If <CODE>XAResource.setTransactionTimeout</CODE> |
duke@1 | 125 | * was not used prior to invoking this method, the return value |
duke@1 | 126 | * is the default timeout set for the resource manager; otherwise, |
duke@1 | 127 | * the value used in the previous <CODE>setTransactionTimeout</CODE> |
duke@1 | 128 | * call is returned. |
duke@1 | 129 | * |
duke@1 | 130 | * @return the transaction timeout value in seconds. |
duke@1 | 131 | * |
duke@1 | 132 | * @exception XAException An error has occurred. Possible exception |
duke@1 | 133 | * values are XAER_RMERR and XAER_RMFAIL. |
duke@1 | 134 | */ |
duke@1 | 135 | int getTransactionTimeout() throws XAException; |
duke@1 | 136 | |
duke@1 | 137 | /** This method is called to determine if the resource manager |
duke@1 | 138 | * instance represented by the target object is the same as the |
duke@1 | 139 | * resouce manager instance represented by the parameter <i>xares</i>. |
duke@1 | 140 | * |
duke@1 | 141 | * @param xares An XAResource object whose resource manager instance |
duke@1 | 142 | * is to be compared with the resource manager instance of the |
duke@1 | 143 | * target object. |
duke@1 | 144 | * |
duke@1 | 145 | * @return <i>true</i> if it's the same RM instance; otherwise |
duke@1 | 146 | * <i>false</i>. |
duke@1 | 147 | * |
duke@1 | 148 | * @exception XAException An error has occurred. Possible exception |
duke@1 | 149 | * values are XAER_RMERR and XAER_RMFAIL. |
duke@1 | 150 | * |
duke@1 | 151 | */ |
duke@1 | 152 | boolean isSameRM(XAResource xares) throws XAException; |
duke@1 | 153 | |
duke@1 | 154 | /** Ask the resource manager to prepare for a transaction commit |
duke@1 | 155 | * of the transaction specified in xid. |
duke@1 | 156 | * |
duke@1 | 157 | * @param xid A global transaction identifier. |
duke@1 | 158 | * |
duke@1 | 159 | * @exception XAException An error has occurred. Possible exception |
duke@1 | 160 | * values are: XA_RB*, XAER_RMERR, XAER_RMFAIL, XAER_NOTA, XAER_INVAL, |
duke@1 | 161 | * or XAER_PROTO. |
duke@1 | 162 | * |
duke@1 | 163 | * @return A value indicating the resource manager's vote on the |
duke@1 | 164 | * outcome of the transaction. The possible values are: XA_RDONLY |
duke@1 | 165 | * or XA_OK. If the resource manager wants to roll back the |
duke@1 | 166 | * transaction, it should do so by raising an appropriate XAException |
duke@1 | 167 | * in the prepare method. |
duke@1 | 168 | */ |
duke@1 | 169 | |
duke@1 | 170 | int prepare(Xid xid) throws XAException; |
duke@1 | 171 | |
duke@1 | 172 | |
duke@1 | 173 | /** Obtains a list of prepared transaction branches from a resource |
duke@1 | 174 | * manager. The transaction manager calls this method during recovery |
duke@1 | 175 | * to obtain the list of transaction branches that are currently in |
duke@1 | 176 | * prepared or heuristically completed states. |
duke@1 | 177 | * |
duke@1 | 178 | * @param flag One of TMSTARTRSCAN, TMENDRSCAN, TMNOFLAGS. TMNOFLAGS |
duke@1 | 179 | * must be used when no other flags are set in the parameter. |
duke@1 | 180 | * |
duke@1 | 181 | * @exception XAException An error has occurred. Possible values are |
duke@1 | 182 | * XAER_RMERR, XAER_RMFAIL, XAER_INVAL, and XAER_PROTO. |
duke@1 | 183 | * |
duke@1 | 184 | * @return The resource manager returns zero or more XIDs of the |
duke@1 | 185 | * transaction branches that are currently in a prepared or |
duke@1 | 186 | * heuristically completed state. If an error occurs during the |
duke@1 | 187 | * operation, the resource manager should throw the appropriate |
duke@1 | 188 | * XAException. |
duke@1 | 189 | * |
duke@1 | 190 | */ |
duke@1 | 191 | |
duke@1 | 192 | Xid[] recover(int flag) throws XAException; |
duke@1 | 193 | |
duke@1 | 194 | |
duke@1 | 195 | /** Informs the resource manager to roll back work done on behalf |
duke@1 | 196 | * of a transaction branch. |
duke@1 | 197 | * |
duke@1 | 198 | * @param xid A global transaction identifier. |
duke@1 | 199 | * |
duke@1 | 200 | * @exception XAException An error has occurred. |
duke@1 | 201 | */ |
duke@1 | 202 | |
duke@1 | 203 | void rollback(Xid xid) throws XAException; |
duke@1 | 204 | |
duke@1 | 205 | |
duke@1 | 206 | /** <P>Sets the current transaction timeout value for this <CODE>XAResource</CODE> |
duke@1 | 207 | * instance. Once set, this timeout value is effective until |
duke@1 | 208 | * <code>setTransactionTimeout</code> is invoked again with a different |
duke@1 | 209 | * value. To reset the timeout value to the default value used by the resource |
duke@1 | 210 | * manager, set the value to zero. |
duke@1 | 211 | * |
duke@1 | 212 | * If the timeout operation is performed successfully, the method returns |
duke@1 | 213 | * <i>true</i>; otherwise <i>false</i>. If a resource manager does not |
duke@1 | 214 | * support explicitly setting the transaction timeout value, this method |
duke@1 | 215 | * returns <i>false</i>. |
duke@1 | 216 | * |
duke@1 | 217 | * @param seconds The transaction timeout value in seconds. |
duke@1 | 218 | * |
duke@1 | 219 | * @return <i>true</i> if the transaction timeout value is set successfully; |
duke@1 | 220 | * otherwise <i>false</i>. |
duke@1 | 221 | * |
duke@1 | 222 | * @exception XAException An error has occurred. Possible exception values |
duke@1 | 223 | * are XAER_RMERR, XAER_RMFAIL, or XAER_INVAL. |
duke@1 | 224 | */ |
duke@1 | 225 | boolean setTransactionTimeout(int seconds) throws XAException; |
duke@1 | 226 | |
duke@1 | 227 | |
duke@1 | 228 | /** Starts work on behalf of a transaction branch specified in |
duke@1 | 229 | * <code>xid</code>. |
duke@1 | 230 | * |
duke@1 | 231 | * If TMJOIN is specified, the start applies to joining a transaction |
duke@1 | 232 | * previously seen by the resource manager. If TMRESUME is specified, |
duke@1 | 233 | * the start applies to resuming a suspended transaction specified in the |
duke@1 | 234 | * parameter <code>xid</code>. |
duke@1 | 235 | * |
duke@1 | 236 | * If neither TMJOIN nor TMRESUME is specified and the transaction |
duke@1 | 237 | * specified by <code>xid</code> has previously been seen by the resource |
duke@1 | 238 | * manager, the resource manager throws the XAException exception with |
duke@1 | 239 | * XAER_DUPID error code. |
duke@1 | 240 | * |
duke@1 | 241 | * @param xid A global transaction identifier to be associated |
duke@1 | 242 | * with the resource. |
duke@1 | 243 | * |
duke@1 | 244 | * @param flags One of TMNOFLAGS, TMJOIN, or TMRESUME. |
duke@1 | 245 | * |
duke@1 | 246 | * @exception XAException An error has occurred. Possible exceptions |
duke@1 | 247 | * are XA_RB*, XAER_RMERR, XAER_RMFAIL, XAER_DUPID, XAER_OUTSIDE, |
duke@1 | 248 | * XAER_NOTA, XAER_INVAL, or XAER_PROTO. |
duke@1 | 249 | * |
duke@1 | 250 | */ |
duke@1 | 251 | void start(Xid xid, int flags) throws XAException; |
duke@1 | 252 | |
duke@1 | 253 | |
duke@1 | 254 | /** |
duke@1 | 255 | * Ends a recovery scan. |
duke@1 | 256 | */ |
duke@1 | 257 | public final static int TMENDRSCAN = 0x00800000; |
duke@1 | 258 | |
duke@1 | 259 | /** |
duke@1 | 260 | * Disassociates the caller and marks the transaction branch |
duke@1 | 261 | * rollback-only. |
duke@1 | 262 | */ |
duke@1 | 263 | public final static int TMFAIL = 0x20000000; |
duke@1 | 264 | |
duke@1 | 265 | /** |
duke@1 | 266 | * Caller is joining existing transaction branch. |
duke@1 | 267 | */ |
duke@1 | 268 | public final static int TMJOIN = 0x00200000; |
duke@1 | 269 | |
duke@1 | 270 | /** |
duke@1 | 271 | * Use TMNOFLAGS to indicate no flags value is selected. |
duke@1 | 272 | */ |
duke@1 | 273 | public final static int TMNOFLAGS = 0x00000000; |
duke@1 | 274 | |
duke@1 | 275 | /** |
duke@1 | 276 | * Caller is using one-phase optimization. |
duke@1 | 277 | */ |
duke@1 | 278 | public final static int TMONEPHASE = 0x40000000; |
duke@1 | 279 | |
duke@1 | 280 | /** |
duke@1 | 281 | * Caller is resuming association with a suspended |
duke@1 | 282 | * transaction branch. |
duke@1 | 283 | */ |
duke@1 | 284 | public final static int TMRESUME = 0x08000000; |
duke@1 | 285 | |
duke@1 | 286 | /** |
duke@1 | 287 | * Starts a recovery scan. |
duke@1 | 288 | */ |
duke@1 | 289 | public final static int TMSTARTRSCAN = 0x01000000; |
duke@1 | 290 | |
duke@1 | 291 | |
duke@1 | 292 | /** |
duke@1 | 293 | * Disassociates caller from a transaction branch. |
duke@1 | 294 | */ |
duke@1 | 295 | public final static int TMSUCCESS = 0x04000000; |
duke@1 | 296 | |
duke@1 | 297 | |
duke@1 | 298 | /** |
duke@1 | 299 | * Caller is suspending (not ending) its association with |
duke@1 | 300 | * a transaction branch. |
duke@1 | 301 | */ |
duke@1 | 302 | public final static int TMSUSPEND = 0x02000000; |
duke@1 | 303 | |
duke@1 | 304 | /** |
duke@1 | 305 | * The transaction branch has been read-only and has been committed. |
duke@1 | 306 | */ |
duke@1 | 307 | public final static int XA_RDONLY = 0x00000003; |
duke@1 | 308 | |
duke@1 | 309 | /** |
duke@1 | 310 | * The transaction work has been prepared normally. |
duke@1 | 311 | */ |
duke@1 | 312 | public final static int XA_OK = 0; |
duke@1 | 313 | |
duke@1 | 314 | } |