/[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.5 by joko, Sun Nov 17 06:35:18 2002 UTC revision 1.26 by joko, Thu Jan 30 22:29:47 2003 UTC
# Line 1  Line 1 
1  #################################  ############################################
2  #  #
3  #  $Id$  #  $Id$
4  #  #
5  #  $Log$  #  $Log$
6    #  Revision 1.26  2003/01/30 22:29:47  joko
7    #  + fixed module usage (removed dependency on 'libp.pm')
8    #
9    #  Revision 1.25  2003/01/19 02:30:05  joko
10    #  + fix: modified call to '_initSchema'
11    #
12    #  Revision 1.24  2002/12/22 14:13:01  joko
13    #  + sub dropDb
14    #
15    #  Revision 1.23  2002/12/19 16:31:53  joko
16    #  +- renamed sub to 'rebuildDb'
17    #
18    #  Revision 1.22  2002/12/18 22:28:16  jonen
19    #  + added extended logging at 'getObjectByGuid()'
20    #
21    #  Revision 1.21  2002/12/16 22:20:49  jonen
22    #  + fixed bug at 'getObjectByGuid()'
23    #
24    #  Revision 1.20  2002/12/16 20:49:17  jonen
25    #  + added sub 'getObjectByGuid()'
26    #  + added functionality to use 'getObjectByGuid' at 'getObjectAsHash()'
27    #
28    #  Revision 1.19  2002/12/16 06:46:09  joko
29    #  + attempt to introduce a generic '_patchSchema' - cancelled!
30    #
31    #  Revision 1.18  2002/12/13 21:48:07  joko
32    #  + fix to 'sub sendQuery'
33    #
34    #  Revision 1.17  2002/12/12 02:51:09  joko
35    #  + cosmetics
36    #
37    #  Revision 1.16  2002/12/11 06:54:10  joko
38    #  + fix: encapsulated object-loading inside an 'eval'
39    #
40    #  Revision 1.15  2002/12/05 13:55:21  joko
41    #  + now utilizing 'object2hash' instead of 'var_deref'
42    #  + played around with having fresh-objects - no progress....
43    #
44    #  Revision 1.14  2002/12/05 09:40:30  jonen
45    #  + added option->{destroy} at getObject for unloading all instance
46    #
47    #  Revision 1.13  2002/12/05 07:59:04  joko
48    #  + now using Tie::SecureHash as a base for the COREHANDLE
49    #  + former public COREHANDLE becomes private _COREHANDLE now
50    #  + sub getCOREHANDLE
51    #
52    #  Revision 1.12  2002/12/04 11:34:49  joko
53    #  - $schema_tangram doesn't have to be in class?
54    #
55    #  Revision 1.11  2002/12/04 08:54:08  jonen
56    #  + untested bugfix: undef($object) after transform to hash at getObjectAsHash
57    #
58    #  Revision 1.10  2002/12/03 15:53:23  joko
59    #  + small bugfix regarding object hierarchy
60    #
61    #  Revision 1.9  2002/12/03 05:29:40  joko
62    #  + sub getObject
63    #  + sub getObjectAsHash
64    #
65    #  Revision 1.8  2002/12/01 22:25:51  joko
66    #  + now utilizing metadata from storage locator when connecting to DBI in "raw"-mode
67    #
68    #  Revision 1.7  2002/12/01 04:46:19  joko
69    #  + sub eraseAll
70    #
71    #  Revision 1.6  2002/11/29 05:02:30  joko
72    #  - sub getNewPerlObjectByPkgName (moved to libp.pm)
73    #  + sub getMetaInfo
74    #  - sub existsChildNode (moved to Abstract.pm)
75    #  + sub getListUnfiltered
76    #  + sub getListFiltered
77    #  + sub createCursor
78    #  + sub createSet
79    #  + sub sendQuery
80    #
81  #  Revision 1.5  2002/11/17 06:35:18  joko  #  Revision 1.5  2002/11/17 06:35:18  joko
82  #  + locator metadata can now be reached via ->{locator}  #  + locator metadata can now be reached via ->{locator}
83  #  - getChildNodes is now wrapped via COREHANDLE  #  - getChildNodes is now wrapped via COREHANDLE
# Line 25  Line 100 
100  #  Revision 1.1  2002/10/10 03:44:07  cvsjoko  #  Revision 1.1  2002/10/10 03:44:07  cvsjoko
101  #  + new  #  + new
102  #  #
103  #  ############################################
104  #################################  
105    
106  package Data::Storage::Handler::Tangram;  package Data::Storage::Handler::Tangram;
107    
108  use strict;  use strict;
109  use warnings;  use warnings;
110    
111    use base ("Data::Storage::Handler");
112  use base ("Data::Storage::Handler::Abstract");  use base ("Data::Storage::Handler::Abstract");
113    
114  use Tangram;  use Tangram;
115  use Data::Dumper;  use Data::Dumper;
116    use DesignPattern::Object;
117    use Data::Storage::Result::Tangram;
118    use Data::Compare::Struct qw( isEmpty );
119    use Data::Transform::Deep qw( object2hash );
120    use Data::Transform::Encode qw( var2utf8 );
121    
122  # get logger instance  # get logger instance
123  my $logger = Log::Dispatch::Config->instance;  my $logger = Log::Dispatch::Config->instance;
124    
125    
126  our $metainfo = {  # this holds the complete instantiated schema from tangram
127    'disconnectMethod' => 'disconnect',  my $schema_tangram;
 };  
128    
129  sub getNewPerlObjectByPkgName {  sub getMetaInfo {
130    my $pkgname = shift;    my $self = shift;
131    my $args = shift;    $logger->debug( __PACKAGE__ . "->getMetaInfo()"  );
132    $logger->debug( __PACKAGE__ . "->getNewPerlObjectByPkgName( pkgname $pkgname args $args )" );    return {
133    my $evstring = "use $pkgname;";      'disconnectMethod' => 'disconnect',
134    eval($evstring);    };
   $@ && $logger->error( __PACKAGE__ . ':' . __LINE__ . " Error in eval $evstring: " .  $@ );  
   return $pkgname->new($args);  
135  }  }
136    
137  sub _initSchema {  sub _initSchema {
138    my $self = shift;    my $self = shift;
139    $logger->debug( __PACKAGE__ . "->_initSchema()" );    $logger->debug( __PACKAGE__ . "->_initSchema()" );
140    #if (!$self->{schema_tangram}) {    #if (!$schema_tangram) {
141      my $obj = getNewPerlObjectByPkgName($self->{locator}->{schema}, { EXPORT_OBJECTS => $self->{locator}->{classnames}, want_transactions => $self->{locator}->{want_transactions} } );      #my $obj = getNewPerlObjectByPkgName($self->{locator}->{schema}, { EXPORT_OBJECTS => $self->{locator}->{classnames}, want_transactions => $self->{locator}->{want_transactions} } );
142      $self->{schema_tangram} = $obj->getSchema();      my $obj = DesignPattern::Object->fromPackage($self->{locator}->{schema}, { 'EXPORT_OBJECTS' => $self->{locator}->{classnames}, 'want_transactions' => $self->{locator}->{want_transactions} } );
143        $schema_tangram = $obj->getSchema();
144    #}    #}
145    if (!$self->{schema_tangram}) {    if (!$schema_tangram) {
146      $logger->error( __PACKAGE__ . "->_initSchema: No Schema available for $self->{schema}" );      $logger->error( __PACKAGE__ . "->_initSchema: No Schema available for $self->{schema}" );
147      return 0;      return 0;
148    }    }
149      #$self->_patchSchema();
150    return 1;    return 1;
151  }  }
152    
153    sub _patchSchema {
154      my $self = shift;
155      foreach (keys %{$schema_tangram->{classes}}) {
156        next if $schema_tangram->{classes}->{$_}->{abstract};
157        #next if ($_ ne 'TsBankAccount');
158        #$_ ne 'AbstractAccount' &&
159        print "class: $_", "\n";
160    #print Dumper($schema_tangram->{classes}->{$_});
161        # create new string property named 'guid'
162        my $tstring = Tangram::String->new();
163        $tstring->{name} = $tstring->{col} = 'guid';
164        # inject property into schema
165        #$schema_tangram->{classes}->{$_}->{root}->{SPECS}->[0]->{fields}->{string}->{$tstring->{name}} = $tstring;
166        print Dumper($schema_tangram->{classes}->{$_}->{root}->{SPECS}->[0]->{fields});
167      }
168    }
169    
170  sub connect {  sub connect {
171    
172      my $self = shift;      my $self = shift;
173            
174      my $dsn = shift;      my $dsn = shift;
175    
176    #print Dumper($self);
177    #exit;
178    
179        # TODO: re-enable
180      $dsn ||= $self->{locator}->{dbi}->{dsn};      $dsn ||= $self->{locator}->{dbi}->{dsn};
       
181      $logger->debug( __PACKAGE__ . "->connect( dsn $dsn )" );      $logger->debug( __PACKAGE__ . "->connect( dsn $dsn )" );
182            
183      #my $storage = Tangram::Relational->connect( $schema, $dsn );      #my $storage = Tangram::Relational->connect( $schema, $dsn );
# Line 88  sub connect { Line 189  sub connect {
189  #      return;  #      return;
190  #    }  #    }
191    
192      return unless $self->_initSchema();      #return unless $self->_initSchema();
193        $self->_initSchema();
194    
195        # create the main tangram storage object
196      #$self->{COREHANDLE} = Tangram::Relational->connect( $schema, $dsn );      #$self->{COREHANDLE} = Tangram::Relational->connect( $schema, $dsn );
197      $self->{COREHANDLE} = Tangram::Relational->connect( $self->{schema_tangram}, $dsn );      $self->{_COREHANDLE} = Tangram::Relational->connect( $schema_tangram, $dsn );
198    
199    #print "connect", "\n";
200    #my $core = $self->{_COREHANDLE};
201    #print Dumper($core);
202        
203        # some attempts for configuring the wrapped underlying dbi.....
204      #$self->{STORAGEHANDLE_UNDERLYING} = $self->getUnderlyingStorage();      #$self->{STORAGEHANDLE_UNDERLYING} = $self->getUnderlyingStorage();
205      #$self->{STORAGEHANDLE_UNDERLYING}->_configureCOREHANDLE();      #$self->{STORAGEHANDLE_UNDERLYING}->_configureCOREHANDLE();
206      #$self->_configureUnderlyingStorage;      #$self->_configureUnderlyingStorage;
207        
208        # ..... encapsulation wins!
209      $self->configureCOREHANDLE();      $self->configureCOREHANDLE();
210    
211    $self->{locator}->{status}->{connected} = 1;    $self->{locator}->{status}->{connected} = 1;
# Line 114  sub getChildNodes { Line 224  sub getChildNodes {
224    # create new DBI - Data::Storage - object from already connected DBI::db - handle inside the current COREHANDLE    # create new DBI - Data::Storage - object from already connected DBI::db - handle inside the current COREHANDLE
225    #my $loc = new Data::Storage::Locator( type => "DBI", dbi => { db => $self->{COREHANDLE}->{db} });    #my $loc = new Data::Storage::Locator( type => "DBI", dbi => { db => $self->{COREHANDLE}->{db} });
226    #my $loc = new Data::Storage::Locator( type => "DBI", COREHANDLE => $self->{COREHANDLE}->{db} );    #my $loc = new Data::Storage::Locator( type => "DBI", COREHANDLE => $self->{COREHANDLE}->{db} );
227      
228      # todo: should we retrieve information from the schema here
229      # rather than poorly getting table names from underlying dbi?
230    my $storage = $self->_getSubLayerHandle();    my $storage = $self->_getSubLayerHandle();
231    @nodes = @{$storage->getChildNodes()};    @nodes = @{$storage->getChildNodes()};
232    #$storage->_configureCOREHANDLE();    #$storage->_configureCOREHANDLE();
# Line 121  sub getChildNodes { Line 234  sub getChildNodes {
234  #print Dumper($self);  #print Dumper($self);
235    #if (my $result = $self->sendCommand( 'SHOW TABLES;' ) ) {    #if (my $result = $self->sendCommand( 'SHOW TABLES;' ) ) {
236        
237    $storage->disconnect();    # TODO: REVIEW
238      #$storage->disconnect();
239        
240    $self->{meta}->{childnodes} = \@nodes;    $self->{meta}->{childnodes} = \@nodes;
241        
# Line 130  sub getChildNodes { Line 244  sub getChildNodes {
244  }  }
245    
246    
 sub existsChildNode {  
   my $self = shift;  
   my $nodename = shift;  
   $logger->debug( __PACKAGE__ . "->getChildNode( nodename $nodename )" );  
   $self->getChildNodes() unless $self->{meta}->{childnodes};  
   #print Dumper($self->{meta}->{childnodes});  
   return grep $nodename, @{$self->{meta}->{childnodes}};  
 }  
   
   
247  sub testIntegrity {  sub testIntegrity {
248    
249    my $self = shift;    my $self = shift;
# Line 200  sub _configureUnderlyingStorage { Line 304  sub _configureUnderlyingStorage {
304    foreach my $key (keys %{$self->{dbi}}) {    foreach my $key (keys %{$self->{dbi}}) {
305      my $val = $self->{dbi}->{$key};      my $val = $self->{dbi}->{$key};
306      print "entry: $key; $val", "\n";      print "entry: $key; $val", "\n";
307      $self->{COREHANDLE}->{db}->{$key} = $val;      $self->{_COREHANDLE}->{db}->{$key} = $val;
308    }    }
309    #print Dumper($self->{COREHANDLE}->{db});    #print Dumper($self->{COREHANDLE}->{db});
310  }  }
# Line 213  sub configureCOREHANDLE { Line 317  sub configureCOREHANDLE {
317    $logger->debug( __PACKAGE__ . "->configureCOREHANDLE" );    $logger->debug( __PACKAGE__ . "->configureCOREHANDLE" );
318    
319    #my $subLayer = $self->_getSubLayerHandle();    #my $subLayer = $self->_getSubLayerHandle();
320      #print Dumper($self);
321      #exit;
322    
323    # apply configured modifications    # apply configured modifications
324      if (exists $self->{dbi}->{trace_level} && exists $self->{dbi}->{trace_file}) {      if (exists $self->{dbi}->{trace_level} && exists $self->{dbi}->{trace_file}) {
325        $self->{COREHANDLE}->{db}->trace($self->{dbi}->{trace_level}, $self->{dbi}->{trace_file});        $self->{_COREHANDLE}->{db}->trace($self->{dbi}->{trace_level}, $self->{dbi}->{trace_file});
326      }      }
327      if (exists $self->{dbi}->{RaiseError}) {      if (exists $self->{dbi}->{RaiseError}) {
328        $self->{COREHANDLE}->{db}->{RaiseError} = $self->{dbi}->{RaiseError};        $self->{_COREHANDLE}->{db}->{RaiseError} = $self->{dbi}->{RaiseError};
329      }      }
330      if (exists $self->{dbi}->{PrintError}) {      if (exists $self->{dbi}->{PrintError}) {
331        $self->{COREHANDLE}->{db}->{PrintError} = $self->{dbi}->{PrintError};        $self->{_COREHANDLE}->{db}->{PrintError} = $self->{dbi}->{PrintError};
332      }      }
333      if (exists $self->{dbi}->{HandleError}) {      if (exists $self->{dbi}->{HandleError}) {
334        $self->{COREHANDLE}->{db}->{HandleError} = $self->{dbi}->{HandleError};        $self->{_COREHANDLE}->{db}->{HandleError} = $self->{dbi}->{HandleError};
335      }      }
336    
337  }  }
# Line 235  sub deploySchema { Line 341  sub deploySchema {
341    my $args = shift;    my $args = shift;
342        
343    my $dsn = $self->{locator}->{dbi}->{dsn};    my $dsn = $self->{locator}->{dbi}->{dsn};
   #my $dsn = $self->{dbi}->{dsn};  
344    
345    $logger->debug( __PACKAGE__ . "->deploySchema( dsn $dsn )" );    $logger->debug( __PACKAGE__ . "->deploySchema( dsn $dsn )" );
346    
347    my $ok;    my $ok;
348    # TODO: is this DBI->connect okay here like it is? regarding errors.....???    if ( my $dbh = DBI->connect($dsn, '', '', $self->{locator}->{dbi} ) ) {
   if ( my $dbh = DBI->connect($dsn, '', '', {  
                                                       PrintError => 0,  
                                                     } ) ) {  
   
349      return unless $self->_initSchema();      return unless $self->_initSchema();
350            $ok = Tangram::Relational->deploy($schema_tangram, $dbh );
     $ok = Tangram::Relational->deploy($self->{schema_tangram}, $dbh );  
351      $dbh->disconnect();      $dbh->disconnect();
352    }    }
353    return $ok;    return $ok;
# Line 257  sub retreatSchema { Line 357  sub retreatSchema {
357    
358    my $self = shift;    my $self = shift;
359    my $dsn = $self->{locator}->{dbi}->{dsn};    my $dsn = $self->{locator}->{dbi}->{dsn};
   #my $dsn = $self->{dbi}->{dsn};  
360    
361    $logger->debug( __PACKAGE__ . "->retreatSchema( dsn $dsn )" );    $logger->debug( __PACKAGE__ . "->retreatSchema( dsn $dsn )" );
362    
363    my $ok;    my $ok;
364    if ( my $dbh = DBI->connect($dsn, '', '', {    if ( my $dbh = DBI->connect($dsn, '', '', $self->{locator}->{dbi} ) ) {
                                                       #PrintError => 0,  
                                                       #RaiseError => 0,  
                                                     } ) ) {  
365    
366      return unless $self->_initSchema();      return unless $self->_initSchema();
367            
368      #use Data::Dumper; print Dumper($self);      #use Data::Dumper; print Dumper($self);
369      $self->{dataStorageLayer}->removeLogDispatchHandler("Tangram11");      $self->{dataStorageLayer}->removeLogDispatchHandler("Tangram11");
370            
371      $ok = Tangram::Relational->retreat($self->{schema_tangram}, $dbh );      $ok = Tangram::Relational->retreat($schema_tangram, $dbh );
372      $ok = 2;    # answer is "maybe" for now since Tangram::Relational->retreat doesn't seem to return a valid status  
373                      # idea: test this by checking for count of tables in database -      # answer "$ok=2" means "maybe" for now - we have to patch this to a constant here because...
374                      #          problem with this: there may be some left not having been included to the schema      # - ... Tangram::Relational->retreat doesn't seem to return a valid status
375        # - possible improvement:
376        #   - test this by checking for count of tables in database
377        #   - problem with this: there may be some left not having been included to the schema
378        #   - maybe better: use "->getChildNodes"?
379        $ok = 2;
380    
381      $dbh->disconnect();      $dbh->disconnect();
382    
383    }    }
384    return $ok;    return $ok;
385  }  }
386    
387  sub rebuildDbAndSchema {  sub rebuildDb {
388    my $self = shift;    my $self = shift;
389    $logger->info( __PACKAGE__ . "->rebuildDbAndSchema()" );    $logger->info( __PACKAGE__ . "->rebuildDb()" );
390    my @results;    my @results;
391    
392    # sum up results (bool (0/1)) in array    # sum up results (bool (0/1)) in array
# Line 301  sub rebuildDbAndSchema { Line 404  sub rebuildDbAndSchema {
404    return $res;    return $res;
405  }  }
406    
407    sub getListUnfiltered {
408      my $self = shift;
409      my $nodename = shift;
410      my @results;
411      $logger->debug( __PACKAGE__ . "->getListUnfiltered( nodename => '" . $nodename . "' )" );
412      # get set of objects from odbms by object name
413      my $object_set = $self->{_COREHANDLE}->remote($nodename);
414      @results = $self->{_COREHANDLE}->select($object_set);
415      return \@results;
416    }
417    
418    sub getListFiltered {
419      my $self = shift;
420    
421      # redirect to unfiltered mode
422      #return $self->getListUnfiltered(@_);
423    
424      my $nodename = shift;
425      my $filters = shift;
426      my @results;
427      $logger->debug( __PACKAGE__ . "->getListFiltered( nodename => '" . $nodename . "' )" );
428    
429      #print Dumper($filters);
430      
431      my @tfilters;
432      
433      foreach my $filter (@$filters) {
434      
435        # get filter - TODO: for each filter
436        #my $filter = $filters->[0];
437      
438        # build filter
439        my $lexpr = $filter->{key};
440        #my $op = $filter->{op};
441        my $op = '=';
442        my $rexpr = $filter->{val};
443        my $tight = 100;
444        
445      #  my $tfilter = Tangram::Filter->new(
446      #    expr => "t1.$lexpr $op '$rexpr'",
447      #    tight => $tight,
448      #    objects => $objects,
449      #  );
450      
451        # HACK: build eval-string (sorry) to get filtered list - please give advice here
452        push @tfilters, '$remote->{' . $filter->{key} . '}' . " $filter->{op} '$filter->{val}'";
453    
454      }
455    
456      my $tfilter = join(' & ', @tfilters);
457    
458      # get set of objects from odbms by object name
459      my $remote = $self->{_COREHANDLE}->remote($nodename);
460      
461      # was:
462      #@results = $self->{COREHANDLE}->select($object_set, $tfilter);
463    
464      # is:
465      # HACK: build eval-string (sorry) to get filtered list - please give advice here
466      my $evalstring = 'return $self->{_COREHANDLE}->select($remote, ' . $tfilter . ');';
467      
468      # get filtered list/set
469      @results = eval($evalstring);
470      die $@ if $@;
471      
472      return \@results;
473    }
474    
475    sub createCursor {
476      my $self = shift;
477      my $node = shift;
478      my $cmdHandle = $self->{_COREHANDLE}->cursor($node);
479      my $result = Data::Storage::Result::Tangram->new( RESULTHANDLE => $cmdHandle );
480      return $result;
481    }
482    
483    sub createSet {
484      my $self = shift;
485    #print "-" x 80, "\n";
486    #print Dumper(@_);
487      my @objects = @_;
488      my $rh = Set::Object->new();
489      foreach (@objects) {
490        if (!isEmpty($_)) {
491    #print Dumper($_);
492          $rh->insert($_);
493        }
494      }
495      #print Dumper($rh->members());
496      my $result = Data::Storage::Result::Tangram->new( RESULTHANDLE => $rh );
497      return $result;
498    }
499    
500    sub sendQuery {
501      my $self = shift;
502      my $query = shift;
503      #my $sql = "SELECT cs FROM $self->{metainfo}->{$descent}->{node} WHERE $self->{metainfo}->{$descent}->{IdentProvider}->{arg}='$self->{entry}->{source}->{ident}';";
504      #my $result = $self->{metainfo}->{$descent}->{storage}->sendCommand($sql);
505    
506      #print Dumper($query);
507    
508      # HACK: special case: querying by id does not translate into a common tangram query
509      # just load the object by given id(ent)
510      if ($query->{criterias}->[0]->{key} eq 'id' && $query->{criterias}->[0]->{op} eq 'eq') {
511        #print "LOAD!!!", "\n";
512        #exit;
513        #return Set::Object->new( $self->{COREHANDLE}->load($query->{criterias}->[0]->{val}) );
514        my $ident = $query->{criterias}->[0]->{val};
515    #print "load obj", "\n";
516        #return $self->createSet() if $ident == 5;
517        $self->{_COREHANDLE}->unload($ident);
518        my $object = $self->{_COREHANDLE}->load($ident);
519    #print "get id", "\n";
520        my $oid = $self->{_COREHANDLE}->id($object);
521    #print Dumper($object);
522    #print "oid: $oid", "\n";
523        return $self->createSet($object);
524        #return $self->createSet( $self->{COREHANDLE}->load('300090018') );
525      }
526    
527      die("This should not be reached for now - redirect to \$self->getListFiltered() here!");
528    
529      # TODO: do a common tangram query here
530    
531      my @crits;
532      foreach (@{$query->{criterias}}) {
533        my $op = '';
534        $op = '=' if lc $_->{op} eq 'eq';
535        push @crits, "$_->{key}$op'$_->{val}'";
536      }
537      my $subnodes = {};
538      map { $subnodes->{$_}++ } @{$query->{subnodes}};
539      # HACK: this is hardcoded ;(    expand possibilities!
540      #my $crit = join(' AND ', @crits);
541      #my $sql = hash2Sql($query->{node}, $subnodes, 'SELECT', $crit);
542      #return $self->sendCommand($sql);
543      #my $h = $self->{COREHANDLE}->remote($query->{node});
544      #my $res = $self->{COREHANDLE}->select($h, $h->{);
545      return $self->createCursor($query->{node});
546    }
547    
548    sub eraseAll {
549      my $self = shift;
550      my $classname = shift;
551      my $remote = $self->{_COREHANDLE}->remote($classname);
552      my @objs = $self->{_COREHANDLE}->select($remote);
553      $self->{_COREHANDLE}->erase(@objs);
554    }
555    
556    sub createDb {
557      my $self = shift;
558      my $storage = $self->_getSubLayerHandle();
559      return $storage->createDb();
560    }
561    
562    sub getObject {
563      my $self = shift;
564      my $oid = shift;
565      my $options = shift;
566    
567      # TODO: create a deep_unload method (currently _all_ objects are unloaded)
568      # unload($oid) will only unload object, not deep object hashes
569      $self->{_COREHANDLE}->unload() if ($options->{destroy});
570    
571      # TODO: review this
572      #if (!$self->{COREHANDLE}) { return; }
573    
574      # TODO: review this
575      my $object = eval('$self->{_COREHANDLE}->load($oid);');
576      print $@, "\n" if $@;
577    
578      return $object if $object;
579    }
580    
581    sub getObjectByGuid {
582      my $self = shift;
583      my $guid = shift;
584      my $options = shift;
585      
586      # Guid and Classname is needed
587      if(!$guid || !$options->{classname}) {
588       $logger->error( __PACKAGE__ . "->getObjectByGuid: No 'guid' OR no Classname in options hash was given but needed!" );
589        return;
590      }
591      
592      # TODO: create a deep_unload method (currently _all_ objects are unloaded)
593      # unload($oid) will only unload object, not deep object hashes
594      $self->{_COREHANDLE}->unload() if ($options->{destroy});
595    
596      # search for object with given Classname and Guid
597      my $obj_tmp = $self->{_COREHANDLE}->remote($options->{classname});
598      my @result = $self->{_COREHANDLE}->select($obj_tmp, $obj_tmp->{guid} eq $guid);
599      
600      # we searched for global unique identifer of some object,
601      # so I think we can trust there would be only one result
602      if($result[0]) {
603        return $result[0];
604      } else {
605        $logger->error( __PACKAGE__ . "->getObjectByGuid: No Object with Classname $options->{classname} and GUID $guid found!" );
606        return;
607      }
608      
609    }
610    
611    sub getObjectAsHash {
612      my $self = shift;
613      my $oid = shift;
614      my $options = shift;  
615      my $obj;
616      
617      if($options->{guid}) {
618        $obj = $self->getObjectByGuid($oid, $options);
619      } else {
620        $obj = $self->getObject($oid, $options);
621      }
622      
623      # build options (a callback to unload autovivified objects) for 'expand'
624      # TODO: use $logger to write to debug here!
625      my $cb; # = sub {};
626    =pod
627      if ($options->{destroy}) {
628        $options->{cb}->{destroy} = sub {
629          print "================ DESTROY", "\n";
630          my $object = shift;
631          #print Dumper($object);
632          $self->{_COREHANDLE}->unload($object);
633          #undef($object);
634        };
635      }
636    =cut
637    
638      my $hash = object2hash($obj, $options);
639      #$options->{cb}->{destroy}->($obj);
640      #$self->{_COREHANDLE}->unload($obj);
641      
642      # convert values in hash to utf8 to be ready for (e.g.) encapsulation in XML
643      # now done in object2hash
644      #var2utf8($hash) if ($options->{utf8});
645      
646      # old (wrong) attempts to get rid of used instances, if requested
647        #$obj->clear_refs;
648        #$self->{COREHANDLE}->unload($obj) if($options->{destroy});
649        #$obj->DESTROY;
650        #undef($obj) if($options->{destroy});
651      
652      return $hash;
653    }
654    
655    sub getSchema {
656      return $schema_tangram;
657    }
658    
659    sub getCOREHANDLE {
660      my $self = shift;
661      return $self->{_COREHANDLE};
662    }
663    
664    sub dropDb {
665      my $self = shift;
666      my $storage = $self->_getSubLayerHandle();
667      return $storage->dropDb();
668    }
669    
670    sub testAvailability {
671      my $self = shift;
672      my $storage = $self->_getSubLayerHandle();
673      return $storage->testAvailability();
674    }
675    
676  1;  1;
677    __END__

Legend:
Removed from v.1.5  
changed lines
  Added in v.1.26

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