From: Kris Jurka <books@ejurka.com>
To: Yaocl <chunlinyao@gmail.com>
Cc: pgsql-jdbc@postgresql.org
Subject: Re: Re: call XAConnection.commit() when autoCommit=true throw InvocationTargetException not SQLException.
Date: Fri, 15 Oct 2010 21:08:44 -0400 (EDT)
Message-ID: <alpine.BSO.2.00.1010152108240.6907@leary.csoft.net> (raw)
In-Reply-To: <AANLkTinV+QX5drYdt-22LE7Mp9w5yET4qSio+im+qdnJ@mail.gmail.com>
References: <AANLkTimTFWMnXoQaY+qVUSPkv-Y=rzCF=dvD_JiumxRA@mail.gmail.com>
<AANLkTinV+QX5drYdt-22LE7Mp9w5yET4qSio+im+qdnJ@mail.gmail.com>
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@gmail.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
>>
>
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-jdbc@postgresql.org
Cc: books@ejurka.com, chunlinyao@gmail.com
Subject: Re: call XAConnection.commit() when autoCommit=true throw InvocationTargetException not SQLException.
In-Reply-To: <alpine.BSO.2.00.1010152108240.6907@leary.csoft.net>
References: <AANLkTimTFWMnXoQaY+qVUSPkv-Y=rzCF=dvD_JiumxRA@mail.gmail.com> <AANLkTinV+QX5drYdt-22LE7Mp9w5yET4qSio+im+qdnJ@mail.gmail.com> <alpine.BSO.2.00.1010152108240.6907@leary.csoft.net>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox