/[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.29 - (hide annotations)
Fri Feb 21 01:47:18 2003 UTC (21 years, 4 months ago) by joko
Branch: MAIN
Changes since 1.28: +22 -18 lines
purged old code
minor cosmetics

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

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