/[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.14 by jonen, Thu Dec 5 09:40:30 2002 UTC revision 1.18 by joko, Fri Dec 13 21:48:07 2002 UTC
# Line 3  Line 3 
3  #  $Id$  #  $Id$
4  #  #
5  #  $Log$  #  $Log$
6    #  Revision 1.18  2002/12/13 21:48:07  joko
7    #  + fix to 'sub sendQuery'
8    #
9    #  Revision 1.17  2002/12/12 02:51:09  joko
10    #  + cosmetics
11    #
12    #  Revision 1.16  2002/12/11 06:54:10  joko
13    #  + fix: encapsulated object-loading inside an 'eval'
14    #
15    #  Revision 1.15  2002/12/05 13:55:21  joko
16    #  + now utilizing 'object2hash' instead of 'var_deref'
17    #  + played around with having fresh-objects - no progress....
18    #
19  #  Revision 1.14  2002/12/05 09:40:30  jonen  #  Revision 1.14  2002/12/05 09:40:30  jonen
20  #  + added option->{destroy} at getObject for unloading all instance  #  + added option->{destroy} at getObject for unloading all instance
21  #  #
# Line 78  use Data::Dumper; Line 91  use Data::Dumper;
91  use libp qw( getNewPerlObjectByPkgName );  use libp qw( getNewPerlObjectByPkgName );
92  use Data::Storage::Result::Tangram;  use Data::Storage::Result::Tangram;
93  use Data::Compare::Struct qw( isEmpty );  use Data::Compare::Struct qw( isEmpty );
94  use Data::Transform::Deep qw( var_deref );  use Data::Transform::Deep qw( object2hash );
95  use Data::Transform::Encode qw( var2utf8 );  use Data::Transform::Encode qw( var2utf8 );
96    
97    
# Line 419  sub createCursor { Line 432  sub createCursor {
432    
433  sub createSet {  sub createSet {
434    my $self = shift;    my $self = shift;
435    #print "-" x 80, "\n";
436    #print Dumper(@_);
437    my @objects = @_;    my @objects = @_;
438    my $rh = Set::Object->new();    my $rh = Set::Object->new();
439    foreach (@objects) {    foreach (@objects) {
440      #print Dumper($_);      if (!isEmpty($_)) {
441      $rh->insert($_) if !isEmpty($_);  #print Dumper($_);
442          $rh->insert($_);
443        }
444    }    }
445    #print Dumper($rh->members());    #print Dumper($rh->members());
446    my $result = Data::Storage::Result::Tangram->new( RESULTHANDLE => $rh );    my $result = Data::Storage::Result::Tangram->new( RESULTHANDLE => $rh );
# Line 447  sub sendQuery { Line 464  sub sendQuery {
464      my $ident = $query->{criterias}->[0]->{val};      my $ident = $query->{criterias}->[0]->{val};
465  #print "load obj", "\n";  #print "load obj", "\n";
466      #return $self->createSet() if $ident == 5;      #return $self->createSet() if $ident == 5;
467        $self->{_COREHANDLE}->unload($ident);
468      my $object = $self->{_COREHANDLE}->load($ident);      my $object = $self->{_COREHANDLE}->load($ident);
469  #print "get id", "\n";  #print "get id", "\n";
470      my $oid = $self->{_COREHANDLE}->id($object);      my $oid = $self->{_COREHANDLE}->id($object);
471    #print Dumper($object);
472    #print "oid: $oid", "\n";
473      return $self->createSet($object);      return $self->createSet($object);
474      #return $self->createSet( $self->{COREHANDLE}->load('300090018') );      #return $self->createSet( $self->{COREHANDLE}->load('300090018') );
475    }    }
# Line 493  sub getObject { Line 513  sub getObject {
513    my $self = shift;    my $self = shift;
514    my $oid = shift;    my $oid = shift;
515    my $options = shift;    my $options = shift;
516    # TODO: create a deep_unload method  
517      # TODO: create a deep_unload method (currently _all_ objects are unloaded)
518    # unload($oid) will only unload object, not deep object hashes    # unload($oid) will only unload object, not deep object hashes
519    $self->{_COREHANDLE}->unload() if($options->{destroy});    $self->{_COREHANDLE}->unload() if ($options->{destroy});
520    
521    # TODO: review this    # TODO: review this
522    #if (!$self->{COREHANDLE}) { return; }    #if (!$self->{COREHANDLE}) { return; }
523    return $self->{_COREHANDLE}->load($oid);  
524      # TODO: review this
525      my $object = eval('$self->{_COREHANDLE}->load($oid);');
526      print $@, "\n" if $@;
527    
528      return $object if $object;
529  }  }
530    
531  sub getObjectAsHash {  sub getObjectAsHash {
# Line 506  sub getObjectAsHash { Line 533  sub getObjectAsHash {
533    my $oid = shift;    my $oid = shift;
534    my $options = shift;    my $options = shift;
535    my $obj = $self->getObject($oid, $options);    my $obj = $self->getObject($oid, $options);
536    my $deref = var_deref($obj);    
537    var2utf8($deref) if ($options->{utf8});    # build options (a callback to unload autovivified objects) for 'expand'
538    #$obj->clear_refs;    # TODO: use $logger to write to debug here!
539    #$self->{COREHANDLE}->unload($obj) if($options->{destroy});    my $cb; # = sub {};
540    #$obj->DESTROY;  =pod
541    #undef($obj) if($options->{destroy});    if ($options->{destroy}) {
542    return $deref;      $options->{cb}->{destroy} = sub {
543          print "================ DESTROY", "\n";
544          my $object = shift;
545          #print Dumper($object);
546          $self->{_COREHANDLE}->unload($object);
547          #undef($object);
548        };
549      }
550    =cut
551    
552      my $hash = object2hash($obj, $options);
553      #$options->{cb}->{destroy}->($obj);
554      #$self->{_COREHANDLE}->unload($obj);
555      
556      # convert values in hash to utf8 to be ready for (e.g.) encapsulation in XML
557      # now done in object2hash
558      #var2utf8($hash) if ($options->{utf8});
559      
560      # old (wrong) attempts to get rid of used instances, if requested
561        #$obj->clear_refs;
562        #$self->{COREHANDLE}->unload($obj) if($options->{destroy});
563        #$obj->DESTROY;
564        #undef($obj) if($options->{destroy});
565      
566      return $hash;
567  }  }
568    
569  sub getSchema {  sub getSchema {

Legend:
Removed from v.1.14  
changed lines
  Added in v.1.18

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