/[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.2 by joko, Thu Oct 17 00:10:05 2002 UTC revision 1.19 by joko, Mon Dec 16 06:46:09 2002 UTC
# Line 1  Line 1 
1  #################################  ############################################
2  #  #
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
23    #  + added option->{destroy} at getObject for unloading all instance
24    #
25    #  Revision 1.13  2002/12/05 07:59:04  joko
26    #  + now using Tie::SecureHash as a base for the COREHANDLE
27    #  + former public COREHANDLE becomes private _COREHANDLE now
28    #  + sub getCOREHANDLE
29    #
30    #  Revision 1.12  2002/12/04 11:34:49  joko
31    #  - $schema_tangram doesn't have to be in class?
32    #
33    #  Revision 1.11  2002/12/04 08:54:08  jonen
34    #  + untested bugfix: undef($object) after transform to hash at getObjectAsHash
35    #
36    #  Revision 1.10  2002/12/03 15:53:23  joko
37    #  + small bugfix regarding object hierarchy
38    #
39    #  Revision 1.9  2002/12/03 05:29:40  joko
40    #  + sub getObject
41    #  + sub getObjectAsHash
42    #
43    #  Revision 1.8  2002/12/01 22:25:51  joko
44    #  + now utilizing metadata from storage locator when connecting to DBI in "raw"-mode
45    #
46    #  Revision 1.7  2002/12/01 04:46:19  joko
47    #  + sub eraseAll
48    #
49    #  Revision 1.6  2002/11/29 05:02:30  joko
50    #  - sub getNewPerlObjectByPkgName (moved to libp.pm)
51    #  + sub getMetaInfo
52    #  - sub existsChildNode (moved to Abstract.pm)
53    #  + sub getListUnfiltered
54    #  + sub getListFiltered
55    #  + sub createCursor
56    #  + sub createSet
57    #  + sub sendQuery
58    #
59    #  Revision 1.5  2002/11/17 06:35:18  joko
60    #  + locator metadata can now be reached via ->{locator}
61    #  - getChildNodes is now wrapped via COREHANDLE
62    #
63    #  Revision 1.4  2002/10/25 11:44:44  joko
64    #  + sub _initSchema
65    #  + sub existsChildNode
66    #  + sub testIntegrity
67    #  + sub rebuildDbAndSchema
68    #
69    #  Revision 1.3  2002/10/17 03:56:55  joko
70    #  + bugfix: trapped eval error
71    #
72  #  Revision 1.2  2002/10/17 00:10:05  joko  #  Revision 1.2  2002/10/17 00:10:05  joko
73  #  + removed dependency from tsobj.pm, schema is now independent  #  + removed dependency from tsobj.pm, schema is now independent
74  #  + sub getNewPerlObjectByPkgName  #  + sub getNewPerlObjectByPkgName
# Line 12  Line 78 
78  #  Revision 1.1  2002/10/10 03:44:07  cvsjoko  #  Revision 1.1  2002/10/10 03:44:07  cvsjoko
79  #  + new  #  + new
80  #  #
81  #  ############################################
82  #################################  
83    
84  package Data::Storage::Handler::Tangram;  package Data::Storage::Handler::Tangram;
85    
86  use strict;  use strict;
87  use warnings;  use warnings;
88    
89    use base ("Data::Storage::Handler");
90  use base ("Data::Storage::Handler::Abstract");  use base ("Data::Storage::Handler::Abstract");
91    
92  use Tangram;  use Tangram;
93  use Data::Dumper;  use Data::Dumper;
94    use libp qw( getNewPerlObjectByPkgName );
95    use Data::Storage::Result::Tangram;
96    use Data::Compare::Struct qw( isEmpty );
97    use Data::Transform::Deep qw( object2hash );
98    use Data::Transform::Encode qw( var2utf8 );
99    
100    
101  # get logger instance  # get logger instance
102  my $logger = Log::Dispatch::Config->instance;  my $logger = Log::Dispatch::Config->instance;
103    
104    
105  our $metainfo = {  # this holds the complete instantiated schema from tangram
106    'disconnectMethod' => 'disconnect',  my $schema_tangram;
 };  
107    
108  sub getNewPerlObjectByPkgName {  sub getMetaInfo {
109    my $pkgname = shift;    my $self = shift;
110    my $args = shift;    $logger->debug( __PACKAGE__ . "->getMetaInfo()"  );
111    my $evstring = "use $pkgname;";    return {
112    eval($evstring);      'disconnectMethod' => 'disconnect',
113    return $pkgname->new($args);    };
114    }
115    
116    sub _initSchema {
117      my $self = shift;
118      $logger->debug( __PACKAGE__ . "->_initSchema()" );
119      #if (!$schema_tangram) {
120        my $obj = getNewPerlObjectByPkgName($self->{locator}->{schema}, { EXPORT_OBJECTS => $self->{locator}->{classnames}, want_transactions => $self->{locator}->{want_transactions} } );
121        $schema_tangram = $obj->getSchema();
122      #}
123      if (!$schema_tangram) {
124        $logger->error( __PACKAGE__ . "->_initSchema: No Schema available for $self->{schema}" );
125        return 0;
126      }
127      #$self->_patchSchema();
128      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 {
# Line 46  sub connect { Line 150  sub connect {
150      my $self = shift;      my $self = shift;
151            
152      my $dsn = shift;      my $dsn = shift;
153      $dsn ||= $self->{dbi}->{dsn};      $dsn ||= $self->{locator}->{dbi}->{dsn};
154            
155      $logger->debug( __PACKAGE__ . "->connect( dsn $dsn )" );      $logger->debug( __PACKAGE__ . "->connect( dsn $dsn )" );
156            
# Line 59  sub connect { Line 163  sub connect {
163  #      return;  #      return;
164  #    }  #    }
165    
166      my $obj = getNewPerlObjectByPkgName($self->{schema}, { EXPORT_OBJECTS => $self->{classnames} } );      return unless $self->_initSchema();
167      $self->{schema_tangram} = $obj->getSchema();  
168            # create the main tangram storage object
169      #$self->{COREHANDLE} = Tangram::Relational->connect( $schema, $dsn );      #$self->{COREHANDLE} = Tangram::Relational->connect( $schema, $dsn );
170      $self->{COREHANDLE} = Tangram::Relational->connect( $self->{schema_tangram}, $dsn );      $self->{_COREHANDLE} = Tangram::Relational->connect( $schema_tangram, $dsn );
171    
172    #print "connect", "\n";
173    #my $core = $self->{_COREHANDLE};
174    #print Dumper($core);
175        
176        # some attempts for configuring the wrapped underlying dbi.....
177      #$self->{STORAGEHANDLE_UNDERLYING} = $self->getUnderlyingStorage();      #$self->{STORAGEHANDLE_UNDERLYING} = $self->getUnderlyingStorage();
178      #$self->{STORAGEHANDLE_UNDERLYING}->_configureCOREHANDLE();      #$self->{STORAGEHANDLE_UNDERLYING}->_configureCOREHANDLE();
179      #$self->_configureUnderlyingStorage;      #$self->_configureUnderlyingStorage;
180        
181        # ..... encapsulation wins!
182      $self->configureCOREHANDLE();      $self->configureCOREHANDLE();
183    
184      $self->{locator}->{status}->{connected} = 1;
185    
186      return 1;
187    
188  }  }
189    
190  sub getChildNodes {  sub getChildNodes {
# Line 77  sub getChildNodes { Line 192  sub getChildNodes {
192    my $self = shift;    my $self = shift;
193    my @nodes;    my @nodes;
194    
195      $logger->debug( __PACKAGE__ . "->getChildNodes()" );
196    
197    # 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
198    #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} });
199    #my $loc = new Data::Storage::Locator( type => "DBI", COREHANDLE => $self->{COREHANDLE}->{db} );    #my $loc = new Data::Storage::Locator( type => "DBI", COREHANDLE => $self->{COREHANDLE}->{db} );
200      
201      # todo: should we retrieve information from the schema here
202      # rather than poorly getting table names from underlying dbi?
203    my $storage = $self->_getSubLayerHandle();    my $storage = $self->_getSubLayerHandle();
204      @nodes = @{$storage->getChildNodes()};
205    #$storage->_configureCOREHANDLE();    #$storage->_configureCOREHANDLE();
206    #print "getchildnodes\n";
207    #print Dumper($self);
208    #if (my $result = $self->sendCommand( 'SHOW TABLES;' ) ) {    #if (my $result = $self->sendCommand( 'SHOW TABLES;' ) ) {
   if (my $result = $storage->sendCommand( 'SHOW TABLES;' ) ) {  
     while ( my $row = $result->_getNextEntry() ) {  
       push @nodes, $row;  
     }  
   }  
209        
210    $storage->disconnect();    # TODO: REVIEW
211      #$storage->disconnect();
212      
213      $self->{meta}->{childnodes} = \@nodes;
214        
215    return \@nodes;    return \@nodes;
216    
217  }  }
218    
219    
220    sub testIntegrity {
221    
222      my $self = shift;
223    
224      $logger->debug( __PACKAGE__ . "->testIntegrity()" );
225    
226      # 1st test: are there tables?
227      if (!$self->getChildNodes()) {
228        $logger->warning( __PACKAGE__ . "->testIntegrity no childnodes exist" );
229        return;
230      }
231    
232      # 2nd test: is there a table named "Tangram"?
233      if (!$self->existsChildNode("Tangram")) {
234        $logger->warning( __PACKAGE__ . "->testIntegrity childnode \"Tangram\" doesn't exist" );
235        return;
236      }
237    
238      $self->{locator}->{status}->{integrity} = 1;
239      return 1;
240    
241    }
242    
243    
244  sub _getSubLayerHandle {  sub _getSubLayerHandle {
245        
246    my $self = shift;    my $self = shift;
247        
248    use Data::Dumper;    $logger->debug( __PACKAGE__ . "->_getSubLayerHandle()" );
249    
250    #print Dumper($self);    #print Dumper($self);
251      
252    # hack, make more generic!    # hack, make more generic!
253    if (!$self->{STORAGE_SUBLAYER}) {    if (!$self->{dataStorageLayer}) {
254      my $loc = Data::Storage::Locator->new( type => "DBI", dbi => $self->{dbi}, COREHANDLE => $self->{COREHANDLE}->{db} );      $logger->debug( __PACKAGE__ . "->_getSubLayerHandle() creating new dataStorageLayer" );
255      $self->{STORAGE_SUBLAYER} = Data::Storage->new( $loc, { protected => 1 } );      #my $loc = Data::Storage::Locator->new( type => "DBI", dbi => $self->{dbi}, COREHANDLE => $self->{COREHANDLE}->{db} );
256        my $loc = Data::Storage::Locator->new( { type => "DBI", dbi => $self->{locator}->{dbi} } );
257        $self->{dataStorageLayer} = Data::Storage->new( $loc, { protected => 1 } );
258      #$self->{STORAGE_UNDER_THE_HOOD}->{STORAGEHANDLE}->_configureCOREHANDLE();      #$self->{STORAGE_UNDER_THE_HOOD}->{STORAGEHANDLE}->_configureCOREHANDLE();
259      #$self->{STORAGE_UNDER_THE_HOOD}->_configureCOREHANDLE();      #$self->{STORAGE_UNDER_THE_HOOD}->_configureCOREHANDLE();
260    }    }
261        
262    #print Dumper($self->{STORAGE_UNDER_THE_HOOD});    #print Dumper($self->{STORAGE_UNDER_THE_HOOD});
263        
264    return $self->{STORAGE_SUBLAYER};    return $self->{dataStorageLayer};
265        
266  }  }
267    
268  sub _configureUnderlyingStorage {  sub _configureUnderlyingStorage {
269        
270    my $self = shift;    my $self = shift;
271    
272      $logger->debug( __PACKAGE__ . "->_configureUnderlyingStorage" );
273    
274    $self->_configureCOREHANDLE_DBI();    $self->_configureCOREHANDLE_DBI();
275    return;    return;
276        
277    foreach my $key (keys %{$self->{dbi}}) {    foreach my $key (keys %{$self->{dbi}}) {
278      my $val = $self->{dbi}->{$key};      my $val = $self->{dbi}->{$key};
279      print "entry: $key; $val", "\n";      print "entry: $key; $val", "\n";
280      $self->{COREHANDLE}->{db}->{$key} = $val;      $self->{_COREHANDLE}->{db}->{$key} = $val;
281    }    }
282    #print Dumper($self->{COREHANDLE}->{db});    #print Dumper($self->{COREHANDLE}->{db});
283  }  }
# Line 137  sub configureCOREHANDLE { Line 287  sub configureCOREHANDLE {
287    
288    my $self = shift;    my $self = shift;
289    
290    $logger->debug( __PACKAGE__ . "->_configureCOREHANDLE" );    $logger->debug( __PACKAGE__ . "->configureCOREHANDLE" );
291    
292    #my $subLayer = $self->_getSubLayerHandle();    #my $subLayer = $self->_getSubLayerHandle();
293    
294    # apply configured modifications    # apply configured modifications
295      if (exists $self->{dbi}->{trace_level} && exists $self->{dbi}->{trace_file}) {      if (exists $self->{dbi}->{trace_level} && exists $self->{dbi}->{trace_file}) {
296        $self->{COREHANDLE}->{db}->trace($self->{dbi}->{trace_level}, $self->{dbi}->{trace_file});        $self->{_COREHANDLE}->{db}->trace($self->{dbi}->{trace_level}, $self->{dbi}->{trace_file});
297      }      }
298      if (exists $self->{dbi}->{RaiseError}) {      if (exists $self->{dbi}->{RaiseError}) {
299        $self->{COREHANDLE}->{db}->{RaiseError} = $self->{dbi}->{RaiseError};        $self->{_COREHANDLE}->{db}->{RaiseError} = $self->{dbi}->{RaiseError};
300      }      }
301      if (exists $self->{dbi}->{PrintError}) {      if (exists $self->{dbi}->{PrintError}) {
302        $self->{COREHANDLE}->{db}->{PrintError} = $self->{dbi}->{PrintError};        $self->{_COREHANDLE}->{db}->{PrintError} = $self->{dbi}->{PrintError};
303      }      }
304      if (exists $self->{dbi}->{HandleError}) {      if (exists $self->{dbi}->{HandleError}) {
305        $self->{COREHANDLE}->{db}->{HandleError} = $self->{dbi}->{HandleError};        $self->{_COREHANDLE}->{db}->{HandleError} = $self->{dbi}->{HandleError};
306      }      }
307    
308  }  }
309    
310  sub deploySchema {  sub deploySchema {
311    my $self = shift;    my $self = shift;
312    #my $dsn = $self->{locator}->{dbi}->{dsn};    my $args = shift;
313    my $dsn = $self->{dbi}->{dsn};    
314      my $dsn = $self->{locator}->{dbi}->{dsn};
315    
316      $logger->debug( __PACKAGE__ . "->deploySchema( dsn $dsn )" );
317    
318    my $ok;    my $ok;
319    if ( my $dbh = DBI->connect($dsn, '', '', {    if ( my $dbh = DBI->connect($dsn, '', '', $self->{locator}->{dbi} ) ) {
320                                                        PrintError => 0,      return unless $self->_initSchema();
321                                                      } ) ) {      $ok = Tangram::Relational->deploy($schema_tangram, $dbh );
     $ok = Tangram::Relational->deploy($self->{schema}, $dbh );  
322      $dbh->disconnect();      $dbh->disconnect();
323    }    }
324    return $ok;    return $ok;
325  }  }
326    
327  sub retreatSchema {  sub retreatSchema {
328    print "retreat\n";  
329    my $self = shift;    my $self = shift;
330    #my $dsn = $self->{locator}->{dbi}->{dsn};    my $dsn = $self->{locator}->{dbi}->{dsn};
331    my $dsn = $self->{dbi}->{dsn};  
332      $logger->debug( __PACKAGE__ . "->retreatSchema( dsn $dsn )" );
333    
334    my $ok;    my $ok;
335    if ( my $dbh = DBI->connect($dsn, '', '', {    if ( my $dbh = DBI->connect($dsn, '', '', $self->{locator}->{dbi} ) ) {
336                                                        PrintError => 0,  
337                                                      } ) ) {      return unless $self->_initSchema();
338      $ok = Tangram::Relational->retreat($self->{schema}, $dbh );      
339        #use Data::Dumper; print Dumper($self);
340        $self->{dataStorageLayer}->removeLogDispatchHandler("Tangram11");
341        
342        $ok = Tangram::Relational->retreat($schema_tangram, $dbh );
343    
344        # answer "$ok=2" means "maybe" for now - we have to patch this to a constant here because...
345        # - ... Tangram::Relational->retreat doesn't seem to return a valid status
346        # - possible improvement:
347        #   - test this by checking for count of tables in database
348        #   - problem with this: there may be some left not having been included to the schema
349        #   - maybe better: use "->getChildNodes"?
350        $ok = 2;
351    
352      $dbh->disconnect();      $dbh->disconnect();
353    
354    }    }
355    return $ok;    return $ok;
356  }  }
357    
358    sub rebuildDbAndSchema {
359      my $self = shift;
360      $logger->info( __PACKAGE__ . "->rebuildDbAndSchema()" );
361      my @results;
362    
363      # sum up results (bool (0/1)) in array
364      push @results, $self->retreatSchema();
365      push @results, $self->{dataStorageLayer}->dropDb();
366      push @results, $self->{dataStorageLayer}->createDb();
367      push @results, $self->deploySchema();
368    
369      # scan array for "bad ones"
370      my $res = 1;
371      map {
372        $res = 0 if (!$_);
373      } @results;
374      
375      return $res;
376    }
377    
378    sub getListUnfiltered {
379      my $self = shift;
380      my $nodename = shift;
381      my @results;
382      $logger->debug( __PACKAGE__ . "->getListUnfiltered( nodename => '" . $nodename . "' )" );
383      # get set of objects from odbms by object name
384      my $object_set = $self->{_COREHANDLE}->remote($nodename);
385      @results = $self->{_COREHANDLE}->select($object_set);
386      return \@results;
387    }
388    
389    sub getListFiltered {
390      my $self = shift;
391    
392      # redirect to unfiltered mode
393      #return $self->getListUnfiltered(@_);
394    
395      my $nodename = shift;
396      my $filters = shift;
397      my @results;
398      $logger->debug( __PACKAGE__ . "->getListFiltered( nodename => '" . $nodename . "' )" );
399    
400      #print Dumper($filters);
401      
402      my @tfilters;
403      
404      foreach my $filter (@$filters) {
405      
406        # get filter - TODO: for each filter
407        #my $filter = $filters->[0];
408      
409        # build filter
410        my $lexpr = $filter->{key};
411        #my $op = $filter->{op};
412        my $op = '=';
413        my $rexpr = $filter->{val};
414        my $tight = 100;
415        
416      #  my $tfilter = Tangram::Filter->new(
417      #    expr => "t1.$lexpr $op '$rexpr'",
418      #    tight => $tight,
419      #    objects => $objects,
420      #  );
421      
422        # HACK: build eval-string (sorry) to get filtered list - please give advice here
423        push @tfilters, '$remote->{' . $filter->{key} . '}' . " $filter->{op} '$filter->{val}'";
424    
425      }
426    
427      my $tfilter = join(' & ', @tfilters);
428    
429      # get set of objects from odbms by object name
430      my $remote = $self->{_COREHANDLE}->remote($nodename);
431      
432      # was:
433      #@results = $self->{COREHANDLE}->select($object_set, $tfilter);
434    
435      # is:
436      # HACK: build eval-string (sorry) to get filtered list - please give advice here
437      my $evalstring = 'return $self->{_COREHANDLE}->select($remote, ' . $tfilter . ');';
438      
439      # get filtered list/set
440      @results = eval($evalstring);
441      die $@ if $@;
442      
443      return \@results;
444    }
445    
446    sub createCursor {
447      my $self = shift;
448      my $node = shift;
449      my $cmdHandle = $self->{_COREHANDLE}->cursor($node);
450      my $result = Data::Storage::Result::Tangram->new( RESULTHANDLE => $cmdHandle );
451      return $result;
452    }
453    
454    sub createSet {
455      my $self = shift;
456    #print "-" x 80, "\n";
457    #print Dumper(@_);
458      my @objects = @_;
459      my $rh = Set::Object->new();
460      foreach (@objects) {
461        if (!isEmpty($_)) {
462    #print Dumper($_);
463          $rh->insert($_);
464        }
465      }
466      #print Dumper($rh->members());
467      my $result = Data::Storage::Result::Tangram->new( RESULTHANDLE => $rh );
468      return $result;
469    }
470    
471    sub sendQuery {
472      my $self = shift;
473      my $query = shift;
474      #my $sql = "SELECT cs FROM $self->{metainfo}->{$descent}->{node} WHERE $self->{metainfo}->{$descent}->{IdentProvider}->{arg}='$self->{entry}->{source}->{ident}';";
475      #my $result = $self->{metainfo}->{$descent}->{storage}->sendCommand($sql);
476    
477      #print Dumper($query);
478    
479      # HACK: special case: querying by id does not translate into a common tangram query
480      # just load the object by given id(ent)
481      if ($query->{criterias}->[0]->{key} eq 'id' && $query->{criterias}->[0]->{op} eq 'eq') {
482        #print "LOAD!!!", "\n";
483        #exit;
484        #return Set::Object->new( $self->{COREHANDLE}->load($query->{criterias}->[0]->{val}) );
485        my $ident = $query->{criterias}->[0]->{val};
486    #print "load obj", "\n";
487        #return $self->createSet() if $ident == 5;
488        $self->{_COREHANDLE}->unload($ident);
489        my $object = $self->{_COREHANDLE}->load($ident);
490    #print "get id", "\n";
491        my $oid = $self->{_COREHANDLE}->id($object);
492    #print Dumper($object);
493    #print "oid: $oid", "\n";
494        return $self->createSet($object);
495        #return $self->createSet( $self->{COREHANDLE}->load('300090018') );
496      }
497    
498      die("This should not be reached for now - redirect to \$self->getListFiltered() here!");
499    
500      # TODO: do a common tangram query here
501    
502      my @crits;
503      foreach (@{$query->{criterias}}) {
504        my $op = '';
505        $op = '=' if lc $_->{op} eq 'eq';
506        push @crits, "$_->{key}$op'$_->{val}'";
507      }
508      my $subnodes = {};
509      map { $subnodes->{$_}++ } @{$query->{subnodes}};
510      # HACK: this is hardcoded ;(    expand possibilities!
511      #my $crit = join(' AND ', @crits);
512      #my $sql = hash2Sql($query->{node}, $subnodes, 'SELECT', $crit);
513      #return $self->sendCommand($sql);
514      #my $h = $self->{COREHANDLE}->remote($query->{node});
515      #my $res = $self->{COREHANDLE}->select($h, $h->{);
516      return $self->createCursor($query->{node});
517    }
518    
519    sub eraseAll {
520      my $self = shift;
521      my $classname = shift;
522      my $remote = $self->{_COREHANDLE}->remote($classname);
523      my @objs = $self->{_COREHANDLE}->select($remote);
524      $self->{_COREHANDLE}->erase(@objs);
525    }
526    
527    sub createDb {
528      my $self = shift;
529      my $storage = $self->_getSubLayerHandle();
530      return $storage->createDb();
531    }
532    
533    sub getObject {
534      my $self = shift;
535      my $oid = shift;
536      my $options = shift;
537    
538      # TODO: create a deep_unload method (currently _all_ objects are unloaded)
539      # unload($oid) will only unload object, not deep object hashes
540      $self->{_COREHANDLE}->unload() if ($options->{destroy});
541    
542      # TODO: review this
543      #if (!$self->{COREHANDLE}) { return; }
544    
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 {
553      my $self = shift;
554      my $oid = shift;
555      my $options = shift;
556      my $obj = $self->getObject($oid, $options);
557      
558      # build options (a callback to unload autovivified objects) for 'expand'
559      # TODO: use $logger to write to debug here!
560      my $cb; # = sub {};
561    =pod
562      if ($options->{destroy}) {
563        $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 {
591      return $schema_tangram;
592    }
593    
594    sub getCOREHANDLE {
595      my $self = shift;
596      return $self->{_COREHANDLE};
597    }
598    
599  1;  1;

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

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