/[cvs]/nfo/perl/libs/Data/Storage/Handler/Tangram.pm
ViewVC logotype

Annotation of /nfo/perl/libs/Data/Storage/Handler/Tangram.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.20 - (hide annotations)
Mon Dec 16 20:49:17 2002 UTC (21 years, 6 months ago) by jonen
Branch: MAIN
Changes since 1.19: +40 -3 lines
+ added sub 'getObjectByGuid()'
+ added functionality to use 'getObjectByGuid' at 'getObjectAsHash()'

1 joko 1.6 ############################################
2 cvsjoko 1.1 #
3 jonen 1.20 # $Id: Tangram.pm,v 1.19 2002/12/16 06:46:09 joko Exp $
4 joko 1.2 #
5     # $Log: Tangram.pm,v $
6 jonen 1.20 # Revision 1.19 2002/12/16 06:46:09 joko
7     # + attempt to introduce a generic '_patchSchema' - cancelled!
8     #
9 joko 1.19 # Revision 1.18 2002/12/13 21:48:07 joko
10     # + fix to 'sub sendQuery'
11     #
12 joko 1.18 # Revision 1.17 2002/12/12 02:51:09 joko
13     # + cosmetics
14     #
15 joko 1.17 # Revision 1.16 2002/12/11 06:54:10 joko
16     # + fix: encapsulated object-loading inside an 'eval'
17     #
18 joko 1.16 # 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 joko 1.15 # Revision 1.14 2002/12/05 09:40:30 jonen
23     # + added option->{destroy} at getObject for unloading all instance
24     #
25 jonen 1.14 # 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 joko 1.13 # Revision 1.12 2002/12/04 11:34:49 joko
31     # - $schema_tangram doesn't have to be in class?
32     #
33 joko 1.12 # Revision 1.11 2002/12/04 08:54:08 jonen
34     # + untested bugfix: undef($object) after transform to hash at getObjectAsHash
35     #
36 jonen 1.11 # Revision 1.10 2002/12/03 15:53:23 joko
37     # + small bugfix regarding object hierarchy
38     #
39 joko 1.10 # Revision 1.9 2002/12/03 05:29:40 joko
40     # + sub getObject
41     # + sub getObjectAsHash
42     #
43 joko 1.9 # 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 joko 1.8 # Revision 1.7 2002/12/01 04:46:19 joko
47     # + sub eraseAll
48     #
49 joko 1.7 # 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 joko 1.6 # 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 joko 1.5 # Revision 1.4 2002/10/25 11:44:44 joko
64     # + sub _initSchema
65     # + sub existsChildNode
66     # + sub testIntegrity
67     # + sub rebuildDbAndSchema
68     #
69 joko 1.4 # Revision 1.3 2002/10/17 03:56:55 joko
70     # + bugfix: trapped eval error
71     #
72 joko 1.3 # Revision 1.2 2002/10/17 00:10:05 joko
73     # + removed dependency from tsobj.pm, schema is now independent
74     # + sub getNewPerlObjectByPkgName
75     # + sub deploySchema
76     # + sub retreatSchema
77     #
78 joko 1.2 # Revision 1.1 2002/10/10 03:44:07 cvsjoko
79     # + new
80 cvsjoko 1.1 #
81 joko 1.6 ############################################
82    
83 cvsjoko 1.1
84     package Data::Storage::Handler::Tangram;
85    
86     use strict;
87     use warnings;
88    
89 joko 1.13 use base ("Data::Storage::Handler");
90 cvsjoko 1.1 use base ("Data::Storage::Handler::Abstract");
91    
92     use Tangram;
93     use Data::Dumper;
94 joko 1.6 use libp qw( getNewPerlObjectByPkgName );
95     use Data::Storage::Result::Tangram;
96     use Data::Compare::Struct qw( isEmpty );
97 joko 1.15 use Data::Transform::Deep qw( object2hash );
98 joko 1.9 use Data::Transform::Encode qw( var2utf8 );
99    
100 cvsjoko 1.1
101     # get logger instance
102     my $logger = Log::Dispatch::Config->instance;
103    
104    
105 joko 1.12 # this holds the complete instantiated schema from tangram
106     my $schema_tangram;
107    
108 joko 1.6 sub getMetaInfo {
109     my $self = shift;
110     $logger->debug( __PACKAGE__ . "->getMetaInfo()" );
111     return {
112     'disconnectMethod' => 'disconnect',
113     };
114 joko 1.2 }
115    
116 joko 1.4 sub _initSchema {
117     my $self = shift;
118     $logger->debug( __PACKAGE__ . "->_initSchema()" );
119 joko 1.12 #if (!$schema_tangram) {
120 joko 1.5 my $obj = getNewPerlObjectByPkgName($self->{locator}->{schema}, { EXPORT_OBJECTS => $self->{locator}->{classnames}, want_transactions => $self->{locator}->{want_transactions} } );
121 joko 1.12 $schema_tangram = $obj->getSchema();
122 joko 1.4 #}
123 joko 1.12 if (!$schema_tangram) {
124 joko 1.4 $logger->error( __PACKAGE__ . "->_initSchema: No Schema available for $self->{schema}" );
125     return 0;
126     }
127 joko 1.19 #$self->_patchSchema();
128 joko 1.4 return 1;
129 joko 1.19 }
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 joko 1.4 }
147    
148 cvsjoko 1.1 sub connect {
149    
150     my $self = shift;
151    
152     my $dsn = shift;
153 joko 1.5 $dsn ||= $self->{locator}->{dbi}->{dsn};
154 cvsjoko 1.1
155 joko 1.2 $logger->debug( __PACKAGE__ . "->connect( dsn $dsn )" );
156 cvsjoko 1.1
157     #my $storage = Tangram::Relational->connect( $schema, $dsn );
158     #my $storage = Tangram::mysql->connect( $schema, $dsn );
159     #$storage = Tangram::Relational->connect( Project->schema, $dsn );
160    
161     # if (!testDsn($dsn)) {
162     # croak("Database at \"$dsn\" is not available");
163     # return;
164     # }
165    
166 joko 1.4 return unless $self->_initSchema();
167    
168 joko 1.6 # create the main tangram storage object
169 joko 1.2 #$self->{COREHANDLE} = Tangram::Relational->connect( $schema, $dsn );
170 joko 1.13 $self->{_COREHANDLE} = Tangram::Relational->connect( $schema_tangram, $dsn );
171    
172     #print "connect", "\n";
173     #my $core = $self->{_COREHANDLE};
174     #print Dumper($core);
175 cvsjoko 1.1
176 joko 1.6 # some attempts for configuring the wrapped underlying dbi.....
177 cvsjoko 1.1 #$self->{STORAGEHANDLE_UNDERLYING} = $self->getUnderlyingStorage();
178     #$self->{STORAGEHANDLE_UNDERLYING}->_configureCOREHANDLE();
179     #$self->_configureUnderlyingStorage;
180 joko 1.6
181     # ..... encapsulation wins!
182 cvsjoko 1.1 $self->configureCOREHANDLE();
183    
184 joko 1.5 $self->{locator}->{status}->{connected} = 1;
185    
186 joko 1.4 return 1;
187    
188 cvsjoko 1.1 }
189    
190     sub getChildNodes {
191    
192     my $self = shift;
193     my @nodes;
194    
195 joko 1.4 $logger->debug( __PACKAGE__ . "->getChildNodes()" );
196    
197 cvsjoko 1.1 # 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} });
199     #my $loc = new Data::Storage::Locator( type => "DBI", COREHANDLE => $self->{COREHANDLE}->{db} );
200 joko 1.6
201     # todo: should we retrieve information from the schema here
202     # rather than poorly getting table names from underlying dbi?
203 cvsjoko 1.1 my $storage = $self->_getSubLayerHandle();
204 joko 1.5 @nodes = @{$storage->getChildNodes()};
205 cvsjoko 1.1 #$storage->_configureCOREHANDLE();
206 joko 1.5 #print "getchildnodes\n";
207     #print Dumper($self);
208 cvsjoko 1.1 #if (my $result = $self->sendCommand( 'SHOW TABLES;' ) ) {
209    
210 joko 1.8 # TODO: REVIEW
211     #$storage->disconnect();
212 cvsjoko 1.1
213 joko 1.4 $self->{meta}->{childnodes} = \@nodes;
214    
215 cvsjoko 1.1 return \@nodes;
216    
217     }
218    
219    
220 joko 1.4 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 joko 1.5 $self->{locator}->{status}->{integrity} = 1;
239 joko 1.4 return 1;
240    
241     }
242    
243    
244 cvsjoko 1.1 sub _getSubLayerHandle {
245    
246     my $self = shift;
247    
248 joko 1.4 $logger->debug( __PACKAGE__ . "->_getSubLayerHandle()" );
249    
250 cvsjoko 1.1 #print Dumper($self);
251 joko 1.5
252 cvsjoko 1.1 # hack, make more generic!
253 joko 1.4 if (!$self->{dataStorageLayer}) {
254     $logger->debug( __PACKAGE__ . "->_getSubLayerHandle() creating new dataStorageLayer" );
255     #my $loc = Data::Storage::Locator->new( type => "DBI", dbi => $self->{dbi}, COREHANDLE => $self->{COREHANDLE}->{db} );
256 joko 1.5 my $loc = Data::Storage::Locator->new( { type => "DBI", dbi => $self->{locator}->{dbi} } );
257 joko 1.4 $self->{dataStorageLayer} = Data::Storage->new( $loc, { protected => 1 } );
258 cvsjoko 1.1 #$self->{STORAGE_UNDER_THE_HOOD}->{STORAGEHANDLE}->_configureCOREHANDLE();
259     #$self->{STORAGE_UNDER_THE_HOOD}->_configureCOREHANDLE();
260     }
261    
262     #print Dumper($self->{STORAGE_UNDER_THE_HOOD});
263    
264 joko 1.4 return $self->{dataStorageLayer};
265 cvsjoko 1.1
266     }
267    
268     sub _configureUnderlyingStorage {
269    
270     my $self = shift;
271 joko 1.4
272     $logger->debug( __PACKAGE__ . "->_configureUnderlyingStorage" );
273    
274 cvsjoko 1.1 $self->_configureCOREHANDLE_DBI();
275     return;
276    
277     foreach my $key (keys %{$self->{dbi}}) {
278     my $val = $self->{dbi}->{$key};
279     print "entry: $key; $val", "\n";
280 joko 1.13 $self->{_COREHANDLE}->{db}->{$key} = $val;
281 cvsjoko 1.1 }
282     #print Dumper($self->{COREHANDLE}->{db});
283     }
284    
285    
286     sub configureCOREHANDLE {
287    
288     my $self = shift;
289    
290 joko 1.4 $logger->debug( __PACKAGE__ . "->configureCOREHANDLE" );
291 cvsjoko 1.1
292     #my $subLayer = $self->_getSubLayerHandle();
293    
294     # apply configured modifications
295     if (exists $self->{dbi}->{trace_level} && exists $self->{dbi}->{trace_file}) {
296 joko 1.13 $self->{_COREHANDLE}->{db}->trace($self->{dbi}->{trace_level}, $self->{dbi}->{trace_file});
297 cvsjoko 1.1 }
298     if (exists $self->{dbi}->{RaiseError}) {
299 joko 1.13 $self->{_COREHANDLE}->{db}->{RaiseError} = $self->{dbi}->{RaiseError};
300 cvsjoko 1.1 }
301     if (exists $self->{dbi}->{PrintError}) {
302 joko 1.13 $self->{_COREHANDLE}->{db}->{PrintError} = $self->{dbi}->{PrintError};
303 cvsjoko 1.1 }
304     if (exists $self->{dbi}->{HandleError}) {
305 joko 1.13 $self->{_COREHANDLE}->{db}->{HandleError} = $self->{dbi}->{HandleError};
306 cvsjoko 1.1 }
307    
308 joko 1.2 }
309    
310     sub deploySchema {
311     my $self = shift;
312 joko 1.5 my $args = shift;
313    
314     my $dsn = $self->{locator}->{dbi}->{dsn};
315 joko 1.4
316     $logger->debug( __PACKAGE__ . "->deploySchema( dsn $dsn )" );
317    
318 joko 1.2 my $ok;
319 joko 1.8 if ( my $dbh = DBI->connect($dsn, '', '', $self->{locator}->{dbi} ) ) {
320 joko 1.4 return unless $self->_initSchema();
321 joko 1.12 $ok = Tangram::Relational->deploy($schema_tangram, $dbh );
322 joko 1.2 $dbh->disconnect();
323     }
324     return $ok;
325     }
326    
327     sub retreatSchema {
328 joko 1.4
329 joko 1.2 my $self = shift;
330 joko 1.5 my $dsn = $self->{locator}->{dbi}->{dsn};
331 joko 1.4
332     $logger->debug( __PACKAGE__ . "->retreatSchema( dsn $dsn )" );
333    
334 joko 1.2 my $ok;
335 joko 1.8 if ( my $dbh = DBI->connect($dsn, '', '', $self->{locator}->{dbi} ) ) {
336 joko 1.4
337     return unless $self->_initSchema();
338    
339     #use Data::Dumper; print Dumper($self);
340     $self->{dataStorageLayer}->removeLogDispatchHandler("Tangram11");
341    
342 joko 1.12 $ok = Tangram::Relational->retreat($schema_tangram, $dbh );
343 joko 1.8
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 joko 1.2 $dbh->disconnect();
353 joko 1.8
354 joko 1.2 }
355     return $ok;
356 joko 1.4 }
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 joko 1.6 }
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 joko 1.13 my $object_set = $self->{_COREHANDLE}->remote($nodename);
385     @results = $self->{_COREHANDLE}->select($object_set);
386 joko 1.6 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 joko 1.13 my $remote = $self->{_COREHANDLE}->remote($nodename);
431 joko 1.6
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 joko 1.13 my $evalstring = 'return $self->{_COREHANDLE}->select($remote, ' . $tfilter . ');';
438 joko 1.6
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 joko 1.13 my $cmdHandle = $self->{_COREHANDLE}->cursor($node);
450 joko 1.6 my $result = Data::Storage::Result::Tangram->new( RESULTHANDLE => $cmdHandle );
451     return $result;
452     }
453    
454     sub createSet {
455     my $self = shift;
456 joko 1.18 #print "-" x 80, "\n";
457     #print Dumper(@_);
458 joko 1.6 my @objects = @_;
459     my $rh = Set::Object->new();
460     foreach (@objects) {
461 joko 1.18 if (!isEmpty($_)) {
462     #print Dumper($_);
463     $rh->insert($_);
464     }
465 joko 1.6 }
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 joko 1.18 $self->{_COREHANDLE}->unload($ident);
489 joko 1.13 my $object = $self->{_COREHANDLE}->load($ident);
490 joko 1.6 #print "get id", "\n";
491 joko 1.13 my $oid = $self->{_COREHANDLE}->id($object);
492 joko 1.18 #print Dumper($object);
493     #print "oid: $oid", "\n";
494 joko 1.6 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 joko 1.7 }
518    
519     sub eraseAll {
520     my $self = shift;
521     my $classname = shift;
522 joko 1.13 my $remote = $self->{_COREHANDLE}->remote($classname);
523     my @objs = $self->{_COREHANDLE}->select($remote);
524     $self->{_COREHANDLE}->erase(@objs);
525 joko 1.8 }
526    
527     sub createDb {
528     my $self = shift;
529     my $storage = $self->_getSubLayerHandle();
530     return $storage->createDb();
531 joko 1.9 }
532    
533     sub getObject {
534     my $self = shift;
535     my $oid = shift;
536 jonen 1.14 my $options = shift;
537 joko 1.16
538     # TODO: create a deep_unload method (currently _all_ objects are unloaded)
539 jonen 1.14 # unload($oid) will only unload object, not deep object hashes
540 joko 1.17 $self->{_COREHANDLE}->unload() if ($options->{destroy});
541 joko 1.16
542 joko 1.9 # TODO: review this
543     #if (!$self->{COREHANDLE}) { return; }
544 joko 1.16
545     # TODO: review this
546     my $object = eval('$self->{_COREHANDLE}->load($oid);');
547     print $@, "\n" if $@;
548    
549     return $object if $object;
550 joko 1.9 }
551    
552 jonen 1.20 sub getObjectByGuid {
553     my $self = shift;
554     my $guid = shift;
555     my $options = shift;
556    
557     # Guid and Classname is needed
558     if(!$guid || !$options->{classname}) {
559     return;
560     }
561    
562     # TODO: create a deep_unload method (currently _all_ objects are unloaded)
563     # unload($oid) will only unload object, not deep object hashes
564     $self->{_COREHANDLE}->unload() if ($options->{destroy});
565    
566     # search for object with given Classname and Guid
567     my $obj_tmp = $self->{_COREHANDLE}->remote($classname);
568     my @result = $self->{_COREHANDLE}->select($obj_tmp, $obj_tmp->{guid} eq $guid);
569    
570     # we searched for global unique identifer of some object,
571     # so it think we can trust there would be only one result
572     if($result[0]) {
573     return $result[0];
574     } else {
575     return "No Object with Classname $classname and GUID $options->{guid} found!";
576     }
577    
578     }
579    
580 joko 1.9 sub getObjectAsHash {
581     my $self = shift;
582     my $oid = shift;
583 jonen 1.20 my $options = shift;
584     my $obj;
585    
586     if($options->{guid}) {
587     $obj = $self->getObjectByGuid($oid, $options);
588     } else {
589     $obj = $self->getObject($oid, $options);
590     }
591 joko 1.15
592     # build options (a callback to unload autovivified objects) for 'expand'
593     # TODO: use $logger to write to debug here!
594     my $cb; # = sub {};
595     =pod
596     if ($options->{destroy}) {
597     $options->{cb}->{destroy} = sub {
598     print "================ DESTROY", "\n";
599     my $object = shift;
600     #print Dumper($object);
601     $self->{_COREHANDLE}->unload($object);
602     #undef($object);
603     };
604     }
605     =cut
606    
607     my $hash = object2hash($obj, $options);
608     #$options->{cb}->{destroy}->($obj);
609     #$self->{_COREHANDLE}->unload($obj);
610    
611     # convert values in hash to utf8 to be ready for (e.g.) encapsulation in XML
612     # now done in object2hash
613     #var2utf8($hash) if ($options->{utf8});
614    
615     # old (wrong) attempts to get rid of used instances, if requested
616     #$obj->clear_refs;
617     #$self->{COREHANDLE}->unload($obj) if($options->{destroy});
618     #$obj->DESTROY;
619     #undef($obj) if($options->{destroy});
620    
621     return $hash;
622 joko 1.12 }
623    
624     sub getSchema {
625     return $schema_tangram;
626 joko 1.13 }
627    
628     sub getCOREHANDLE {
629     my $self = shift;
630     return $self->{_COREHANDLE};
631 cvsjoko 1.1 }
632    
633     1;

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