Path: blob/master/src/java.transaction.xa/share/classes/javax/transaction/xa/XAResource.java
41159 views
/*1* Copyright (c) 2000, 2001, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package javax.transaction.xa;2627/**28* The XAResource interface is a Java mapping of the industry standard29* XA interface based on the X/Open CAE Specification (Distributed30* Transaction Processing: The XA Specification).31*32* <p>The XA interface defines the contract between a Resource Manager33* and a Transaction Manager in a distributed transaction processing34* (DTP) environment. A JDBC driver or a JMS provider implements35* this interface to support the association between a global transaction36* and a database or message service connection.37*38* <p>The XAResource interface can be supported by any transactional39* resource that is intended to be used by application programs in an40* environment where transactions are controlled by an external41* transaction manager. An example of such a resource is a database42* management system. An application may access data through multiple43* database connections. Each database connection is enlisted with44* the transaction manager as a transactional resource. The transaction45* manager obtains an XAResource for each connection participating46* in a global transaction. The transaction manager uses the47* <code>start</code> method48* to associate the global transaction with the resource, and it uses the49* <code>end</code> method to disassociate the transaction from50* the resource. The resource51* manager is responsible for associating the global transaction to all52* work performed on its data between the start and end method invocations.53*54* <p>At transaction commit time, the resource managers are informed by55* the transaction manager to prepare, commit, or rollback a transaction56* according to the two-phase commit protocol.</p>57*58* @since 1.459*/60public interface XAResource {6162/**63* Commits the global transaction specified by xid.64*65* @param xid A global transaction identifier66*67* @param onePhase If true, the resource manager should use a one-phase68* commit protocol to commit the work done on behalf of xid.69*70* @exception XAException An error has occurred. Possible XAExceptions71* are XA_HEURHAZ, XA_HEURCOM, XA_HEURRB, XA_HEURMIX, XAER_RMERR,72* XAER_RMFAIL, XAER_NOTA, XAER_INVAL, or XAER_PROTO.73*74* <P>If the resource manager did not commit the transaction and the75* paramether onePhase is set to true, the resource manager may throw76* one of the XA_RB* exceptions. Upon return, the resource manager has77* rolled back the branch's work and has released all held resources.78*/79void commit(Xid xid, boolean onePhase) throws XAException;8081/**82* Ends the work performed on behalf of a transaction branch.83* The resource manager disassociates the XA resource from the84* transaction branch specified and lets the transaction85* complete.86*87* <p>If TMSUSPEND is specified in the flags, the transaction branch88* is temporarily suspended in an incomplete state. The transaction89* context is in a suspended state and must be resumed via the90* <code>start</code> method with TMRESUME specified.</p>91*92* <p>If TMFAIL is specified, the portion of work has failed.93* The resource manager may mark the transaction as rollback-only</p>94*95* <p>If TMSUCCESS is specified, the portion of work has completed96* successfully.</p>97*98* @param xid A global transaction identifier that is the same as99* the identifier used previously in the <code>start</code> method.100*101* @param flags One of TMSUCCESS, TMFAIL, or TMSUSPEND.102*103* @exception XAException An error has occurred. Possible XAException104* values are XAER_RMERR, XAER_RMFAILED, XAER_NOTA, XAER_INVAL,105* XAER_PROTO, or XA_RB*.106*/107void end(Xid xid, int flags) throws XAException;108109/**110* Tells the resource manager to forget about a heuristically111* completed transaction branch.112*113* @param xid A global transaction identifier.114*115* @exception XAException An error has occurred. Possible exception116* values are XAER_RMERR, XAER_RMFAIL, XAER_NOTA, XAER_INVAL, or117* XAER_PROTO.118*/119void forget(Xid xid) throws XAException;120121/**122* Obtains the current transaction timeout value set for this123* XAResource instance. If <CODE>XAResource.setTransactionTimeout</CODE>124* was not used prior to invoking this method, the return value125* is the default timeout set for the resource manager; otherwise,126* the value used in the previous <CODE>setTransactionTimeout</CODE>127* call is returned.128*129* @return the transaction timeout value in seconds.130*131* @exception XAException An error has occurred. Possible exception132* values are XAER_RMERR and XAER_RMFAIL.133*/134int getTransactionTimeout() throws XAException;135136/**137* This method is called to determine if the resource manager138* instance represented by the target object is the same as the139* resouce manager instance represented by the parameter <i>xares</i>.140*141* @param xares An XAResource object whose resource manager instance142* is to be compared with the resource manager instance of the143* target object.144*145* @return <i>true</i> if it's the same RM instance; otherwise146* <i>false</i>.147*148* @exception XAException An error has occurred. Possible exception149* values are XAER_RMERR and XAER_RMFAIL.150*/151boolean isSameRM(XAResource xares) throws XAException;152153/**154* Ask the resource manager to prepare for a transaction commit155* of the transaction specified in xid.156*157* @param xid A global transaction identifier.158*159* @exception XAException An error has occurred. Possible exception160* values are: XA_RB*, XAER_RMERR, XAER_RMFAIL, XAER_NOTA, XAER_INVAL,161* or XAER_PROTO.162*163* @return A value indicating the resource manager's vote on the164* outcome of the transaction. The possible values are: XA_RDONLY165* or XA_OK. If the resource manager wants to roll back the166* transaction, it should do so by raising an appropriate XAException167* in the prepare method.168*/169int prepare(Xid xid) throws XAException;170171/**172* Obtains a list of prepared transaction branches from a resource173* manager. The transaction manager calls this method during recovery174* to obtain the list of transaction branches that are currently in175* prepared or heuristically completed states.176*177* @param flag One of TMSTARTRSCAN, TMENDRSCAN, TMNOFLAGS. TMNOFLAGS178* must be used when no other flags are set in the parameter.179*180* @exception XAException An error has occurred. Possible values are181* XAER_RMERR, XAER_RMFAIL, XAER_INVAL, and XAER_PROTO.182*183* @return The resource manager returns zero or more XIDs of the184* transaction branches that are currently in a prepared or185* heuristically completed state. If an error occurs during the186* operation, the resource manager should throw the appropriate187* XAException.188*/189Xid[] recover(int flag) throws XAException;190191/**192* Informs the resource manager to roll back work done on behalf193* of a transaction branch.194*195* @param xid A global transaction identifier.196*197* @exception XAException An error has occurred.198*/199void rollback(Xid xid) throws XAException;200201/**202* Sets the current transaction timeout value for this <CODE>XAResource</CODE>203* instance. Once set, this timeout value is effective until204* <code>setTransactionTimeout</code> is invoked again with a different205* value. To reset the timeout value to the default value used by the resource206* manager, set the value to zero.207*208* If the timeout operation is performed successfully, the method returns209* <i>true</i>; otherwise <i>false</i>. If a resource manager does not210* support explicitly setting the transaction timeout value, this method211* returns <i>false</i>.212*213* @param seconds The transaction timeout value in seconds.214*215* @return <i>true</i> if the transaction timeout value is set successfully;216* otherwise <i>false</i>.217*218* @exception XAException An error has occurred. Possible exception values219* are XAER_RMERR, XAER_RMFAIL, or XAER_INVAL.220*/221boolean setTransactionTimeout(int seconds) throws XAException;222223/**224* Starts work on behalf of a transaction branch specified in225* <code>xid</code>.226*227* If TMJOIN is specified, the start applies to joining a transaction228* previously seen by the resource manager. If TMRESUME is specified,229* the start applies to resuming a suspended transaction specified in the230* parameter <code>xid</code>.231*232* If neither TMJOIN nor TMRESUME is specified and the transaction233* specified by <code>xid</code> has previously been seen by the resource234* manager, the resource manager throws the XAException exception with235* XAER_DUPID error code.236*237* @param xid A global transaction identifier to be associated238* with the resource.239*240* @param flags One of TMNOFLAGS, TMJOIN, or TMRESUME.241*242* @exception XAException An error has occurred. Possible exceptions243* are XA_RB*, XAER_RMERR, XAER_RMFAIL, XAER_DUPID, XAER_OUTSIDE,244* XAER_NOTA, XAER_INVAL, or XAER_PROTO.245*/246void start(Xid xid, int flags) throws XAException;247248/**249* Ends a recovery scan.250*/251public static final int TMENDRSCAN = 0x00800000;252253/**254* Disassociates the caller and marks the transaction branch255* rollback-only.256*/257public static final int TMFAIL = 0x20000000;258259/**260* Caller is joining existing transaction branch.261*/262public static final int TMJOIN = 0x00200000;263264/**265* Use TMNOFLAGS to indicate no flags value is selected.266*/267public static final int TMNOFLAGS = 0x00000000;268269/**270* Caller is using one-phase optimization.271*/272public static final int TMONEPHASE = 0x40000000;273274/**275* Caller is resuming association with a suspended276* transaction branch.277*/278public static final int TMRESUME = 0x08000000;279280/**281* Starts a recovery scan.282*/283public static final int TMSTARTRSCAN = 0x01000000;284285/**286* Disassociates caller from a transaction branch.287*/288public static final int TMSUCCESS = 0x04000000;289290/**291* Caller is suspending (not ending) its association with292* a transaction branch.293*/294public static final int TMSUSPEND = 0x02000000;295296/**297* The transaction branch has been read-only and has been committed.298*/299public static final int XA_RDONLY = 0x00000003;300301/**302* The transaction work has been prepared normally.303*/304public static final int XA_OK = 0;305}306307308