You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jackrabbit.apache.org by ju...@apache.org on 2007/09/08 00:39:15 UTC

svn commit: r573739 - in /jackrabbit/trunk/jackrabbit-jcr-rmi/src/main/java/org/apache/jackrabbit/rmi: client/ remote/ server/

Author: jukka
Date: Fri Sep  7 15:39:13 2007
New Revision: 573739

URL: http://svn.apache.org/viewvc?rev=573739&view=rev
Log:
JCR-953: Added XASession support to JCR-RMI based on a patch by Berry van Halderen.

Added:
    jackrabbit/trunk/jackrabbit-jcr-rmi/src/main/java/org/apache/jackrabbit/rmi/client/ClientXAResource.java   (with props)
    jackrabbit/trunk/jackrabbit-jcr-rmi/src/main/java/org/apache/jackrabbit/rmi/client/ClientXASession.java   (with props)
    jackrabbit/trunk/jackrabbit-jcr-rmi/src/main/java/org/apache/jackrabbit/rmi/remote/RemoteXAResource.java   (with props)
    jackrabbit/trunk/jackrabbit-jcr-rmi/src/main/java/org/apache/jackrabbit/rmi/remote/RemoteXASession.java   (with props)
    jackrabbit/trunk/jackrabbit-jcr-rmi/src/main/java/org/apache/jackrabbit/rmi/server/ServerXAResource.java   (with props)
    jackrabbit/trunk/jackrabbit-jcr-rmi/src/main/java/org/apache/jackrabbit/rmi/server/ServerXASession.java   (with props)
Modified:
    jackrabbit/trunk/jackrabbit-jcr-rmi/src/main/java/org/apache/jackrabbit/rmi/client/ClientAdapterFactory.java
    jackrabbit/trunk/jackrabbit-jcr-rmi/src/main/java/org/apache/jackrabbit/rmi/client/LocalAdapterFactory.java
    jackrabbit/trunk/jackrabbit-jcr-rmi/src/main/java/org/apache/jackrabbit/rmi/server/RemoteAdapterFactory.java
    jackrabbit/trunk/jackrabbit-jcr-rmi/src/main/java/org/apache/jackrabbit/rmi/server/ServerAdapterFactory.java

Modified: jackrabbit/trunk/jackrabbit-jcr-rmi/src/main/java/org/apache/jackrabbit/rmi/client/ClientAdapterFactory.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-rmi/src/main/java/org/apache/jackrabbit/rmi/client/ClientAdapterFactory.java?rev=573739&r1=573738&r2=573739&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-rmi/src/main/java/org/apache/jackrabbit/rmi/client/ClientAdapterFactory.java (original)
+++ jackrabbit/trunk/jackrabbit-jcr-rmi/src/main/java/org/apache/jackrabbit/rmi/client/ClientAdapterFactory.java Fri Sep  7 15:39:13 2007
@@ -41,6 +41,7 @@
 import javax.jcr.version.Version;
 import javax.jcr.version.VersionHistory;
 import javax.jcr.version.VersionIterator;
+import javax.transaction.xa.XAResource;
 
 import org.apache.jackrabbit.rmi.client.iterator.ClientNodeIterator;
 import org.apache.jackrabbit.rmi.client.iterator.ClientNodeTypeIterator;
@@ -68,6 +69,8 @@
 import org.apache.jackrabbit.rmi.remote.RemoteVersion;
 import org.apache.jackrabbit.rmi.remote.RemoteVersionHistory;
 import org.apache.jackrabbit.rmi.remote.RemoteWorkspace;
+import org.apache.jackrabbit.rmi.remote.RemoteXAResource;
+import org.apache.jackrabbit.rmi.remote.RemoteXASession;
 
 /**
  * Default implementation of the
@@ -91,11 +94,18 @@
 
     /**
      * Creates and returns a {@link ClientSession ClientSession} instance.
+     * In case the remote session is transaction enabled, the returned session
+     * will be transaction enabled too through the {@link ClientXASession}.
      *
      * {@inheritDoc}
      */
     public Session getSession(Repository repository, RemoteSession remote) {
-        return new ClientSession(repository, remote, this);
+        if (remote instanceof RemoteXASession) {
+            return new ClientXASession(
+                    repository, (RemoteXASession) remote, this);
+        } else {
+            return new ClientSession(repository, remote, this);
+        }
     }
 
     /**
@@ -310,6 +320,13 @@
      */
     public RowIterator getRowIterator(RemoteIterator remote) {
         return new ClientRowIterator(remote, this);
+    }
+
+    /**
+     * Creates and returns a {@link ClientXAResource} instance.
+     */
+    public XAResource getXAResource(RemoteXAResource remote) {
+        return new ClientXAResource(remote);
     }
 
 }

Added: jackrabbit/trunk/jackrabbit-jcr-rmi/src/main/java/org/apache/jackrabbit/rmi/client/ClientXAResource.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-rmi/src/main/java/org/apache/jackrabbit/rmi/client/ClientXAResource.java?rev=573739&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-rmi/src/main/java/org/apache/jackrabbit/rmi/client/ClientXAResource.java (added)
+++ jackrabbit/trunk/jackrabbit-jcr-rmi/src/main/java/org/apache/jackrabbit/rmi/client/ClientXAResource.java Fri Sep  7 15:39:13 2007
@@ -0,0 +1,135 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.rmi.client;
+
+import java.rmi.RemoteException;
+
+import javax.transaction.xa.XAException;
+import javax.transaction.xa.XAResource;
+import javax.transaction.xa.Xid;
+
+import org.apache.jackrabbit.rmi.remote.RemoteXAResource;
+
+/**
+ * Local adapter for the JCR-RMI {@link RemoteXAResource} interface.
+ *
+ * @since 1.4
+ */
+public class ClientXAResource implements XAResource {
+
+    /**
+     * The adapted remote XA resource.
+     */
+    private RemoteXAResource remote;
+
+    /**
+     * Returns <code>true</code> if the given object is a local
+     * adapter that refers to the same remote XA resource.
+     * 
+     * @see http://blogs.sun.com/fkieviet/entry/j2ee_jca_resource_adapters_the
+     */
+    public boolean isSameRM(XAResource xares) throws XAException {
+        return xares instanceof ClientXAResource
+            && remote == ((ClientXAResource) xares).remote;
+    }
+
+    /**
+     * Creates a client adapter for the given remote XA resource.
+     */
+    public ClientXAResource(RemoteXAResource remote) {
+        this.remote = remote;
+    }
+
+    private XAException getXAException(RemoteException e) {
+        XAException exception = new XAException("Remote operation failed");
+        exception.initCause(e);
+        return exception;
+    }
+
+    public void commit(Xid xid, boolean onePhase) throws XAException {
+        try {
+            remote.commit(xid, onePhase);
+        } catch (RemoteException e) {
+            throw getXAException(e);
+        }
+    }
+
+    public void end(Xid xid, int flags) throws XAException {
+        try {
+            remote.end(xid, flags);
+        } catch (RemoteException e) {
+            throw getXAException(e);
+        }
+    }
+
+    public void forget(Xid xid) throws XAException {
+        try {
+            remote.forget(xid);
+        } catch (RemoteException e) {
+            throw getXAException(e);
+        }
+    }
+
+    public int getTransactionTimeout() throws XAException {
+        try {
+            return remote.getTransactionTimeout();
+        } catch (RemoteException e) {
+            throw getXAException(e);
+        }
+    }
+
+    public int prepare(Xid xid) throws XAException {
+        try {
+            return remote.prepare(xid);
+        } catch (RemoteException e) {
+            throw getXAException(e);
+        }
+    }
+
+    public Xid[] recover(int flag) throws XAException {
+        try {
+            return remote.recover(flag);
+        } catch (RemoteException e) {
+            throw getXAException(e);
+        }
+    }
+
+    public void rollback(Xid xid) throws XAException {
+        try {
+            remote.rollback(xid);
+        } catch (RemoteException e) {
+            throw getXAException(e);
+        }
+    }
+
+    public boolean setTransactionTimeout(int seconds) throws XAException {
+        try {
+            return remote.setTransactionTimeout(seconds);
+        } catch (RemoteException e) {
+            throw getXAException(e);
+        }
+    }
+
+    public void start(Xid xid, int flags) throws XAException {
+        try {
+            remote.start(xid, flags);
+        } catch (RemoteException e) {
+            throw getXAException(e);
+        }
+    }
+
+}

Propchange: jackrabbit/trunk/jackrabbit-jcr-rmi/src/main/java/org/apache/jackrabbit/rmi/client/ClientXAResource.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: jackrabbit/trunk/jackrabbit-jcr-rmi/src/main/java/org/apache/jackrabbit/rmi/client/ClientXASession.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-rmi/src/main/java/org/apache/jackrabbit/rmi/client/ClientXASession.java?rev=573739&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-rmi/src/main/java/org/apache/jackrabbit/rmi/client/ClientXASession.java (added)
+++ jackrabbit/trunk/jackrabbit-jcr-rmi/src/main/java/org/apache/jackrabbit/rmi/client/ClientXASession.java Fri Sep  7 15:39:13 2007
@@ -0,0 +1,61 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.rmi.client;
+
+import java.rmi.RemoteException;
+
+import javax.transaction.xa.XAResource;
+
+import javax.jcr.Repository;
+
+import org.apache.jackrabbit.api.XASession;
+import org.apache.jackrabbit.rmi.remote.RemoteXASession;
+
+/**
+ * Local adapter for the JCR-RMI
+ * {@link org.apache.jackrabbit.rmi.remote.RemoteXASession RemoteXASession}
+ * interface.
+ *
+ * @since 1.4
+ */
+public class ClientXASession extends ClientSession implements XASession {
+
+    /**
+     * The adapted remote transaction enabled session.
+     */
+    private RemoteXASession remote;
+
+    /**
+     * Creates a client adapter for the given remote session which is
+     * transaction enabled.
+     */
+    public ClientXASession(
+            Repository repository, RemoteXASession remote,
+            LocalAdapterFactory factory) {
+        super(repository, remote, factory);
+        this.remote = remote;
+    }
+
+    public XAResource getXAResource() {
+        try {
+            return getFactory().getXAResource(remote.getXAResource());
+        } catch (RemoteException e) {
+            throw new RemoteRuntimeException(e);
+        }
+    }
+
+}

Propchange: jackrabbit/trunk/jackrabbit-jcr-rmi/src/main/java/org/apache/jackrabbit/rmi/client/ClientXASession.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: jackrabbit/trunk/jackrabbit-jcr-rmi/src/main/java/org/apache/jackrabbit/rmi/client/LocalAdapterFactory.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-rmi/src/main/java/org/apache/jackrabbit/rmi/client/LocalAdapterFactory.java?rev=573739&r1=573738&r2=573739&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-rmi/src/main/java/org/apache/jackrabbit/rmi/client/LocalAdapterFactory.java (original)
+++ jackrabbit/trunk/jackrabbit-jcr-rmi/src/main/java/org/apache/jackrabbit/rmi/client/LocalAdapterFactory.java Fri Sep  7 15:39:13 2007
@@ -41,6 +41,7 @@
 import javax.jcr.version.Version;
 import javax.jcr.version.VersionHistory;
 import javax.jcr.version.VersionIterator;
+import javax.transaction.xa.XAResource;
 
 import org.apache.jackrabbit.rmi.remote.RemoteItem;
 import org.apache.jackrabbit.rmi.remote.RemoteItemDefinition;
@@ -63,6 +64,7 @@
 import org.apache.jackrabbit.rmi.remote.RemoteVersion;
 import org.apache.jackrabbit.rmi.remote.RemoteVersionHistory;
 import org.apache.jackrabbit.rmi.remote.RemoteWorkspace;
+import org.apache.jackrabbit.rmi.remote.RemoteXAResource;
 
 /**
  * Factory interface for creating local adapters for remote references.
@@ -316,5 +318,13 @@
      * @return local row iterator adapter
      */
     RowIterator getRowIterator(RemoteIterator remote);
+
+    /**
+     * Factory method for creating a local adapter for a remote XA resource.
+     *
+     * @param remote remote XA resource
+     * @return local XA adapter
+     */
+    XAResource getXAResource(RemoteXAResource remote);
 
 }

Added: jackrabbit/trunk/jackrabbit-jcr-rmi/src/main/java/org/apache/jackrabbit/rmi/remote/RemoteXAResource.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-rmi/src/main/java/org/apache/jackrabbit/rmi/remote/RemoteXAResource.java?rev=573739&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-rmi/src/main/java/org/apache/jackrabbit/rmi/remote/RemoteXAResource.java (added)
+++ jackrabbit/trunk/jackrabbit-jcr-rmi/src/main/java/org/apache/jackrabbit/rmi/remote/RemoteXAResource.java Fri Sep  7 15:39:13 2007
@@ -0,0 +1,87 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.rmi.remote;
+
+import java.rmi.Remote;
+import java.rmi.RemoteException;
+
+import javax.transaction.xa.XAException;
+import javax.transaction.xa.Xid;
+
+/**
+ * Remote version of the {@link javax.transaction.xa.XAResource} interface.
+ *
+ * @since 1.4
+ */
+public interface RemoteXAResource extends Remote {
+
+    /**
+     * Remote version of the
+     * {@link javax.transaction.xa.XAResource#commit(Xid, boolean)} method.
+     */
+    void commit(Xid xid, boolean onePhase) throws XAException, RemoteException;
+
+    /**
+     * Remote version of the
+     * {@link javax.transaction.xa.XAResource#end(Xid, int)} method.
+     */
+    void end(Xid xid, int flags) throws XAException, RemoteException;
+
+    /**
+     * Remote version of the
+     * {@link javax.transaction.xa.XAResource#forget(Xid)} method.
+     */
+    void forget(Xid xid) throws XAException, RemoteException;
+
+    /**
+     * Remote version of the
+     * {@link javax.transaction.xa.XAResource#getTransactionTimeout()} method.
+     */
+    int getTransactionTimeout() throws XAException, RemoteException;
+
+    /**
+     * Remote version of the
+     * {@link javax.transaction.xa.XAResource#prepare(Xid)} method.
+     */
+    int prepare(Xid xid) throws XAException, RemoteException;
+
+    /**
+     * Remote version of the
+     * {@link javax.transaction.xa.XAResource#recover(int)} method.
+     */
+    Xid[] recover(int flag) throws XAException, RemoteException;
+
+    /**
+     * Remote version of the
+     * {@link javax.transaction.xa.XAResource#rollback(Xid)} method.
+     */
+    void rollback(Xid xid) throws XAException, RemoteException;
+
+    /**
+     * Remote version of the
+     * {@link javax.transaction.xa.XAResource#setTransactionTimeout(int)} method.
+     */
+    boolean setTransactionTimeout(int seconds)
+        throws XAException, RemoteException;
+
+    /**
+     * Remote version of the
+     * {@link javax.transaction.xa.XAResource#start(Xid, int)} method.
+     */
+    void start(Xid xid, int flags) throws XAException, RemoteException;
+
+}

Propchange: jackrabbit/trunk/jackrabbit-jcr-rmi/src/main/java/org/apache/jackrabbit/rmi/remote/RemoteXAResource.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: jackrabbit/trunk/jackrabbit-jcr-rmi/src/main/java/org/apache/jackrabbit/rmi/remote/RemoteXASession.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-rmi/src/main/java/org/apache/jackrabbit/rmi/remote/RemoteXASession.java?rev=573739&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-rmi/src/main/java/org/apache/jackrabbit/rmi/remote/RemoteXASession.java (added)
+++ jackrabbit/trunk/jackrabbit-jcr-rmi/src/main/java/org/apache/jackrabbit/rmi/remote/RemoteXASession.java Fri Sep  7 15:39:13 2007
@@ -0,0 +1,36 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.rmi.remote;
+
+import java.rmi.Remote;
+import java.rmi.RemoteException;
+
+/**
+ * Remote version of the {@link org.apache.jackrabbit.api.XASession}
+ * interface.
+ *
+ * @since 1.4
+ */
+public interface RemoteXASession extends RemoteSession, Remote {
+
+    /**
+     * Remote version of the
+     * {@link org.apache.jackrabbit.api.XASession#getXAResource()} method.
+     */
+    RemoteXAResource getXAResource() throws RemoteException;
+
+}

Propchange: jackrabbit/trunk/jackrabbit-jcr-rmi/src/main/java/org/apache/jackrabbit/rmi/remote/RemoteXASession.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: jackrabbit/trunk/jackrabbit-jcr-rmi/src/main/java/org/apache/jackrabbit/rmi/server/RemoteAdapterFactory.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-rmi/src/main/java/org/apache/jackrabbit/rmi/server/RemoteAdapterFactory.java?rev=573739&r1=573738&r2=573739&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-rmi/src/main/java/org/apache/jackrabbit/rmi/server/RemoteAdapterFactory.java (original)
+++ jackrabbit/trunk/jackrabbit-jcr-rmi/src/main/java/org/apache/jackrabbit/rmi/server/RemoteAdapterFactory.java Fri Sep  7 15:39:13 2007
@@ -44,6 +44,7 @@
 import javax.jcr.version.Version;
 import javax.jcr.version.VersionHistory;
 import javax.jcr.version.VersionIterator;
+import javax.transaction.xa.XAResource;
 
 import org.apache.jackrabbit.rmi.remote.RemoteEventCollection;
 import org.apache.jackrabbit.rmi.remote.RemoteItem;
@@ -67,6 +68,7 @@
 import org.apache.jackrabbit.rmi.remote.RemoteVersion;
 import org.apache.jackrabbit.rmi.remote.RemoteVersionHistory;
 import org.apache.jackrabbit.rmi.remote.RemoteWorkspace;
+import org.apache.jackrabbit.rmi.remote.RemoteXAResource;
 
 /**
  * Factory interface for creating remote adapters for local resources.
@@ -348,6 +350,16 @@
      * @throws RemoteException on RMI errors
      */
     RemoteIterator getRemoteRowIterator(RowIterator iterator)
+        throws RemoteException;
+
+    /**
+     * Returns a remote adapter for the given local XA resource.
+     *
+     * @param iterator local XA resource
+     * @return remote XA resource adapter
+     * @throws RemoteException on RMI errors
+     */
+    RemoteXAResource getRemoteXAResource(XAResource resource)
         throws RemoteException;
 
 }

Modified: jackrabbit/trunk/jackrabbit-jcr-rmi/src/main/java/org/apache/jackrabbit/rmi/server/ServerAdapterFactory.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-rmi/src/main/java/org/apache/jackrabbit/rmi/server/ServerAdapterFactory.java?rev=573739&r1=573738&r2=573739&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-rmi/src/main/java/org/apache/jackrabbit/rmi/server/ServerAdapterFactory.java (original)
+++ jackrabbit/trunk/jackrabbit-jcr-rmi/src/main/java/org/apache/jackrabbit/rmi/server/ServerAdapterFactory.java Fri Sep  7 15:39:13 2007
@@ -48,7 +48,9 @@
 import javax.jcr.version.Version;
 import javax.jcr.version.VersionHistory;
 import javax.jcr.version.VersionIterator;
+import javax.transaction.xa.XAResource;
 
+import org.apache.jackrabbit.api.XASession;
 import org.apache.jackrabbit.rmi.remote.ArrayIterator;
 import org.apache.jackrabbit.rmi.remote.BufferIterator;
 import org.apache.jackrabbit.rmi.remote.RemoteEventCollection;
@@ -73,6 +75,7 @@
 import org.apache.jackrabbit.rmi.remote.RemoteVersion;
 import org.apache.jackrabbit.rmi.remote.RemoteVersionHistory;
 import org.apache.jackrabbit.rmi.remote.RemoteWorkspace;
+import org.apache.jackrabbit.rmi.remote.RemoteXAResource;
 import org.apache.jackrabbit.rmi.server.iterator.ServerNodeIterator;
 import org.apache.jackrabbit.rmi.server.iterator.ServerNodeTypeIterator;
 import org.apache.jackrabbit.rmi.server.iterator.ServerPropertyIterator;
@@ -127,11 +130,19 @@
 
     /**
      * Creates a {@link ServerSession ServerSession} instance.
+     * In case the underlying session is transaction enabled, the
+     * remote interface is will be transaction enabled too through
+     * the {@link ServerXASession}.
+     *
      * {@inheritDoc}
      */
     public RemoteSession getRemoteSession(Session session)
             throws RemoteException {
-        return new ServerSession(session, this);
+        if (session instanceof XASession) {
+            return new ServerXASession((XASession) session, this);
+        } else {
+            return new ServerSession(session, this);
+        }
     }
 
     /**
@@ -394,6 +405,14 @@
             throws RemoteException {
         return optimizeIterator(
                 new ServerRowIterator(iterator, this, bufferSize));
+    }
+
+    /**
+     * Creates a {@link ServerXAResource} instance.
+     */
+    public RemoteXAResource getRemoteXAResource(XAResource resource)
+            throws RemoteException {
+        return new ServerXAResource(resource);
     }
 
 }

Added: jackrabbit/trunk/jackrabbit-jcr-rmi/src/main/java/org/apache/jackrabbit/rmi/server/ServerXAResource.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-rmi/src/main/java/org/apache/jackrabbit/rmi/server/ServerXAResource.java?rev=573739&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-rmi/src/main/java/org/apache/jackrabbit/rmi/server/ServerXAResource.java (added)
+++ jackrabbit/trunk/jackrabbit-jcr-rmi/src/main/java/org/apache/jackrabbit/rmi/server/ServerXAResource.java Fri Sep  7 15:39:13 2007
@@ -0,0 +1,122 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.rmi.server;
+
+import java.rmi.RemoteException;
+
+import javax.transaction.xa.XAException;
+import javax.transaction.xa.XAResource;
+import javax.transaction.xa.Xid;
+
+import org.apache.jackrabbit.rmi.remote.RemoteXAResource;
+
+/**
+ * Remote adapter for the {@link XAResource} interface.
+ *
+ * @since 1.4
+ */
+public class ServerXAResource implements RemoteXAResource {
+
+    /**
+     * The adapted local XA resource
+     */
+    private XAResource resource;
+
+    /**
+     * Creates a remote adapter for the given local XA resource.
+     */
+    public ServerXAResource(XAResource resource) throws RemoteException {
+        this.resource = resource;
+    }
+
+    private static XAException getXAException(XAException e) {
+        return new XAException(e.getMessage());
+    }
+
+    public void commit(Xid xid, boolean onePhase) throws XAException {
+        try {
+            resource.commit(xid, onePhase);
+        } catch (XAException e) {
+            throw getXAException(e);
+        }
+    }
+
+    public void end(Xid xid, int flags) throws XAException {
+        try {
+            resource.end(xid, flags);
+        } catch (XAException e) {
+            throw getXAException(e);
+        }
+    }
+
+    public void forget(Xid xid) throws XAException {
+        try {
+            resource.forget(xid);
+        } catch (XAException e) {
+            throw getXAException(e);
+        }
+    }
+
+    public int getTransactionTimeout() throws XAException {
+        try {
+            return resource.getTransactionTimeout();
+        } catch (XAException e) {
+            throw getXAException(e);
+        }
+    }
+
+    public int prepare(Xid xid) throws XAException {
+        try {
+            return resource.prepare(xid);
+        } catch (XAException e) {
+            throw getXAException(e);
+        }
+    }
+
+    public Xid[] recover(int flag) throws XAException {
+        try {
+            return resource.recover(flag);
+        } catch (XAException e) {
+            throw getXAException(e);
+        }
+    }
+
+    public void rollback(Xid xid) throws XAException {
+        try {
+            resource.rollback(xid);
+        } catch (XAException e) {
+            throw getXAException(e);
+        }
+    }
+
+    public boolean setTransactionTimeout(int seconds) throws XAException {
+        try {
+            return resource.setTransactionTimeout(seconds);
+        } catch (XAException e) {
+            throw getXAException(e);
+        }
+    }
+
+    public void start(Xid xid, int flags) throws XAException {
+        try {
+            resource.start(xid, flags);
+        } catch (XAException e) {
+            throw getXAException(e);
+        }
+    }
+
+}

Propchange: jackrabbit/trunk/jackrabbit-jcr-rmi/src/main/java/org/apache/jackrabbit/rmi/server/ServerXAResource.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: jackrabbit/trunk/jackrabbit-jcr-rmi/src/main/java/org/apache/jackrabbit/rmi/server/ServerXASession.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-rmi/src/main/java/org/apache/jackrabbit/rmi/server/ServerXASession.java?rev=573739&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-rmi/src/main/java/org/apache/jackrabbit/rmi/server/ServerXASession.java (added)
+++ jackrabbit/trunk/jackrabbit-jcr-rmi/src/main/java/org/apache/jackrabbit/rmi/server/ServerXASession.java Fri Sep  7 15:39:13 2007
@@ -0,0 +1,51 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.rmi.server;
+
+import java.rmi.RemoteException;
+
+import org.apache.jackrabbit.api.XASession;
+import org.apache.jackrabbit.rmi.remote.RemoteXAResource;
+import org.apache.jackrabbit.rmi.remote.RemoteXASession;
+
+/**
+ * Remote adapter for the Jackrabbit {@link XASession} interface.
+ *
+ * @since 1.4
+ */
+public class ServerXASession extends ServerSession implements RemoteXASession {
+
+    /**
+     * The adapted transaction enabled local session.
+     */
+    private XASession session;
+
+    /**
+     * Creates a remote adapter for the given local, transaction enabled,
+     * session.
+     */
+    public ServerXASession(XASession session, RemoteAdapterFactory factory)
+            throws RemoteException {
+        super(session, factory);
+        this.session = session;
+    }
+
+    public RemoteXAResource getXAResource() throws RemoteException {
+        return getFactory().getRemoteXAResource(session.getXAResource());
+    }
+
+}

Propchange: jackrabbit/trunk/jackrabbit-jcr-rmi/src/main/java/org/apache/jackrabbit/rmi/server/ServerXASession.java
------------------------------------------------------------------------------
    svn:eol-style = native