/[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.13 by joko, Thu Dec 5 07:59:04 2002 UTC revision 1.21 by jonen, Mon Dec 16 22:20:49 2002 UTC
# Line 3  Line 3 
3  #  $Id$  #  $Id$
4  #  #
5  #  $Log$  #  $Log$
6    #  Revision 1.21  2002/12/16 22:20:49  jonen
7    #  + fixed bug at 'getObjectByGuid()'
8    #
9    #  Revision 1.20  2002/12/16 20:49:17  jonen
10    #  + added sub 'getObjectByGuid()'
11    #  + added functionality to use 'getObjectByGuid' at 'getObjectAsHash()'
12    #
13    #  Revision 1.19  2002/12/16 06:46:09  joko
14    #  + attempt to introduce a generic '_patchSchema' - cancelled!
15    #
16    #  Revision 1.18  2002/12/13 21:48:07  joko
17    #  + fix to 'sub sendQuery'
18    #
19    #  Revision 1.17  2002/12/12 02:51:09  joko
20    #  + cosmetics
21    #
22    #  Revision 1.16  2002/12/11 06:54:10  joko
23    #  + fix: encapsulated object-loading inside an 'eval'
24    #
25    #  Revision 1.15  2002/12/05 13:55:21  joko
26    #  + now utilizing 'object2hash' instead of 'var_deref'
27    #  + played around with having fresh-objects - no progress....
28    #
29    #  Revision 1.14  2002/12/05 09:40:30  jonen
30    #  + added option->{destroy} at getObject for unloading all instance
31    #
32  #  Revision 1.13  2002/12/05 07:59:04  joko  #  Revision 1.13  2002/12/05 07:59:04  joko
33  #  + now using Tie::SecureHash as a base for the COREHANDLE  #  + now using Tie::SecureHash as a base for the COREHANDLE
34  #  + former public COREHANDLE becomes private _COREHANDLE now  #  + former public COREHANDLE becomes private _COREHANDLE now
# Line 75  use Data::Dumper; Line 101  use Data::Dumper;
101  use libp qw( getNewPerlObjectByPkgName );  use libp qw( getNewPerlObjectByPkgName );
102  use Data::Storage::Result::Tangram;  use Data::Storage::Result::Tangram;
103  use Data::Compare::Struct qw( isEmpty );  use Data::Compare::Struct qw( isEmpty );
104  use Data::Transform::Deep qw( var_deref );  use Data::Transform::Deep qw( object2hash );
105  use Data::Transform::Encode qw( var2utf8 );  use Data::Transform::Encode qw( var2utf8 );
106    
107    
# Line 105  sub _initSchema { Line 131  sub _initSchema {
131      $logger->error( __PACKAGE__ . "->_initSchema: No Schema available for $self->{schema}" );      $logger->error( __PACKAGE__ . "->_initSchema: No Schema available for $self->{schema}" );
132      return 0;      return 0;
133    }    }
134      #$self->_patchSchema();
135    return 1;    return 1;
136  }  }
137    
138    sub _patchSchema {
139      my $self = shift;
140      foreach (keys %{$schema_tangram->{classes}}) {
141        next if $schema_tangram->{classes}->{$_}->{abstract};
142        #next if ($_ ne 'TsBankAccount');
143        #$_ ne 'AbstractAccount' &&
144        print "class: $_", "\n";
145    #print Dumper($schema_tangram->{classes}->{$_});
146        # create new string property named 'guid'
147        my $tstring = Tangram::String->new();
148        $tstring->{name} = $tstring->{col} = 'guid';
149        # inject property into schema
150        #$schema_tangram->{classes}->{$_}->{root}->{SPECS}->[0]->{fields}->{string}->{$tstring->{name}} = $tstring;
151        print Dumper($schema_tangram->{classes}->{$_}->{root}->{SPECS}->[0]->{fields});
152      }
153    }
154    
155  sub connect {  sub connect {
156    
157      my $self = shift;      my $self = shift;
# Line 416  sub createCursor { Line 460  sub createCursor {
460    
461  sub createSet {  sub createSet {
462    my $self = shift;    my $self = shift;
463    #print "-" x 80, "\n";
464    #print Dumper(@_);
465    my @objects = @_;    my @objects = @_;
466    my $rh = Set::Object->new();    my $rh = Set::Object->new();
467    foreach (@objects) {    foreach (@objects) {
468      #print Dumper($_);      if (!isEmpty($_)) {
469      $rh->insert($_) if !isEmpty($_);  #print Dumper($_);
470          $rh->insert($_);
471        }
472    }    }
473    #print Dumper($rh->members());    #print Dumper($rh->members());
474    my $result = Data::Storage::Result::Tangram->new( RESULTHANDLE => $rh );    my $result = Data::Storage::Result::Tangram->new( RESULTHANDLE => $rh );
# Line 444  sub sendQuery { Line 492  sub sendQuery {
492      my $ident = $query->{criterias}->[0]->{val};      my $ident = $query->{criterias}->[0]->{val};
493  #print "load obj", "\n";  #print "load obj", "\n";
494      #return $self->createSet() if $ident == 5;      #return $self->createSet() if $ident == 5;
495        $self->{_COREHANDLE}->unload($ident);
496      my $object = $self->{_COREHANDLE}->load($ident);      my $object = $self->{_COREHANDLE}->load($ident);
497  #print "get id", "\n";  #print "get id", "\n";
498      my $oid = $self->{_COREHANDLE}->id($object);      my $oid = $self->{_COREHANDLE}->id($object);
499    #print Dumper($object);
500    #print "oid: $oid", "\n";
501      return $self->createSet($object);      return $self->createSet($object);
502      #return $self->createSet( $self->{COREHANDLE}->load('300090018') );      #return $self->createSet( $self->{COREHANDLE}->load('300090018') );
503    }    }
# Line 489  sub createDb { Line 540  sub createDb {
540  sub getObject {  sub getObject {
541    my $self = shift;    my $self = shift;
542    my $oid = shift;    my $oid = shift;
543      my $options = shift;
544    
545      # TODO: create a deep_unload method (currently _all_ objects are unloaded)
546      # unload($oid) will only unload object, not deep object hashes
547      $self->{_COREHANDLE}->unload() if ($options->{destroy});
548    
549    # TODO: review this    # TODO: review this
550    #if (!$self->{COREHANDLE}) { return; }    #if (!$self->{COREHANDLE}) { return; }
551    return $self->{_COREHANDLE}->load($oid);  
552      # TODO: review this
553      my $object = eval('$self->{_COREHANDLE}->load($oid);');
554      print $@, "\n" if $@;
555    
556      return $object if $object;
557    }
558    
559    sub getObjectByGuid {
560      my $self = shift;
561      my $guid = shift;
562      my $options = shift;
563      
564      # Guid and Classname is needed
565      if(!$guid || !$options->{classname}) {
566        return;
567      }
568      
569      # TODO: create a deep_unload method (currently _all_ objects are unloaded)
570      # unload($oid) will only unload object, not deep object hashes
571      $self->{_COREHANDLE}->unload() if ($options->{destroy});
572    
573      # search for object with given Classname and Guid
574      my $obj_tmp = $self->{_COREHANDLE}->remote($options->{classname});
575      my @result = $self->{_COREHANDLE}->select($obj_tmp, $obj_tmp->{guid} eq $guid);
576      
577      # we searched for global unique identifer of some object,
578      # so it think we can trust there would be only one result
579      if($result[0]) {
580        return $result[0];
581      } else {
582        return "No Object with Classname $options->{classname} and GUID $options->{guid} found!";
583      }
584      
585  }  }
586    
587  sub getObjectAsHash {  sub getObjectAsHash {
588    my $self = shift;    my $self = shift;
589    my $oid = shift;    my $oid = shift;
590    my $options = shift;    my $options = shift;  
591    my $obj = $self->getObject($oid);    my $obj;
592    my $deref = var_deref($obj);    
593    var2utf8($deref) if ($options->{utf8});    if($options->{guid}) {
594    undef($obj) if($options->{destroy});      $obj = $self->getObjectByGuid($oid, $options);
595    return $deref;    } else {
596        $obj = $self->getObject($oid, $options);
597      }
598      
599      # build options (a callback to unload autovivified objects) for 'expand'
600      # TODO: use $logger to write to debug here!
601      my $cb; # = sub {};
602    =pod
603      if ($options->{destroy}) {
604        $options->{cb}->{destroy} = sub {
605          print "================ DESTROY", "\n";
606          my $object = shift;
607          #print Dumper($object);
608          $self->{_COREHANDLE}->unload($object);
609          #undef($object);
610        };
611      }
612    =cut
613    
614      my $hash = object2hash($obj, $options);
615      #$options->{cb}->{destroy}->($obj);
616      #$self->{_COREHANDLE}->unload($obj);
617      
618      # convert values in hash to utf8 to be ready for (e.g.) encapsulation in XML
619      # now done in object2hash
620      #var2utf8($hash) if ($options->{utf8});
621      
622      # old (wrong) attempts to get rid of used instances, if requested
623        #$obj->clear_refs;
624        #$self->{COREHANDLE}->unload($obj) if($options->{destroy});
625        #$obj->DESTROY;
626        #undef($obj) if($options->{destroy});
627      
628      return $hash;
629  }  }
630    
631  sub getSchema {  sub getSchema {

Legend:
Removed from v.1.13  
changed lines
  Added in v.1.21

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