/[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.31 - (show annotations)
Sat Apr 5 21:24:09 2003 UTC (21 years, 3 months ago) by joko
Branch: MAIN
Changes since 1.30: +51 -20 lines
modified 'sub getChildNodes': now contains code from 'querySchema'

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

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