| 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 |
# Revision 1.16 2002/12/11 06:54:10 joko |
| 60 |
# + fix: encapsulated object-loading inside an 'eval' |
# + fix: encapsulated object-loading inside an 'eval' |
| 61 |
# |
# |
| 62 |
# Revision 1.15 2002/12/05 13:55:21 joko |
# Revision 1.15 2002/12/05 13:55:21 joko |
| 63 |
# + now utilizing 'object2hash' instead of 'var_deref' |
# + now utilizing 'expand' instead of 'var_deref' |
| 64 |
# + played around with having fresh-objects - no progress.... |
# + played around with having fresh-objects - no progress.... |
| 65 |
# |
# |
| 66 |
# Revision 1.14 2002/12/05 09:40:30 jonen |
# Revision 1.14 2002/12/05 09:40:30 jonen |
| 133 |
use base ("Data::Storage::Handler"); |
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( object2hash ); |
|
|
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; |
| 161 |
my $self = shift; |
my $self = shift; |
| 162 |
$logger->debug( __PACKAGE__ . "->_initSchema()" ); |
$logger->debug( __PACKAGE__ . "->_initSchema()" ); |
| 163 |
#if (!$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 |
|
my $obj = DesignPattern::Object->fromPackage($self->{locator}->{schema}, { 'EXPORT_OBJECTS' => $self->{locator}->{classnames}, 'want_transactions' => $self->{locator}->{want_transactions} } ); |
| 166 |
$schema_tangram = $obj->getSchema(); |
$schema_tangram = $obj->getSchema(); |
| 167 |
#} |
#} |
| 168 |
if (!$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 ); |
| 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 ); |
| 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; |
| 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}) { |
| 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 |
| 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 |
|
|
| 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); |
| 526 |
die $@ if $@; |
die $@ if $@; |
| 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 ); |
| 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 { |
| 710 |
|
|
| 711 |
# TODO: create a deep_unload method (currently _all_ objects are unloaded) |
# TODO: create a deep_unload method (currently _all_ objects are unloaded) |
| 712 |
# unload($oid) will only unload object, not deep object hashes |
# unload($oid) will only unload object, not deep object hashes |
| 713 |
$self->{_COREHANDLE}->unload() if($options->{destroy}); |
$self->{_COREHANDLE}->unload() if ($options->{destroy}); |
| 714 |
|
|
| 715 |
# TODO: review this |
# TODO: review this |
| 716 |
#if (!$self->{COREHANDLE}) { return; } |
#if (!$self->{COREHANDLE}) { return; } |
| 722 |
return $object if $object; |
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, $options); |
|
| 730 |
|
# Guid and Classname is needed |
| 731 |
|
if(!$guid || !$options->{classname}) { |
| 732 |
|
$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' |
# build options (a callback to unload autovivified objects) for 'expand' |
| 768 |
# TODO: use $logger to write to debug here! |
# TODO: use $logger to write to debug here! |
| 769 |
my $cb; # = sub {}; |
my $cb; # = sub {}; |
| 770 |
|
|
| 771 |
|
# deactivated way to get rid of used instances, if requested |
| 772 |
=pod |
=pod |
| 773 |
if ($options->{destroy}) { |
if ($options->{destroy}) { |
| 774 |
$options->{cb}->{destroy} = sub { |
$options->{cb}->{destroy} = sub { |
| 775 |
print "================ DESTROY", "\n"; |
print "================ DESTROY", "\n"; |
| 776 |
my $object = shift; |
my $object = shift; |
| 777 |
#print Dumper($object); |
#print Dumper($object); |
| 778 |
$self->{_COREHANDLE}->unload($object); |
$self->{_COREHANDLE}->unload($object); |
| 779 |
#undef($object); |
#undef($object); |
| 780 |
}; |
}; |
| 781 |
} |
} |
| 782 |
=cut |
=cut |
| 783 |
|
|
| 784 |
my $hash = object2hash($obj, $options); |
my $hash = expand($obj, $options); |
| 785 |
#$options->{cb}->{destroy}->($obj); |
|
| 786 |
#$self->{_COREHANDLE}->unload($obj); |
# old (unsuccessful) attempts to get rid of used instances, if requested |
| 787 |
|
|
| 788 |
# convert values in hash to utf8 to be ready for (e.g.) encapsulation in XML |
# V1: |
| 789 |
# now done in object2hash |
#$options->{cb}->{destroy}->($obj); |
| 790 |
#var2utf8($hash) if ($options->{utf8}); |
#$self->{_COREHANDLE}->unload($obj); |
| 791 |
|
|
| 792 |
# old (wrong) attempts to get rid of used instances, if requested |
# V2: |
| 793 |
#$obj->clear_refs; |
#$obj->clear_refs; |
| 794 |
#$self->{COREHANDLE}->unload($obj) if($options->{destroy}); |
#$self->{COREHANDLE}->unload($obj) if($options->{destroy}); |
| 795 |
#$obj->DESTROY; |
#$obj->DESTROY; |
| 807 |
return $self->{_COREHANDLE}; |
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__ |