From db82e9fc23f50d62118d1b235218b215dac2a230 Mon Sep 17 00:00:00 2001 From: miker Date: Fri, 16 Sep 2005 22:05:17 +0000 Subject: [PATCH 1/1] throw error on "optimistic locking" failure detection git-svn-id: svn://svn.open-ils.org/ILS/trunk@1836 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- .../perlmods/OpenILS/Application/Storage/CDBI.pm | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/Open-ILS/src/perlmods/OpenILS/Application/Storage/CDBI.pm b/Open-ILS/src/perlmods/OpenILS/Application/Storage/CDBI.pm index 7ec18e0084..0155c9683f 100644 --- a/Open-ILS/src/perlmods/OpenILS/Application/Storage/CDBI.pm +++ b/Open-ILS/src/perlmods/OpenILS/Application/Storage/CDBI.pm @@ -245,6 +245,7 @@ sub create_from_fieldmapper { sub delete { my $self = shift; my $arg = shift; + my $orig = $self; my $class = ref($self) || $self; @@ -258,7 +259,13 @@ sub delete { if ($class->find_column( 'last_xact_id' )) { my $xact_id = $self->current_xact_id; - throw Error unless ($xact_id); + + throw Error ("Deleting from $class requires a transaction be established") + unless ($xact_id); + + throw Error ("The row you are attempting to delete has been changed since you read it") + unless ( $orig->last_xact_id eq $self->last_xact_id); + $self->last_xact_id( $class->current_xact_id ); $self->SUPER::update; } @@ -287,6 +294,7 @@ sub update { sub modify_from_fieldmapper { my $obj = shift; my $fm = shift; + my $orig = $obj; $log->debug("Modifying object using fieldmapper", DEBUG); @@ -322,7 +330,10 @@ sub modify_from_fieldmapper { if ($class->find_column( 'last_xact_id' ) and $obj->is_changed) { my $xact_id = $obj->current_xact_id; - throw Error unless ($xact_id); + throw Error ("Updating $class requires a transaction be established") + unless ($xact_id); + throw Error ("The row you are attempting to delete has been changed since you read it") + unless ( $orig->last_xact_id eq $self->last_xact_id); $obj->last_xact_id( $xact_id ); } else { $obj->autoupdate($au) -- 2.43.2