/[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.19 by joko, Mon Dec 16 06:46:09 2002 UTC
# Line 3  Line 3 
3  #  $Id$  #  $Id$
4  #  #
5  #  $Log$  #  $Log$
6    #  Revision 1.19  2002/12/16 06:46:09  joko
7    #  + attempt to introduce a generic '_patchSchema' - cancelled!
8    #
9    #  Revision 1.18  2002/12/13 21:48:07  joko
10    #  + fix to 'sub sendQuery'
11    #
12    #  Revision 1.17  2002/12/12 02:51:09  joko
13    #  + cosmetics
14    #
15    #  Revision 1.16  2002/12/11 06:54:10  joko
16    #  + fix: encapsulated object-loading inside an 'eval'
17    #
18    #  Revision 1.15  2002/12/05 13:55:21  joko
19    #  + now utilizing 'object2hash' instead of 'var_deref'
20    #  + played around with having fresh-objects - no progress....
21    #
22  #  Revision 1.14  2002/12/05 09:40:30  jonen  #  Revision 1.14  2002/12/05 09:40:30  jonen
23  #  + added option->{destroy} at getObject for unloading all instance  #  + added option->{destroy} at getObject for unloading all instance
24  #  #
# Line 78  use Data::Dumper; Line 94  use Data::Dumper;
94  use libp qw( getNewPerlObjectByPkgName );  use libp qw( getNewPerlObjectByPkgName );
95  use Data::Storage::Result::Tangram;  use Data::Storage::Result::Tangram;
96  use Data::Compare::Struct qw( isEmpty );  use Data::Compare::Struct qw( isEmpty );
97  use Data::Transform::Deep qw( var_deref );  use Data::Transform::Deep qw( object2hash );
98  use Data::Transform::Encode qw( var2utf8 );  use Data::Transform::Encode qw( var2utf8 );
99    
100    
# Line 108  sub _initSchema { Line 124  sub _initSchema {
124      $logger->error( __PACKAGE__ . "->_initSchema: No Schema available for $self->{schema}" );      $logger->error( __PACKAGE__ . "->_initSchema: No Schema available for $self->{schema}" );
125      return 0;      return 0;
126    }    }
127      #$self->_patchSchema();
128    return 1;    return 1;
129  }  }
130    
131    sub _patchSchema {
132      my $self = shift;
133      foreach (keys %{$schema_tangram->{classes}}) {
134        next if $schema_tangram->{classes}->{$_}->{abstract};
135        #next if ($_ ne 'TsBankAccount');
136        #$_ ne 'AbstractAccount' &&
137        print "class: $_", "\n";
138    #print Dumper($schema_tangram->{classes}->{$_});
139        # create new string property named 'guid'
140        my $tstring = Tangram::String->new();
141        $tstring->{name} = $tstring->{col} = 'guid';
142        # inject property into schema
143        #$schema_tangram->{classes}->{$_}->{root}->{SPECS}->[0]->{fields}->{string}->{$tstring->{name}} = $tstring;
144        print Dumper($schema_tangram->{classes}->{$_}->{root}->{SPECS}->[0]->{fields});
145      }
146    }
147    
148  sub connect {  sub connect {
149    
150      my $self = shift;      my $self = shift;
# Line 419  sub createCursor { Line 453  sub createCursor {
453    
454  sub createSet {  sub createSet {
455    my $self = shift;    my $self = shift;
456    #print "-" x 80, "\n";
457    #print Dumper(@_);
458    my @objects = @_;    my @objects = @_;
459    my $rh = Set::Object->new();    my $rh = Set::Object->new();
460    foreach (@objects) {    foreach (@objects) {
461      #print Dumper($_);      if (!isEmpty($_)) {
462      $rh->insert($_) if !isEmpty($_);  #print Dumper($_);
463          $rh->insert($_);
464        }
465    }    }
466    #print Dumper($rh->members());    #print Dumper($rh->members());
467    my $result = Data::Storage::Result::Tangram->new( RESULTHANDLE => $rh );    my $result = Data::Storage::Result::Tangram->new( RESULTHANDLE => $rh );
# Line 447  sub sendQuery { Line 485  sub sendQuery {
485      my $ident = $query->{criterias}->[0]->{val};      my $ident = $query->{criterias}->[0]->{val};
486  #print "load obj", "\n";  #print "load obj", "\n";
487      #return $self->createSet() if $ident == 5;      #return $self->createSet() if $ident == 5;
488        $self->{_COREHANDLE}->unload($ident);
489      my $object = $self->{_COREHANDLE}->load($ident);      my $object = $self->{_COREHANDLE}->load($ident);
490  #print "get id", "\n";  #print "get id", "\n";
491      my $oid = $self->{_COREHANDLE}->id($object);      my $oid = $self->{_COREHANDLE}->id($object);
492    #print Dumper($object);
493    #print "oid: $oid", "\n";
494      return $self->createSet($object);      return $self->createSet($object);
495      #return $self->createSet( $self->{COREHANDLE}->load('300090018') );      #return $self->createSet( $self->{COREHANDLE}->load('300090018') );
496    }    }
# Line 493  sub getObject { Line 534  sub getObject {
534    my $self = shift;    my $self = shift;
535    my $oid = shift;    my $oid = shift;
536    my $options = shift;    my $options = shift;
537    # TODO: create a deep_unload method  
538      # TODO: create a deep_unload method (currently _all_ objects are unloaded)
539    # unload($oid) will only unload object, not deep object hashes    # unload($oid) will only unload object, not deep object hashes
540    $self->{_COREHANDLE}->unload() if($options->{destroy});    $self->{_COREHANDLE}->unload() if ($options->{destroy});
541    
542    # TODO: review this    # TODO: review this
543    #if (!$self->{COREHANDLE}) { return; }    #if (!$self->{COREHANDLE}) { return; }
544    return $self->{_COREHANDLE}->load($oid);  
545      # TODO: review this
546      my $object = eval('$self->{_COREHANDLE}->load($oid);');
547      print $@, "\n" if $@;
548    
549      return $object if $object;
550  }  }
551    
552  sub getObjectAsHash {  sub getObjectAsHash {
# Line 506  sub getObjectAsHash { Line 554  sub getObjectAsHash {
554    my $oid = shift;    my $oid = shift;
555    my $options = shift;    my $options = shift;
556    my $obj = $self->getObject($oid, $options);    my $obj = $self->getObject($oid, $options);
557    my $deref = var_deref($obj);    
558    var2utf8($deref) if ($options->{utf8});    # build options (a callback to unload autovivified objects) for 'expand'
559    #$obj->clear_refs;    # TODO: use $logger to write to debug here!
560    #$self->{COREHANDLE}->unload($obj) if($options->{destroy});    my $cb; # = sub {};
561    #$obj->DESTROY;  =pod
562    #undef($obj) if($options->{destroy});    if ($options->{destroy}) {
563    return $deref;      $options->{cb}->{destroy} = sub {
564          print "================ DESTROY", "\n";
565          my $object = shift;
566          #print Dumper($object);
567          $self->{_COREHANDLE}->unload($object);
568          #undef($object);
569        };
570      }
571    =cut
572    
573      my $hash = object2hash($obj, $options);
574      #$options->{cb}->{destroy}->($obj);
575      #$self->{_COREHANDLE}->unload($obj);
576      
577      # convert values in hash to utf8 to be ready for (e.g.) encapsulation in XML
578      # now done in object2hash
579      #var2utf8($hash) if ($options->{utf8});
580      
581      # old (wrong) attempts to get rid of used instances, if requested
582        #$obj->clear_refs;
583        #$self->{COREHANDLE}->unload($obj) if($options->{destroy});
584        #$obj->DESTROY;
585        #undef($obj) if($options->{destroy});
586      
587      return $hash;
588  }  }
589    
590  sub getSchema {  sub getSchema {

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

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