[jboss-svn-commits] JBL Code SVN: r27743 - in labs/jbosstm/workspace/jhalliday/nestedjdbc: src and 4 other directories.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Wed Jul 8 10:26:05 EDT 2009


Author: jhalliday
Date: 2009-07-08 10:26:04 -0400 (Wed, 08 Jul 2009)
New Revision: 27743

Added:
   labs/jbosstm/workspace/jhalliday/nestedjdbc/build.xml
   labs/jbosstm/workspace/jhalliday/nestedjdbc/src/
   labs/jbosstm/workspace/jhalliday/nestedjdbc/src/org/
   labs/jbosstm/workspace/jhalliday/nestedjdbc/src/org/jboss/
   labs/jbosstm/workspace/jhalliday/nestedjdbc/src/org/jboss/jbossts/
   labs/jbosstm/workspace/jhalliday/nestedjdbc/src/org/jboss/jbossts/nestedjdbc/
   labs/jbosstm/workspace/jhalliday/nestedjdbc/src/org/jboss/jbossts/nestedjdbc/DataSourceImple.java
   labs/jbosstm/workspace/jhalliday/nestedjdbc/src/org/jboss/jbossts/nestedjdbc/Test.java
   labs/jbosstm/workspace/jhalliday/nestedjdbc/src/org/jboss/jbossts/nestedjdbc/UserTransactionImple.java
   labs/jbosstm/workspace/jhalliday/nestedjdbc/src/org/jboss/jbossts/nestedjdbc/XAResourceImple.java
Log:
Added simple nested tx withJDBC savepoints prototype.


Added: labs/jbosstm/workspace/jhalliday/nestedjdbc/build.xml
===================================================================
--- labs/jbosstm/workspace/jhalliday/nestedjdbc/build.xml	                        (rev 0)
+++ labs/jbosstm/workspace/jhalliday/nestedjdbc/build.xml	2009-07-08 14:26:04 UTC (rev 27743)
@@ -0,0 +1,74 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA  02110-1301, USA.
+ *
+ * (C) 2009
+ * @author JBoss, a division of Red Hat.
+-->
+
+<project name="nestedjdbc" default="test" basedir=".">
+
+    <!-- Note: in addition to a jbossts build, you need to drop an Oracle jdbc driver jar into
+            the same dir as this build.xml for test purposes. -->
+    <property name="jbossts.home" location="/home/jhalli/IdeaProjects/jboss/jbossts_trunk"/>
+
+	<property name="src" location="src"/>
+	<property name="build" location="build"/>
+
+	<path id="build-prereqs">
+        <fileset dir="${jbossts.home}/install/lib">
+            <include name="*.jar"/>
+            <include name="ext/*.jar"/>
+            <include name="ext/*.zip"/>
+        </fileset>
+        <fileset dir="." includes="*.jar"/>
+        <pathelement location="."/>
+        <pathelement location="${jbossts.home}/install/etc"/>
+	</path>
+
+	<target name="clean" description="clean up">
+		<delete dir="${build}"/>
+	</target>
+
+	<target name="init">
+		<tstamp/>
+		<mkdir dir="${build}"/>
+	</target>
+
+	<target name="compile" depends="init"
+			description="compile the source ">
+		<mkdir dir="${build}/classes"/>
+		<javac srcdir="${src}" destdir="${build}/classes" debug="true">
+			<classpath refid="build-prereqs"/>
+		</javac>
+	</target>
+
+    <target  name="test" depends="compile">
+        <java classname="org.jboss.jbossts.nestedjdbc.Test" fork="true">
+            <classpath>
+                <pathelement location="${build}/classes"/>
+                <path refid="build-prereqs"/>
+
+            </classpath>
+            <jvmarg value="-Xdebug"/>
+            <jvmarg value="-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5006"/>
+        </java>
+    </target>
+
+</project>
+

Added: labs/jbosstm/workspace/jhalliday/nestedjdbc/src/org/jboss/jbossts/nestedjdbc/DataSourceImple.java
===================================================================
--- labs/jbosstm/workspace/jhalliday/nestedjdbc/src/org/jboss/jbossts/nestedjdbc/DataSourceImple.java	                        (rev 0)
+++ labs/jbosstm/workspace/jhalliday/nestedjdbc/src/org/jboss/jbossts/nestedjdbc/DataSourceImple.java	2009-07-08 14:26:04 UTC (rev 27743)
@@ -0,0 +1,150 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA  02110-1301, USA.
+ *
+ * (C) 2009,
+ * @author JBoss, a division of Red Hat.
+ */
+package org.jboss.jbossts.nestedjdbc;
+
+import javax.sql.DataSource;
+import java.sql.Connection;
+import java.sql.SQLException;
+import java.io.PrintWriter;
+
+/**
+ * Laughably simple DataSource wrapper than enlists new connections with a UserTransactionImple
+ * so that they can participate in transactions.
+ *
+ * This is a proof of concept prototype. Do not let it anywhere near a production system.
+ *
+ * @author Jonathan Halliday (jonathan.halliday at redhat.com)
+ * @since 2009-07
+ */
+
+public class DataSourceImple implements DataSource
+{
+    private DataSource datasource;
+    private UserTransactionImple userTransactionImple;
+
+    /**
+     * Create a new DataSource, warpping the provided read DataSource and associating new connections
+     * to the provided UserTransactionImple.
+     * 
+     * @param datasource
+     * @param userTransactionImple
+     */
+    public DataSourceImple(DataSource datasource, UserTransactionImple userTransactionImple)
+    {
+        this.datasource = datasource;
+        this.userTransactionImple = userTransactionImple;
+    }
+
+    //////////////////
+
+    @Override
+    public Connection getConnection() throws SQLException
+    {
+        Connection connection = datasource.getConnection();
+
+        registerConnection(connection);
+
+        return connection;
+    }
+
+    @Override
+    public Connection getConnection(String username, String password) throws SQLException
+    {
+        Connection connection = datasource.getConnection(username, password);
+
+        registerConnection(connection);
+
+        return connection;
+    }
+
+    @Override
+    public PrintWriter getLogWriter() throws SQLException
+    {
+        return datasource.getLogWriter();
+    }
+
+    @Override
+    public void setLogWriter(PrintWriter out) throws SQLException
+    {
+        datasource.setLogWriter(out);
+    }
+
+    @Override
+    public void setLoginTimeout(int seconds) throws SQLException
+    {
+        datasource.setLoginTimeout(seconds);
+    }
+
+    @Override
+    public int getLoginTimeout() throws SQLException
+    {
+        return datasource.getLoginTimeout();
+    }
+
+    @Override
+    public <T> T unwrap(Class<T> iface) throws SQLException
+    {
+        if (iface != null) {
+            if (iface.isInstance(this)) {
+                return (T) this;
+            } else {
+                if (datasource != null) {
+                    if (iface.isInstance(datasource)) {
+                        return (T) datasource;
+                    } else if(datasource.isWrapperFor(iface)) {
+                        return datasource.unwrap(iface);
+                    }
+                }
+            }
+        }
+        return null;
+    }
+
+    @Override
+    public boolean isWrapperFor(Class<?> iface) throws SQLException
+    {
+        if (iface != null) {
+            if (iface.isInstance(this)) {
+                return true;
+            } else {
+                if (datasource != null) {
+                    if (iface.isInstance(datasource)) {
+                        return true;
+                    } else {
+                        return datasource.isWrapperFor(iface);
+                    }
+                }
+            }
+        }
+        return false;
+    }
+
+    //////////////////
+
+    /**
+     * Inform the userTransaction about a new connection, so that it can associate it to a transaction if required.
+     * @param connection
+     */
+    private void registerConnection(Connection connection) throws SQLException
+    {
+        userTransactionImple.registerConnection(connection);
+    }
+}

Added: labs/jbosstm/workspace/jhalliday/nestedjdbc/src/org/jboss/jbossts/nestedjdbc/Test.java
===================================================================
--- labs/jbosstm/workspace/jhalliday/nestedjdbc/src/org/jboss/jbossts/nestedjdbc/Test.java	                        (rev 0)
+++ labs/jbosstm/workspace/jhalliday/nestedjdbc/src/org/jboss/jbossts/nestedjdbc/Test.java	2009-07-08 14:26:04 UTC (rev 27743)
@@ -0,0 +1,97 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA  02110-1301, USA.
+ *
+ * (C) 2009,
+ * @author JBoss, a division of Red Hat.
+ */
+package org.jboss.jbossts.nestedjdbc;
+
+import oracle.jdbc.pool.OracleDataSource;
+
+import javax.transaction.UserTransaction;
+import javax.sql.DataSource;
+import java.sql.Connection;
+import java.sql.Statement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+
+/**
+ * Command line client for rudimentary manual test/debug of pseudo nested transactions using JDBC savepoints.
+ *
+ * @author Jonathan Halliday (jonathan.halliday at redhat.com)
+ * @since 2009-07
+ */
+public class Test
+{
+    public static void main(String[] args) throws Exception
+    {
+        UserTransactionImple userTransactionImple = new UserTransactionImple();
+
+        OracleDataSource oracleDataSource = new OracleDataSource();
+        oracleDataSource.setURL("jdbc:oracle:thin:user/pass at host:port:sid");
+        DataSource dataSource = new DataSourceImple(oracleDataSource, userTransactionImple);
+
+        UserTransaction ut = userTransactionImple;
+
+        /////////////////////////////
+
+
+        ut.begin();
+
+        Connection connection = dataSource.getConnection();
+
+        Statement stmt = connection.createStatement();
+        //stmt.executeUpdate("CREATE TABLE foo (bar int)");
+        stmt.executeUpdate("DELETE FROM foo");
+        connection.commit();
+        ut.commit();
+
+
+        ut.begin();
+        connection = dataSource.getConnection();
+
+        getCount(connection);
+
+        ut.begin();
+
+        stmt = connection.createStatement();
+        stmt.executeUpdate("INSERT INTO foo VALUES (1)");
+        stmt.close();
+
+        getCount(connection);
+
+        ut.commit();
+
+        getCount(connection);
+
+        ut.rollback();
+
+        connection = dataSource.getConnection();
+        getCount(connection);
+        connection.close();
+    }
+
+    private static void getCount(Connection connection) throws SQLException
+    {
+        Statement stmt = connection.createStatement();
+        ResultSet rs = stmt.executeQuery("SELECT count(*) FROM foo");
+        rs.next();
+        System.out.println("count: "+rs.getInt(1));
+        rs.close();
+        stmt.close();
+    }
+}

Added: labs/jbosstm/workspace/jhalliday/nestedjdbc/src/org/jboss/jbossts/nestedjdbc/UserTransactionImple.java
===================================================================
--- labs/jbosstm/workspace/jhalliday/nestedjdbc/src/org/jboss/jbossts/nestedjdbc/UserTransactionImple.java	                        (rev 0)
+++ labs/jbosstm/workspace/jhalliday/nestedjdbc/src/org/jboss/jbossts/nestedjdbc/UserTransactionImple.java	2009-07-08 14:26:04 UTC (rev 27743)
@@ -0,0 +1,236 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA  02110-1301, USA.
+ *
+ * (C) 2009,
+ * @author JBoss, a division of Red Hat.
+ */
+package org.jboss.jbossts.nestedjdbc;
+
+import javax.transaction.*;
+import javax.transaction.xa.XAResource;
+import java.sql.Savepoint;
+import java.sql.Connection;
+import java.sql.SQLException;
+import java.util.*;
+
+/**
+ * Wrapper around a real transaction manager, to provide elementary support for non-XA database connections
+ * with 1PC behaviour and support for pseudo nested transaction semantics using JDBC savepoints.
+ *
+ * Note: This implementation is not transactionally safe and not JTA spec compliant.
+ *
+ * This is a proof of concept prototype. Do not let it anywhere near a production system.
+ *
+ * @author Jonathan Halliday (jonathan.halliday at redhat.com)
+ * @since 2009-07
+ */
+public class UserTransactionImple implements UserTransaction
+{
+    private UserTransaction userTransaction;
+    private TransactionSynchronizationRegistry transactionSynchronizationRegistry;
+    private TransactionManager transactionManager;
+
+    public UserTransactionImple()
+    {
+        this.userTransaction = new com.arjuna.ats.internal.jta.transaction.arjunacore.UserTransactionImple();
+        this.transactionSynchronizationRegistry = new com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionSynchronizationRegistryImple();
+        this.transactionManager = new com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionManagerImple();
+    }
+
+    //////////////////
+
+    @Override
+    public void begin() throws NotSupportedException, SystemException
+    {
+        if(userTransaction.getStatus() == Status.STATUS_NO_TRANSACTION)
+        {
+            userTransaction.begin();
+        }
+        else
+        {
+                createSavepoint();
+        }
+    }
+
+    @Override
+    public void commit() throws RollbackException, HeuristicMixedException, HeuristicRollbackException, SecurityException, IllegalStateException, SystemException
+    {
+        List<Set<ConnSavepoint>> savepoints = getSavepoints();
+
+        if(savepoints == null || savepoints.size() == 0)
+        {
+            userTransaction.commit();
+        }
+        else
+        {
+            // in a nested transaciton, rollback the most deeply nested.
+            Set<ConnSavepoint> toRelease = savepoints.remove(savepoints.size()-1);
+            processSavepoints(toRelease, true);
+        }
+    }
+
+    @Override
+    public void rollback() throws IllegalStateException, SecurityException, SystemException
+    {
+        List<Set<ConnSavepoint>> savepoints = getSavepoints();
+
+        if(savepoints == null || savepoints.size() == 0)
+        {
+            userTransaction.rollback();
+        } else {
+            // in a nested transaciton, rollback the most deeply nested.
+            Set<ConnSavepoint> toRollback = savepoints.remove(savepoints.size()-1);
+            processSavepoints(toRollback, false);
+        }
+    }
+
+    @Override
+    public void setRollbackOnly() throws IllegalStateException, SystemException
+    {
+        userTransaction.setRollbackOnly();
+    }
+
+    @Override
+    public int getStatus() throws SystemException
+    {
+        return userTransaction.getStatus();
+    }
+
+    @Override
+    public void setTransactionTimeout(int timeout) throws SystemException
+    {
+        userTransaction.setTransactionTimeout(timeout);
+    }
+
+    //////////////////
+
+    private static String CONNECTION_KEY = "org.jboss.jbossts.nestedjdbc.connection_key";
+
+    /**
+     * Register a new Connection with the currently running transaction.
+     * @param connection
+     */
+    public void registerConnection(Connection connection) throws SQLException
+    {
+        try
+        {
+            if(userTransaction.getStatus() == Status.STATUS_NO_TRANSACTION) {
+                return;
+            }
+
+            connection.setAutoCommit(false);
+            Set<Connection> connections = (Set<Connection>) transactionSynchronizationRegistry.getResource(CONNECTION_KEY);
+
+            XAResource xaResource = new XAResourceImple(connection);
+            
+            transactionManager.getTransaction().enlistResource(xaResource);
+
+            if(connections == null) {
+                connections = new HashSet<Connection>();
+                transactionSynchronizationRegistry.putResource(CONNECTION_KEY, connections);
+            }
+
+            connections.add(connection);
+        }
+        catch(Exception e)
+        {
+            throw new SQLException(e);
+        }
+    }
+
+    private static String SAVEPOINT_KEY = "org.jboss.jbossts.nestedjdbc.savepoint_key";
+
+    /**
+     * Get the List of savepoints for the current transaction.
+     * The list contains a chronologically ordered (oldest to most recent) collection of Sets,
+     * each Set having zero or more ConnSavepoints, a ConnSavepoint being a (Connection, Savepoint) tuple.
+     * @return
+     */
+    private List<Set<ConnSavepoint>> getSavepoints()
+    {
+        return (List<Set<ConnSavepoint>>) transactionSynchronizationRegistry.getResource(SAVEPOINT_KEY);
+    }
+
+    private void createSavepoint() throws SystemException
+    {
+        List<Set<ConnSavepoint>> savepoints = getSavepoints();
+
+        if(savepoints == null) {
+            savepoints = new LinkedList<Set<ConnSavepoint>>();
+            transactionSynchronizationRegistry.putResource(SAVEPOINT_KEY, savepoints);
+        }
+
+        savepoints.add( createSavepointForEachConnection() );
+    }
+
+    private Set<ConnSavepoint> createSavepointForEachConnection() throws SystemException
+    {
+        Set<Connection> connections = (Set<Connection>) transactionSynchronizationRegistry.getResource(CONNECTION_KEY);
+        Set<ConnSavepoint> savepoints = new HashSet<ConnSavepoint>();
+
+        for(Connection connection : connections) {
+            try
+            {
+                if(!connection.isClosed()) {
+                    savepoints.add( new ConnSavepoint(connection, connection.setSavepoint()) );
+                }
+            }
+            catch(SQLException e)
+            {
+                userTransaction.setRollbackOnly();
+                SystemException systemException = new SystemException();
+                systemException.initCause(e);
+                throw systemException;
+            }
+        }
+
+        return savepoints;
+    }
+
+    private void processSavepoints(Set<ConnSavepoint> savepoints, boolean commit) throws SystemException
+    {
+        for(ConnSavepoint connSavepoint : savepoints) {
+            try
+            {
+                if(commit) {
+                    // unsupported on Oracle.
+                    //connSavepoint.connection.releaseSavepoint(connSavepoint.savepoint);
+                } else {
+                    connSavepoint.connection.rollback(connSavepoint.savepoint);
+                }
+            }
+            catch(SQLException e)
+            {
+                userTransaction.setRollbackOnly();
+                SystemException systemException = new SystemException();
+                systemException.initCause(e);
+                throw systemException;
+            }
+        }
+    }
+
+    private class ConnSavepoint {
+        public Connection connection;
+        public Savepoint savepoint;
+
+        public ConnSavepoint(Connection connection, Savepoint savepoint)
+        {
+            this.connection = connection;
+            this.savepoint = savepoint;
+        }
+    }
+}

Added: labs/jbosstm/workspace/jhalliday/nestedjdbc/src/org/jboss/jbossts/nestedjdbc/XAResourceImple.java
===================================================================
--- labs/jbosstm/workspace/jhalliday/nestedjdbc/src/org/jboss/jbossts/nestedjdbc/XAResourceImple.java	                        (rev 0)
+++ labs/jbosstm/workspace/jhalliday/nestedjdbc/src/org/jboss/jbossts/nestedjdbc/XAResourceImple.java	2009-07-08 14:26:04 UTC (rev 27743)
@@ -0,0 +1,130 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA  02110-1301, USA.
+ *
+ * (C) 2009,
+ * @author JBoss, a division of Red Hat.
+ */
+package org.jboss.jbossts.nestedjdbc;
+
+import javax.transaction.xa.XAResource;
+import javax.transaction.xa.Xid;
+import javax.transaction.xa.XAException;
+import java.sql.Connection;
+import java.sql.SQLException;
+
+/**
+ * Simple XARerource implementation that allows non-XA database connections to work with an JTA transaction manager.
+ *
+ * This is a proof of concept prototype. Do not let it anywhere near a production system.
+ *
+ * @author Jonathan Halliday (jonathan.halliday at redhat.com)
+ * @since 2009-07
+ */
+public class XAResourceImple implements XAResource
+{
+    private Connection connection;
+
+    /**
+     * Create a new XAResourceImple associated with the provide non-xa JDBC database Connection.
+     * @param connection
+     */
+    public XAResourceImple(Connection connection)
+    {
+        this.connection = connection;
+    }
+
+    //////////////////
+
+    @Override
+    public void commit(Xid xid, boolean onePhase) throws XAException
+    {
+        if(onePhase) {
+            prepare(xid);
+        }
+    }
+
+    @Override
+    public void end(Xid xid, int i) throws XAException
+    {
+    }
+
+    @Override
+    public void forget(Xid xid) throws XAException
+    {
+    }
+
+    @Override
+    public int getTransactionTimeout() throws XAException
+    {
+        return 0;
+    }
+
+    @Override
+    public boolean isSameRM(XAResource xaResource) throws XAException
+    {
+        return false;
+    }
+
+    @Override
+    public int prepare(Xid xid) throws XAException
+    {
+        try
+        {
+            connection.commit();
+        }
+        catch(SQLException e)
+        {
+            XAException xaException = new XAException(XAException.XA_RBROLLBACK);
+            xaException.initCause(e);
+            throw xaException;
+        }
+
+        return XA_OK;
+    }
+
+    @Override
+    public Xid[] recover(int i) throws XAException
+    {
+        return new Xid[0];  //To change body of implemented methods use File | Settings | File Templates.
+    }
+
+    @Override
+    public void rollback(Xid xid) throws XAException
+    {
+        try
+        {
+            connection.rollback();
+        }
+        catch(SQLException e)
+        {
+            XAException xaException = new XAException(XAException.XA_RBROLLBACK);
+            xaException.initCause(e);
+            throw xaException;
+        }
+    }
+
+    @Override
+    public boolean setTransactionTimeout(int i) throws XAException
+    {
+        return false;
+    }
+
+    @Override
+    public void start(Xid xid, int i) throws XAException
+    {
+    }
+}




More information about the jboss-svn-commits mailing list