You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-dev@db.apache.org by Julius Stroffek <Ju...@Sun.COM> on 2007/05/11 11:35:11 UTC

DRDA help needed

I am working on implementing a XA transaction timeout for client driver 
in DERBY-2509
https://issues.apache.org/jira/browse/DERBY-2509
which should behave the same way as described in comments of DERBY-2508.

XAResource interface has functions set/getTransactionTimeout which 
provides the only interface to the application to manage the timeout 
value. DRDA protocol does not have terms which might be used for this 
but timeout for xa transaction might be present in a SYNCCTL term when 
starting a new unit of work. It's ok to remember the timeout in the 
client driver and send it to server every time XAResource.start function 
is called with TMNOFLAGS.

However, the javadoc on XAResource.getTransactionTimeout
http://java.sun.com/javase/6/docs/api/javax/transaction/xa/XAResource.html#getTransactionTimeout()
requires that when the function is called before any call to 
setTransactionTimeout it should return the default value of the resource 
manager. I have not found any DRDA term which can be directly used to 
obtain the default value from the server. Does anybody has an idea how 
this could be done?

Thanks,

Julo


Re: DRDA help needed

Posted by Julius Stroffek <Ju...@Sun.COM>.
Thanks Bryan,

I tried using the IBM JCC driver but it seems that the feature is not 
implemented there. I used setDriverType method of DB2XADataSource to 
specify the driver type 4 which only seems to work to connect to derby. 
Is it possible that I am doing something wrong?

I used the following code to query the functionality 
(setTransactionTimeout should return false if the feature is not supported):
        try {
            XAConnection xaConn = 
createXAConnection("jdbc:derby:net://localhost:1527/TestDB;create=true", 
"julo", "julo");
            XAResource xaRes = xaConn.getXAResource();

            if (xaRes.setTransactionTimeout(10)) {
                System.out.println("Supports XA transaction timeout.");
            } else {
                System.out.println("Does not support XA transaction 
timeout.");
            }
            System.out.println("XA transaction timeout: " + 
xaRes.getTransactionTimeout());
        } catch (Throwable t) {
            t.printStackTrace();
        }

and the following code to create an XAConnection object:

    public static XAConnection createXAConnection(String dbUrl, String 
username, String password) throws Exception {
        Class dataSourceClass = 
Class.forName("com.ibm.db2.jcc.DB2XADataSource");
        XADataSource dataSourceInstance = (XADataSource) 
dataSourceClass.newInstance();
        Class [] stringParam = new Class [] {String.class};
       
        dbUrl = dbUrl.substring("jdbc:derby:net://".length(), 
dbUrl.length());
        String [] array1 = dbUrl.split("/");
        String [] array2 = array1[0].split(":");
        String serverName = array2[0];
        int portNumber = Integer.valueOf(array2[1]).intValue();
        String databaseOrSchemaName = array1[1];
       
        dataSourceClass.getMethod("setServerName", 
stringParam).invoke(dataSourceInstance, new Object [] {serverName});
        dataSourceClass.getMethod("setPortNumber", new Class [] 
{int.class}).invoke(dataSourceInstance, new Object [] {portNumber});
        dataSourceClass.getMethod("setDatabaseName", 
stringParam).invoke(dataSourceInstance, new Object [] 
{databaseOrSchemaName});
        dataSourceClass.getMethod("setDriverType", new Class [] 
{int.class}).invoke(dataSourceInstance, new Object [] {4});
        if (username.length() > 0)
            dataSourceClass.getMethod("setUser", 
stringParam).invoke(dataSourceInstance, new Object [] {username});
        if (password.length() > 0)
            dataSourceClass.getMethod("setPassword", 
stringParam).invoke(dataSourceInstance, new Object [] {password});
        return dataSourceInstance.getXAConnection();
    }

Thanks,

Julo

Bryan Pendleton wrote:
>> requires that when the function is called before any call to 
>> setTransactionTimeout it should return the default value of the 
>> resource manager. I have not found any DRDA term which can be 
>> directly used to obtain the default value from the server. 
>
> Is this functionality implemented in the IBM JCC driver?
>
> If so, you could run a test program using the JCC driver against Derby,
> and instrument your Derby server to see what DRDA traffic the JCC
> driver sends to Derby.
>
> thanks,
>
> bryan
>

Re: DRDA help needed

Posted by Bryan Pendleton <bp...@amberpoint.com>.
> requires that when the function is called before any call to 
> setTransactionTimeout it should return the default value of the resource 
> manager. I have not found any DRDA term which can be directly used to 
> obtain the default value from the server. 

Is this functionality implemented in the IBM JCC driver?

If so, you could run a test program using the JCC driver against Derby,
and instrument your Derby server to see what DRDA traffic the JCC
driver sends to Derby.

thanks,

bryan