cvsuser     03/06/19 10:18:05

  Modified:    App-Repository/lib/App Repository.pm
               App-Repository/lib/App/Repository MySQL.pm MySQL2.pm
  Log:
  added table locking support (concurrency mgmt) at the generic Repository level 
(using ResourceLocker)
  
  Revision  Changes    Path
  1.5       +41 -1     p5ee/App-Repository/lib/App/Repository.pm
  
  Index: Repository.pm
  ===================================================================
  RCS file: /cvs/public/p5ee/App-Repository/lib/App/Repository.pm,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -w -r1.4 -r1.5
  --- Repository.pm     19 May 2003 17:41:15 -0000      1.4
  +++ Repository.pm     19 Jun 2003 17:18:04 -0000      1.5
  @@ -1,6 +1,6 @@
   
   #############################################################################
  -## $Id: Repository.pm,v 1.4 2003/05/19 17:41:15 spadkins Exp $
  +## $Id: Repository.pm,v 1.5 2003/06/19 17:18:04 spadkins Exp $
   #############################################################################
   
   package App::Repository;
  @@ -1076,6 +1076,46 @@
       };
       bless $object, $class;
       return $object;
  +}
  +
  +#############################################################################
  +# METHODS
  +#############################################################################
  +
  +=head1 Methods: Locking (Concurrency Management)
  +
  +=cut
  +
  +# this is a write lock for the table
  +sub _lock_table {
  +    &App::sub_entry if ($App::trace_subs);
  +    my ($self, $table) = @_;
  +    if (! $self->{locked}) {   # I have locked it myself, so I don't need to again
  +        my ($name, $dbname, $context, $rlock);
  +        $name = $self->{name};
  +        $dbname = $self->{dbname};
  +        $context = $self->{context};
  +        $rlock = $context->resource_locker($name);  # get the one that corresponds 
to this repository
  +        $rlock->lock("db.$dbname.$table");
  +        $self->{locked} = 1;
  +    }
  +    &App::sub_exit() if ($App::trace_subs);
  +}
  +
  +# unlocks the write lock for the table
  +sub _unlock_table {
  +    &App::sub_entry if ($App::trace_subs);
  +    my ($self, $table) = @_;
  +    if ($self->{locked}) {
  +        my ($name, $dbname, $context, $rlock);
  +        $name = $self->{name};
  +        $dbname = $self->{dbname};
  +        $context = $self->{context};
  +        $rlock = $context->resource_locker($name);  # get the one that corresponds 
to this repository
  +        $rlock->unlock("db.$dbname.$table");
  +        delete $self->{locked};
  +    }
  +    &App::sub_exit() if ($App::trace_subs);
   }
   
   #############################################################################
  
  
  
  1.6       +2 -34     p5ee/App-Repository/lib/App/Repository/MySQL.pm
  
  Index: MySQL.pm
  ===================================================================
  RCS file: /cvs/public/p5ee/App-Repository/lib/App/Repository/MySQL.pm,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -w -r1.5 -r1.6
  --- MySQL.pm  13 Jun 2003 17:56:53 -0000      1.5
  +++ MySQL.pm  19 Jun 2003 17:18:05 -0000      1.6
  @@ -1,12 +1,12 @@
   
   ######################################################################
  -## File: $Id: MySQL.pm,v 1.5 2003/06/13 17:56:53 spadkins Exp $
  +## File: $Id: MySQL.pm,v 1.6 2003/06/19 17:18:05 spadkins Exp $
   ######################################################################
   
   use App::Repository::DBI;
   
   package App::Repository::MySQL;
  -$VERSION = do { my @r=(q$Revision: 1.5 $=~/\d+/g); sprintf "%d."."%02d"x$#r,@r};
  +$VERSION = do { my @r=(q$Revision: 1.6 $=~/\d+/g); sprintf "%d."."%02d"x$#r,@r};
   
   @ISA = ( "App::Repository::DBI" );
   
  @@ -74,38 +74,6 @@
       }
       &App::sub_exit($suffix) if ($App::trace_subs);
       return($suffix);
  -}
  -
  -# this is a write lock for the table
  -sub _store_begin {
  -    &App::sub_entry if ($App::trace_subs);
  -    my ($self, $table) = @_;
  -    if (! $self->{locked}) {   # I have locked it myself, so I don't need to again
  -        my ($name, $dbname, $context, $rlock);
  -        $name = $self->{name};
  -        $dbname = $self->{dbname};
  -        $context = $self->{context};
  -        $rlock = $context->resource_locker($name);  # get the one that corresponds 
to this repository
  -        $rlock->lock("db.$dbname.$table");
  -        $self->{locked} = 1;
  -    }
  -    &App::sub_exit() if ($App::trace_subs);
  -}
  -
  -# this is an unlock for the table
  -sub _store_end {
  -    &App::sub_entry if ($App::trace_subs);
  -    my ($self, $table) = @_;
  -    if ($self->{locked}) {
  -        my ($name, $dbname, $context, $rlock);
  -        $name = $self->{name};
  -        $dbname = $self->{dbname};
  -        $context = $self->{context};
  -        $rlock = $context->resource_locker($name);  # get the one that corresponds 
to this repository
  -        $rlock->unlock("db.$dbname.$table");
  -        delete $self->{locked};
  -    }
  -    &App::sub_exit() if ($App::trace_subs);
   }
   
   1;
  
  
  
  1.5       +6 -6      p5ee/App-Repository/lib/App/Repository/MySQL2.pm
  
  Index: MySQL2.pm
  ===================================================================
  RCS file: /cvs/public/p5ee/App-Repository/lib/App/Repository/MySQL2.pm,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -w -r1.4 -r1.5
  --- MySQL2.pm 13 Jun 2003 17:56:53 -0000      1.4
  +++ MySQL2.pm 19 Jun 2003 17:18:05 -0000      1.5
  @@ -1,12 +1,12 @@
   
   ######################################################################
  -## File: $Id: MySQL2.pm,v 1.4 2003/06/13 17:56:53 spadkins Exp $
  +## File: $Id: MySQL2.pm,v 1.5 2003/06/19 17:18:05 spadkins Exp $
   ######################################################################
   
   use App::Repository::MySQL;
   
   package App::Repository::MySQL2;
  -$VERSION = do { my @r=(q$Revision: 1.4 $=~/\d+/g); sprintf "%d."."%02d"x$#r,@r};
  +$VERSION = do { my @r=(q$Revision: 1.5 $=~/\d+/g); sprintf "%d."."%02d"x$#r,@r};
   
   @ISA = ( "App::Repository::MySQL" );
   
  @@ -24,7 +24,7 @@
       $self->{error} = "";
       $context = $self->{context};
   
  -    # $self->_store_begin($table);
  +    $self->_lock_table($table);
       $tabledef = $self->{table}{$table};
       $table_ih = $tabledef->{table_ih} || "";
       $column_change_dttm = $tabledef->{column_change_dttm} || "";
  @@ -252,7 +252,7 @@
           }
       }
   
  -    # $self->_store_end($table);
  +    $self->_unlock_table($table);
       $self->{numrows} = $nrows;
       &App::sub_exit($nrows) if ($App::trace_subs);
       return($nrows);
  @@ -281,7 +281,7 @@
       $self->{error} = "";
       $context = $self->{context};
   
  -    # $self->_store_begin($table);
  +    $self->_lock_table($table);
       $tabledef = $self->{table}{$table};
       $table_ih = $tabledef->{table_ih} || "";
       $column_change_dttm = $tabledef->{column_change_dttm} || "";
  @@ -458,7 +458,7 @@
           }
       }
   
  -    # $self->_store_end($table);
  +    $self->_unlock_table($table);
       $self->{numrows} = $nrows;
       &App::sub_exit() if ($App::trace_subs);
       return($nrows);
  
  
  

Reply via email to