/[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.33 - (show annotations)
Wed Apr 9 06:07:43 2003 UTC (21 years, 3 months ago) by joko
Branch: MAIN
Changes since 1.32: +131 -48 lines
revamped 'sub sendQuery'

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

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