[Jifty-commit] r4982 - Jifty-DBI/trunk/lib/Jifty/DBI

Jifty commits jifty-commit at lists.jifty.org
Sat Feb 2 00:56:27 EST 2008


Author: audreyt
Date: Sat Feb  2 00:56:25 2008
New Revision: 4982

Modified:
   Jifty-DBI/trunk/lib/Jifty/DBI/Handle.pm

Log:
* Jifty::DBI::Handle - When "begin_transaction", "commit" and "rollback"
  did not succeed, the internal $TRANSDEPTH should be left unchanged.
  (Otherwise, a failed ->commit will cause future transactions to never
  really take place.)

Modified: Jifty-DBI/trunk/lib/Jifty/DBI/Handle.pm
==============================================================================
--- Jifty-DBI/trunk/lib/Jifty/DBI/Handle.pm	(original)
+++ Jifty-DBI/trunk/lib/Jifty/DBI/Handle.pm	Sat Feb  2 00:56:25 2008
@@ -731,12 +731,18 @@
 
 sub begin_transaction {
     my $self = shift;
-    $TRANSDEPTH++;
-    if ( $TRANSDEPTH > 1 ) {
-        return ($TRANSDEPTH);
-    } else {
-        return ( $self->dbh->begin_work );
+
+    if ( $TRANSDEPTH > 0 ) {
+        # We're inside a transaction.
+        $TRANSDEPTH++;
+        return $TRANSDEPTH;
     }
+
+    my $rv = $self->dbh->begin_work;
+    if ($rv) {
+        $TRANSDEPTH++;
+    }
+    return $rv;
 }
 
 =head2 commit
@@ -752,13 +758,18 @@
         Carp::confess(
             "Attempted to commit a transaction with none in progress");
     }
-    $TRANSDEPTH--;
 
-    if ( $TRANSDEPTH == 0 ) {
-        return ( $self->dbh->commit );
-    } else {    #we're inside a transaction
-        return ($TRANSDEPTH);
+    if ($TRANSDEPTH > 1) {
+        # We're inside a nested transaction.
+        $TRANSDEPTH--;
+        return $TRANSDEPTH;
+    }
+
+    my $rv = $self->dbh->commit;
+    if ($rv) {
+        $TRANSDEPTH--;
     }
+    return $rv;
 }
 
 =head2 rollback [FORCE]
@@ -786,13 +797,22 @@
         return ( $dbh->rollback );
     }
 
-    $TRANSDEPTH-- if ( $TRANSDEPTH >= 1 );
-    if ( $TRANSDEPTH == 0 ) {
-        return ( $dbh->rollback );
-    } else {    #we're inside a transaction
-        return ($TRANSDEPTH);
+    if ($TRANSDEPTH == 0) {
+        # We're not actually in a transaction.
+        return 1;
     }
 
+    if ($TRANSDEPTH > 1) {
+        # We're inside a nested transaction.
+        $TRANSDEPTH--;
+        return $TRANSDEPTH;
+    }
+
+    my $rv = $self->dbh->rollback;
+    if ($rv) {
+        $TRANSDEPTH--;
+    }
+    return $rv;
 }
 
 =head2 force_rollback


More information about the Jifty-commit mailing list