/[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.21 - (hide annotations)
Mon Dec 16 22:20:49 2002 UTC (21 years, 6 months ago) by jonen
Branch: MAIN
Changes since 1.20: +7 -3 lines
+ fixed bug at 'getObjectByGuid()'

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

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