--- nfo/perl/libs/Data/Storage/Handler/Tangram.pm 2003/06/25 22:57:54 1.40 +++ nfo/perl/libs/Data/Storage/Handler/Tangram.pm 2004/10/28 11:35:51 1.48 @@ -1,8 +1,34 @@ ############################################ # -# $Id: Tangram.pm,v 1.40 2003/06/25 22:57:54 joko Exp $ +# $Id: Tangram.pm,v 1.48 2004/10/28 11:35:51 jonen Exp $ # # $Log: Tangram.pm,v $ +# Revision 1.48 2004/10/28 11:35:51 jonen +# + bugfix related to select-criterias(filter) +# +# Revision 1.47 2004/08/31 14:26:08 jonen +# updated +# +# Revision 1.46 2004/05/06 12:54:34 jonen +# + bugfix related to multiple select-'filter' +# +# Revision 1.45 2003/12/14 01:48:36 jonen +# small HACK at _insertChildNode: some special Childnodes should not be created because existing objects have to be selected! +# TODO: make this more generic, e.g. implement a special flag at Schema +# +# Revision 1.44 2003/12/04 01:01:50 joko +# + sendQuery now returns result even on crud=UPDATE +# +# Revision 1.43 2003/07/02 11:07:12 jonen +# re-activate filtering of results *after* results are fetched from tangram +# (needed for e.g. UserManagment) +# +# Revision 1.42 2003/07/01 23:24:17 joko +# now using package before using function +# +# Revision 1.41 2003/06/29 02:03:45 joko +# fix:? initialize schema on startup +# # Revision 1.40 2003/06/25 22:57:54 joko # major rework of "sub sendQuery / sub getListFiltered": now should be capable of "sorting" # @@ -163,6 +189,7 @@ use Data::Dumper; use Tangram; +use Class::Tangram; use DesignPattern::Object; use Data::Storage::Result::Tangram; @@ -172,6 +199,7 @@ # get logger instance my $logger = Log::Dispatch::Config->instance; +#$Tangram::TRACE = *STDOUT; # this holds the complete instantiated schema from tangram my $schema_tangram; @@ -190,10 +218,10 @@ #if (!$schema_tangram) { #my $obj = getNewPerlObjectByPkgName($self->{locator}->{schema}, { EXPORT_OBJECTS => $self->{locator}->{classnames}, want_transactions => $self->{locator}->{want_transactions} } ); my $obj = DesignPattern::Object->fromPackage($self->{locator}->{schema}, { 'EXPORT_OBJECTS' => $self->{locator}->{classnames}, 'want_transactions' => $self->{locator}->{want_transactions} } ); - $schema_tangram = $obj->getSchema(); + $schema_tangram = $obj->getSchema() if $obj; #} if (!$schema_tangram) { - $logger->error( __PACKAGE__ . "->_initSchema: No Schema available for $self->{schema}" ); + $logger->error( __PACKAGE__ . "->_initSchema: No Schema available for $self->{locator}->{schema}." ); return 0; } #$self->_patchSchema(); @@ -239,8 +267,8 @@ # return; # } - #return unless $self->_initSchema(); - $self->_initSchema(); + return unless $self->_initSchema(); + #$self->_initSchema(); # create the main tangram storage object #$self->{COREHANDLE} = Tangram::Relational->connect( $schema, $dsn ); @@ -510,7 +538,7 @@ my @results; $logger->debug( __PACKAGE__ . "->getListFiltered( nodename => '" . $in->{nodename} . "' )" ); - #print Dumper($filters); + #print "Filter_payload: " . Dumper($in->{filters}) . "\n"; # 1. "Remote Object Handle" - get set of objects from odbms by object name my $remote = $self->{_COREHANDLE}->remote($in->{nodename}); @@ -566,7 +594,7 @@ $orm_filter_tmp = $left->$op($right); } - if (not $orm_filter) { + if (!ref($orm_filter)) { $orm_filter = $orm_filter_tmp; } else { $orm_filter = $orm_filter->and($orm_filter_tmp); @@ -575,6 +603,9 @@ } $orm_query->{filter} = $orm_filter; + + # debug point: + #print "Filter: " . Dumper($orm_query->{filter}) . "\n"; # was: @@ -612,12 +643,11 @@ #@results = eval($evalstring); #die $@ if $@; -=pod - # filter results - if ($filters->[0]->{op} && ($filters->[0]->{op} eq "ref")) { + # filter results - NEEDED for e.g. UserManagment !! + if ($in->{filters}->[0]->{op} && ($in->{filters}->[0]->{op} eq "ref")) { #print "Filter->op eq 'ref'.\n"; - my $att_name = $filters->[0]->{key}; - my $att_val = $filters->[0]->{val}; + my $att_name = $in->{filters}->[0]->{key}; + my $att_val = $in->{filters}->[0]->{val}; my @filtered; foreach(@results) { if(ref($_->{$att_name}) eq $att_val) { @@ -626,7 +656,6 @@ } @results = @filtered; } -=cut #print "results: " . Dumper(\@results); @@ -698,13 +727,20 @@ } elsif (my $guid = $query->{options}->{GUID}) { $type = 'TRANSPARENT'; - $query->{criterias} = [ { key => 'guid', op => 'eq', val => $guid } ]; - + if(ref($query->{criterias}) eq 'ARRAY') { + push @{$query->{criterias}}, { key => 'guid', op => 'eq', val => $guid }; + } else { + $query->{criterias} = [ { key => 'guid', op => 'eq', val => $guid } ]; + } + } # if operator is different (dispatcher for 'getListFiltered') - } elsif (my $op = $query->{options}->{op}) { + if (my $op = $query->{options}->{op}) { $type = 'TRANSPARENT'; - $query->{criterias} = [ { key => $query->{options}->{meta_label}, op => $op, val => $query->{options}->{meta_value} } ]; - + if(ref($query->{criterias}) eq 'ARRAY') { + push @{$query->{criterias}}, { key => $query->{options}->{meta_label}, op => $op, val => $query->{options}->{meta_value} }; + } else { + $query->{criterias} = [ { key => $query->{options}->{meta_label}, op => $op, val => $query->{options}->{meta_value} } ]; + } } # HACK: special case: querying by id does not translate into a common tangram query @@ -800,8 +836,11 @@ my $options = { utf8 => 1, php => 1 }; merge_to($object, $query->{payload}, $options); + #print Dumper($object); + # Execute update operation at orm. $self->update($object); + $result = $self->createResult([ $object ]); } elsif ($crud eq 'DELETE') { @@ -815,6 +854,7 @@ my $object = $cursor->getNextEntry(); $self->erase($object); + $self->unload($object); } elsif ($crud eq 'CREATE') { @@ -1004,7 +1044,16 @@ $obj->{$_} = '0000-00-00 00:00:00'; } elsif($attr_types->{$_} eq 'ref') { if($attr_options->{$_}->{class}) { - $obj->{$_} = $self->createNode($attr_options->{$_}->{class}); + # HACK!!! + # STANDALONE Objects (objects which make sense to instanciat alone) should not created automaticly + # because they maybe exists and should only be SETTED not CREATED! + # TODO: Create a flag at the scheme for that reason! + # (e.g child_node => 1 for child-nodes only like e.g. UserData) + if($attr_options->{$_}->{class} eq 'NetPerson' || $attr_options->{$_}->{class} eq 'Event' || $attr_options->{$_}->{class} eq 'BetRule') { + #$obj->{$_} = undef(); + } else { + $obj->{$_} = $self->createNode($attr_options->{$_}->{class}); + } } else { #$obj->{$_} = undef(); }