From: Kevin Grittner <Kevin.Grittner@wicourts.gov>
To: taktos <taktos@gmail.com>
To: Oliver Jowett <oliver@opencloud.com>
Cc: pgsql-jdbc@postgresql.org
Cc: Kevin Grittner <Kevin.Grittner@wicourts.gov>
Subject: Re: commit and rollback don't throw exceptions when they should
Date: Wed, 04 Nov 2009 16:40:17 -0600
Message-ID: <4AF1AE71020000250002C2C3@gw.wicourts.gov> (raw)
In-Reply-To: <4AE00316.8030107@gmail.com>
References: <4ADDCCE1020000250002BBEA@gw.wicourts.gov>
<4ADF0210.4010100@opencloud.com>
<4ADED72A020000250002BC40@gw.wicourts.gov>
<4ADF85C8.6040408@opencloud.com>
<4AE00316.8030107@gmail.com>
taktos <taktos@gmail.com> wrote:
> Drivers other than PosrgreSQL throws exception as I had expected,
> but PostgreSQL didn't throw exception.
Having received no feedback on the preliminary patch I previously
posted, I'll suggest this (fairly minimal) patch. I didn't attempt to
deal with the distributed transaction issue, since it seemed pretty
messy and I wasn't sure the fix was worth the mess it would make. As
far as I can see, it should fix the OP's problem, although it would be
nice to get a confirmation of that.
This patch is basically the same as the previous one, except that I've
updated the javadocs to match the new behavior.
If there are any issues with this, I can have another go at it.
-Kevin
Attachments:commit-rollback-exceptions-1.patch (text/plain, 3.7K) download
Index: org/postgresql/jdbc2/AbstractJdbc2Connection.java
===================================================================
RCS file: /cvsroot/jdbc/pgjdbc/org/postgresql/jdbc2/AbstractJdbc2Connection.java,v
retrieving revision 1.52
diff -c -r1.52 AbstractJdbc2Connection.java
*** org/postgresql/jdbc2/AbstractJdbc2Connection.java 1 Jul 2009 05:00:40 -0000 1.52
--- org/postgresql/jdbc2/AbstractJdbc2Connection.java 4 Nov 2009 22:28:59 -0000
***************
*** 676,691 ****
* The method commit() makes all changes made since the previous
* commit/rollback permanent and releases any database locks currently
* held by the Connection. This method should only be used when
! * auto-commit has been disabled. (If autoCommit == true, then we
! * just return anyhow)
*
! * @exception SQLException if a database access error occurs
* @see setAutoCommit
*/
public void commit() throws SQLException
{
if (autoCommit)
! return ;
if (protoConnection.getTransactionState() != ProtocolConnection.TRANSACTION_IDLE)
executeTransactionCommand(commitQuery);
--- 676,697 ----
* The method commit() makes all changes made since the previous
* commit/rollback permanent and releases any database locks currently
* held by the Connection. This method should only be used when
! * auto-commit has been disabled.
*
! * @exception SQLException if a database access error occurs,
! * this method is called on a closed connection or
! * this Connection object is in auto-commit mode
* @see setAutoCommit
*/
public void commit() throws SQLException
{
+ if (isClosed())+ throw new PSQLException(GT.tr("Cannot commit when connection is closed."),+ PSQLState.CONNECTION_FAILURE);+
if (autoCommit)
! throw new PSQLException(GT.tr("Cannot commit when autoCommit is enabled."),
! PSQLState.NO_ACTIVE_SQL_TRANSACTION);
if (protoConnection.getTransactionState() != ProtocolConnection.TRANSACTION_IDLE)
executeTransactionCommand(commitQuery);
***************
*** 696,708 ****
* commit/rollback and releases any database locks currently held by
* the Connection.
*
! * @exception SQLException if a database access error occurs
* @see commit
*/
public void rollback() throws SQLException
{
if (autoCommit)
! return ;
if (protoConnection.getTransactionState() != ProtocolConnection.TRANSACTION_IDLE)
executeTransactionCommand(rollbackQuery);
--- 702,721 ----
* commit/rollback and releases any database locks currently held by
* the Connection.
*
! * @exception SQLException if a database access error occurs,
! * this method is called on a closed connection or
! * this Connection object is in auto-commit mode
* @see commit
*/
public void rollback() throws SQLException
{
+ if (isClosed())+ throw new PSQLException(GT.tr("Cannot rollback when connection is closed."),+ PSQLState.CONNECTION_FAILURE);+
if (autoCommit)
! throw new PSQLException(GT.tr("Cannot rollback when autoCommit is enabled."),
! PSQLState.NO_ACTIVE_SQL_TRANSACTION);
if (protoConnection.getTransactionState() != ProtocolConnection.TRANSACTION_IDLE)
executeTransactionCommand(rollbackQuery);
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: Kevin.Grittner@wicourts.gov, taktos@gmail.com, oliver@opencloud.com
Subject: Re: commit and rollback don't throw exceptions when they should
In-Reply-To: <4AF1AE71020000250002C2C3@gw.wicourts.gov>
References: <4ADDCCE1020000250002BBEA@gw.wicourts.gov> <4ADF0210.4010100@opencloud.com> <4ADED72A020000250002BC40@gw.wicourts.gov> <4ADF85C8.6040408@opencloud.com> <4AE00316.8030107@gmail.com> <4AF1AE71020000250002C2C3@gw.wicourts.gov>
* 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