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

Поиск
Список
Период
Сортировка
От Yaocl
Тема call XAConnection.commit() when autoCommit=true throw InvocationTargetException not SQLException.
Дата
Msg-id AANLkTimTFWMnXoQaY+qVUSPkv-Y=rzCF=dvD_JiumxRA@mail.gmail.com
обсуждение исходный текст
Ответы Re: call XAConnection.commit() when autoCommit=true throw InvocationTargetException not SQLException.  (Yaocl <chunlinyao@gmail.com>)
Список 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

В списке pgsql-jdbc по дате отправления:

Предыдущее
От: Robert Haas
Дата:
Сообщение: Re: [HACKERS] Support for JDBC setQueryTimeout, et al.
Следующее
От: Yaocl
Дата:
Сообщение: Re: call XAConnection.commit() when autoCommit=true throw InvocationTargetException not SQLException.