You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-user@db.apache.org by Mick Jordan <Mi...@sun.com> on 2006/09/27 04:37:12 UTC
Help with creating XA transaction Ids
I'm trying to run a distributed transaction on two Derby instances using
a my application program as the transaction manager. I'm stuck on how to
create a global transaction id that I can pass to the start method of
the XAResource object that I get from the XAConnection object (an
instance of NetXAResource).
I've searched for examples but both that I found used external classes
to create the Xid. Looking at the Derby code the most likely candidate
seemed to be org.apache.derby.client.ClientXid but I have no idea what
to pass to the constructor. The best example I found on an IBM site used
com.ibm.db2.jcc.DB2Xid. I've not found any Derby-specific examples of
how to create an Xid.
Any pointers much appreciated.
Thanks
Mick Jordan
Re: Help with creating XA transaction Ids
Posted by Mick Jordan <Mi...@sun.com>.
Myrna van Lunteren wrote:
>
>
> I'm a complete novice, but by coincidence I've been staring at the
> Derby functional test
> org.apache.derbyTesting.functionTests.tests.jdbcapi.checkDataSource.java.
> In this test, the author(s) have made an internal class which
> implements javax.transaction.xa.Xid that creates the Xid:
Thanks! Having looked at that code, whixh was functionally equivalent
to the existing ClientXid class, I just used the latter. The content of
the id seems not to matter (to Derby anyway).
Mick
Re: Help with creating XA transaction Ids
Posted by Myrna van Lunteren <m....@gmail.com>.
On 9/26/06, Mick Jordan <Mi...@sun.com> wrote:
> I'm trying to run a distributed transaction on two Derby instances using
> a my application program as the transaction manager. I'm stuck on how to
> create a global transaction id that I can pass to the start method of
> the XAResource object that I get from the XAConnection object (an
> instance of NetXAResource).
>
> I've searched for examples but both that I found used external classes
> to create the Xid. Looking at the Derby code the most likely candidate
> seemed to be org.apache.derby.client.ClientXid but I have no idea what
> to pass to the constructor. The best example I found on an IBM site used
> com.ibm.db2.jcc.DB2Xid. I've not found any Derby-specific examples of
> how to create an Xid.
>
> Any pointers much appreciated.
>
> Thanks
> Mick Jordan
>
>
Hi Mick,
I'm a complete novice, but by coincidence I've been staring at the
Derby functional test
org.apache.derbyTesting.functionTests.tests.jdbcapi.checkDataSource.java.
In this test, the author(s) have made an internal class which
implements javax.transaction.xa.Xid that creates the Xid:
-------------------------
class cdsXid implements Xid, Serializable
{
private static final long serialVersionUID = 64467338100036L;
private final int format_id;
private byte[] global_id;
private byte[] branch_id;
cdsXid(int xid, byte b1, byte b2)
{
format_id = xid;
global_id = new byte[Xid.MAXGTRIDSIZE];
branch_id = new byte[Xid.MAXBQUALSIZE];
for (int i = 0; i < global_id.length; i++) {
global_id[i] = b1;
}
for (int i = 0; i < branch_id.length; i++) {
branch_id[i] = b2;
}
}
/**
* Obtain the format id part of the Xid.
* <p>
*
* @return Format identifier. O means the OSI CCR format.
**/
public int getFormatId()
{
return(format_id);
}
/**
* Obtain the global transaction identifier part of XID as an array of
* bytes.
* <p>
*
* @return A byte array containing the global transaction identifier.
**/
public byte[] getGlobalTransactionId()
{
return(global_id);
}
/**
* Obtain the transaction branch qualifier part of the Xid in a byte array.
* <p>
*
* @return A byte array containing the branch qualifier of the transaction.
**/
public byte[] getBranchQualifier()
{
return(branch_id);
}
}
----------------------------
A new Xid is then obtained as follows:
Xid xid = new cdsXid(1, (byte) 35, (byte) 47);
or
Xid xid = new cdsXid(1, (byte) 93, (byte) 103);
HTH
Myrna