From: John Napiorkowski Date: Thu, 19 Jun 2008 14:45:42 +0000 (+0000) Subject: removed ->reload_row from storage, changed this to a method based on the actual row... X-Git-Tag: v0.08240~402^2~16 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=b9b4e52f923e01eb496eb04a70e82824ecbe9dbe;p=dbsrgits%2FDBIx-Class.git 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 --- diff --git a/lib/DBIx/Class/PK.pm b/lib/DBIx/Class/PK.pm index e281dd4..f664cc6 100644 --- a/lib/DBIx/Class/PK.pm +++ b/lib/DBIx/Class/PK.pm @@ -39,21 +39,21 @@ sub discard_changes { 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 diff --git a/lib/DBIx/Class/Row.pm b/lib/DBIx/Class/Row.pm index ffe0359..eab11d9 100644 --- a/lib/DBIx/Class/Row.pm +++ b/lib/DBIx/Class/Row.pm @@ -785,6 +785,21 @@ sub register_column { $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 diff --git a/lib/DBIx/Class/Storage.pm b/lib/DBIx/Class/Storage.pm index e57a48b..dd61ba0 100644 --- a/lib/DBIx/Class/Storage.pm +++ b/lib/DBIx/Class/Storage.pm @@ -438,15 +438,6 @@ only. sub select_single { die "Virtual method!" } -=head2 reload_row ($row) - -given a L 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 diff --git a/lib/DBIx/Class/Storage/DBI.pm b/lib/DBIx/Class/Storage/DBI.pm index d9063c7..d1c1ac7 100644 --- a/lib/DBIx/Class/Storage/DBI.pm +++ b/lib/DBIx/Class/Storage/DBI.pm @@ -1296,16 +1296,6 @@ sub select_single { 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 diff --git a/lib/DBIx/Class/Storage/DBI/Replicated.pm b/lib/DBIx/Class/Storage/DBI/Replicated.pm index bb6517a..0987ee7 100644 --- a/lib/DBIx/Class/Storage/DBI/Replicated.pm +++ b/lib/DBIx/Class/Storage/DBI/Replicated.pm @@ -481,20 +481,6 @@ around 'txn_do' => sub { $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.