jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From un...@apache.org
Subject svn commit: r1390933 - in /jackrabbit/branches/2.2/jackrabbit-core/src/main/java/org/apache/jackrabbit/core: TransactionContext.java util/db/ConnectionHelper.java
Date Thu, 27 Sep 2012 10:36:14 GMT
Author: unico
Date: Thu Sep 27 10:36:13 2012
New Revision: 1390933

URL: http://svn.apache.org/viewvc?rev=1390933&view=rev
Log:
JCR-3425 revert backport because bad merge

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

Modified: jackrabbit/branches/2.2/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/TransactionContext.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/2.2/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/TransactionContext.java?rev=1390933&r1=1390932&r2=1390933&view=diff
==============================================================================
--- jackrabbit/branches/2.2/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/TransactionContext.java
(original)
+++ jackrabbit/branches/2.2/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/TransactionContext.java
Thu Sep 27 10:36:13 2012
@@ -363,21 +363,21 @@ public class TransactionContext extends 
      * Returns the {@link Xid} bind to the {@link #CURRENT_XID} ThreadLocal
      * @return current Xid or null
      */
-    private static Xid getCurrentXid() {
+    public 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 wrapped 
-     * in a {@link XidWrapper}, when running under a transaction.
+     * current thread instance or the global transaction identifier when
+     * running under a transaction.
      *
      * @return current thread identifier
      */
     public static Object getCurrentThreadId() {
         Xid xid = TransactionContext.getCurrentXid();
         if (xid != null) {
-            return new XidWrapper(xid.getGlobalTransactionId());
+            return xid.getGlobalTransactionId();
         } else {
             return Thread.currentThread();
         }
@@ -391,36 +391,11 @@ public class TransactionContext extends 
     public static boolean isSameThreadId(Object a, Object b) {
         if (a == b) {
             return true;
-        } else if (a != null) {
-        	return a.equals(b);
+        } else if (a instanceof byte[] && b instanceof byte[]) {
+            return Arrays.equals((byte[]) a, (byte[]) 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.2/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/util/db/ConnectionHelper.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/2.2/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/util/db/ConnectionHelper.java?rev=1390933&r1=1390932&r2=1390933&view=diff
==============================================================================
--- jackrabbit/branches/2.2/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/util/db/ConnectionHelper.java
(original)
+++ jackrabbit/branches/2.2/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/util/db/ConnectionHelper.java
Thu Sep 27 10:36:13 2012
@@ -22,6 +22,7 @@ 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 +450,7 @@ public class ConnectionHelper {
      */
     private Connection getTransactionAwareBatchConnection() {
     	Object threadId = TransactionContext.getCurrentThreadId();
-       	return batchConnectionMap.get(threadId);
+       	return batchConnectionMap.get(threadIdToObject(threadId));
 	}
 
     /**
@@ -461,7 +462,7 @@ public class ConnectionHelper {
      */
 	private void setTransactionAwareBatchConnection(Connection batchConnection) {
     	Object threadId = TransactionContext.getCurrentThreadId();
-    	batchConnectionMap.put(threadId, batchConnection);
+    	batchConnectionMap.put(threadIdToObject(threadId), batchConnection);
 	}
 
     /**
@@ -469,9 +470,23 @@ public class ConnectionHelper {
      */
 	private void removeTransactionAwareBatchConnection() {
     	Object threadId = TransactionContext.getCurrentThreadId();
-    	batchConnectionMap.remove(threadId);
+    	batchConnectionMap.remove(threadIdToObject(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.
      *
@@ -552,4 +567,29 @@ public class ConnectionHelper {
 
         protected abstract T call() throws SQLException;
     }
+    
+    /**
+     * 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