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

Legend:
Removed from v.1.3  
changed lines
  Added in v.1.17

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