/[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.31 - (hide 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 joko 1.6 ############################################
2 cvsjoko 1.1 #
3 joko 1.31 # $Id: Tangram.pm,v 1.30 2003/03/27 15:31:14 joko Exp $
4 joko 1.2 #
5     # $Log: Tangram.pm,v $
6 joko 1.31 # Revision 1.30 2003/03/27 15:31:14 joko
7     # fixes to modules regarding new namespace(s) below Data::Mungle::*
8     #
9 joko 1.30 # Revision 1.29 2003/02/21 01:47:18 joko
10     # purged old code
11     # minor cosmetics
12     #
13 joko 1.29 # Revision 1.28 2003/02/20 20:20:26 joko
14     # tried to get auto-disconnect working again - failed with that
15     #
16 joko 1.28 # Revision 1.27 2003/01/31 06:30:59 joko
17     # + enabled 'sendQuery'
18     #
19 joko 1.27 # Revision 1.26 2003/01/30 22:29:47 joko
20     # + fixed module usage (removed dependency on 'libp.pm')
21     #
22 joko 1.26 # Revision 1.25 2003/01/19 02:30:05 joko
23     # + fix: modified call to '_initSchema'
24     #
25 joko 1.25 # Revision 1.24 2002/12/22 14:13:01 joko
26     # + sub dropDb
27     #
28 joko 1.24 # Revision 1.23 2002/12/19 16:31:53 joko
29     # +- renamed sub to 'rebuildDb'
30     #
31 joko 1.23 # Revision 1.22 2002/12/18 22:28:16 jonen
32     # + added extended logging at 'getObjectByGuid()'
33     #
34 jonen 1.22 # Revision 1.21 2002/12/16 22:20:49 jonen
35     # + fixed bug at 'getObjectByGuid()'
36     #
37 jonen 1.21 # Revision 1.20 2002/12/16 20:49:17 jonen
38     # + added sub 'getObjectByGuid()'
39     # + added functionality to use 'getObjectByGuid' at 'getObjectAsHash()'
40     #
41 jonen 1.20 # Revision 1.19 2002/12/16 06:46:09 joko
42     # + attempt to introduce a generic '_patchSchema' - cancelled!
43     #
44 joko 1.19 # Revision 1.18 2002/12/13 21:48:07 joko
45     # + fix to 'sub sendQuery'
46     #
47 joko 1.18 # Revision 1.17 2002/12/12 02:51:09 joko
48     # + cosmetics
49     #
50 joko 1.17 # Revision 1.16 2002/12/11 06:54:10 joko
51     # + fix: encapsulated object-loading inside an 'eval'
52     #
53 joko 1.16 # Revision 1.15 2002/12/05 13:55:21 joko
54 joko 1.28 # + now utilizing 'expand' instead of 'var_deref'
55 joko 1.16 # + played around with having fresh-objects - no progress....
56     #
57 joko 1.15 # Revision 1.14 2002/12/05 09:40:30 jonen
58     # + added option->{destroy} at getObject for unloading all instance
59     #
60 jonen 1.14 # 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 joko 1.13 # Revision 1.12 2002/12/04 11:34:49 joko
66     # - $schema_tangram doesn't have to be in class?
67     #
68 joko 1.12 # Revision 1.11 2002/12/04 08:54:08 jonen
69     # + untested bugfix: undef($object) after transform to hash at getObjectAsHash
70     #
71 jonen 1.11 # Revision 1.10 2002/12/03 15:53:23 joko
72     # + small bugfix regarding object hierarchy
73     #
74 joko 1.10 # Revision 1.9 2002/12/03 05:29:40 joko
75     # + sub getObject
76     # + sub getObjectAsHash
77     #
78 joko 1.9 # 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 joko 1.8 # Revision 1.7 2002/12/01 04:46:19 joko
82     # + sub eraseAll
83     #
84 joko 1.7 # 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 joko 1.6 # 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 joko 1.5 # Revision 1.4 2002/10/25 11:44:44 joko
99     # + sub _initSchema
100     # + sub existsChildNode
101     # + sub testIntegrity
102     # + sub rebuildDbAndSchema
103     #
104 joko 1.4 # Revision 1.3 2002/10/17 03:56:55 joko
105     # + bugfix: trapped eval error
106     #
107 joko 1.3 # 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 joko 1.2 # Revision 1.1 2002/10/10 03:44:07 cvsjoko
114     # + new
115 cvsjoko 1.1 #
116 joko 1.6 ############################################
117    
118 cvsjoko 1.1
119     package Data::Storage::Handler::Tangram;
120    
121     use strict;
122     use warnings;
123    
124 joko 1.13 use base ("Data::Storage::Handler");
125 cvsjoko 1.1 use base ("Data::Storage::Handler::Abstract");
126    
127 joko 1.28
128     use Data::Dumper;
129 cvsjoko 1.1 use Tangram;
130 joko 1.28
131 joko 1.26 use DesignPattern::Object;
132 joko 1.6 use Data::Storage::Result::Tangram;
133 joko 1.30 use Data::Mungle::Compare::Struct qw( isEmpty );
134     use Data::Mungle::Transform::Deep qw( expand );
135 joko 1.9
136 cvsjoko 1.1 # get logger instance
137     my $logger = Log::Dispatch::Config->instance;
138    
139    
140 joko 1.12 # this holds the complete instantiated schema from tangram
141     my $schema_tangram;
142    
143 joko 1.6 sub getMetaInfo {
144     my $self = shift;
145     $logger->debug( __PACKAGE__ . "->getMetaInfo()" );
146     return {
147     'disconnectMethod' => 'disconnect',
148     };
149 joko 1.2 }
150    
151 joko 1.4 sub _initSchema {
152     my $self = shift;
153     $logger->debug( __PACKAGE__ . "->_initSchema()" );
154 joko 1.12 #if (!$schema_tangram) {
155 joko 1.26 #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 joko 1.12 $schema_tangram = $obj->getSchema();
158 joko 1.4 #}
159 joko 1.12 if (!$schema_tangram) {
160 joko 1.4 $logger->error( __PACKAGE__ . "->_initSchema: No Schema available for $self->{schema}" );
161     return 0;
162     }
163 joko 1.19 #$self->_patchSchema();
164 joko 1.4 return 1;
165 joko 1.19 }
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 joko 1.4 }
183    
184 cvsjoko 1.1 sub connect {
185    
186     my $self = shift;
187    
188     my $dsn = shift;
189 joko 1.25
190     #print Dumper($self);
191     #exit;
192    
193     # TODO: re-enable
194 joko 1.5 $dsn ||= $self->{locator}->{dbi}->{dsn};
195 joko 1.2 $logger->debug( __PACKAGE__ . "->connect( dsn $dsn )" );
196 cvsjoko 1.1
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 joko 1.25 #return unless $self->_initSchema();
207     $self->_initSchema();
208 joko 1.4
209 joko 1.6 # create the main tangram storage object
210 joko 1.2 #$self->{COREHANDLE} = Tangram::Relational->connect( $schema, $dsn );
211 joko 1.13 $self->{_COREHANDLE} = Tangram::Relational->connect( $schema_tangram, $dsn );
212    
213     #print "connect", "\n";
214     #my $core = $self->{_COREHANDLE};
215     #print Dumper($core);
216 cvsjoko 1.1
217 joko 1.6 # some attempts for configuring the wrapped underlying dbi.....
218 cvsjoko 1.1 #$self->{STORAGEHANDLE_UNDERLYING} = $self->getUnderlyingStorage();
219     #$self->{STORAGEHANDLE_UNDERLYING}->_configureCOREHANDLE();
220     #$self->_configureUnderlyingStorage;
221 joko 1.6
222     # ..... encapsulation wins!
223 cvsjoko 1.1 $self->configureCOREHANDLE();
224    
225 joko 1.5 $self->{locator}->{status}->{connected} = 1;
226    
227 joko 1.4 return 1;
228    
229 cvsjoko 1.1 }
230    
231     sub getChildNodes {
232    
233     my $self = shift;
234 joko 1.31 my $mode = shift;
235     $mode ||= 'core';
236    
237     $logger->debug( __PACKAGE__ . "->getChildNodes($mode)" );
238    
239     if ($mode eq 'core') {
240 cvsjoko 1.1
241 joko 1.31 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 joko 1.4
261 joko 1.31 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 cvsjoko 1.1
278 joko 1.31 my $result = {
279     all => \@object_names,
280     concrete => \@concret_names,
281     };
282     return $result;
283 cvsjoko 1.1
284 joko 1.31 }
285 joko 1.4
286 cvsjoko 1.1
287     }
288    
289 joko 1.4 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 joko 1.5 $self->{locator}->{status}->{integrity} = 1;
308 joko 1.4 return 1;
309    
310     }
311    
312    
313 cvsjoko 1.1 sub _getSubLayerHandle {
314    
315     my $self = shift;
316    
317 joko 1.4 $logger->debug( __PACKAGE__ . "->_getSubLayerHandle()" );
318    
319 cvsjoko 1.1 #print Dumper($self);
320 joko 1.5
321 cvsjoko 1.1 # hack, make more generic!
322 joko 1.4 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 joko 1.5 my $loc = Data::Storage::Locator->new( { type => "DBI", dbi => $self->{locator}->{dbi} } );
326 joko 1.4 $self->{dataStorageLayer} = Data::Storage->new( $loc, { protected => 1 } );
327 cvsjoko 1.1 #$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 joko 1.4 return $self->{dataStorageLayer};
334 cvsjoko 1.1
335     }
336    
337     sub _configureUnderlyingStorage {
338    
339     my $self = shift;
340 joko 1.4
341     $logger->debug( __PACKAGE__ . "->_configureUnderlyingStorage" );
342    
343 cvsjoko 1.1 $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 joko 1.13 $self->{_COREHANDLE}->{db}->{$key} = $val;
350 cvsjoko 1.1 }
351     #print Dumper($self->{COREHANDLE}->{db});
352     }
353    
354    
355     sub configureCOREHANDLE {
356    
357     my $self = shift;
358    
359 joko 1.4 $logger->debug( __PACKAGE__ . "->configureCOREHANDLE" );
360 cvsjoko 1.1
361     #my $subLayer = $self->_getSubLayerHandle();
362 joko 1.26 #print Dumper($self);
363     #exit;
364 cvsjoko 1.1
365     # apply configured modifications
366     if (exists $self->{dbi}->{trace_level} && exists $self->{dbi}->{trace_file}) {
367 joko 1.13 $self->{_COREHANDLE}->{db}->trace($self->{dbi}->{trace_level}, $self->{dbi}->{trace_file});
368 cvsjoko 1.1 }
369     if (exists $self->{dbi}->{RaiseError}) {
370 joko 1.13 $self->{_COREHANDLE}->{db}->{RaiseError} = $self->{dbi}->{RaiseError};
371 cvsjoko 1.1 }
372     if (exists $self->{dbi}->{PrintError}) {
373 joko 1.13 $self->{_COREHANDLE}->{db}->{PrintError} = $self->{dbi}->{PrintError};
374 cvsjoko 1.1 }
375     if (exists $self->{dbi}->{HandleError}) {
376 joko 1.13 $self->{_COREHANDLE}->{db}->{HandleError} = $self->{dbi}->{HandleError};
377 cvsjoko 1.1 }
378    
379 joko 1.2 }
380    
381     sub deploySchema {
382     my $self = shift;
383 joko 1.5 my $args = shift;
384    
385     my $dsn = $self->{locator}->{dbi}->{dsn};
386 joko 1.4
387     $logger->debug( __PACKAGE__ . "->deploySchema( dsn $dsn )" );
388    
389 joko 1.2 my $ok;
390 joko 1.8 if ( my $dbh = DBI->connect($dsn, '', '', $self->{locator}->{dbi} ) ) {
391 joko 1.4 return unless $self->_initSchema();
392 joko 1.12 $ok = Tangram::Relational->deploy($schema_tangram, $dbh );
393 joko 1.2 $dbh->disconnect();
394     }
395     return $ok;
396     }
397    
398     sub retreatSchema {
399 joko 1.4
400 joko 1.2 my $self = shift;
401 joko 1.5 my $dsn = $self->{locator}->{dbi}->{dsn};
402 joko 1.4
403     $logger->debug( __PACKAGE__ . "->retreatSchema( dsn $dsn )" );
404    
405 joko 1.2 my $ok;
406 joko 1.8 if ( my $dbh = DBI->connect($dsn, '', '', $self->{locator}->{dbi} ) ) {
407 joko 1.4
408     return unless $self->_initSchema();
409    
410     #use Data::Dumper; print Dumper($self);
411     $self->{dataStorageLayer}->removeLogDispatchHandler("Tangram11");
412    
413 joko 1.12 $ok = Tangram::Relational->retreat($schema_tangram, $dbh );
414 joko 1.8
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 joko 1.2 $dbh->disconnect();
424 joko 1.8
425 joko 1.2 }
426     return $ok;
427 joko 1.4 }
428    
429 joko 1.23 sub rebuildDb {
430 joko 1.4 my $self = shift;
431 joko 1.23 $logger->info( __PACKAGE__ . "->rebuildDb()" );
432 joko 1.4 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 joko 1.6 }
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 joko 1.13 my $object_set = $self->{_COREHANDLE}->remote($nodename);
456     @results = $self->{_COREHANDLE}->select($object_set);
457 joko 1.6 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 joko 1.27 #print Dumper($filters);
472 joko 1.6
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 joko 1.13 my $remote = $self->{_COREHANDLE}->remote($nodename);
502 joko 1.6
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 joko 1.13 my $evalstring = 'return $self->{_COREHANDLE}->select($remote, ' . $tfilter . ');';
509 joko 1.6
510 joko 1.27 #print "eval: $evalstring", "\n";
511    
512 joko 1.6 # 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 joko 1.13 my $cmdHandle = $self->{_COREHANDLE}->cursor($node);
523 joko 1.6 my $result = Data::Storage::Result::Tangram->new( RESULTHANDLE => $cmdHandle );
524     return $result;
525     }
526    
527     sub createSet {
528     my $self = shift;
529 joko 1.18 #print "-" x 80, "\n";
530     #print Dumper(@_);
531 joko 1.6 my @objects = @_;
532     my $rh = Set::Object->new();
533     foreach (@objects) {
534 joko 1.18 if (!isEmpty($_)) {
535     #print Dumper($_);
536     $rh->insert($_);
537     }
538 joko 1.6 }
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 joko 1.18 $self->{_COREHANDLE}->unload($ident);
562 joko 1.13 my $object = $self->{_COREHANDLE}->load($ident);
563 joko 1.6 #print "get id", "\n";
564 joko 1.13 my $oid = $self->{_COREHANDLE}->id($object);
565 joko 1.18 #print Dumper($object);
566     #print "oid: $oid", "\n";
567 joko 1.6 return $self->createSet($object);
568     #return $self->createSet( $self->{COREHANDLE}->load('300090018') );
569     }
570    
571 joko 1.27 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 joko 1.6
580    
581 joko 1.27 # try a generic tangram query here
582     # TODO: try to place an oql on top of that (search.cpan.org!)
583 joko 1.6 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 joko 1.7 }
599    
600     sub eraseAll {
601     my $self = shift;
602     my $classname = shift;
603 joko 1.13 my $remote = $self->{_COREHANDLE}->remote($classname);
604     my @objs = $self->{_COREHANDLE}->select($remote);
605     $self->{_COREHANDLE}->erase(@objs);
606 joko 1.8 }
607    
608     sub createDb {
609     my $self = shift;
610     my $storage = $self->_getSubLayerHandle();
611     return $storage->createDb();
612 joko 1.9 }
613    
614     sub getObject {
615     my $self = shift;
616     my $oid = shift;
617 jonen 1.14 my $options = shift;
618 joko 1.16
619     # TODO: create a deep_unload method (currently _all_ objects are unloaded)
620 jonen 1.14 # unload($oid) will only unload object, not deep object hashes
621 joko 1.17 $self->{_COREHANDLE}->unload() if ($options->{destroy});
622 joko 1.16
623 joko 1.9 # TODO: review this
624     #if (!$self->{COREHANDLE}) { return; }
625 joko 1.16
626     # TODO: review this
627     my $object = eval('$self->{_COREHANDLE}->load($oid);');
628     print $@, "\n" if $@;
629    
630     return $object if $object;
631 joko 1.9 }
632    
633 jonen 1.20 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 jonen 1.22 $logger->error( __PACKAGE__ . "->getObjectByGuid: No 'guid' OR no Classname in options hash was given but needed!" );
641 jonen 1.20 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 jonen 1.21 my $obj_tmp = $self->{_COREHANDLE}->remote($options->{classname});
650 jonen 1.20 my @result = $self->{_COREHANDLE}->select($obj_tmp, $obj_tmp->{guid} eq $guid);
651    
652     # we searched for global unique identifer of some object,
653 jonen 1.22 # so I think we can trust there would be only one result
654 jonen 1.20 if($result[0]) {
655     return $result[0];
656     } else {
657 jonen 1.22 $logger->error( __PACKAGE__ . "->getObjectByGuid: No Object with Classname $options->{classname} and GUID $guid found!" );
658     return;
659 jonen 1.20 }
660    
661     }
662    
663 joko 1.9 sub getObjectAsHash {
664     my $self = shift;
665     my $oid = shift;
666 jonen 1.20 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 joko 1.15
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 joko 1.29
679     # deactivated way to get rid of used instances, if requested
680 joko 1.15 =pod
681 joko 1.29 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 joko 1.15 =cut
691    
692 joko 1.28 my $hash = expand($obj, $options);
693 joko 1.29
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 joko 1.15
700 joko 1.29 # V2:
701 joko 1.15 #$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 joko 1.12 }
708    
709     sub getSchema {
710     return $schema_tangram;
711 joko 1.13 }
712    
713     sub getCOREHANDLE {
714     my $self = shift;
715     return $self->{_COREHANDLE};
716 joko 1.24 }
717    
718     sub dropDb {
719     my $self = shift;
720     my $storage = $self->_getSubLayerHandle();
721     return $storage->dropDb();
722 cvsjoko 1.1 }
723    
724 joko 1.26 sub testAvailability {
725     my $self = shift;
726     my $storage = $self->_getSubLayerHandle();
727     return $storage->testAvailability();
728 joko 1.28 }
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 joko 1.26 }
745    
746 cvsjoko 1.1 1;
747 joko 1.26 __END__

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