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

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