⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mysqlxaconnection.java

📁 mysql5.0 JDBC 驱动 放在glassfish或者tomcat的lib文件夹下就可以了
💻 JAVA
字号:
/* Copyright  2005 MySQL AB, 2008 Sun Microsystems This program is free software; you can redistribute it and/or modify it under the terms of version 2 of the GNU General Public License as  published by the Free Software Foundation. There are special exceptions to the terms and conditions of the GPL  as it is applied to this software. View the full text of the  exception in file EXCEPTIONS-CONNECTOR-J in the directory of this  software distribution. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */package com.mysql.jdbc.jdbc2.optional;import java.lang.reflect.Constructor;import java.sql.Connection;import java.sql.ResultSet;import java.sql.SQLException;import java.sql.Statement;import java.util.ArrayList;import java.util.Collections;import java.util.HashMap;import java.util.List;import java.util.Map;import javax.sql.XAConnection;import javax.transaction.xa.XAException;import javax.transaction.xa.XAResource;import javax.transaction.xa.Xid;import com.mysql.jdbc.ConnectionImpl;import com.mysql.jdbc.Constants;import com.mysql.jdbc.Util;import com.mysql.jdbc.log.Log;/* * XA BEGIN <xid> [JOIN | RESUME] XA START TRANSACTION <xid> [JOIN | RESUME] XA * COMMIT <xid> [ONE PHASE] XA END <xid> [SUSPEND [FOR MIGRATE]] XA PREPARE * <xid> XA RECOVER XA ROLLBACK <xid> *//** * An object that provides support for distributed transactions. An * <code>XAConnection</code> object may be enlisted in a distributed * transaction by means of an <code>XAResource</code> object. A transaction * manager, usually part of a middle tier server, manages an * <code>XAConnection</code> object through the <code>XAResource</code> * object. * <P> * An application programmer does not use this interface directly; rather, it is * used by a transaction manager working in the middle tier server. *  * @since 1.4 */public class MysqlXAConnection extends MysqlPooledConnection implements		XAConnection, XAResource {	private com.mysql.jdbc.ConnectionImpl underlyingConnection;	private final static Map MYSQL_ERROR_CODES_TO_XA_ERROR_CODES;	private Log log;	protected boolean logXaCommands;		static {		HashMap temp = new HashMap();		temp.put(Constants.integerValueOf(1397), Constants.integerValueOf(XAException.XAER_NOTA));		temp.put(Constants.integerValueOf(1398), Constants.integerValueOf(XAException.XAER_INVAL));		temp.put(Constants.integerValueOf(1399), Constants.integerValueOf(XAException.XAER_RMFAIL));		temp.put(Constants.integerValueOf(1400), Constants.integerValueOf(XAException.XAER_OUTSIDE));		temp.put(Constants.integerValueOf(1401), Constants.integerValueOf(XAException.XAER_RMERR));		temp.put(Constants.integerValueOf(1402), Constants.integerValueOf(XAException.XA_RBROLLBACK));		MYSQL_ERROR_CODES_TO_XA_ERROR_CODES = Collections.unmodifiableMap(temp);	}		private static final Constructor JDBC_4_XA_CONNECTION_WRAPPER_CTOR;	static {		if (Util.isJdbc4()) {			try {				JDBC_4_XA_CONNECTION_WRAPPER_CTOR = Class.forName(						"com.mysql.jdbc.jdbc2.optional.JDBC4MysqlXAConnection")						.getConstructor(								new Class[] { ConnectionImpl.class, Boolean.TYPE });			} catch (SecurityException e) {				throw new RuntimeException(e);			} catch (NoSuchMethodException e) {				throw new RuntimeException(e);			} catch (ClassNotFoundException e) {				throw new RuntimeException(e);			}		} else {			JDBC_4_XA_CONNECTION_WRAPPER_CTOR = null;		}	}	protected static MysqlXAConnection getInstance(ConnectionImpl mysqlConnection, 			boolean logXaCommands) throws SQLException {		if (!Util.isJdbc4()) {			return new MysqlXAConnection(mysqlConnection, logXaCommands);		}		return (MysqlXAConnection) Util.handleNewInstance(				JDBC_4_XA_CONNECTION_WRAPPER_CTOR, new Object[] {						mysqlConnection,						Boolean.valueOf(logXaCommands) });	}	/**	 * @param connection	 */	public MysqlXAConnection(ConnectionImpl connection, boolean logXaCommands)			throws SQLException {		super(connection);		this.underlyingConnection = connection;		this.log = connection.getLog();		this.logXaCommands = logXaCommands;	}	/**	 * Retrieves an <code>XAResource</code> object that the transaction	 * manager will use to manage this <code>XAConnection</code> object's	 * participation in a distributed transaction.	 * 	 * @return the <code>XAResource</code> object	 * @exception SQLException	 *                if a database access error occurs	 */	public XAResource getXAResource() throws SQLException {		return this;	}	/**	 * Obtains the current transaction timeout value set for this XAResource	 * instance. If XAResource.setTransactionTimeout was not used prior to	 * invoking this method, the return value is the default timeout set for the	 * resource manager; otherwise, the value used in the previous	 * setTransactionTimeout call is returned.	 * 	 * @return the transaction timeout value in seconds.	 * 	 * @throws XAException	 *             An error has occurred. Possible exception values are	 *             XAER_RMERR and XAER_RMFAIL.	 */	public int getTransactionTimeout() throws XAException {		// TODO Auto-generated method stub		return 0;	}	/**	 * Sets the current transaction timeout value for this XAResource instance.	 * Once set, this timeout value is effective until setTransactionTimeout is	 * invoked again with a different value.	 * 	 * To reset the timeout value to the default value used by the resource	 * manager, set the value to zero. If the timeout operation is performed	 * successfully, the method returns true; otherwise false.	 * 	 * If a resource manager does not support explicitly setting the transaction	 * timeout value, this method returns false.	 * 	 * @parameter seconds The transaction timeout value in seconds.	 * 	 * @return true if the transaction timeout value is set successfully;	 *         otherwise false.	 * 	 * @throws XAException	 *             An error has occurred. Possible exception values are	 *             XAER_RMERR, XAER_RMFAIL, or XAER_INVAL.	 */	public boolean setTransactionTimeout(int arg0) throws XAException {		// TODO Auto-generated method stub		return false;	}	/**	 * This method is called to determine if the resource manager instance	 * represented by the target object is the same as the resouce manager	 * instance represented by the parameter xares.	 * 	 * @parameter xares An XAResource object whose resource manager instance is	 *            to be compared with the resource manager instance of the	 *            target object.	 * 	 * @return true if it's the same RM instance; otherwise false.	 * 	 * @throws XAException	 *             An error has occurred. Possible exception values are	 *             XAER_RMERR and XAER_RMFAIL.	 */	public boolean isSameRM(XAResource xares) throws XAException {		if (xares instanceof MysqlXAConnection) {			return this.underlyingConnection					.isSameResource(((MysqlXAConnection) xares).underlyingConnection);		}		return false;	}	/**	 * This method is called to obtain a list of prepared transaction branches	 * from a resource manager. The transaction manager calls this method during	 * recovery to obtain the list of transaction branches that are currently in	 * prepared or heuristically completed states. 	 * 	 * The flag parameter indicates where the recover scan should start or end, 	 * or start and end. This method may be invoked one or more times during a 	 * recovery scan. The resource manager maintains a cursor which marks the 	 * current position of the prepared or heuristically completed transaction list. 	 * Each invocation of the recover method moves the cursor passed the set of Xids 	 * that are returned. 	 * 	 * Two consecutive invocation of this method that starts from the	 * beginning of the list must return the same list of transaction branches	 * unless one of the following takes place: 	 * 	 * - the transaction manager invokes the commit, forget, prepare, or rollback method for that resource	 * manager, between the two consecutive invocation of the recovery scan. 	 * 	 * - the resource manager heuristically completes some transaction branches	 * between the two invocation of the recovery scan.	 * 	 * @param flag	 *            One of TMSTARTRSCAN, TMENDRSCAN, TMNOFLAGS. TMNOFLAGS must be	 *            used when no other flags are set in the parameter.	 * 	 * @returns The resource manager returns zero or more XIDs of the	 *          transaction branches that are currently in a prepared or	 *          heuristically completed state. If an error occurs during the	 *          operation, the resource manager should throw the appropriate	 *          XAException.	 * 	 * @throws XAException	 *             An error has occurred. Possible values are XAER_RMERR,	 *             XAER_RMFAIL, XAER_INVAL, and XAER_PROTO.	 */	public Xid[] recover(int flag) throws XAException {		return recover(this.underlyingConnection, flag);	}		protected static Xid[] recover(Connection c, int flag) throws XAException {		/*		    The XA RECOVER statement returns information for those XA transactions on the MySQL server that are in the PREPARED state. (See Section 13.4.7.2, 揦A Transaction States

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -