--- nfo/perl/libs/Tangram/Storage.pm 2002/12/16 05:08:22 1.3 +++ nfo/perl/libs/Tangram/Storage.pm 2003/04/24 00:21:27 1.9 @@ -247,6 +247,33 @@ return sprintf "%d%0$self->{cid_size}d", $id, $class_id; } + +# create global unique identifers using Data::UUID +sub make_guid + { + my $self = shift; + + my $guid; + + # try to use Data::UUID first ... + eval("use Data::UUID;"); + if (!$@) { + my $ug = Data::UUID->new(); + $guid = $ug->create_str(); + + # ... if this fails, try to fallback to Data::UUID::PurePerl instead ... + } else { + eval("use Data::UUID::PurePerl;"); + if (!$@) { + $guid = Data::UUID::PurePerl::generate_id(); + } else { + croak "couldn't create globally unique identifier"; + } + } + + return $guid; + } + sub make_1st_id_in_tx { my ($self) = @_; @@ -455,6 +482,9 @@ return $self->id($obj) if $self->id($obj); + # insert global unique identifier in object to persist across re-deploys + $obj->{guid} = $self->make_guid(); + $saving->insert($obj); my $class_name = ref $obj; @@ -484,7 +514,7 @@ if ($Tangram::TRACE) { printf $Tangram::TRACE "executing %s with (%s)\n", - $cache->{INSERTS}[$i], + $cache->{INSERTS}[$i], join(', ', map { $_ || 'NULL' } @state[ @{ $fields->[$i] } ] ) } @@ -675,6 +705,7 @@ my $row = _fetch_object_state($self, $id, $class); my $obj = $self->read_object($id, $class->{name}, $row); + return undef unless defined $row; # ??? $self->{-residue} = \@row; @@ -692,6 +723,7 @@ my $class = $self->{schema}->classdef( $self->{id2class}{ int(substr($id, -$self->{cid_size})) } ); my $row = _fetch_object_state($self, $id, $class); + return undef unless defined $row; _row_to_object($self, $obj, $id, $class->{name}, $row); return $obj; @@ -763,6 +795,11 @@ $sth->execute($self->{export_id}->($id)); my $state = [ $sth->fetchrow_array() ]; + croak "no object with id $id" unless (@{$state}); + unless (@$state) { + return undef unless $sth->err; + croak "error during load of object id=$id: $sth->err"; + } $sth->finish(); return $state;