[jboss-cvs] JBossAS SVN: r57745 - in branches/Branch_4_0/connector/src/main/org/jboss/resource/connectionmanager: . xa

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Fri Oct 20 00:43:48 EDT 2006


Author: weston.price at jboss.com
Date: 2006-10-20 00:43:46 -0400 (Fri, 20 Oct 2006)
New Revision: 57745

Added:
   branches/Branch_4_0/connector/src/main/org/jboss/resource/connectionmanager/xa/
   branches/Branch_4_0/connector/src/main/org/jboss/resource/connectionmanager/xa/JcaXAResourceWrapper.java
   branches/Branch_4_0/connector/src/main/org/jboss/resource/connectionmanager/xa/JcaXid.java
Log:
[JBAS-3183] [JBAS-1405] Added JcaXAResourceWrapped and JcaXid to support 
thirdparty integration as well as Xid padding in JCA layer.

Added: branches/Branch_4_0/connector/src/main/org/jboss/resource/connectionmanager/xa/JcaXAResourceWrapper.java
===================================================================
--- branches/Branch_4_0/connector/src/main/org/jboss/resource/connectionmanager/xa/JcaXAResourceWrapper.java	2006-10-19 22:43:42 UTC (rev 57744)
+++ branches/Branch_4_0/connector/src/main/org/jboss/resource/connectionmanager/xa/JcaXAResourceWrapper.java	2006-10-20 04:43:46 UTC (rev 57745)
@@ -0,0 +1,143 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.resource.connectionmanager.xa;
+
+import java.io.Serializable;
+
+import javax.transaction.xa.XAException;
+import javax.transaction.xa.XAResource;
+import javax.transaction.xa.Xid;
+
+/**
+ * A XAResourceWrapper supporting JCA specific constructs for XAResource management.
+ * 
+ * @author <a href="weston.price at jboss.com">Weston Price</a>
+ * @version $Revision: 1.1 $
+ */
+public class JcaXAResourceWrapper implements XAResource, Serializable
+{
+   
+   /** The serialVersionUID */
+   private static final long serialVersionUID = -5041272057070910154L;
+   private final boolean pad;
+   private final XAResource resource;
+   private Boolean overrideSameRM;
+   private boolean convertXid;
+  
+   public JcaXAResourceWrapper(final XAResource resource, final boolean pad, final Boolean overrideSameRM)
+   {
+      this.resource = resource;
+      this.pad = pad;
+      this.overrideSameRM = overrideSameRM;
+   }
+   
+   public void commit(Xid xid, boolean onePhase) throws XAException
+   {
+      xid = convertXid(xid);
+      resource.commit(xid, onePhase);
+   }
+
+   public void end(Xid xid, int flags) throws XAException
+   {
+      xid = convertXid(xid);
+      resource.end(xid, flags);
+   }
+
+   public void forget(Xid xid) throws XAException
+   {
+      xid = convertXid(xid);
+      resource.forget(xid);
+   }
+
+   public int getTransactionTimeout() throws XAException
+   {
+      return resource.getTransactionTimeout();
+   }
+
+   public boolean isSameRM(XAResource xaRes) throws XAException
+   {
+      
+      if(overrideSameRM != null)
+      {
+         return overrideSameRM.booleanValue();         
+      }
+      
+      if(xaRes instanceof JcaXAResourceWrapper)
+      {
+         final JcaXAResourceWrapper jca = (JcaXAResourceWrapper)xaRes;         
+         xaRes = jca.getRawResource();         
+      }
+      
+      final XAResource current = getRawResource();
+      
+      return current.isSameRM(xaRes);
+      
+   }
+
+   public int prepare(Xid xid) throws XAException
+   {
+      xid = convertXid(xid);
+      return resource.prepare(xid);
+   }
+
+   public Xid[] recover(int flag) throws XAException
+   {
+      return resource.recover(flag);
+   }
+
+   public void rollback(Xid xid) throws XAException
+   {
+      xid = convertXid(xid);
+      resource.rollback(xid);
+   }
+
+   public boolean setTransactionTimeout(int seconds) throws XAException
+   {
+      return resource.setTransactionTimeout(seconds);
+   }
+
+   public void start(Xid xid, int flags) throws XAException
+   {
+      xid = convertXid(xid);
+      resource.start(xid, flags);
+   }
+   
+   private Xid convertXid(final Xid xid) throws XAException
+   {
+      
+      if (xid == null)
+      {
+         XAException e = new XAException("Null xid");
+         e.errorCode = XAException.XAER_NOTA;
+         throw e;
+      }
+      
+      return (convertXid && xid instanceof JcaXid) ? xid : new JcaXid(xid, pad);
+   
+   }      
+   
+   private XAResource getRawResource()
+   {
+      return this.resource;
+   }
+}

Added: branches/Branch_4_0/connector/src/main/org/jboss/resource/connectionmanager/xa/JcaXid.java
===================================================================
--- branches/Branch_4_0/connector/src/main/org/jboss/resource/connectionmanager/xa/JcaXid.java	2006-10-19 22:43:42 UTC (rev 57744)
+++ branches/Branch_4_0/connector/src/main/org/jboss/resource/connectionmanager/xa/JcaXid.java	2006-10-20 04:43:46 UTC (rev 57745)
@@ -0,0 +1,141 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.resource.connectionmanager.xa;
+
+import java.io.Serializable;
+import java.util.Arrays;
+
+import javax.transaction.xa.Xid;
+
+/**
+ * @author <a href="mailto:weston.price at jboss.com>Weston Price</a>
+ * @version $Revision: 45310 $
+ */
+public class JcaXid implements Serializable, Xid
+{
+
+   /** The serialVersionUID */
+   private static final long serialVersionUID = 5805807959548006486L;
+
+   /** The format id */
+   private final int formatId;
+      
+   /** The gid */
+   private final byte[] globalTransactionId;
+
+   /** The branch */
+   private final byte[] branchQualifier;
+
+   /** Cached toString() */
+   private transient String cachedToString;
+
+   /** Cached hashCode() */
+   private transient int cachedHashCode;
+
+   public JcaXid(final Xid xid, final boolean pad)
+   {
+      //Copy global id, pad where necessary
+      if(pad)
+      {
+         globalTransactionId = new byte[Xid.MAXGTRIDSIZE];
+         System.arraycopy(xid.getGlobalTransactionId(), 0, this.globalTransactionId, 0, xid.getGlobalTransactionId().length);
+      }
+      else
+      {
+         globalTransactionId = xid.getGlobalTransactionId();
+         
+      }
+      
+      this.branchQualifier = xid.getBranchQualifier();
+      this.formatId = xid.getFormatId();
+      
+   }
+   /**
+    * Create a new wrapper Xid
+    * 
+    * @param xid the wrapped xid
+    */
+   public JcaXid(final Xid xid)
+   {
+     this(xid, false);
+   }
+
+   public int getFormatId()
+   {
+      return formatId;
+   }
+
+   public byte[] getGlobalTransactionId()
+   {
+      return globalTransactionId;
+   }
+
+   public byte[] getBranchQualifier()
+   {
+      return branchQualifier;
+   }
+
+   public boolean equals(Object object)
+   {
+      
+      if(!(object instanceof JcaXid))
+         return false;
+      
+      Xid other = (Xid) object;
+      return
+      (
+         formatId == other.getFormatId() && 
+         Arrays.equals(globalTransactionId, other.getGlobalTransactionId()) &&
+         Arrays.equals(branchQualifier, other.getBranchQualifier())
+      );
+   }
+
+   public int hashCode()
+   {
+      if (cachedHashCode == 0)
+      {
+         cachedHashCode = formatId;
+         for (int i = 0; i < globalTransactionId.length; ++i)
+            cachedHashCode += globalTransactionId[i];
+      }
+      return cachedHashCode;
+   }
+
+   public String toString()
+   {
+      if (cachedToString == null)
+      {
+         StringBuffer buffer = new StringBuffer();
+         buffer.append("JcaXid[FormatId=").append(getFormatId());
+         buffer.append(" GlobalId=").append(new String(getGlobalTransactionId()).trim());
+         byte[] branchQualifer = getBranchQualifier();
+         buffer.append(" BranchQual=");
+         if (branchQualifer == null)
+            buffer.append("null");
+         else
+            buffer.append(new String(getBranchQualifier()).trim());
+         buffer.append(']');
+         cachedToString = buffer.toString();
+      }
+      return cachedToString;
+   }
+}
\ No newline at end of file




More information about the jboss-cvs-commits mailing list