[Bast-commits] r4506 - in DBIx-Class/0.08/branches/replication_dedux/lib/DBIx/Class: . Storage Storage/DBI

jnapiorkowski at dev.catalyst.perl.org jnapiorkowski at dev.catalyst.perl.org
Thu Jun 19 15:45:42 BST 2008


Author: jnapiorkowski
Date: 2008-06-19 15:45:42 +0100 (Thu, 19 Jun 2008)
New Revision: 4506

Modified:
   DBIx-Class/0.08/branches/replication_dedux/lib/DBIx/Class/PK.pm
   DBIx-Class/0.08/branches/replication_dedux/lib/DBIx/Class/Row.pm
   DBIx-Class/0.08/branches/replication_dedux/lib/DBIx/Class/Storage.pm
   DBIx-Class/0.08/branches/replication_dedux/lib/DBIx/Class/Storage/DBI.pm
   DBIx-Class/0.08/branches/replication_dedux/lib/DBIx/Class/Storage/DBI/Replicated.pm
Log:
removed ->reload_row from storage, changed this to a method based on the actual row object.  discard_changes is still semantically ambiguous but this solution is better

Modified: DBIx-Class/0.08/branches/replication_dedux/lib/DBIx/Class/PK.pm
===================================================================
--- DBIx-Class/0.08/branches/replication_dedux/lib/DBIx/Class/PK.pm	2008-06-19 13:06:57 UTC (rev 4505)
+++ DBIx-Class/0.08/branches/replication_dedux/lib/DBIx/Class/PK.pm	2008-06-19 14:45:42 UTC (rev 4506)
@@ -39,21 +39,21 @@
   my ($self) = @_;
   delete $self->{_dirty_columns};
   return unless $self->in_storage; # Don't reload if we aren't real!
-
-  my $reload = $self->result_source->schema->storage->reload_row($self);
   
-  unless ($reload) { # If we got deleted in the mean-time
+  if( my $current_storage = $self->get_current_storage) {
+  	
+    # Set $self to the current.
+  	%$self = %$current_storage;
+  	
+    # Avoid a possible infinite loop with
+    # sub DESTROY { $_[0]->discard_changes }
+    bless $current_storage, 'Do::Not::Exist';
+    
+    return $self;  	
+  } else {
     $self->in_storage(0);
-    return $self;
+    return $self;  	
   }
-
-  %$self = %$reload;
-  
-  # Avoid a possible infinite loop with
-  # sub DESTROY { $_[0]->discard_changes }
-  bless $reload, 'Do::Not::Exist';
-
-  return $self;
 }
 
 =head2 id

Modified: DBIx-Class/0.08/branches/replication_dedux/lib/DBIx/Class/Row.pm
===================================================================
--- DBIx-Class/0.08/branches/replication_dedux/lib/DBIx/Class/Row.pm	2008-06-19 13:06:57 UTC (rev 4505)
+++ DBIx-Class/0.08/branches/replication_dedux/lib/DBIx/Class/Row.pm	2008-06-19 14:45:42 UTC (rev 4506)
@@ -785,7 +785,22 @@
   $class->mk_group_accessors('column' => $acc);
 }
 
+=head2 get_current_storage
 
+Returns a new Row which is whatever the Storage has for the currently created
+Row object.  You ca use this to see if the storage has become inconsistent with
+whatever your Row object is.
+
+=cut
+
+sub get_current_storage {
+    my $self = shift @_;
+    my @primary_columns = map { $self->$_ } $self->primary_columns;
+    return $self->result_source->schema->txn_do(sub {
+      return $self->result_source->resultset->find(@primary_columns); 	
+    });
+}
+
 =head2 throw_exception
 
 See Schema's throw_exception.

Modified: DBIx-Class/0.08/branches/replication_dedux/lib/DBIx/Class/Storage/DBI/Replicated.pm
===================================================================
--- DBIx-Class/0.08/branches/replication_dedux/lib/DBIx/Class/Storage/DBI/Replicated.pm	2008-06-19 13:06:57 UTC (rev 4505)
+++ DBIx-Class/0.08/branches/replication_dedux/lib/DBIx/Class/Storage/DBI/Replicated.pm	2008-06-19 14:45:42 UTC (rev 4506)
@@ -481,20 +481,6 @@
   $self->execute_reliably(sub {$self->$txn_do($coderef, @args)}); 
 };
 
-=head2 reload_row ($row)
-
-Overload to the reload_row method so that the reloading is always directed to
-the master storage.
-
-=cut
-
-around 'reload_row' => sub {
-  my ($reload_row, $self, $row) = @_;
-  return $self->execute_reliably(sub {
-    return $self->$reload_row(shift);
-  }, $row);
-};
-
 =head2 connected
 
 Check that the master and at least one of the replicants is connected.

Modified: DBIx-Class/0.08/branches/replication_dedux/lib/DBIx/Class/Storage/DBI.pm
===================================================================
--- DBIx-Class/0.08/branches/replication_dedux/lib/DBIx/Class/Storage/DBI.pm	2008-06-19 13:06:57 UTC (rev 4505)
+++ DBIx-Class/0.08/branches/replication_dedux/lib/DBIx/Class/Storage/DBI.pm	2008-06-19 14:45:42 UTC (rev 4506)
@@ -1296,16 +1296,6 @@
   return @row;
 }
 
-sub reload_row {
-	my ($self, $row) = @_;
-	
-    my $reload = $row->result_source->resultset->find(
-        map { $row->$_ } $row->primary_columns
-    );
-    
-    return $reload;
-}
-
 =head2 sth
 
 =over 4

Modified: DBIx-Class/0.08/branches/replication_dedux/lib/DBIx/Class/Storage.pm
===================================================================
--- DBIx-Class/0.08/branches/replication_dedux/lib/DBIx/Class/Storage.pm	2008-06-19 13:06:57 UTC (rev 4505)
+++ DBIx-Class/0.08/branches/replication_dedux/lib/DBIx/Class/Storage.pm	2008-06-19 14:45:42 UTC (rev 4506)
@@ -438,15 +438,6 @@
 
 sub select_single { die "Virtual method!" }
 
-=head2 reload_row ($row)
-
-given a L<DBIx::Class::Row> object, loads and returns the matching version from
-storage.  Does not effect the existing row object.
-
-=cut
-
-sub reload_row { die "Virtual method!" }
-
 =head2 columns_info_for
 
 Returns metadata for the given source's columns.  This




More information about the Bast-commits mailing list