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

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

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.8 by joko, Sun Dec 1 22:25:51 2002 UTC revision 1.34 by joko, Fri Apr 11 01:18:53 2003 UTC
# Line 3  Line 3 
3  #  $Id$  #  $Id$
4  #  #
5  #  $Log$  #  $Log$
6    #  Revision 1.34  2003/04/11 01:18:53  joko
7    #  sendQuery:
8    #  + introduced crud action 'DELETE'
9    #
10    #  Revision 1.33  2003/04/09 06:07:43  joko
11    #  revamped 'sub sendQuery'
12    #
13    #  Revision 1.32  2003/04/08 22:52:22  joko
14    #  modified 'querySchema': better behaviour regarding filtering result
15    #
16    #  Revision 1.31  2003/04/05 21:24:09  joko
17    #  modified 'sub getChildNodes': now contains code from 'querySchema'
18    #
19    #  Revision 1.30  2003/03/27 15:31:14  joko
20    #  fixes to modules regarding new namespace(s) below Data::Mungle::*
21    #
22    #  Revision 1.29  2003/02/21 01:47:18  joko
23    #  purged old code
24    #  minor cosmetics
25    #
26    #  Revision 1.28  2003/02/20 20:20:26  joko
27    #  tried to get auto-disconnect working again - failed with that
28    #
29    #  Revision 1.27  2003/01/31 06:30:59  joko
30    #  + enabled 'sendQuery'
31    #
32    #  Revision 1.26  2003/01/30 22:29:47  joko
33    #  + fixed module usage (removed dependency on 'libp.pm')
34    #
35    #  Revision 1.25  2003/01/19 02:30:05  joko
36    #  + fix: modified call to '_initSchema'
37    #
38    #  Revision 1.24  2002/12/22 14:13:01  joko
39    #  + sub dropDb
40    #
41    #  Revision 1.23  2002/12/19 16:31:53  joko
42    #  +- renamed sub to 'rebuildDb'
43    #
44    #  Revision 1.22  2002/12/18 22:28:16  jonen
45    #  + added extended logging at 'getObjectByGuid()'
46    #
47    #  Revision 1.21  2002/12/16 22:20:49  jonen
48    #  + fixed bug at 'getObjectByGuid()'
49    #
50    #  Revision 1.20  2002/12/16 20:49:17  jonen
51    #  + added sub 'getObjectByGuid()'
52    #  + added functionality to use 'getObjectByGuid' at 'getObjectAsHash()'
53    #
54    #  Revision 1.19  2002/12/16 06:46:09  joko
55    #  + attempt to introduce a generic '_patchSchema' - cancelled!
56    #
57    #  Revision 1.18  2002/12/13 21:48:07  joko
58    #  + fix to 'sub sendQuery'
59    #
60    #  Revision 1.17  2002/12/12 02:51:09  joko
61    #  + cosmetics
62    #
63    #  Revision 1.16  2002/12/11 06:54:10  joko
64    #  + fix: encapsulated object-loading inside an 'eval'
65    #
66    #  Revision 1.15  2002/12/05 13:55:21  joko
67    #  + now utilizing 'expand' instead of 'var_deref'
68    #  + played around with having fresh-objects - no progress....
69    #
70    #  Revision 1.14  2002/12/05 09:40:30  jonen
71    #  + added option->{destroy} at getObject for unloading all instance
72    #
73    #  Revision 1.13  2002/12/05 07:59:04  joko
74    #  + now using Tie::SecureHash as a base for the COREHANDLE
75    #  + former public COREHANDLE becomes private _COREHANDLE now
76    #  + sub getCOREHANDLE
77    #
78    #  Revision 1.12  2002/12/04 11:34:49  joko
79    #  - $schema_tangram doesn't have to be in class?
80    #
81    #  Revision 1.11  2002/12/04 08:54:08  jonen
82    #  + untested bugfix: undef($object) after transform to hash at getObjectAsHash
83    #
84    #  Revision 1.10  2002/12/03 15:53:23  joko
85    #  + small bugfix regarding object hierarchy
86    #
87    #  Revision 1.9  2002/12/03 05:29:40  joko
88    #  + sub getObject
89    #  + sub getObjectAsHash
90    #
91  #  Revision 1.8  2002/12/01 22:25:51  joko  #  Revision 1.8  2002/12/01 22:25:51  joko
92  #  + now utilizing metadata from storage locator when connecting to DBI in "raw"-mode  #  + now utilizing metadata from storage locator when connecting to DBI in "raw"-mode
93  #  #
# Line 49  package Data::Storage::Handler::Tangram; Line 134  package Data::Storage::Handler::Tangram;
134  use strict;  use strict;
135  use warnings;  use warnings;
136    
137    use base ("Data::Storage::Handler");
138  use base ("Data::Storage::Handler::Abstract");  use base ("Data::Storage::Handler::Abstract");
139    
140  use Tangram;  
141  use Data::Dumper;  use Data::Dumper;
142  use libp qw( getNewPerlObjectByPkgName );  use Tangram;
143    
144    use DesignPattern::Object;
145  use Data::Storage::Result::Tangram;  use Data::Storage::Result::Tangram;
146  use Data::Compare::Struct qw( isEmpty );  use Data::Mungle::Compare::Struct qw( isEmpty );
147    use Data::Mungle::Transform::Deep qw( expand deep_copy merge_to );
148    
149  # get logger instance  # get logger instance
150  my $logger = Log::Dispatch::Config->instance;  my $logger = Log::Dispatch::Config->instance;
151    
152    
153    # this holds the complete instantiated schema from tangram
154    my $schema_tangram;
155    
156  sub getMetaInfo {  sub getMetaInfo {
157    my $self = shift;    my $self = shift;
158    $logger->debug( __PACKAGE__ . "->getMetaInfo()"  );    $logger->debug( __PACKAGE__ . "->getMetaInfo()"  );
# Line 72  sub getMetaInfo { Line 164  sub getMetaInfo {
164  sub _initSchema {  sub _initSchema {
165    my $self = shift;    my $self = shift;
166    $logger->debug( __PACKAGE__ . "->_initSchema()" );    $logger->debug( __PACKAGE__ . "->_initSchema()" );
167    #if (!$self->{schema_tangram}) {    #if (!$schema_tangram) {
168      my $obj = getNewPerlObjectByPkgName($self->{locator}->{schema}, { EXPORT_OBJECTS => $self->{locator}->{classnames}, want_transactions => $self->{locator}->{want_transactions} } );      #my $obj = getNewPerlObjectByPkgName($self->{locator}->{schema}, { EXPORT_OBJECTS => $self->{locator}->{classnames}, want_transactions => $self->{locator}->{want_transactions} } );
169      $self->{schema_tangram} = $obj->getSchema();      my $obj = DesignPattern::Object->fromPackage($self->{locator}->{schema}, { 'EXPORT_OBJECTS' => $self->{locator}->{classnames}, 'want_transactions' => $self->{locator}->{want_transactions} } );
170        $schema_tangram = $obj->getSchema();
171    #}    #}
172    if (!$self->{schema_tangram}) {    if (!$schema_tangram) {
173      $logger->error( __PACKAGE__ . "->_initSchema: No Schema available for $self->{schema}" );      $logger->error( __PACKAGE__ . "->_initSchema: No Schema available for $self->{schema}" );
174      return 0;      return 0;
175    }    }
176      #$self->_patchSchema();
177    return 1;    return 1;
178  }  }
179    
180    sub _patchSchema {
181      my $self = shift;
182      foreach (keys %{$schema_tangram->{classes}}) {
183        next if $schema_tangram->{classes}->{$_}->{abstract};
184        #next if ($_ ne 'TsBankAccount');
185        #$_ ne 'AbstractAccount' &&
186        print "class: $_", "\n";
187    #print Dumper($schema_tangram->{classes}->{$_});
188        # create new string property named 'guid'
189        my $tstring = Tangram::String->new();
190        $tstring->{name} = $tstring->{col} = 'guid';
191        # inject property into schema
192        #$schema_tangram->{classes}->{$_}->{root}->{SPECS}->[0]->{fields}->{string}->{$tstring->{name}} = $tstring;
193        print Dumper($schema_tangram->{classes}->{$_}->{root}->{SPECS}->[0]->{fields});
194      }
195    }
196    
197  sub connect {  sub connect {
198    
199      my $self = shift;      my $self = shift;
200            
201      my $dsn = shift;      my $dsn = shift;
202    
203    #print Dumper($self);
204    #exit;
205    
206        # TODO: re-enable
207      $dsn ||= $self->{locator}->{dbi}->{dsn};      $dsn ||= $self->{locator}->{dbi}->{dsn};
       
208      $logger->debug( __PACKAGE__ . "->connect( dsn $dsn )" );      $logger->debug( __PACKAGE__ . "->connect( dsn $dsn )" );
209            
210      #my $storage = Tangram::Relational->connect( $schema, $dsn );      #my $storage = Tangram::Relational->connect( $schema, $dsn );
# Line 101  sub connect { Line 216  sub connect {
216  #      return;  #      return;
217  #    }  #    }
218    
219      return unless $self->_initSchema();      #return unless $self->_initSchema();
220        $self->_initSchema();
221    
222      # create the main tangram storage object      # create the main tangram storage object
223      #$self->{COREHANDLE} = Tangram::Relational->connect( $schema, $dsn );      #$self->{COREHANDLE} = Tangram::Relational->connect( $schema, $dsn );
224      $self->{COREHANDLE} = Tangram::Relational->connect( $self->{schema_tangram}, $dsn );      $self->{_COREHANDLE} = Tangram::Relational->connect( $schema_tangram, $dsn );
225    
226    #print "connect", "\n";
227    #my $core = $self->{_COREHANDLE};
228    #print Dumper($core);
229        
230      # some attempts for configuring the wrapped underlying dbi.....      # some attempts for configuring the wrapped underlying dbi.....
231      #$self->{STORAGEHANDLE_UNDERLYING} = $self->getUnderlyingStorage();      #$self->{STORAGEHANDLE_UNDERLYING} = $self->getUnderlyingStorage();
# Line 124  sub connect { Line 244  sub connect {
244  sub getChildNodes {  sub getChildNodes {
245    
246    my $self = shift;    my $self = shift;
247    my @nodes;    my $mode = shift;
248      my $filter = shift;
249      
250      $mode ||= 'core';
251      $filter ||= 'all';
252      
253      $logger->debug( __PACKAGE__ . "->getChildNodes($mode)" );
254    
255    $logger->debug( __PACKAGE__ . "->getChildNodes()" );    if ($mode eq 'core') {
256    
257    # create new DBI - Data::Storage - object from already connected DBI::db - handle inside the current COREHANDLE      my @nodes;
258    #my $loc = new Data::Storage::Locator( type => "DBI", dbi => { db => $self->{COREHANDLE}->{db} });      
259    #my $loc = new Data::Storage::Locator( type => "DBI", COREHANDLE => $self->{COREHANDLE}->{db} );      # create new DBI - Data::Storage - object from already connected DBI::db - handle inside the current COREHANDLE
260          #my $loc = new Data::Storage::Locator( type => "DBI", dbi => { db => $self->{COREHANDLE}->{db} });
261    # todo: should we retrieve information from the schema here      #my $loc = new Data::Storage::Locator( type => "DBI", COREHANDLE => $self->{COREHANDLE}->{db} );
262    # rather than poorly getting table names from underlying dbi?      
263    my $storage = $self->_getSubLayerHandle();      # todo: should we retrieve information from the schema here
264    @nodes = @{$storage->getChildNodes()};      # rather than poorly getting table names from underlying dbi?
265    #$storage->_configureCOREHANDLE();      my $storage = $self->_getSubLayerHandle();
266  #print "getchildnodes\n";      @nodes = @{$storage->getChildNodes()};
267  #print Dumper($self);      #$storage->_configureCOREHANDLE();
268    #if (my $result = $self->sendCommand( 'SHOW TABLES;' ) ) {    #print "getchildnodes\n";
269      #print Dumper($self);
270        #if (my $result = $self->sendCommand( 'SHOW TABLES;' ) ) {
271        
272        # TODO: REVIEW
273        #$storage->disconnect();
274        
275        $self->{meta}->{childnodes} = \@nodes;
276    
277        return \@nodes;
278        
279    # TODO: REVIEW    } elsif ($mode eq 'root') {
280    #$storage->disconnect();      
281        # FIXME: this will return *all* known classes to 'Class::Tangram',
282        # which might not be what you expect since more than one instance
283        # of Tangram may be in memory and Class::Tangram seems to
284        # offer no methods to determine this or filter its result(s) according
285        # to a specific database.
286        my @object_names = Class::Tangram::known_classes();
287        my @concret_names;
288        my $o_cnt;
289        foreach (sort @object_names) {
290          push @concret_names, $_  if (!Class::Tangram::class_is_abstract($_));
291          $o_cnt++;
292        }
293    
294        if ($filter eq 'all') {
295          return \@object_names;
296        } elsif ($filter eq 'concrete') {
297          return \@concret_names;
298        }
299        
300    $self->{meta}->{childnodes} = \@nodes;    }
301        
   return \@nodes;  
302    
303  }  }
304    
   
305  sub testIntegrity {  sub testIntegrity {
306    
307    my $self = shift;    my $self = shift;
# Line 211  sub _configureUnderlyingStorage { Line 362  sub _configureUnderlyingStorage {
362    foreach my $key (keys %{$self->{dbi}}) {    foreach my $key (keys %{$self->{dbi}}) {
363      my $val = $self->{dbi}->{$key};      my $val = $self->{dbi}->{$key};
364      print "entry: $key; $val", "\n";      print "entry: $key; $val", "\n";
365      $self->{COREHANDLE}->{db}->{$key} = $val;      $self->{_COREHANDLE}->{db}->{$key} = $val;
366    }    }
367    #print Dumper($self->{COREHANDLE}->{db});    #print Dumper($self->{COREHANDLE}->{db});
368  }  }
# Line 224  sub configureCOREHANDLE { Line 375  sub configureCOREHANDLE {
375    $logger->debug( __PACKAGE__ . "->configureCOREHANDLE" );    $logger->debug( __PACKAGE__ . "->configureCOREHANDLE" );
376    
377    #my $subLayer = $self->_getSubLayerHandle();    #my $subLayer = $self->_getSubLayerHandle();
378      #print Dumper($self);
379      #exit;
380    
381    # apply configured modifications    # apply configured modifications
382      if (exists $self->{dbi}->{trace_level} && exists $self->{dbi}->{trace_file}) {      if (exists $self->{dbi}->{trace_level} && exists $self->{dbi}->{trace_file}) {
383        $self->{COREHANDLE}->{db}->trace($self->{dbi}->{trace_level}, $self->{dbi}->{trace_file});        $self->{_COREHANDLE}->{db}->trace($self->{dbi}->{trace_level}, $self->{dbi}->{trace_file});
384      }      }
385      if (exists $self->{dbi}->{RaiseError}) {      if (exists $self->{dbi}->{RaiseError}) {
386        $self->{COREHANDLE}->{db}->{RaiseError} = $self->{dbi}->{RaiseError};        $self->{_COREHANDLE}->{db}->{RaiseError} = $self->{dbi}->{RaiseError};
387      }      }
388      if (exists $self->{dbi}->{PrintError}) {      if (exists $self->{dbi}->{PrintError}) {
389        $self->{COREHANDLE}->{db}->{PrintError} = $self->{dbi}->{PrintError};        $self->{_COREHANDLE}->{db}->{PrintError} = $self->{dbi}->{PrintError};
390      }      }
391      if (exists $self->{dbi}->{HandleError}) {      if (exists $self->{dbi}->{HandleError}) {
392        $self->{COREHANDLE}->{db}->{HandleError} = $self->{dbi}->{HandleError};        $self->{_COREHANDLE}->{db}->{HandleError} = $self->{dbi}->{HandleError};
393      }      }
394    
395  }  }
# Line 252  sub deploySchema { Line 405  sub deploySchema {
405    my $ok;    my $ok;
406    if ( my $dbh = DBI->connect($dsn, '', '', $self->{locator}->{dbi} ) ) {    if ( my $dbh = DBI->connect($dsn, '', '', $self->{locator}->{dbi} ) ) {
407      return unless $self->_initSchema();      return unless $self->_initSchema();
408      $ok = Tangram::Relational->deploy($self->{schema_tangram}, $dbh );      $ok = Tangram::Relational->deploy($schema_tangram, $dbh );
409      $dbh->disconnect();      $dbh->disconnect();
410    }    }
411    return $ok;    return $ok;
# Line 273  sub retreatSchema { Line 426  sub retreatSchema {
426      #use Data::Dumper; print Dumper($self);      #use Data::Dumper; print Dumper($self);
427      $self->{dataStorageLayer}->removeLogDispatchHandler("Tangram11");      $self->{dataStorageLayer}->removeLogDispatchHandler("Tangram11");
428            
429      $ok = Tangram::Relational->retreat($self->{schema_tangram}, $dbh );      $ok = Tangram::Relational->retreat($schema_tangram, $dbh );
430    
431      # answer "$ok=2" means "maybe" for now - we have to patch this to a constant here because...      # answer "$ok=2" means "maybe" for now - we have to patch this to a constant here because...
432      # - ... Tangram::Relational->retreat doesn't seem to return a valid status      # - ... Tangram::Relational->retreat doesn't seem to return a valid status
# Line 289  sub retreatSchema { Line 442  sub retreatSchema {
442    return $ok;    return $ok;
443  }  }
444    
445  sub rebuildDbAndSchema {  sub rebuildDb {
446    my $self = shift;    my $self = shift;
447    $logger->info( __PACKAGE__ . "->rebuildDbAndSchema()" );    $logger->info( __PACKAGE__ . "->rebuildDb()" );
448    my @results;    my @results;
449    
450    # sum up results (bool (0/1)) in array    # sum up results (bool (0/1)) in array
# Line 315  sub getListUnfiltered { Line 468  sub getListUnfiltered {
468    my @results;    my @results;
469    $logger->debug( __PACKAGE__ . "->getListUnfiltered( nodename => '" . $nodename . "' )" );    $logger->debug( __PACKAGE__ . "->getListUnfiltered( nodename => '" . $nodename . "' )" );
470    # get set of objects from odbms by object name    # get set of objects from odbms by object name
471    my $object_set = $self->{COREHANDLE}->remote($nodename);    my $object_set = $self->{_COREHANDLE}->remote($nodename);
472    @results = $self->{COREHANDLE}->select($object_set);    @results = $self->{_COREHANDLE}->select($object_set);
473    return \@results;    return \@results;
474  }  }
475    
# Line 331  sub getListFiltered { Line 484  sub getListFiltered {
484    my @results;    my @results;
485    $logger->debug( __PACKAGE__ . "->getListFiltered( nodename => '" . $nodename . "' )" );    $logger->debug( __PACKAGE__ . "->getListFiltered( nodename => '" . $nodename . "' )" );
486    
487    #print Dumper($filters);  #print Dumper($filters);
488        
489    my @tfilters;    my @tfilters;
490        
# Line 361  sub getListFiltered { Line 514  sub getListFiltered {
514    my $tfilter = join(' & ', @tfilters);    my $tfilter = join(' & ', @tfilters);
515    
516    # get set of objects from odbms by object name    # get set of objects from odbms by object name
517    my $remote = $self->{COREHANDLE}->remote($nodename);    my $remote = $self->{_COREHANDLE}->remote($nodename);
518        
519    # was:    # was:
520    #@results = $self->{COREHANDLE}->select($object_set, $tfilter);    #@results = $self->{COREHANDLE}->select($object_set, $tfilter);
521    
522    # is:    # is:
523    # HACK: build eval-string (sorry) to get filtered list - please give advice here    # HACK: build eval-string (sorry) to get filtered list - please give advice here
524    my $evalstring = 'return $self->{COREHANDLE}->select($remote, ' . $tfilter . ');';    my $evalstring = 'return $self->{_COREHANDLE}->select($remote, ' . $tfilter . ');';
525      
526      #print "eval: $evalstring", "\n";
527        
528    # get filtered list/set    # get filtered list/set
529    @results = eval($evalstring);    @results = eval($evalstring);
# Line 380  sub getListFiltered { Line 535  sub getListFiltered {
535  sub createCursor {  sub createCursor {
536    my $self = shift;    my $self = shift;
537    my $node = shift;    my $node = shift;
538    my $cmdHandle = $self->{COREHANDLE}->cursor($node);    my $cmdHandle = $self->{_COREHANDLE}->cursor($node);
539    my $result = Data::Storage::Result::Tangram->new( RESULTHANDLE => $cmdHandle );    my $result = Data::Storage::Result::Tangram->new( RESULTHANDLE => $cmdHandle );
540    return $result;    return $result;
541  }  }
542    
543  sub createSet {  sub createSet {
544    my $self = shift;    my $self = shift;
545    #print "-" x 80, "\n";
546    #print Dumper(@_);
547    my @objects = @_;    my @objects = @_;
548    my $rh = Set::Object->new();    my $rh = Set::Object->new();
549    foreach (@objects) {    foreach (@objects) {
550      #print Dumper($_);      if (!isEmpty($_)) {
551      $rh->insert($_) if !isEmpty($_);  #print Dumper($_);
552          $rh->insert($_);
553        }
554    }    }
555    #print Dumper($rh->members());    #print Dumper($rh->members());
556    my $result = Data::Storage::Result::Tangram->new( RESULTHANDLE => $rh );    my $result = Data::Storage::Result::Tangram->new( RESULTHANDLE => $rh );
# Line 401  sub createSet { Line 560  sub createSet {
560  sub sendQuery {  sub sendQuery {
561    my $self = shift;    my $self = shift;
562    my $query = shift;    my $query = shift;
   #my $sql = "SELECT cs FROM $self->{metainfo}->{$descent}->{node} WHERE $self->{metainfo}->{$descent}->{IdentProvider}->{arg}='$self->{entry}->{source}->{ident}';";  
   #my $result = $self->{metainfo}->{$descent}->{storage}->sendCommand($sql);  
563    
564    #print Dumper($query);    #print Dumper($query);
565    
566    # HACK: special case: querying by id does not translate into a common tangram query    # type = ITEM|LIST|TRANSPARENT
567    # just load the object by given id(ent)    my $type = '';
568    if ($query->{criterias}->[0]->{key} eq 'id' && $query->{criterias}->[0]->{op} eq 'eq') {    # mode = OID|SPECIAL
569      #print "LOAD!!!", "\n";    my $mode = '';
570      #exit;    my $ident = '';
571      #return Set::Object->new( $self->{COREHANDLE}->load($query->{criterias}->[0]->{val}) );    my $crud = '';
572      my $ident = $query->{criterias}->[0]->{val};    
573  #print "load obj", "\n";    
574      #return $self->createSet() if $ident == 5;    # dispatch type and mode
575      my $object = $self->{COREHANDLE}->load($ident);    
576  #print "get id", "\n";      # defaults - 1
577      my $oid = $self->{COREHANDLE}->id($object);      if ($query->{options}) {
578      return $self->createSet($object);        $crud = $query->{options}->{crud};
579      #return $self->createSet( $self->{COREHANDLE}->load('300090018') );        $crud ||= $query->{options}->{action};
580    }      }
581    
582    die("This should not be reached for now - redirect to \$self->getListFiltered() here!");      # defaults - 2
583        $type ||= 'TRANSPARENT';
584    # TODO: do a common tangram query here      $crud ||= 'RETRIEVE';
585    
586    my @crits;      if ($query->{options}->{OID}) {
587    foreach (@{$query->{criterias}}) {        $type = 'ITEM';
588      my $op = '';        $mode = 'OID';
589      $op = '=' if lc $_->{op} eq 'eq';        $ident = $query->{options}->{OID};
590      push @crits, "$_->{key}$op'$_->{val}'";      
591    }      } elsif (my $guid = $query->{options}->{GUID}) {
592    my $subnodes = {};        $type = 'TRANSPARENT';
593    map { $subnodes->{$_}++ } @{$query->{subnodes}};        $query->{criterias} = [ { key => 'guid', op => 'eq', val => $guid } ];
594    # HACK: this is hardcoded ;(    expand possibilities!      
595    #my $crit = join(' AND ', @crits);      }
596    #my $sql = hash2Sql($query->{node}, $subnodes, 'SELECT', $crit);    
597    #return $self->sendCommand($sql);      # HACK: special case: querying by id does not translate into a common tangram query
598    #my $h = $self->{COREHANDLE}->remote($query->{node});      # just load the object by given identifier (OID) named 'id' - this is required by Data::Transfer::Sync!
599    #my $res = $self->{COREHANDLE}->select($h, $h->{);      if ($query->{criterias} && ($query->{criterias}->[0]->{key} eq 'id' && $query->{criterias}->[0]->{op} eq 'eq')) {
600    return $self->createCursor($query->{node});        $type = 'ITEM';
601          $mode = 'SPECIAL.SYNC';
602          $ident = $query->{criterias}->[0]->{val};
603        }
604      
605    
606      # execute query
607      my $result;
608    
609      if ($type eq 'ITEM' && $ident) {
610    
611        if ($mode eq 'OID') {    
612          # TODO: review this case!
613          $result = $self->getObject($ident, $query->{options});
614        
615        } elsif ($mode eq 'SPECIAL.SYNC') {
616    
617          # V1 - failed
618          #return Set::Object->new( $self->{COREHANDLE}->load($query->{criterias}->[0]->{val}) );
619      
620          # hmm....
621          #return $self->createSet() if $ident == 5;
622          
623          # Unload single object before doing any further operations to
624          # expect a "fresh" object from orm when performing the next calls.
625          $self->{_COREHANDLE}->unload($ident);
626          
627          # Load object from orm.
628          my $object = $self->{_COREHANDLE}->load($ident);
629      
630          # determine object identifier (OID)
631          my $oid = $self->{_COREHANDLE}->id($object);
632          
633          # encapsulate into result/response container and return this one
634          $result = $self->createSet($object);
635          
636          # debugging
637          #$result = $self->createSet( $self->{COREHANDLE}->load('300090018') );
638    
639        }
640        
641      
642      } elsif ($type eq 'TRANSPARENT') {
643    
644        if ($crud eq 'RETRIEVE') {
645    
646          my $list = $self->getListFiltered($query->{node}, $query->{criterias});
647          #return $self->createSet($object);
648          #return $self->createSet($list);
649          return $self->createSet(@$list);
650        
651          #die("This should not be reached for now - redirect to \$self->getListFiltered() here!");
652        
653          # try a generic tangram query here
654          # TODO: try to place an oql on top of that (search.cpan.org!)
655          my @crits;
656          foreach (@{$query->{criterias}}) {
657            my $op = '';
658            $op = '=' if lc $_->{op} eq 'eq';
659            push @crits, "$_->{key}$op'$_->{val}'";
660          }
661          my $subnodes = {};
662          map { $subnodes->{$_}++ } @{$query->{subnodes}};
663          # HACK: this is hardcoded ;(    expand possibilities!
664          #my $crit = join(' AND ', @crits);
665          #my $sql = hash2Sql($query->{node}, $subnodes, 'SELECT', $crit);
666          #return $self->sendCommand($sql);
667          #my $h = $self->{COREHANDLE}->remote($query->{node});
668          #my $res = $self->{COREHANDLE}->select($h, $h->{);
669          $result = $self->createCursor($query->{node});
670    
671        } elsif ($crud eq 'UPDATE') {
672    
673          # Patch current query to be a loader (e.g. change action, remove payload) ...
674          my $childquery = deep_copy($query);
675          $childquery->{options}->{crud} = 'RETRIEVE';
676          delete $childquery->{payload};
677    
678          # ... to use it to fetch a fresh object using ourselves (sendQuery).
679          my $cursor = $self->sendQuery($childquery);
680          my $status = $cursor->getStatus();
681          my $object = $cursor->getNextEntry();
682    
683          # Merge values and apply value modifiers.
684          my $options = { utf8 => 1, php => 1 };
685          merge_to($object, $query->{payload}, $options);
686    
687          # Execute update operation at orm.
688          $self->update($object);
689        
690        } elsif ($crud eq 'DELETE') {
691    
692          # Patch current query to be a loader (e.g. change action) ...
693          my $childquery = deep_copy($query);
694          $childquery->{options}->{crud} = 'RETRIEVE';
695    
696          # ... to use it to fetch a fresh object using ourselves (sendQuery).
697          my $cursor = $self->sendQuery($childquery);
698          my $status = $cursor->getStatus();
699          my $object = $cursor->getNextEntry();
700    
701          $self->erase($object);
702    
703        }
704    
705      }
706    
707      return $result;
708    
709  }  }
710    
711  sub eraseAll {  sub eraseAll {
712    my $self = shift;    my $self = shift;
713    my $classname = shift;    my $classname = shift;
714    my $remote = $self->{storage}->remote($classname);    my $remote = $self->{_COREHANDLE}->remote($classname);
715    my @objs = $self->{storage}->select($remote);    my @objs = $self->{_COREHANDLE}->select($remote);
716    $self->{COREHANDLE}->erase(@objs);    $self->{_COREHANDLE}->erase(@objs);
717  }  }
718    
719  sub createDb {  sub createDb {
# Line 457  sub createDb { Line 722  sub createDb {
722    return $storage->createDb();    return $storage->createDb();
723  }  }
724    
725    sub getObject {
726      my $self = shift;
727      my $oid = shift;
728      my $options = shift;
729    
730      # TODO: create a deep_unload method (currently _all_ objects are unloaded)
731      # unload($oid) will only unload object, not deep object hashes
732      $self->{_COREHANDLE}->unload() if ($options->{destroy});
733    
734      # TODO: review this
735      #if (!$self->{COREHANDLE}) { return; }
736    
737      # TODO: review this
738      my $object = eval('$self->{_COREHANDLE}->load($oid);');
739      print $@, "\n" if $@;
740    
741      return $object if $object;
742    }
743    
744    sub getObjectByGuid_old {
745      my $self = shift;
746      my $guid = shift;
747      my $options = shift;
748      
749      # Guid and Classname is needed
750      if(!$guid || !$options->{classname}) {
751       $logger->error( __PACKAGE__ . "->getObjectByGuid: No 'guid' OR no Classname in options hash was given but needed!" );
752        return;
753      }
754      
755      # TODO: create a deep_unload method (currently _all_ objects are unloaded)
756      # unload($oid) will only unload object, not deep object hashes
757      $self->{_COREHANDLE}->unload() if ($options->{destroy});
758    
759      # search for object with given Classname and Guid
760      my $obj_tmp = $self->{_COREHANDLE}->remote($options->{classname});
761      my @result = $self->{_COREHANDLE}->select($obj_tmp, $obj_tmp->{guid} eq $guid);
762      
763      # we searched for global unique identifer of some object,
764      # so I think we can trust there would be only one result
765      if($result[0]) {
766        return $result[0];
767      } else {
768        $logger->error( __PACKAGE__ . "->getObjectByGuid: No Object with Classname $options->{classname} and GUID $guid found!" );
769        return;
770      }
771      
772    }
773    
774    sub getObjectAsHash_old {
775      my $self = shift;
776      my $oid = shift;
777      my $options = shift;  
778      my $obj;
779      
780      if($options->{guid}) {
781        $obj = $self->getObjectByGuid($oid, $options);
782      } else {
783        $obj = $self->getObject($oid, $options);
784      }
785      
786      # build options (a callback to unload autovivified objects) for 'expand'
787      # TODO: use $logger to write to debug here!
788      my $cb; # = sub {};
789    
790      # deactivated way to get rid of used instances, if requested
791    =pod
792        if ($options->{destroy}) {
793          $options->{cb}->{destroy} = sub {
794            print "================ DESTROY", "\n";
795            my $object = shift;
796            #print Dumper($object);
797            $self->{_COREHANDLE}->unload($object);
798            #undef($object);
799          };
800        }
801    =cut
802    
803      my $hash = expand($obj, $options);
804    
805      # old (unsuccessful) attempts to get rid of used instances, if requested
806    
807        # V1:
808        #$options->{cb}->{destroy}->($obj);
809        #$self->{_COREHANDLE}->unload($obj);
810      
811        # V2:
812        #$obj->clear_refs;
813        #$self->{COREHANDLE}->unload($obj) if($options->{destroy});
814        #$obj->DESTROY;
815        #undef($obj) if($options->{destroy});
816      
817      return $hash;
818    }
819    
820    sub getSchema {
821      return $schema_tangram;
822    }
823    
824    sub getCOREHANDLE {
825      my $self = shift;
826      return $self->{_COREHANDLE};
827    }
828    
829    sub dropDb {
830      my $self = shift;
831      my $storage = $self->_getSubLayerHandle();
832      return $storage->dropDb();
833    }
834    
835    sub testAvailability {
836      my $self = shift;
837      my $storage = $self->_getSubLayerHandle();
838      return $storage->testAvailability();
839    }
840    
841    sub disconnect2 {
842      my $self = shift;
843      my $storage = $self->_getSubLayerHandle();
844      print "DISC!", "\n";
845    
846      my $storage_ll = $storage->{_COREHANDLE};
847      $storage_ll->disconnect();
848      
849      print Dumper($storage);
850      exit;
851      
852      #$self->{_COREHANDLE}
853      #$storage->disconnect();
854      $self->{dataStorageLayer}->disconnect();
855    }
856    
857  1;  1;
858    __END__

Legend:
Removed from v.1.8  
changed lines
  Added in v.1.34

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