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

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

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