jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r628289 - in /jackrabbit/trunk/jackrabbit-jcr-rmi/src/main/java/org/apache/jackrabbit/rmi: client/ClientXAResource.java remote/SerializableXid.java server/ServerXAResource.java
Date Sat, 16 Feb 2008 13:17:51 GMT
Author: jukka
Date: Sat Feb 16 05:17:49 2008
New Revision: 628289

URL: http://svn.apache.org/viewvc?rev=628289&view=rev
Log:
JCR-1333: jackrabbit-jcr-rmi: Supplied javax.transaction.xa.Xid is assumed serializable, but
is not on some environments
    - Added the SerializableXid class and adapted XAResources to use it

Added:
    jackrabbit/trunk/jackrabbit-jcr-rmi/src/main/java/org/apache/jackrabbit/rmi/remote/SerializableXid.java
Modified:
    jackrabbit/trunk/jackrabbit-jcr-rmi/src/main/java/org/apache/jackrabbit/rmi/client/ClientXAResource.java
    jackrabbit/trunk/jackrabbit-jcr-rmi/src/main/java/org/apache/jackrabbit/rmi/server/ServerXAResource.java

Modified: 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=628289&r1=628288&r2=628289&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-rmi/src/main/java/org/apache/jackrabbit/rmi/client/ClientXAResource.java
(original)
+++ jackrabbit/trunk/jackrabbit-jcr-rmi/src/main/java/org/apache/jackrabbit/rmi/client/ClientXAResource.java
Sat Feb 16 05:17:49 2008
@@ -23,6 +23,7 @@
 import javax.transaction.xa.Xid;
 
 import org.apache.jackrabbit.rmi.remote.RemoteXAResource;
+import org.apache.jackrabbit.rmi.remote.SerializableXid;
 
 /**
  * Local adapter for the JCR-RMI {@link RemoteXAResource} interface.
@@ -62,7 +63,7 @@
 
     public void commit(Xid xid, boolean onePhase) throws XAException {
         try {
-            remote.commit(xid, onePhase);
+            remote.commit(new SerializableXid(xid), onePhase);
         } catch (RemoteException e) {
             throw getXAException(e);
         }
@@ -70,7 +71,7 @@
 
     public void end(Xid xid, int flags) throws XAException {
         try {
-            remote.end(xid, flags);
+            remote.end(new SerializableXid(xid), flags);
         } catch (RemoteException e) {
             throw getXAException(e);
         }
@@ -78,7 +79,7 @@
 
     public void forget(Xid xid) throws XAException {
         try {
-            remote.forget(xid);
+            remote.forget(new SerializableXid(xid));
         } catch (RemoteException e) {
             throw getXAException(e);
         }
@@ -94,7 +95,7 @@
 
     public int prepare(Xid xid) throws XAException {
         try {
-            return remote.prepare(xid);
+            return remote.prepare(new SerializableXid(xid));
         } catch (RemoteException e) {
             throw getXAException(e);
         }
@@ -110,7 +111,7 @@
 
     public void rollback(Xid xid) throws XAException {
         try {
-            remote.rollback(xid);
+            remote.rollback(new SerializableXid(xid));
         } catch (RemoteException e) {
             throw getXAException(e);
         }
@@ -126,7 +127,7 @@
 
     public void start(Xid xid, int flags) throws XAException {
         try {
-            remote.start(xid, flags);
+            remote.start(new SerializableXid(xid), flags);
         } catch (RemoteException e) {
             throw getXAException(e);
         }

Added: jackrabbit/trunk/jackrabbit-jcr-rmi/src/main/java/org/apache/jackrabbit/rmi/remote/SerializableXid.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-rmi/src/main/java/org/apache/jackrabbit/rmi/remote/SerializableXid.java?rev=628289&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-rmi/src/main/java/org/apache/jackrabbit/rmi/remote/SerializableXid.java
(added)
+++ jackrabbit/trunk/jackrabbit-jcr-rmi/src/main/java/org/apache/jackrabbit/rmi/remote/SerializableXid.java
Sat Feb 16 05:17:49 2008
@@ -0,0 +1,71 @@
+/*
+ * 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.io.Serializable;
+import java.util.Arrays;
+
+import javax.transaction.xa.Xid;
+
+/**
+ * Serializable {@link Xid}.
+ *
+ * @since Jackrabbit JCR-RMI 1.5
+ */
+public class SerializableXid implements Serializable, Xid {
+
+    private final int formatId;
+
+    private final byte[] globalTransactionId;
+
+    private final byte[] branchQualifier;
+
+    private final int hashCode;
+
+    public SerializableXid(Xid xid) {
+        formatId = xid.getFormatId();
+        globalTransactionId = xid.getGlobalTransactionId();
+        branchQualifier = xid.getBranchQualifier();
+        hashCode = xid.hashCode();
+    }
+
+    public int getFormatId() {
+        return formatId;
+    }
+
+    public byte[] getGlobalTransactionId() {
+        return globalTransactionId;
+    }
+
+    public byte[] getBranchQualifier() {
+        return branchQualifier;
+    }
+
+    public int hashCode() {
+        return hashCode;
+    }
+
+    public boolean equals(Object xid) {
+        return (xid instanceof Xid)
+            && formatId == ((Xid) xid).getFormatId()
+            && Arrays.equals(
+                    globalTransactionId, ((Xid) xid).getGlobalTransactionId())
+            && Arrays.equals(
+                    branchQualifier, ((Xid) xid).getBranchQualifier());
+    }
+
+}

Modified: 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=628289&r1=628288&r2=628289&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-rmi/src/main/java/org/apache/jackrabbit/rmi/server/ServerXAResource.java
(original)
+++ jackrabbit/trunk/jackrabbit-jcr-rmi/src/main/java/org/apache/jackrabbit/rmi/server/ServerXAResource.java
Sat Feb 16 05:17:49 2008
@@ -24,6 +24,7 @@
 import javax.transaction.xa.Xid;
 
 import org.apache.jackrabbit.rmi.remote.RemoteXAResource;
+import org.apache.jackrabbit.rmi.remote.SerializableXid;
 
 /**
  * Remote adapter for the {@link XAResource} interface.
@@ -91,7 +92,11 @@
 
     public Xid[] recover(int flag) throws XAException {
         try {
-            return resource.recover(flag);
+            Xid[] xids = resource.recover(flag);
+            for (int i = 0; i < xids.length; i++) {
+                xids[i] = new SerializableXid(xids[i]);
+            }
+            return xids;
         } catch (XAException e) {
             throw getXAException(e);
         }



Mime
View raw message