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

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

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