cvsuser     03/06/13 10:56:53

  Modified:    App-Repository/lib/App/Repository MySQL.pm MySQL2.pm
  Log:
  add write locking
  
  Revision  Changes    Path
  1.5       +17 -11    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.4
  retrieving revision 1.5
  diff -u -w -r1.4 -r1.5
  --- MySQL.pm  12 Jun 2003 18:46:04 -0000      1.4
  +++ MySQL.pm  13 Jun 2003 17:56:53 -0000      1.5
  @@ -1,12 +1,12 @@
   
   ######################################################################
  -## File: $Id: MySQL.pm,v 1.4 2003/06/12 18:46:04 spadkins Exp $
  +## File: $Id: MySQL.pm,v 1.5 2003/06/13 17:56:53 spadkins Exp $
   ######################################################################
   
   use App::Repository::DBI;
   
   package App::Repository::MySQL;
  -$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::DBI" );
   
  @@ -76,28 +76,34 @@
       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}) {
  -        my ($lock_stmt, $alias, $table_ih);
  -        $lock_stmt = "lock tables $table write";
  -        $alias = $self->{table}{$table}{alias};
  -        $lock_stmt .= ", $table $alias write" if ($alias);
  -        $table_ih = $self->{table}{$table}{table_ih};
  -        $lock_stmt .= ", $table_ih write" if ($table_ih);
  -        $self->{dbh}->do($lock_stmt);
  +    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};
  -        $self->{dbh}->do("unlock tables");
       }
       &App::sub_exit() if ($App::trace_subs);
   }
  
  
  
  1.4       +35 -2     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.3
  retrieving revision 1.4
  diff -u -w -r1.3 -r1.4
  --- MySQL2.pm 13 Jun 2003 17:28:59 -0000      1.3
  +++ MySQL2.pm 13 Jun 2003 17:56:53 -0000      1.4
  @@ -1,12 +1,12 @@
   
   ######################################################################
  -## File: $Id: MySQL2.pm,v 1.3 2003/06/13 17:28:59 spadkins Exp $
  +## File: $Id: MySQL2.pm,v 1.4 2003/06/13 17:56:53 spadkins Exp $
   ######################################################################
   
   use App::Repository::MySQL;
   
   package App::Repository::MySQL2;
  -$VERSION = do { my @r=(q$Revision: 1.3 $=~/\d+/g); sprintf "%d."."%02d"x$#r,@r};
  +$VERSION = do { my @r=(q$Revision: 1.4 $=~/\d+/g); sprintf "%d."."%02d"x$#r,@r};
   
   @ISA = ( "App::Repository::MySQL" );
   
  @@ -481,6 +481,39 @@
   
       return $id;
   }
  +
  +################################################################
  +# the following routines would use native MySQL table locking
  +# which is too severe for most cases I am interested in where
  +# a dirty read is OK.  I am preserving the commented-out code
  +# here for reconsideration later.
  +################################################################
  +
  +#sub _store_begin {
  +#    &App::sub_entry if ($App::trace_subs);
  +#    my ($self, $table) = @_;
  +#    if (! $self->{locked}) {
  +#        my ($lock_stmt, $alias, $table_ih);
  +#        $lock_stmt = "lock tables $table write";
  +#        $alias = $self->{table}{$table}{alias};
  +#        $lock_stmt .= ", $table $alias write" if ($alias);
  +#        $table_ih = $self->{table}{$table}{table_ih};
  +#        $lock_stmt .= ", $table_ih write" if ($table_ih);
  +#        $self->{dbh}->do($lock_stmt);
  +#        $self->{locked} = 1;
  +#    }
  +#    &App::sub_exit() if ($App::trace_subs);
  +#}
  +
  +#sub _store_end {
  +#    &App::sub_entry if ($App::trace_subs);
  +#    my ($self, $table) = @_;
  +#    if ($self->{locked}) {
  +#        delete $self->{locked};
  +#        $self->{dbh}->do("unlock tables");
  +#    }
  +#    &App::sub_exit() if ($App::trace_subs);
  +#}
   
   1;
   
  
  
  

Reply via email to