jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cko...@apache.org
Subject svn commit: r1389754 - in /jackrabbit/branches/2.4/jackrabbit-core/src/main/java/org/apache/jackrabbit/core: TransactionContext.java util/db/ConnectionHelper.java
Date Tue, 25 Sep 2012 08:29:51 GMT
Author: ckoell
Date: Tue Sep 25 08:29:50 2012
New Revision: 1389754

URL: http://svn.apache.org/viewvc?rev=1389754&view=rev
Log:
JCR-3425 XAAwareRWLock implementation fails with IllegalStateException on JBoss AS7

Modified:
    jackrabbit/branches/2.4/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/TransactionContext.java
    jackrabbit/branches/2.4/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/util/db/ConnectionHelper.java

Modified: jackrabbit/branches/2.4/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/TransactionContext.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/2.4/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/TransactionContext.java?rev=1389754&r1=1389753&r2=1389754&view=diff
==============================================================================
--- jackrabbit/branches/2.4/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/TransactionContext.java
(original)
+++ jackrabbit/branches/2.4/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/TransactionContext.java
Tue Sep 25 08:29:50 2012
@@ -308,21 +308,21 @@ public class TransactionContext {
      * Returns the {@link Xid} bind to the {@link #CURRENT_XID} ThreadLocal
      * @return current Xid or null
      */
-    public static Xid getCurrentXid() {
+    private static Xid getCurrentXid() {
         return CURRENT_XID.get();
     }
 
     /**
      * Returns the current thread identifier. The identifier is either the
-     * current thread instance or the global transaction identifier when
-     * running under a transaction.
+     * current thread instance or the global transaction identifier wrapped 
+     * in a {@link XidWrapper}, when running under a transaction.
      *
      * @return current thread identifier
      */
     public static Object getCurrentThreadId() {
         Xid xid = TransactionContext.getCurrentXid();
         if (xid != null) {
-            return xid.getGlobalTransactionId();
+            return new XidWrapper(xid.getGlobalTransactionId());
         } else {
             return Thread.currentThread();
         }
@@ -336,11 +336,36 @@ public class TransactionContext {
     public static boolean isSameThreadId(Object a, Object b) {
         if (a == b) {
             return true;
-        } else if (a instanceof byte[] && b instanceof byte[]) {
-            return Arrays.equals((byte[]) a, (byte[]) b);
+        } else if (a != null) {
+        	return a.equals(b);
         } else {
             return false;
         }
     }
+    
+    /**
+     * Wrapper around a global transaction id (byte[]) 
+     * that handles hashCode and equals in a proper way.
+     */
+    private static class XidWrapper {
+    	private byte[] gtid;
+    	
+    	public XidWrapper(byte[] gtid) {
+    		this.gtid = gtid;
+    	}
+
+        @Override
+        public boolean equals(Object other) {
+            if (!(other instanceof XidWrapper)) {
+                return false;
+            }
+            return Arrays.equals((byte[]) gtid, ((XidWrapper)other).gtid);
+        }
+
+        @Override
+        public int hashCode() {
+            return Arrays.hashCode(gtid);
+        }
+    }
 
 }

Modified: jackrabbit/branches/2.4/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/util/db/ConnectionHelper.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/2.4/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/util/db/ConnectionHelper.java?rev=1389754&r1=1389753&r2=1389754&view=diff
==============================================================================
--- jackrabbit/branches/2.4/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/util/db/ConnectionHelper.java
(original)
+++ jackrabbit/branches/2.4/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/util/db/ConnectionHelper.java
Tue Sep 25 08:29:50 2012
@@ -22,7 +22,6 @@ import java.sql.PreparedStatement;
 import java.sql.ResultSet;
 import java.sql.SQLException;
 import java.sql.Statement;
-import java.util.Arrays;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.Map;
@@ -449,7 +448,7 @@ public class ConnectionHelper {
      */
     private Connection getTransactionAwareBatchConnection() {
     	Object threadId = TransactionContext.getCurrentThreadId();
-       	return batchConnectionMap.get(threadIdToObject(threadId));
+       	return batchConnectionMap.get(threadId);
 	}
 
     /**
@@ -461,7 +460,7 @@ public class ConnectionHelper {
      */
 	private void setTransactionAwareBatchConnection(Connection batchConnection) {
     	Object threadId = TransactionContext.getCurrentThreadId();
-    	batchConnectionMap.put(threadIdToObject(threadId), batchConnection);
+    	batchConnectionMap.put(threadId, batchConnection);
 	}
 
     /**
@@ -469,23 +468,9 @@ public class ConnectionHelper {
      */
 	private void removeTransactionAwareBatchConnection() {
     	Object threadId = TransactionContext.getCurrentThreadId();
-    	batchConnectionMap.remove(threadIdToObject(threadId));
+    	batchConnectionMap.remove(threadId);
 	}
 	
-    /**
-     * Creates a comparable String from the given threadId
-     * 
-     * @param threadId
-     * @return String
-     */
-    private Object threadIdToObject(Object threadId) {
-    	if (threadId instanceof byte[]) {
-    		return new XidWrapper((byte[]) threadId);
-    	} else {
-    		return threadId.toString();
-    	}
-    }
-
 	/**
      * Closes the given resources given the {@code batchMode} state.
      *
@@ -605,29 +590,4 @@ public class ConnectionHelper {
 		    }
 		}
     }
-    
-    /**
-     * Wrapper around a global transaction id (byte[]) 
-     * that handles hashCode and equals in a proper way.
-     */
-    private class XidWrapper {
-    	private byte[] gtid;
-    	
-    	public XidWrapper(byte[] gtid) {
-    		this.gtid = gtid;
-    	}
-
-        @Override
-        public boolean equals(Object other) {
-            if (!(other instanceof XidWrapper)) {
-                return false;
-            }
-            return TransactionContext.isSameThreadId(gtid, ((XidWrapper)other).gtid);
-        }
-
-        @Override
-        public int hashCode() {
-            return Arrays.hashCode(gtid);
-        }
-    }
 }



Mime
View raw message