/[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.30 by joko, Thu Mar 27 15:31:14 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
14    #  modified 'querySchema': better behaviour regarding filtering result
15    #
16    #  Revision 1.31  2003/04/05 21:24:09  joko
17    #  modified 'sub getChildNodes': now contains code from 'querySchema'
18    #
19  #  Revision 1.30  2003/03/27 15:31:14  joko  #  Revision 1.30  2003/03/27 15:31:14  joko
20  #  fixes to modules regarding new namespace(s) below Data::Mungle::*  #  fixes to modules regarding new namespace(s) below Data::Mungle::*
21  #  #
# Line 131  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 231  sub connect { Line 244  sub connect {
244  sub getChildNodes {  sub getChildNodes {
245    
246    my $self = shift;    my $self = shift;
247    my @nodes;    my $mode = shift;
248      my $filter = shift;
249      
250      $mode ||= 'core';
251      $filter ||= 'all';
252      
253      $logger->debug( __PACKAGE__ . "->getChildNodes($mode)" );
254    
255    $logger->debug( __PACKAGE__ . "->getChildNodes()" );    if ($mode eq 'core') {
256    
257    # create new DBI - Data::Storage - object from already connected DBI::db - handle inside the current COREHANDLE      my @nodes;
258    #my $loc = new Data::Storage::Locator( type => "DBI", dbi => { db => $self->{COREHANDLE}->{db} });      
259    #my $loc = new Data::Storage::Locator( type => "DBI", COREHANDLE => $self->{COREHANDLE}->{db} );      # create new DBI - Data::Storage - object from already connected DBI::db - handle inside the current COREHANDLE
260          #my $loc = new Data::Storage::Locator( type => "DBI", dbi => { db => $self->{COREHANDLE}->{db} });
261    # todo: should we retrieve information from the schema here      #my $loc = new Data::Storage::Locator( type => "DBI", COREHANDLE => $self->{COREHANDLE}->{db} );
262    # rather than poorly getting table names from underlying dbi?      
263    my $storage = $self->_getSubLayerHandle();      # todo: should we retrieve information from the schema here
264    @nodes = @{$storage->getChildNodes()};      # rather than poorly getting table names from underlying dbi?
265    #$storage->_configureCOREHANDLE();      my $storage = $self->_getSubLayerHandle();
266  #print "getchildnodes\n";      @nodes = @{$storage->getChildNodes()};
267  #print Dumper($self);      #$storage->_configureCOREHANDLE();
268    #if (my $result = $self->sendCommand( 'SHOW TABLES;' ) ) {    #print "getchildnodes\n";
269      #print Dumper($self);
270        #if (my $result = $self->sendCommand( 'SHOW TABLES;' ) ) {
271        
272        # TODO: REVIEW
273        #$storage->disconnect();
274        
275        $self->{meta}->{childnodes} = \@nodes;
276    
277        return \@nodes;
278        
279    # TODO: REVIEW    } elsif ($mode eq 'root') {
280    #$storage->disconnect();      
281        # FIXME: this will return *all* known classes to 'Class::Tangram',
282        # which might not be what you expect since more than one instance
283        # of Tangram may be in memory and Class::Tangram seems to
284        # offer no methods to determine this or filter its result(s) according
285        # to a specific database.
286        my @object_names = Class::Tangram::known_classes();
287        my @concret_names;
288        my $o_cnt;
289        foreach (sort @object_names) {
290          push @concret_names, $_  if (!Class::Tangram::class_is_abstract($_));
291          $o_cnt++;
292        }
293    
294        if ($filter eq 'all') {
295          return \@object_names;
296        } elsif ($filter eq 'concrete') {
297          return \@concret_names;
298        }
299        
300    $self->{meta}->{childnodes} = \@nodes;    }
301        
   return \@nodes;  
302    
303  }  }
304    
   
305  sub testIntegrity {  sub testIntegrity {
306    
307    my $self = shift;    my $self = shift;
# Line 516  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}->[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 602  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 632  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.30  
changed lines
  Added in v.1.34

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