/[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.27 by joko, Fri Jan 31 06:30:59 2003 UTC revision 1.31 by joko, Sat Apr 5 21:24:09 2003 UTC
# Line 3  Line 3 
3  #  $Id$  #  $Id$
4  #  #
5  #  $Log$  #  $Log$
6    #  Revision 1.31  2003/04/05 21:24:09  joko
7    #  modified 'sub getChildNodes': now contains code from 'querySchema'
8    #
9    #  Revision 1.30  2003/03/27 15:31:14  joko
10    #  fixes to modules regarding new namespace(s) below Data::Mungle::*
11    #
12    #  Revision 1.29  2003/02/21 01:47:18  joko
13    #  purged old code
14    #  minor cosmetics
15    #
16    #  Revision 1.28  2003/02/20 20:20:26  joko
17    #  tried to get auto-disconnect working again - failed with that
18    #
19  #  Revision 1.27  2003/01/31 06:30:59  joko  #  Revision 1.27  2003/01/31 06:30:59  joko
20  #  + enabled 'sendQuery'  #  + enabled 'sendQuery'
21  #  #
# Line 41  Line 54 
54  #  + fix: encapsulated object-loading inside an 'eval'  #  + fix: encapsulated object-loading inside an 'eval'
55  #  #
56  #  Revision 1.15  2002/12/05 13:55:21  joko  #  Revision 1.15  2002/12/05 13:55:21  joko
57  #  + now utilizing 'object2hash' instead of 'var_deref'  #  + now utilizing 'expand' instead of 'var_deref'
58  #  + played around with having fresh-objects - no progress....  #  + played around with having fresh-objects - no progress....
59  #  #
60  #  Revision 1.14  2002/12/05 09:40:30  jonen  #  Revision 1.14  2002/12/05 09:40:30  jonen
# Line 114  use warnings; Line 127  use warnings;
127  use base ("Data::Storage::Handler");  use base ("Data::Storage::Handler");
128  use base ("Data::Storage::Handler::Abstract");  use base ("Data::Storage::Handler::Abstract");
129    
130  use Tangram;  
131  use Data::Dumper;  use Data::Dumper;
132    use Tangram;
133    
134  use DesignPattern::Object;  use DesignPattern::Object;
135  use Data::Storage::Result::Tangram;  use Data::Storage::Result::Tangram;
136  use Data::Compare::Struct qw( isEmpty );  use Data::Mungle::Compare::Struct qw( isEmpty );
137  use Data::Transform::Deep qw( object2hash );  use Data::Mungle::Transform::Deep qw( expand );
 use Data::Transform::Encode qw( var2utf8 );  
138    
139  # get logger instance  # get logger instance
140  my $logger = Log::Dispatch::Config->instance;  my $logger = Log::Dispatch::Config->instance;
# Line 220  sub connect { Line 234  sub connect {
234  sub getChildNodes {  sub getChildNodes {
235    
236    my $self = shift;    my $self = shift;
237    my @nodes;    my $mode = shift;
238      $mode ||= 'core';
239      
240      $logger->debug( __PACKAGE__ . "->getChildNodes($mode)" );
241    
242    $logger->debug( __PACKAGE__ . "->getChildNodes()" );    if ($mode eq 'core') {
243    
244    # create new DBI - Data::Storage - object from already connected DBI::db - handle inside the current COREHANDLE      my @nodes;
245    #my $loc = new Data::Storage::Locator( type => "DBI", dbi => { db => $self->{COREHANDLE}->{db} });      
246    #my $loc = new Data::Storage::Locator( type => "DBI", COREHANDLE => $self->{COREHANDLE}->{db} );      # create new DBI - Data::Storage - object from already connected DBI::db - handle inside the current COREHANDLE
247        #my $loc = new Data::Storage::Locator( type => "DBI", dbi => { db => $self->{COREHANDLE}->{db} });
248        #my $loc = new Data::Storage::Locator( type => "DBI", COREHANDLE => $self->{COREHANDLE}->{db} );
249        
250        # todo: should we retrieve information from the schema here
251        # rather than poorly getting table names from underlying dbi?
252        my $storage = $self->_getSubLayerHandle();
253        @nodes = @{$storage->getChildNodes()};
254        #$storage->_configureCOREHANDLE();
255      #print "getchildnodes\n";
256      #print Dumper($self);
257        #if (my $result = $self->sendCommand( 'SHOW TABLES;' ) ) {
258        
259        # TODO: REVIEW
260        #$storage->disconnect();
261        
262        $self->{meta}->{childnodes} = \@nodes;
263    
264        return \@nodes;
265        
266    # todo: should we retrieve information from the schema here    } elsif ($mode eq 'root') {
267    # rather than poorly getting table names from underlying dbi?      
268    my $storage = $self->_getSubLayerHandle();      # FIXME: this will return *all* known classes to 'Class::Tangram',
269    @nodes = @{$storage->getChildNodes()};      # which might not be what you expect since more than one instance
270    #$storage->_configureCOREHANDLE();      # of Tangram may be in memory and Class::Tangram seems to
271  #print "getchildnodes\n";      # offer no methods to determine this or filter its result(s) according
272  #print Dumper($self);      # to a specific database.
273    #if (my $result = $self->sendCommand( 'SHOW TABLES;' ) ) {      my @object_names = Class::Tangram::known_classes();
274        my @concret_names;
275        my $o_cnt;
276        foreach (sort @object_names) {
277          push @concret_names, $_  if (!Class::Tangram::class_is_abstract($_));
278          $o_cnt++;
279        }
280        
281    # TODO: REVIEW      my $result = {
282    #$storage->disconnect();        all => \@object_names,
283          concrete => \@concret_names,
284        };
285        return $result;
286        
287    $self->{meta}->{childnodes} = \@nodes;    }
288        
   return \@nodes;  
289    
290  }  }
291    
   
292  sub testIntegrity {  sub testIntegrity {
293    
294    my $self = shift;    my $self = shift;
# Line 636  sub getObjectAsHash { Line 678  sub getObjectAsHash {
678    # build options (a callback to unload autovivified objects) for 'expand'    # build options (a callback to unload autovivified objects) for 'expand'
679    # TODO: use $logger to write to debug here!    # TODO: use $logger to write to debug here!
680    my $cb; # = sub {};    my $cb; # = sub {};
681    
682      # deactivated way to get rid of used instances, if requested
683  =pod  =pod
684    if ($options->{destroy}) {      if ($options->{destroy}) {
685      $options->{cb}->{destroy} = sub {        $options->{cb}->{destroy} = sub {
686        print "================ DESTROY", "\n";          print "================ DESTROY", "\n";
687        my $object = shift;          my $object = shift;
688        #print Dumper($object);          #print Dumper($object);
689        $self->{_COREHANDLE}->unload($object);          $self->{_COREHANDLE}->unload($object);
690        #undef($object);          #undef($object);
691      };        };
692    }      }
693  =cut  =cut
694    
695    my $hash = object2hash($obj, $options);    my $hash = expand($obj, $options);
696    #$options->{cb}->{destroy}->($obj);  
697    #$self->{_COREHANDLE}->unload($obj);    # old (unsuccessful) attempts to get rid of used instances, if requested
698      
699    # convert values in hash to utf8 to be ready for (e.g.) encapsulation in XML      # V1:
700    # now done in object2hash      #$options->{cb}->{destroy}->($obj);
701    #var2utf8($hash) if ($options->{utf8});      #$self->{_COREHANDLE}->unload($obj);
702        
703    # old (wrong) attempts to get rid of used instances, if requested      # V2:
704      #$obj->clear_refs;      #$obj->clear_refs;
705      #$self->{COREHANDLE}->unload($obj) if($options->{destroy});      #$self->{COREHANDLE}->unload($obj) if($options->{destroy});
706      #$obj->DESTROY;      #$obj->DESTROY;
# Line 686  sub testAvailability { Line 730  sub testAvailability {
730    return $storage->testAvailability();    return $storage->testAvailability();
731  }  }
732    
733    sub disconnect2 {
734      my $self = shift;
735      my $storage = $self->_getSubLayerHandle();
736      print "DISC!", "\n";
737    
738      my $storage_ll = $storage->{_COREHANDLE};
739      $storage_ll->disconnect();
740      
741      print Dumper($storage);
742      exit;
743      
744      #$self->{_COREHANDLE}
745      #$storage->disconnect();
746      $self->{dataStorageLayer}->disconnect();
747    }
748    
749  1;  1;
750  __END__  __END__

Legend:
Removed from v.1.27  
changed lines
  Added in v.1.31

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