Re: call XAConnection.commit() when autoCommit=true throw InvocationTargetException not SQLException.

Lists: pgsql-jdbc
From: Yaocl <chunlinyao(at)gmail(dot)com>
To: pgsql-jdbc(at)postgresql(dot)org
Subject: call XAConnection.commit() when autoCommit=true throw InvocationTargetException not SQLException.
Date: 2010-10-14 10:24:08
Message-ID: AANLkTimTFWMnXoQaY+qVUSPkv-Y=rzCF=dvD_JiumxRA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-jdbc

Hi

According to the javadoc call commit() on autoCommit=true connection
will throw a SQLException. But a PGXAConnection
thrown a InvocationTargetException.

Because the following code, It use reflection internally.
method.invoke() will throw InvocationTargetException when underlying
method throw a Exception.

 /*
     * A java.sql.Connection proxy class to forbid calls to transaction
     * control methods while the connection is used for an XA transaction.
     */
    private class ConnectionHandler implements InvocationHandler
    {
private Connection con;
public ConnectionHandler(Connection con)
{
            this.con = con;
        }
        public Object invoke(Object proxy, Method method, Object[] args)
        throws Throwable
        {
   if (state != STATE_IDLE)
            {
                String methodName = method.getName();
                if (methodName.equals("commit") ||
                    methodName.equals("rollback") ||
                    methodName.equals("setSavePoint") ||
                    (methodName.equals("setAutoCommit") && ((Boolean)
args[0]).booleanValue()))
                {
   throw new PSQLException(GT.tr("Transaction control methods
setAutoCommit(true), commit, rollback and setSavePoint not allowed
while an XA transaction is active."),
   PSQLState.OBJECT_NOT_IN_STATE);
                }
            }
   return method.invoke(con, args);
        }
    }

Regards,
Yao


From: Yaocl <chunlinyao(at)gmail(dot)com>
To: pgsql-jdbc(at)postgresql(dot)org
Subject: Re: call XAConnection.commit() when autoCommit=true throw InvocationTargetException not SQLException.
Date: 2010-10-14 12:18:36
Message-ID: AANLkTinV+QX5drYdt-22LE7Mp9w5yET4qSio+im+qdnJ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-jdbc

Hi

This is a quick patch to current head.

Regards,
Yao

On Thu, Oct 14, 2010 at 6:24 PM, Yaocl <chunlinyao(at)gmail(dot)com> wrote:
> Hi
>
> According to the javadoc call commit() on autoCommit=true connection
> will throw a SQLException. But a PGXAConnection
> thrown a InvocationTargetException.
>
> Because the following code, It use reflection internally.
> method.invoke() will throw InvocationTargetException when underlying
> method throw a Exception.
>
>  /*
>      * A java.sql.Connection proxy class to forbid calls to transaction
>      * control methods while the connection is used for an XA transaction.
>      */
>     private class ConnectionHandler implements InvocationHandler
>     {
> private Connection con;
> public ConnectionHandler(Connection con)
> {
>             this.con = con;
>         }
>         public Object invoke(Object proxy, Method method, Object[] args)
>         throws Throwable
>         {
>    if (state != STATE_IDLE)
>             {
>                 String methodName = method.getName();
>                 if (methodName.equals("commit") ||
>                     methodName.equals("rollback") ||
>                     methodName.equals("setSavePoint") ||
>                     (methodName.equals("setAutoCommit") && ((Boolean)
> args[0]).booleanValue()))
>                 {
>    throw new PSQLException(GT.tr("Transaction control methods
> setAutoCommit(true), commit, rollback and setSavePoint not allowed
> while an XA transaction is active."),
>    PSQLState.OBJECT_NOT_IN_STATE);
>                 }
>             }
>    return method.invoke(con, args);
>         }
>     }
>
> Regards,
> Yao
>

Attachment Content-Type Size
xaconnection.patch application/octet-stream 786 bytes

From: Kris Jurka <books(at)ejurka(dot)com>
To: Yaocl <chunlinyao(at)gmail(dot)com>
Cc: pgsql-jdbc(at)postgresql(dot)org
Subject: Re: Re: call XAConnection.commit() when autoCommit=true throw InvocationTargetException not SQLException.
Date: 2010-10-16 01:08:44
Message-ID: alpine.BSO.2.00.1010152108240.6907@leary.csoft.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-jdbc


Thanks, I've applied this patch to CVS.

Kris Jurka

On Thu, 14 Oct 2010, Yaocl wrote:

> Hi
>
> This is a quick patch to current head.
>
> Regards,
> Yao
>
> On Thu, Oct 14, 2010 at 6:24 PM, Yaocl <chunlinyao(at)gmail(dot)com> wrote:
>> Hi
>>
>> According to the javadoc call commit() on autoCommit=true connection
>> will throw a SQLException. But a PGXAConnection
>> thrown a InvocationTargetException.
>>
>> Because the following code, It use reflection internally.
>> method.invoke() will throw InvocationTargetException when underlying
>> method throw a Exception.
>>
>>  /*
>>      * A java.sql.Connection proxy class to forbid calls to transaction
>>      * control methods while the connection is used for an XA transaction.
>>      */
>>     private class ConnectionHandler implements InvocationHandler
>>     {
>> private Connection con;
>> public ConnectionHandler(Connection con)
>> {
>>             this.con = con;
>>         }
>>         public Object invoke(Object proxy, Method method, Object[] args)
>>         throws Throwable
>>         {
>>    if (state != STATE_IDLE)
>>             {
>>                 String methodName = method.getName();
>>                 if (methodName.equals("commit") ||
>>                     methodName.equals("rollback") ||
>>                     methodName.equals("setSavePoint") ||
>>                     (methodName.equals("setAutoCommit") && ((Boolean)
>> args[0]).booleanValue()))
>>                 {
>>    throw new PSQLException(GT.tr("Transaction control methods
>> setAutoCommit(true), commit, rollback and setSavePoint not allowed
>> while an XA transaction is active."),
>>    PSQLState.OBJECT_NOT_IN_STATE);
>>                 }
>>             }
>>    return method.invoke(con, args);
>>         }
>>     }
>>
>> Regards,
>> Yao
>>
>