/[cvs]/nfo/perl/libs/Data/Storage/Handler/Tangram.pm
ViewVC logotype

Diff of /nfo/perl/libs/Data/Storage/Handler/Tangram.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.32 by joko, Tue Apr 8 22:52:22 2003 UTC revision 1.34 by joko, Fri Apr 11 01:18:53 2003 UTC
# Line 3  Line 3 
3  #  $Id$  #  $Id$
4  #  #
5  #  $Log$  #  $Log$
6    #  Revision 1.34  2003/04/11 01:18:53  joko
7    #  sendQuery:
8    #  + introduced crud action 'DELETE'
9    #
10    #  Revision 1.33  2003/04/09 06:07:43  joko
11    #  revamped 'sub sendQuery'
12    #
13  #  Revision 1.32  2003/04/08 22:52:22  joko  #  Revision 1.32  2003/04/08 22:52:22  joko
14  #  modified 'querySchema': better behaviour regarding filtering result  #  modified 'querySchema': better behaviour regarding filtering result
15  #  #
# Line 137  use Tangram; Line 144  use Tangram;
144  use DesignPattern::Object;  use DesignPattern::Object;
145  use Data::Storage::Result::Tangram;  use Data::Storage::Result::Tangram;
146  use Data::Mungle::Compare::Struct qw( isEmpty );  use Data::Mungle::Compare::Struct qw( isEmpty );
147  use Data::Mungle::Transform::Deep qw( expand );  use Data::Mungle::Transform::Deep qw( expand deep_copy merge_to );
148    
149  # get logger instance  # get logger instance
150  my $logger = Log::Dispatch::Config->instance;  my $logger = Log::Dispatch::Config->instance;
# Line 553  sub createSet { Line 560  sub createSet {
560  sub sendQuery {  sub sendQuery {
561    my $self = shift;    my $self = shift;
562    my $query = shift;    my $query = shift;
   #my $sql = "SELECT cs FROM $self->{metainfo}->{$descent}->{node} WHERE $self->{metainfo}->{$descent}->{IdentProvider}->{arg}='$self->{entry}->{source}->{ident}';";  
   #my $result = $self->{metainfo}->{$descent}->{storage}->sendCommand($sql);  
563    
564    #print Dumper($query);    #print Dumper($query);
565    
566    # HACK: special case: querying by id does not translate into a common tangram query    # type = ITEM|LIST|TRANSPARENT
567    # just load the object by given id(ent)    my $type = '';
568    if ($query->{criterias} && ($query->{criterias}->[0]->{key} eq 'id' && $query->{criterias}->[0]->{op} eq 'eq')) {    # mode = OID|SPECIAL
569      #print "LOAD!!!", "\n";    my $mode = '';
570      #exit;    my $ident = '';
571      #return Set::Object->new( $self->{COREHANDLE}->load($query->{criterias}->[0]->{val}) );    my $crud = '';
572      my $ident = $query->{criterias}->[0]->{val};    
573  #print "load obj", "\n";    
574      #return $self->createSet() if $ident == 5;    # dispatch type and mode
575      $self->{_COREHANDLE}->unload($ident);    
576      my $object = $self->{_COREHANDLE}->load($ident);      # defaults - 1
577  #print "get id", "\n";      if ($query->{options}) {
578      my $oid = $self->{_COREHANDLE}->id($object);        $crud = $query->{options}->{crud};
579  #print Dumper($object);        $crud ||= $query->{options}->{action};
580  #print "oid: $oid", "\n";      }
581      return $self->createSet($object);  
582      #return $self->createSet( $self->{COREHANDLE}->load('300090018') );      # defaults - 2
583    }      $type ||= 'TRANSPARENT';
584        $crud ||= 'RETRIEVE';
585    my $list = $self->getListFiltered($query->{node}, $query->{criterias});  
586    #return $self->createSet($object);      if ($query->{options}->{OID}) {
587    #return $self->createSet($list);        $type = 'ITEM';
588    return $self->createSet(@$list);        $mode = 'OID';
589          $ident = $query->{options}->{OID};
590    #die("This should not be reached for now - redirect to \$self->getListFiltered() here!");      
591        } elsif (my $guid = $query->{options}->{GUID}) {
592          $type = 'TRANSPARENT';
593          $query->{criterias} = [ { key => 'guid', op => 'eq', val => $guid } ];
594        
595        }
596      
597        # HACK: special case: querying by id does not translate into a common tangram query
598        # just load the object by given identifier (OID) named 'id' - this is required by Data::Transfer::Sync!
599        if ($query->{criterias} && ($query->{criterias}->[0]->{key} eq 'id' && $query->{criterias}->[0]->{op} eq 'eq')) {
600          $type = 'ITEM';
601          $mode = 'SPECIAL.SYNC';
602          $ident = $query->{criterias}->[0]->{val};
603        }
604      
605    
606      # execute query
607      my $result;
608    
609      if ($type eq 'ITEM' && $ident) {
610    
611        if ($mode eq 'OID') {    
612          # TODO: review this case!
613          $result = $self->getObject($ident, $query->{options});
614        
615        } elsif ($mode eq 'SPECIAL.SYNC') {
616    
617          # V1 - failed
618          #return Set::Object->new( $self->{COREHANDLE}->load($query->{criterias}->[0]->{val}) );
619      
620          # hmm....
621          #return $self->createSet() if $ident == 5;
622          
623          # Unload single object before doing any further operations to
624          # expect a "fresh" object from orm when performing the next calls.
625          $self->{_COREHANDLE}->unload($ident);
626          
627          # Load object from orm.
628          my $object = $self->{_COREHANDLE}->load($ident);
629      
630          # determine object identifier (OID)
631          my $oid = $self->{_COREHANDLE}->id($object);
632          
633          # encapsulate into result/response container and return this one
634          $result = $self->createSet($object);
635          
636          # debugging
637          #$result = $self->createSet( $self->{COREHANDLE}->load('300090018') );
638    
639        }
640        
641      
642      } elsif ($type eq 'TRANSPARENT') {
643    
644        if ($crud eq 'RETRIEVE') {
645    
646          my $list = $self->getListFiltered($query->{node}, $query->{criterias});
647          #return $self->createSet($object);
648          #return $self->createSet($list);
649          return $self->createSet(@$list);
650        
651          #die("This should not be reached for now - redirect to \$self->getListFiltered() here!");
652        
653          # try a generic tangram query here
654          # TODO: try to place an oql on top of that (search.cpan.org!)
655          my @crits;
656          foreach (@{$query->{criterias}}) {
657            my $op = '';
658            $op = '=' if lc $_->{op} eq 'eq';
659            push @crits, "$_->{key}$op'$_->{val}'";
660          }
661          my $subnodes = {};
662          map { $subnodes->{$_}++ } @{$query->{subnodes}};
663          # HACK: this is hardcoded ;(    expand possibilities!
664          #my $crit = join(' AND ', @crits);
665          #my $sql = hash2Sql($query->{node}, $subnodes, 'SELECT', $crit);
666          #return $self->sendCommand($sql);
667          #my $h = $self->{COREHANDLE}->remote($query->{node});
668          #my $res = $self->{COREHANDLE}->select($h, $h->{);
669          $result = $self->createCursor($query->{node});
670    
671        } elsif ($crud eq 'UPDATE') {
672    
673          # Patch current query to be a loader (e.g. change action, remove payload) ...
674          my $childquery = deep_copy($query);
675          $childquery->{options}->{crud} = 'RETRIEVE';
676          delete $childquery->{payload};
677    
678          # ... to use it to fetch a fresh object using ourselves (sendQuery).
679          my $cursor = $self->sendQuery($childquery);
680          my $status = $cursor->getStatus();
681          my $object = $cursor->getNextEntry();
682    
683          # Merge values and apply value modifiers.
684          my $options = { utf8 => 1, php => 1 };
685          merge_to($object, $query->{payload}, $options);
686    
687          # Execute update operation at orm.
688          $self->update($object);
689        
690        } elsif ($crud eq 'DELETE') {
691    
692          # Patch current query to be a loader (e.g. change action) ...
693          my $childquery = deep_copy($query);
694          $childquery->{options}->{crud} = 'RETRIEVE';
695    
696          # ... to use it to fetch a fresh object using ourselves (sendQuery).
697          my $cursor = $self->sendQuery($childquery);
698          my $status = $cursor->getStatus();
699          my $object = $cursor->getNextEntry();
700    
701          $self->erase($object);
702    
703        }
704    
705      }
706    
707      return $result;
708    
   # try a generic tangram query here  
   # TODO: try to place an oql on top of that (search.cpan.org!)  
   my @crits;  
   foreach (@{$query->{criterias}}) {  
     my $op = '';  
     $op = '=' if lc $_->{op} eq 'eq';  
     push @crits, "$_->{key}$op'$_->{val}'";  
   }  
   my $subnodes = {};  
   map { $subnodes->{$_}++ } @{$query->{subnodes}};  
   # HACK: this is hardcoded ;(    expand possibilities!  
   #my $crit = join(' AND ', @crits);  
   #my $sql = hash2Sql($query->{node}, $subnodes, 'SELECT', $crit);  
   #return $self->sendCommand($sql);  
   #my $h = $self->{COREHANDLE}->remote($query->{node});  
   #my $res = $self->{COREHANDLE}->select($h, $h->{);  
   return $self->createCursor($query->{node});  
709  }  }
710    
711  sub eraseAll {  sub eraseAll {
# Line 639  sub getObject { Line 741  sub getObject {
741    return $object if $object;    return $object if $object;
742  }  }
743    
744  sub getObjectByGuid {  sub getObjectByGuid_old {
745    my $self = shift;    my $self = shift;
746    my $guid = shift;    my $guid = shift;
747    my $options = shift;    my $options = shift;
# Line 669  sub getObjectByGuid { Line 771  sub getObjectByGuid {
771        
772  }  }
773    
774  sub getObjectAsHash {  sub getObjectAsHash_old {
775    my $self = shift;    my $self = shift;
776    my $oid = shift;    my $oid = shift;
777    my $options = shift;      my $options = shift;  

Legend:
Removed from v.1.32  
changed lines
  Added in v.1.34

MailToCvsAdmin">MailToCvsAdmin
ViewVC Help
Powered by ViewVC 1.1.26 RSS 2.0 feed