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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.32 - (show annotations)
Tue Apr 8 22:52:22 2003 UTC (21 years, 3 months ago) by joko
Branch: MAIN
Changes since 1.31: +14 -8 lines
modified 'querySchema': better behaviour regarding filtering result

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

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