--- nfo/perl/libs/Data/Storage/Handler/Tangram.pm 2003/04/09 06:07:43 1.33 +++ nfo/perl/libs/Data/Storage/Handler/Tangram.pm 2003/04/19 16:09:48 1.35 @@ -1,8 +1,15 @@ ############################################ # -# $Id: Tangram.pm,v 1.33 2003/04/09 06:07:43 joko Exp $ +# $Id: Tangram.pm,v 1.35 2003/04/19 16:09:48 jonen Exp $ # # $Log: Tangram.pm,v $ +# Revision 1.35 2003/04/19 16:09:48 jonen +# + added operator dispatching (currently for getting ref-type) at 'getListFiltered' +# +# Revision 1.34 2003/04/11 01:18:53 joko +# sendQuery: +# + introduced crud action 'DELETE' +# # Revision 1.33 2003/04/09 06:07:43 joko # revamped 'sub sendQuery' # @@ -502,8 +509,14 @@ # objects => $objects, # ); - # HACK: build eval-string (sorry) to get filtered list - please give advice here - push @tfilters, '$remote->{' . $filter->{key} . '}' . " $filter->{op} '$filter->{val}'"; + # TODO: is_op? + # dispatch un-common operators if exists + if($filter->{op} eq "ref") { + push @tfilters, 'ref($remote->{' . $filter->{key} . '})' . " eq '$filter->{val}'"; + } else { + # HACK: build eval-string (sorry) to get filtered list - please give advice here + push @tfilters, '$remote->{' . $filter->{key} . '}' . " $filter->{op} '$filter->{val}'"; + } } @@ -564,19 +577,20 @@ # mode = OID|SPECIAL my $mode = ''; my $ident = ''; - my $action = ''; + my $crud = ''; # dispatch type and mode # defaults - 1 if ($query->{options}) { - $action = $query->{options}->{action}; + $crud = $query->{options}->{crud}; + $crud ||= $query->{options}->{action}; } # defaults - 2 $type ||= 'TRANSPARENT'; - $action ||= 'load'; + $crud ||= 'RETRIEVE'; if ($query->{options}->{OID}) { $type = 'ITEM'; @@ -585,8 +599,13 @@ } elsif (my $guid = $query->{options}->{GUID}) { $type = 'TRANSPARENT'; - $query->{criterias} = [ { key => 'guid', op => 'eq', val => $guid } ]; - + $query->{criterias} = [ { key => 'guid', op => 'eq', val => $guid } ]; + + # if operator is different (dispatcher for 'getListFiltered') + } elsif (my $op = $query->{options}->{op}) { + $type = 'TRANSPARENT'; + $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 @@ -604,6 +623,7 @@ if ($type eq 'ITEM' && $ident) { if ($mode eq 'OID') { + # TODO: review this case! $result = $self->getObject($ident, $query->{options}); } elsif ($mode eq 'SPECIAL.SYNC') { @@ -635,7 +655,7 @@ } elsif ($type eq 'TRANSPARENT') { - if ($action eq 'load') { + if ($crud eq 'RETRIEVE') { my $list = $self->getListFiltered($query->{node}, $query->{criterias}); #return $self->createSet($object); @@ -662,14 +682,14 @@ #my $res = $self->{COREHANDLE}->select($h, $h->{); $result = $self->createCursor($query->{node}); - } elsif ($action eq 'save') { + } elsif ($crud eq 'UPDATE') { # Patch current query to be a loader (e.g. change action, remove payload) ... my $childquery = deep_copy($query); - $childquery->{options}->{action} = 'load'; + $childquery->{options}->{crud} = 'RETRIEVE'; delete $childquery->{payload}; - # ... to use it to fetch fresh object using ourselves (sendQuery). + # ... to use it to fetch a fresh object using ourselves (sendQuery). my $cursor = $self->sendQuery($childquery); my $status = $cursor->getStatus(); my $object = $cursor->getNextEntry(); @@ -681,6 +701,19 @@ # Execute update operation at orm. $self->update($object); + } elsif ($crud eq 'DELETE') { + + # Patch current query to be a loader (e.g. change action) ... + my $childquery = deep_copy($query); + $childquery->{options}->{crud} = 'RETRIEVE'; + + # ... to use it to fetch a fresh object using ourselves (sendQuery). + my $cursor = $self->sendQuery($childquery); + my $status = $cursor->getStatus(); + my $object = $cursor->getNextEntry(); + + $self->erase($object); + } }