Skip Menu |

This queue is for tickets about the Tangram CPAN distribution.

Report information
The Basics
Id: 24581
Status: stalled
Worked: 10 min
Priority: 0/
Queue: Tangram

People
Owner: Nobody in particular
Requestors: pt [...] tchorbadjiev.com
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



Subject: Tangram::Storage.pm,Schema.pod patch - adding object propagation to make_id
Date: Fri, 26 Jan 2007 01:02:12 +0200
To: bug-Tangram [...] rt.cpan.org
From: Assen Tchorbadjiev <pt [...] tchorbadjiev.com>
Hello, its not a bug :), its a feature that I find useful. Here's the case: The current make_id() call, when inserting objects into the storage, does not propagate the $o[bject] to be inserted. Some applications (as mine does) might find it useful to have this instance when they define/generate custom ids for the backend. Regards, Assen
diff --git a/lib/Tangram/Schema.pod b/lib/Tangram/Schema.pod index 1f9319d..568d7fc 100644 --- a/lib/Tangram/Schema.pod +++ b/lib/Tangram/Schema.pod @@ -179,10 +179,11 @@ Sequences are emulated on pretend databa This is a I<closure> that is expected to return an unique ID. It is called like this: - $make_id->($class_id, $storage) + $make_id->($class_id, $storage, $object) Where C<$class_id> is the Class identifier for_the newly created object, and C<$storage> is the B<Tangram::Storage> object. +The C<$object> is the instance of the object to be inserted. =item * cid
diff --git a/lib/Tangram/Storage.pm b/lib/Tangram/Storage.pm index 842451b..45d9175 100644 --- a/lib/Tangram/Storage.pm +++ b/lib/Tangram/Storage.pm @@ -311,7 +311,7 @@ sub prepare # XXX - lots of options here not tested by test suite sub make_id { - my ($self, $class_id) = @_; + my ($self, $class_id, $o) = @_; # see if the class has its own ID generator my $cname = $self->{id2class}{$class_id}; @@ -319,7 +319,7 @@ sub make_id my $id; if ( $classdef->{make_id} ) { - $id = $classdef->{make_id}->($class_id, $self); + $id = $classdef->{make_id}->($class_id, $self, $o); print $Tangram::TRACE "Tangram: custom per-class ($cname) make ID function returned ".(pretty($id))."\n" if $Tangram::TRACE; } elsif ( $classdef->{oid_sequence} ) { eval { $id = $self->get_sequence($classdef->{oid_sequence}) }; @@ -328,7 +328,7 @@ sub make_id # maybe the entire schema has its own ID generator if ( !defined($id) and $self->{schema}{sql}{make_id} ) { - $id = $self->{schema}{sql}{make_id}->($class_id, $self); + $id = $self->{schema}{sql}{make_id}->($class_id, $self, $o); print $Tangram::TRACE "Tangram: custom schema make ID function returned " .(pretty($id))."\n" if $Tangram::TRACE; } elsif ( !defined($id) && @@ -655,7 +655,7 @@ sub _insert my $class = $self->{schema}->classdef($class_name); - my $id = $self->make_id($classId); + my $id = $self->make_id($classId, $obj); $self->welcome($obj, $id); $self->tx_on_rollback( sub { $self->goodbye($obj, $id) } );
RT-Send-CC: t2-users [...] lists.utsl.gen.nz
Thanks Assen, this looks like a good change and very useful to some people. My only reservation is that people might use it to work around the lack of decent primary key support in Tangram. Let me explain a bit more. Quite often you want to mark a particular object property or group of properties as the primary key, and then the "id" property becomes a surrogate, and a nuisance. In this instance you want Tangram to treat the marked columns as the ID, and combine the data in the primary keys and the type into an "oid". The limiting factors are the classes that perform associations, such as the Tangram::Type::Abstract::Coll related classes and Tangram::Type::Ref::* - as well as various other assumptions that the combined (id + type) tuple can be expressed as an integer. I don't think that these problems are insurmountable, though. Thanks for your contribution, Sam. On Thu Jan 25 18:04:02 2007, pt@tchorbadjiev.com wrote: Show quoted text
> > Hello, > > its not a bug :), its a feature that I find useful. > > Here's the case: > The current make_id() call, when inserting objects into the storage, > does not propagate the $o[bject] to be inserted. > Some applications (as mine does) might find it useful to have this > instance when they define/generate custom ids for the backend. > > Regards, > Assen