### Eclipse Workspace Patch 1.0 #P jackrabbit-core Index: src/main/java/org/apache/jackrabbit/core/TransactionContext.java =================================================================== --- src/main/java/org/apache/jackrabbit/core/TransactionContext.java (revision 1241895) +++ src/main/java/org/apache/jackrabbit/core/TransactionContext.java (working copy) @@ -308,21 +308,21 @@ * 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 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); + } + } + } Index: src/main/java/org/apache/jackrabbit/core/util/db/ConnectionHelper.java =================================================================== --- src/main/java/org/apache/jackrabbit/core/util/db/ConnectionHelper.java (revision 1367057) +++ src/main/java/org/apache/jackrabbit/core/util/db/ConnectionHelper.java (working copy) @@ -22,7 +22,6 @@ 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 @@ */ private Connection getTransactionAwareBatchConnection() { Object threadId = TransactionContext.getCurrentThreadId(); - return batchConnectionMap.get(threadIdToObject(threadId)); + return batchConnectionMap.get(threadId); } /** @@ -461,7 +460,7 @@ */ private void setTransactionAwareBatchConnection(Connection batchConnection) { Object threadId = TransactionContext.getCurrentThreadId(); - batchConnectionMap.put(threadIdToObject(threadId), batchConnection); + batchConnectionMap.put(threadId, batchConnection); } /** @@ -469,23 +468,9 @@ */ 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 @@ } } } - - /** - * 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); - } - } }