@@ -0,0 +1,2597 @@
+/*%0A * (C) Copyright 2007-2010 Nuxeo SA (http://nuxeo.com/) and contributors.%0A *%0A * All rights reserved. This program and the accompanying materials%0A * are made available under the terms of the GNU Lesser General Public License%0A * (LGPL) version 2.1 which accompanies this distribution, and is available at%0A * http://www.gnu.org/licenses/lgpl.html%0A *%0A * This library is distributed in the hope that it will be useful,%0A * but WITHOUT ANY WARRANTY; without even the implied warranty of%0A * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU%0A * Lesser General Public License for more details.%0A *%0A * Contributors:%0A *     Florent Guillaume%0A *     Sun Seng David TAN%0A */%0A%0Apackage org.nuxeo.common.utils;%0A%0Aimport java.io.Serializable;%0Aimport java.util.Arrays;%0A%0Aimport javax.transaction.xa.Xid;%0A%0A/**%0A * A Serializable %7B@link Xid%7D independent of the transaction manager%0A * implementation.%0A */%0Apublic class XidImpl implements Xid, Serializable %7B%0A%0A    private static final long serialVersionUID = 1L;%0A%0A    public final int fid;%0A%0A    public final byte%5B%5D gtrid;%0A%0A    public final byte%5B%5D bqual;%0A%0A    /**%0A     * Copy constructor.%0A     *%0A     * @param xid the xid to copy%0A     */%0A    public XidImpl(Xid xid) %7B%0A        fid = xid.getFormatId();%0A        gtrid = (byte%5B%5D) xid.getGlobalTransactionId().clone();%0A        bqual = (byte%5B%5D) xid.getBranchQualifier().clone();%0A    %7D%0A%0A    /**%0A     * Constructor mostly used in unit tests.%0A     *%0A     * @param id the global transaction id%0A     */%0A    public XidImpl(String id) %7B%0A        fid = 0;%0A        gtrid = id.getBytes();%0A        // MySQL JDBC driver needs a non 0-length branch qualifier%0A        bqual = new byte%5B%5D %7B 0 %7D;%0A    %7D%0A%0A    public int getFormatId() %7B%0A        return fid;%0A    %7D%0A%0A    public byte%5B%5D getGlobalTransactionId() %7B%0A        return (byte%5B%5D) gtrid.clone();%0A    %7D%0A%0A    public byte%5B%5D getBranchQualifier() %7B%0A        return (byte%5B%5D) bqual.clone();%0A    %7D%0A%0A    @Override%0A    public int hashCode() %7B%0A        final int prime = 31;%0A        int hash = 1;%0A        hash = prime * hash + fid;%0A        hash = prime * hash + Arrays.hashCode(gtrid);%0A        hash = prime * hash + Arrays.hashCode(bqual);%0A        return hash;%0A    %7D%0A%0A    @Override%0A    public boolean equals(Object other) %7B%0A        if (!(other instanceof XidImpl)) %7B%0A            return false;%0A        %7D%0A        return equals((XidImpl) other);%0A    %7D%0A%0A    private final boolean equals(XidImpl other) %7B%0A        if (other == this) %7B%0A            return true;%0A        %7D%0A        return fid == other.fid && Arrays.equals(gtrid, other.gtrid)%0A                && Arrays.equals(bqual, other.bqual);%0A    %7D%0A%0A%7D%0A

move generic Xid implementation to nuxeo-common