/[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.47 by jonen, Tue Aug 31 14:26:08 2004 UTC
# Line 3  Line 3 
3  #  $Id$  #  $Id$
4  #  #
5  #  $Log$  #  $Log$
6    #  Revision 1.47  2004/08/31 14:26:08  jonen
7    #  updated
8    #
9    #  Revision 1.46  2004/05/06 12:54:34  jonen
10    #  + bugfix related to multiple select-'filter'
11    #
12    #  Revision 1.45  2003/12/14 01:48:36  jonen
13    #  small HACK at _insertChildNode: some special Childnodes should not be created because existing objects have to be selected!
14    #  TODO: make this more generic, e.g. implement a special flag at Schema
15    #
16    #  Revision 1.44  2003/12/04 01:01:50  joko
17    #  + sendQuery now returns result even on crud=UPDATE
18    #
19    #  Revision 1.43  2003/07/02 11:07:12  jonen
20    #  re-activate filtering of results *after* results are fetched from tangram
21    #    (needed for e.g. UserManagment)
22    #
23    #  Revision 1.42  2003/07/01 23:24:17  joko
24    #  now using package before using function
25    #
26    #  Revision 1.41  2003/06/29 02:03:45  joko
27    #  fix:? initialize schema on startup
28    #
29    #  Revision 1.40  2003/06/25 22:57:54  joko
30    #  major rework of "sub sendQuery / sub getListFiltered": now should be capable of "sorting"
31    #
32    #  Revision 1.39  2003/06/06 11:40:40  jonen
33    #  fixed bug at 'getFilteredList'
34    #
35    #  Revision 1.38  2003/05/13 16:38:38  joko
36    #  problems with "tied" on 5.6.1/win32
37    #
38    #  Revision 1.37  2003/05/10 17:37:39  jonen
39    #  corrected last commit
40    #
41    #  Revision 1.36  2003/05/10 17:31:18  jonen
42    #  + added new functions related to 'create' item
43    #   - createNode()
44    #     # creates non-persistent 'deep dummy filled' object
45    #   - insertChildNode()
46    #     # inserts child node at given parent (child node haven't to exists,
47    #         createNode will be injected transparently)
48    #
49    #  Revision 1.35  2003/04/19 16:09:48  jonen
50    #  + added operator dispatching (currently for getting ref-type) at 'getListFiltered'
51    #
52    #  Revision 1.34  2003/04/11 01:18:53  joko
53    #  sendQuery:
54    #  + introduced crud action 'DELETE'
55    #
56    #  Revision 1.33  2003/04/09 06:07:43  joko
57    #  revamped 'sub sendQuery'
58    #
59  #  Revision 1.32  2003/04/08 22:52:22  joko  #  Revision 1.32  2003/04/08 22:52:22  joko
60  #  modified 'querySchema': better behaviour regarding filtering result  #  modified 'querySchema': better behaviour regarding filtering result
61  #  #
# Line 133  use base ("Data::Storage::Handler::Abstr Line 186  use base ("Data::Storage::Handler::Abstr
186    
187  use Data::Dumper;  use Data::Dumper;
188  use Tangram;  use Tangram;
189    use Class::Tangram;
190    
191  use DesignPattern::Object;  use DesignPattern::Object;
192  use Data::Storage::Result::Tangram;  use Data::Storage::Result::Tangram;
193  use Data::Mungle::Compare::Struct qw( isEmpty );  use Data::Mungle::Compare::Struct qw( isEmpty );
194  use Data::Mungle::Transform::Deep qw( expand );  use Data::Mungle::Transform::Deep qw( expand deep_copy merge_to );
195    
196  # get logger instance  # get logger instance
197  my $logger = Log::Dispatch::Config->instance;  my $logger = Log::Dispatch::Config->instance;
198    
199    #$Tangram::TRACE = *STDOUT;
200    
201  # this holds the complete instantiated schema from tangram  # this holds the complete instantiated schema from tangram
202  my $schema_tangram;  my $schema_tangram;
# Line 160  sub _initSchema { Line 215  sub _initSchema {
215    #if (!$schema_tangram) {    #if (!$schema_tangram) {
216      #my $obj = getNewPerlObjectByPkgName($self->{locator}->{schema}, { EXPORT_OBJECTS => $self->{locator}->{classnames}, want_transactions => $self->{locator}->{want_transactions} } );      #my $obj = getNewPerlObjectByPkgName($self->{locator}->{schema}, { EXPORT_OBJECTS => $self->{locator}->{classnames}, want_transactions => $self->{locator}->{want_transactions} } );
217      my $obj = DesignPattern::Object->fromPackage($self->{locator}->{schema}, { 'EXPORT_OBJECTS' => $self->{locator}->{classnames}, 'want_transactions' => $self->{locator}->{want_transactions} } );      my $obj = DesignPattern::Object->fromPackage($self->{locator}->{schema}, { 'EXPORT_OBJECTS' => $self->{locator}->{classnames}, 'want_transactions' => $self->{locator}->{want_transactions} } );
218      $schema_tangram = $obj->getSchema();      $schema_tangram = $obj->getSchema() if $obj;
219    #}    #}
220    if (!$schema_tangram) {    if (!$schema_tangram) {
221      $logger->error( __PACKAGE__ . "->_initSchema: No Schema available for $self->{schema}" );      $logger->error( __PACKAGE__ . "->_initSchema: No Schema available for $self->{locator}->{schema}." );
222      return 0;      return 0;
223    }    }
224    #$self->_patchSchema();    #$self->_patchSchema();
# Line 209  sub connect { Line 264  sub connect {
264  #      return;  #      return;
265  #    }  #    }
266    
267      #return unless $self->_initSchema();      return unless $self->_initSchema();
268      $self->_initSchema();      #$self->_initSchema();
269    
270      # create the main tangram storage object      # create the main tangram storage object
271      #$self->{COREHANDLE} = Tangram::Relational->connect( $schema, $dsn );      #$self->{COREHANDLE} = Tangram::Relational->connect( $schema, $dsn );
# Line 472  sub getListFiltered { Line 527  sub getListFiltered {
527    # redirect to unfiltered mode    # redirect to unfiltered mode
528    #return $self->getListUnfiltered(@_);    #return $self->getListUnfiltered(@_);
529    
530    my $nodename = shift;    my $in = {};
531    my $filters = shift;    $in->{nodename} = shift;
532      $in->{filters} = shift;
533      $in->{sorting} = shift;
534      
535    my @results;    my @results;
536    $logger->debug( __PACKAGE__ . "->getListFiltered( nodename => '" . $nodename . "' )" );    $logger->debug( __PACKAGE__ . "->getListFiltered( nodename => '" . $in->{nodename} . "' )" );
537    
538      #print "Filter_payload: " . Dumper($in->{filters}) . "\n";
539    
540  #print Dumper($filters);    # 1. "Remote Object Handle" - get set of objects from odbms by object name
541      my $remote = $self->{_COREHANDLE}->remote($in->{nodename});
542      
543      # 2. Transfer $in to $orm_query
544      my $orm_query = {};
545        
546      # 2.a. Filters
547    my @tfilters;    my @tfilters;
548      my $orm_filter = undef;
549        
550    foreach my $filter (@$filters) {    foreach my $filter (@{$in->{filters}}) {
551        
552      # get filter - TODO: for each filter      # get filter - TODO: for each filter
553      #my $filter = $filters->[0];      #my $filter = $filters->[0];
554      
555      # build filter      # 1. The parts of a filter source entry
556      my $lexpr = $filter->{key};      my $lexpr = $filter->{key};
557      #my $op = $filter->{op};      #my $op = $filter->{op};
558      my $op = '=';      my $op = '=';
559      my $rexpr = $filter->{val};      my $rexpr = $filter->{val};
560      my $tight = 100;      my $tight = 100;
561    
562        # 2. Build filter target entry
563            
564    #  my $tfilter = Tangram::Filter->new(      # Test 1 - didn't work out!
565    #    expr => "t1.$lexpr $op '$rexpr'",      #  my $tfilter = Tangram::Filter->new(
566    #    tight => $tight,      #    expr => "t1.$lexpr $op '$rexpr'",
567    #    objects => $objects,      #    tight => $tight,
568    #  );      #    objects => $objects,
569        #  );
570    
571        my $orm_filter_tmp = undef;
572        # was:
573        # TODO: is_op?
574        # dispatch un-common operators if exists
575        if ($filter->{op} eq "ref") {
576          # do nothing, results will be filtered later cause 'tangram-filter' doesn't support 'ref' query
577          #print "Filter->op eq 'ref'.\n";
578          #push @tfilters, 'ref($remote->{' . $filter->{key} . '})' . " eq '$filter->{val}'";
579        } else {
580          # HACK: build eval-string (sorry) to get filtered list - please give advice here
581          #push @tfilters, '$remote->{' . $filter->{key} . '}' . " $filter->{op} '$filter->{val}'";
582          # better: calculate expression right here!
583          #push @tfilters, '$remote->{' . $filter->{key} . '}' . " $filter->{op} '$filter->{val}'";
584          
585          #print "key: ", $filter->{key}, "\n";
586          
587          my $left = $remote->{$filter->{key}};
588          #my $r = Tangram::Expr->new( 'string' => "'" . $filter->{val} . "'" );
589          my $right = $filter->{val};
590          my $op = $filter->{op};
591          $orm_filter_tmp = $left->$op($right);
592        }
593    
594        if (!ref($orm_filter)) {
595          $orm_filter = $orm_filter_tmp;
596        } else {
597          $orm_filter = $orm_filter->and($orm_filter_tmp);
598        }
599    
600      }
601    
602      $orm_query->{filter} = $orm_filter;
603        
604      # HACK: build eval-string (sorry) to get filtered list - please give advice here    # debug point:
605      push @tfilters, '$remote->{' . $filter->{key} . '}' . " $filter->{op} '$filter->{val}'";    #print "Filter: " . Dumper($orm_query->{filter}) . "\n";
606    
607      # was:
608    
609      # 2.b. sorting [new as of 2003-06-17]
610      if ($in->{sorting}) {
611        my $sorting_rules = [];
612        my $sorting_order = 'ASC';
613        foreach my $sorting_column (keys %{$in->{sorting}}) {
614          $sorting_order = $in->{sorting}->{$sorting_column} if $in->{sorting}->{$sorting_column};
615          push @$sorting_rules, Tangram::Expr->new( 'string' => $sorting_column );
616        }
617        $orm_query->{order} = $sorting_rules;
618        if ($sorting_order eq 'DESC') {
619          $orm_query->{desc} = 1;
620        }
621    }    }
622    
   my $tfilter = join(' & ', @tfilters);  
623    
624    # get set of objects from odbms by object name    # 3. build and issue query - return result as Tangram::Cursor
   my $remote = $self->{_COREHANDLE}->remote($nodename);  
625        
626    # was:    # coerce hash into array (This is valid in Perl)
627    #@results = $self->{COREHANDLE}->select($object_set, $tfilter);    my @orm_query_args = %$orm_query;
628      # send query (arguments) to orm
629      @results = $self->{_COREHANDLE}->select($remote, @orm_query_args);
630      
631      #my $cursor = $self->{_COREHANDLE}->cursor($remote, @orm_query_args);
632      #return $cursor;
633      #print Dumper(@results);
634    
635    # is:    # is:
636    # HACK: build eval-string (sorry) to get filtered list - please give advice here    # HACK: build eval-string (sorry) to get filtered list - please give advice here
637    my $evalstring = 'return $self->{_COREHANDLE}->select($remote, ' . $tfilter . ');';      #my $evalstring = 'return $self->{_COREHANDLE}->select($remote, ' . $tfilter . $sorting . ');';
638          #print "eval: $evalstring", "\n";
639    #print "eval: $evalstring", "\n";      # get filtered list/set
640          #@results = eval($evalstring);
641    # get filtered list/set      #die $@ if $@;
642    @results = eval($evalstring);  
643    die $@ if $@;    # filter results - NEEDED for e.g. UserManagment !!
644      if ($in->{filters}->[0]->{op} && ($in->{filters}->[0]->{op} eq "ref")) {
645          #print "Filter->op eq 'ref'.\n";
646          my $att_name = $in->{filters}->[0]->{key};
647          my $att_val = $in->{filters}->[0]->{val};
648          my @filtered;
649          foreach(@results) {
650            if(ref($_->{$att_name}) eq $att_val) {
651              push @filtered, $_;
652            }
653          }
654          @results = @filtered;
655      }
656    
657      #print "results: " . Dumper(\@results);
658        
659    return \@results;    return \@results;
660  }  }
# Line 550  sub createSet { Line 684  sub createSet {
684    return $result;    return $result;
685  }  }
686    
687    sub createResult {
688      my $self = shift;
689      my $rh = shift;
690      my $result = Data::Storage::Result::Tangram->new( RESULTHANDLE => $rh );
691      return $result;
692    }
693    
694  sub sendQuery {  sub sendQuery {
695    my $self = shift;    my $self = shift;
696    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);  
697    
698    #print Dumper($query);    #print Dumper($query);
699    
700    # HACK: special case: querying by id does not translate into a common tangram query    # type = ITEM|LIST|TRANSPARENT
701    # just load the object by given id(ent)    my $type = '';
702    if ($query->{criterias} && ($query->{criterias}->[0]->{key} eq 'id' && $query->{criterias}->[0]->{op} eq 'eq')) {    # mode = OID|SPECIAL
703      #print "LOAD!!!", "\n";    my $mode = '';
704      #exit;    my $ident = '';
705      #return Set::Object->new( $self->{COREHANDLE}->load($query->{criterias}->[0]->{val}) );    my $crud = '';
706      my $ident = $query->{criterias}->[0]->{val};    
707  #print "load obj", "\n";    
708      #return $self->createSet() if $ident == 5;    # dispatch type and mode
709      $self->{_COREHANDLE}->unload($ident);    
710      my $object = $self->{_COREHANDLE}->load($ident);      # defaults - 1
711  #print "get id", "\n";      if ($query->{options}) {
712      my $oid = $self->{_COREHANDLE}->id($object);        $crud = $query->{options}->{crud};
713  #print Dumper($object);        $crud ||= $query->{options}->{action};
714  #print "oid: $oid", "\n";      }
715      return $self->createSet($object);  
716      #return $self->createSet( $self->{COREHANDLE}->load('300090018') );      # defaults - 2
717    }      $type ||= 'TRANSPARENT';
718        $crud ||= 'RETRIEVE';
719    my $list = $self->getListFiltered($query->{node}, $query->{criterias});  
720    #return $self->createSet($object);      if ($query->{options}->{OID}) {
721    #return $self->createSet($list);        $type = 'ITEM';
722    return $self->createSet(@$list);        $mode = 'OID';
723          $ident = $query->{options}->{OID};
724    #die("This should not be reached for now - redirect to \$self->getListFiltered() here!");      
725        } elsif (my $guid = $query->{options}->{GUID}) {
726          $type = 'TRANSPARENT';
727          $query->{criterias} = [ { key => 'guid', op => 'eq', val => $guid } ];    
728    
729        # if operator is different (dispatcher for 'getListFiltered')
730        } elsif (my $op = $query->{options}->{op}) {
731          $type = 'TRANSPARENT';
732          $query->{criterias} = [ { key => $query->{options}->{meta_label}, op => $op, val => $query->{options}->{meta_value} } ];    
733    
734        }
735      
736        # HACK: special case: querying by id does not translate into a common tangram query
737        # just load the object by given identifier (OID) named 'id' - this is required by Data::Transfer::Sync!
738        if ($query->{criterias} && ($query->{criterias}->[0]->{key} eq 'id' && $query->{criterias}->[0]->{op} eq 'eq')) {
739          $type = 'ITEM';
740          $mode = 'SPECIAL.SYNC';
741          $ident = $query->{criterias}->[0]->{val};
742        }
743      
744    
745      # execute query
746      my $result;
747    
748      if ($type eq 'ITEM' && $ident) {
749    
750        if ($mode eq 'OID') {    
751          # TODO: review this case!
752          $result = $self->getObject($ident, $query->{options});
753        
754        } elsif ($mode eq 'SPECIAL.SYNC') {
755    
756          # V1 - failed
757          #return Set::Object->new( $self->{COREHANDLE}->load($query->{criterias}->[0]->{val}) );
758      
759          # hmm....
760          #return $self->createSet() if $ident == 5;
761          
762          # Unload single object before doing any further operations to
763          # expect a "fresh" object from orm when performing the next calls.
764          $self->{_COREHANDLE}->unload($ident);
765          
766          # Load object from orm.
767          my $object = $self->{_COREHANDLE}->load($ident);
768      
769          # determine object identifier (OID)
770          my $oid = $self->{_COREHANDLE}->id($object);
771          
772          # encapsulate into result/response container and return this one
773          $result = $self->createSet($object);
774          
775          # debugging
776          #$result = $self->createSet( $self->{COREHANDLE}->load('300090018') );
777    
778        }
779        
780      
781      } elsif ($type eq 'TRANSPARENT') {
782    
783        if ($crud eq 'RETRIEVE') {
784    
785          my $list = $self->getListFiltered($query->{node}, $query->{criterias}, $query->{sorting});
786          #return $list;
787          return $self->createResult($list);
788          
789          #return $self->createSet($object);
790          #return $self->createSet($list);
791          return $self->createSet(@$list);
792        
793          #die("This should not be reached for now - redirect to \$self->getListFiltered() here!");
794        
795          # try a generic tangram query here
796          # TODO: try to place an oql on top of that (search.cpan.org!)
797          my @crits;
798          foreach (@{$query->{criterias}}) {
799            my $op = '';
800            $op = '=' if lc $_->{op} eq 'eq';
801            push @crits, "$_->{key}$op'$_->{val}'";
802          }
803          my $subnodes = {};
804          map { $subnodes->{$_}++ } @{$query->{subnodes}};
805          # HACK: this is hardcoded ;(    expand possibilities!
806          #my $crit = join(' AND ', @crits);
807          #my $sql = hash2Sql($query->{node}, $subnodes, 'SELECT', $crit);
808          #return $self->sendCommand($sql);
809          #my $h = $self->{COREHANDLE}->remote($query->{node});
810          #my $res = $self->{COREHANDLE}->select($h, $h->{);
811          $result = $self->createCursor($query->{node});
812    
813        } elsif ($crud eq 'UPDATE') {
814    
815          # Patch current query to be a loader (e.g. change action, remove payload) ...
816          my $childquery = deep_copy($query);
817          $childquery->{options}->{crud} = 'RETRIEVE';
818          delete $childquery->{payload};
819    
820          # ... to use it to fetch a fresh object using ourselves (sendQuery).
821          my $cursor = $self->sendQuery($childquery);
822          my $status = $cursor->getStatus();
823          my $object = $cursor->getNextEntry();
824    
825          # Merge values and apply value modifiers.
826          my $options = { utf8 => 1, php => 1 };
827          merge_to($object, $query->{payload}, $options);
828    
829          #print Dumper($object);
830          
831          # Execute update operation at orm.
832          $self->update($object);
833          $result = $self->createResult([ $object ]);
834        
835        } elsif ($crud eq 'DELETE') {
836    
837          # Patch current query to be a loader (e.g. change action) ...
838          my $childquery = deep_copy($query);
839          $childquery->{options}->{crud} = 'RETRIEVE';
840    
841          # ... to use it to fetch a fresh object using ourselves (sendQuery).
842          my $cursor = $self->sendQuery($childquery);
843          my $status = $cursor->getStatus();
844          my $object = $cursor->getNextEntry();
845    
846          $self->erase($object);
847          $self->unload($object);
848    
849        } elsif ($crud eq 'CREATE') {
850          
851          my $nodename = $query->{node};      
852          my $newnode = $self->createNode($nodename);
853          my $id = $self->{_COREHANDLE}->insert($newnode);
854      
855          print "Saved new node $nodename with GUID $newnode->{guid}, OID '$id': " . Dumper($newnode) . "\n";
856          
857          return $newnode;
858    
859        }
860    
861      }
862    
863      return $result;
864    
   # 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});  
865  }  }
866    
867  sub eraseAll {  sub eraseAll {
# Line 639  sub getObject { Line 897  sub getObject {
897    return $object if $object;    return $object if $object;
898  }  }
899    
900  sub getObjectByGuid {  sub getObjectByGuid_old {
901    my $self = shift;    my $self = shift;
902    my $guid = shift;    my $guid = shift;
903    my $options = shift;    my $options = shift;
# Line 669  sub getObjectByGuid { Line 927  sub getObjectByGuid {
927        
928  }  }
929    
930  sub getObjectAsHash {  sub getObjectAsHash_old {
931    my $self = shift;    my $self = shift;
932    my $oid = shift;    my $oid = shift;
933    my $options = shift;      my $options = shift;  
# Line 752  sub disconnect2 { Line 1010  sub disconnect2 {
1010    $self->{dataStorageLayer}->disconnect();    $self->{dataStorageLayer}->disconnect();
1011  }  }
1012    
1013    
1014    sub createNode {
1015      my $self = shift;
1016      my $classname = shift;
1017    
1018      my $obj = $classname->new();
1019      
1020      my $attr_options = Class::Tangram::attribute_options($classname);
1021      #print "Attribute Options: " . Dumper($attr_options);
1022    
1023      my $attr_types = Class::Tangram::attribute_types($classname);
1024      #print "Attribute Types: " . Dumper($attr_types);
1025      
1026      foreach(keys %{$attr_types}) {
1027        if($attr_types->{$_} eq 'string') {
1028          $obj->{$_} = '';
1029        } elsif($attr_types->{$_} eq 'int') {
1030          $obj->{$_} = 0;
1031        } elsif($attr_types->{$_} eq 'real') {
1032          $obj->{$_} = 0;
1033        } elsif($attr_types->{$_} eq 'rawdatetime') {
1034          $obj->{$_} = '0000-00-00 00:00:00';
1035        } elsif($attr_types->{$_} eq 'ref') {
1036          if($attr_options->{$_}->{class}) {
1037            # HACK!!!
1038            # STANDALONE Objects (objects which make sense to instanciat alone) should not created automaticly
1039            # because they maybe exists and should only be SETTED not CREATED!
1040            # TODO: Create a flag at the scheme for that reason!
1041            #   (e.g child_node => 1 for child-nodes only like e.g. UserData)
1042            if($attr_options->{$_}->{class} eq 'NetPerson' || $attr_options->{$_}->{class} eq 'Event' || $attr_options->{$_}->{class} eq 'BetRule') {
1043              #$obj->{$_} = undef();
1044            } else {
1045              $obj->{$_} = $self->createNode($attr_options->{$_}->{class});
1046            }
1047          } else {
1048            #$obj->{$_} = undef();
1049          }
1050        } elsif($attr_types->{$_} eq 'iarray') {
1051            $obj->{$_} = [ ];
1052        } elsif($attr_types->{$_} eq 'hash') {
1053            $obj->{$_} = {  };
1054        } elsif($attr_types->{$_} eq 'flat_hash') {
1055            $obj->{$_} = { };
1056        }
1057      }
1058      
1059      #print "New Object: " . Dumper($obj);
1060      
1061      return $obj;
1062    }
1063    
1064    
1065      sub insertChildNode {
1066        my $self = shift;
1067        my $child_entry = shift;
1068        my $query_args = shift;
1069        
1070        my $core = $self->{_COREHANDLE};
1071        my $nodename = $query_args->{nodename};
1072        
1073        # get parent object
1074        my $query = {
1075              node => $query_args->{parent}->{nodename},
1076              options => { GUID => $query_args->{parent}->{guid}, },
1077              };
1078        my $cursor = $self->sendQuery($query);
1079        my $parent = $cursor->getNextEntry();
1080    
1081        # debug
1082        #print "Parent_org: " . Dumper($parent);
1083            
1084        # Create child node object if isn't already done
1085        # ($child_entry have to be the class name then...)
1086        if(!ref($child_entry)) {
1087          $child_entry = $self->createNode($child_entry);
1088          # it could be insert 'manually' or will be insert 'transparent' if parent will be updated
1089          #$core->insert($child_entry);
1090          #print "Create child object [$nodename]: " . Dumper($child_entry);
1091        }
1092    
1093        # get reference of tied node (seems, only on Linux node's are tied!!)
1094        my $tied_node = tied $parent->{$nodename};
1095    
1096        # insert/change child entry at parent
1097        #print "reference: " . ref($parent->{$nodename}) . "\n";
1098        if(ref($parent->{$nodename}) eq 'ARRAY') {
1099          # (seems, only on Linux node's are tied!!)
1100          if($tied_node) {
1101            # all tangram types are tied as 'SCALAR' with special 'FETCH', 'STORE' methods per type,
1102            # so a 'PUSH' is not implemented (which could be then done transparently)
1103            my $array = $tied_node->FETCH;
1104            push @$array, $child_entry;
1105            $tied_node->STORE($array);
1106            # node will be normaly untied at 'STORE'
1107            if(tied $parent->{$nodename}) { print "already tied !!\n"; }
1108            else { undef $tied_node; }
1109          } else {
1110            push @{$parent->{$nodename}}, $child_entry;
1111          }
1112        }
1113        elsif(ref($parent->{$nodename}) eq 'HASH') {
1114          if(my $key = $query_args->{hash_key}) {
1115            # (seems, only on Linux node's are tied!!)
1116            if($tied_node) {
1117              # same problem as with 'ARRAY':
1118              # all tangram types are tied as 'SCALAR' with special 'FETCH', 'STORE' methods per type.
1119              my $hash = $tied_node->FETCH;
1120              $hash->{$key} = $child_entry;
1121              $tied_node->STORE($hash);
1122              # node will be normaly untied at 'STORE'
1123              if(tied $parent->{$nodename}) { print "already tied !!\n"; }
1124              else { undef $tied_node; }
1125            } else {
1126              $parent->{$nodename}->{$key} = $child_entry;
1127            }
1128          } else {
1129           print "ERROR: No HASH KEY given, so not able to insert hash entry!";
1130          }
1131        }
1132        else {
1133          $parent->{$nodename} = $child_entry;
1134        }
1135    
1136        # debug
1137        #print "Parent_new: " . Dumper($parent);
1138        
1139        # save parent
1140        $core->update($parent);
1141        
1142        # debug
1143        #print "Saved Parent: ". Dumper($parent);
1144        
1145        return $child_entry;
1146      }
1147    
1148    
1149  1;  1;
1150  __END__  __END__

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

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