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

Legend:
Removed from v.1.10  
changed lines
  Added in v.1.33

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