3 |
# $Id$ |
# $Id$ |
4 |
# |
# |
5 |
# $Log$ |
# $Log$ |
6 |
|
# Revision 1.35 2003/04/19 16:09:48 jonen |
7 |
|
# + added operator dispatching (currently for getting ref-type) at 'getListFiltered' |
8 |
|
# |
9 |
|
# Revision 1.34 2003/04/11 01:18:53 joko |
10 |
|
# sendQuery: |
11 |
|
# + introduced crud action 'DELETE' |
12 |
|
# |
13 |
|
# Revision 1.33 2003/04/09 06:07:43 joko |
14 |
|
# revamped 'sub sendQuery' |
15 |
|
# |
16 |
|
# Revision 1.32 2003/04/08 22:52:22 joko |
17 |
|
# modified 'querySchema': better behaviour regarding filtering result |
18 |
|
# |
19 |
|
# Revision 1.31 2003/04/05 21:24:09 joko |
20 |
|
# modified 'sub getChildNodes': now contains code from 'querySchema' |
21 |
|
# |
22 |
|
# Revision 1.30 2003/03/27 15:31:14 joko |
23 |
|
# fixes to modules regarding new namespace(s) below Data::Mungle::* |
24 |
|
# |
25 |
|
# Revision 1.29 2003/02/21 01:47:18 joko |
26 |
|
# purged old code |
27 |
|
# minor cosmetics |
28 |
|
# |
29 |
|
# Revision 1.28 2003/02/20 20:20:26 joko |
30 |
|
# tried to get auto-disconnect working again - failed with that |
31 |
|
# |
32 |
|
# Revision 1.27 2003/01/31 06:30:59 joko |
33 |
|
# + enabled 'sendQuery' |
34 |
|
# |
35 |
|
# Revision 1.26 2003/01/30 22:29:47 joko |
36 |
|
# + fixed module usage (removed dependency on 'libp.pm') |
37 |
|
# |
38 |
|
# Revision 1.25 2003/01/19 02:30:05 joko |
39 |
|
# + fix: modified call to '_initSchema' |
40 |
|
# |
41 |
|
# Revision 1.24 2002/12/22 14:13:01 joko |
42 |
|
# + sub dropDb |
43 |
|
# |
44 |
|
# Revision 1.23 2002/12/19 16:31:53 joko |
45 |
|
# +- renamed sub to 'rebuildDb' |
46 |
|
# |
47 |
|
# Revision 1.22 2002/12/18 22:28:16 jonen |
48 |
|
# + added extended logging at 'getObjectByGuid()' |
49 |
|
# |
50 |
|
# Revision 1.21 2002/12/16 22:20:49 jonen |
51 |
|
# + fixed bug at 'getObjectByGuid()' |
52 |
|
# |
53 |
# Revision 1.20 2002/12/16 20:49:17 jonen |
# Revision 1.20 2002/12/16 20:49:17 jonen |
54 |
# + added sub 'getObjectByGuid()' |
# + added sub 'getObjectByGuid()' |
55 |
# + added functionality to use 'getObjectByGuid' at 'getObjectAsHash()' |
# + added functionality to use 'getObjectByGuid' at 'getObjectAsHash()' |
67 |
# + fix: encapsulated object-loading inside an 'eval' |
# + fix: encapsulated object-loading inside an 'eval' |
68 |
# |
# |
69 |
# Revision 1.15 2002/12/05 13:55:21 joko |
# Revision 1.15 2002/12/05 13:55:21 joko |
70 |
# + now utilizing 'object2hash' instead of 'var_deref' |
# + now utilizing 'expand' instead of 'var_deref' |
71 |
# + played around with having fresh-objects - no progress.... |
# + played around with having fresh-objects - no progress.... |
72 |
# |
# |
73 |
# Revision 1.14 2002/12/05 09:40:30 jonen |
# Revision 1.14 2002/12/05 09:40:30 jonen |
140 |
use base ("Data::Storage::Handler"); |
use base ("Data::Storage::Handler"); |
141 |
use base ("Data::Storage::Handler::Abstract"); |
use base ("Data::Storage::Handler::Abstract"); |
142 |
|
|
143 |
use Tangram; |
|
144 |
use Data::Dumper; |
use Data::Dumper; |
145 |
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 ); |
|
146 |
|
|
147 |
|
use DesignPattern::Object; |
148 |
|
use Data::Storage::Result::Tangram; |
149 |
|
use Data::Mungle::Compare::Struct qw( isEmpty ); |
150 |
|
use Data::Mungle::Transform::Deep qw( expand deep_copy merge_to ); |
151 |
|
|
152 |
# get logger instance |
# get logger instance |
153 |
my $logger = Log::Dispatch::Config->instance; |
my $logger = Log::Dispatch::Config->instance; |
168 |
my $self = shift; |
my $self = shift; |
169 |
$logger->debug( __PACKAGE__ . "->_initSchema()" ); |
$logger->debug( __PACKAGE__ . "->_initSchema()" ); |
170 |
#if (!$schema_tangram) { |
#if (!$schema_tangram) { |
171 |
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} } ); |
172 |
|
my $obj = DesignPattern::Object->fromPackage($self->{locator}->{schema}, { 'EXPORT_OBJECTS' => $self->{locator}->{classnames}, 'want_transactions' => $self->{locator}->{want_transactions} } ); |
173 |
$schema_tangram = $obj->getSchema(); |
$schema_tangram = $obj->getSchema(); |
174 |
#} |
#} |
175 |
if (!$schema_tangram) { |
if (!$schema_tangram) { |
202 |
my $self = shift; |
my $self = shift; |
203 |
|
|
204 |
my $dsn = shift; |
my $dsn = shift; |
205 |
|
|
206 |
|
#print Dumper($self); |
207 |
|
#exit; |
208 |
|
|
209 |
|
# TODO: re-enable |
210 |
$dsn ||= $self->{locator}->{dbi}->{dsn}; |
$dsn ||= $self->{locator}->{dbi}->{dsn}; |
|
|
|
211 |
$logger->debug( __PACKAGE__ . "->connect( dsn $dsn )" ); |
$logger->debug( __PACKAGE__ . "->connect( dsn $dsn )" ); |
212 |
|
|
213 |
#my $storage = Tangram::Relational->connect( $schema, $dsn ); |
#my $storage = Tangram::Relational->connect( $schema, $dsn ); |
219 |
# return; |
# return; |
220 |
# } |
# } |
221 |
|
|
222 |
return unless $self->_initSchema(); |
#return unless $self->_initSchema(); |
223 |
|
$self->_initSchema(); |
224 |
|
|
225 |
# create the main tangram storage object |
# create the main tangram storage object |
226 |
#$self->{COREHANDLE} = Tangram::Relational->connect( $schema, $dsn ); |
#$self->{COREHANDLE} = Tangram::Relational->connect( $schema, $dsn ); |
247 |
sub getChildNodes { |
sub getChildNodes { |
248 |
|
|
249 |
my $self = shift; |
my $self = shift; |
250 |
my @nodes; |
my $mode = shift; |
251 |
|
my $filter = shift; |
252 |
|
|
253 |
|
$mode ||= 'core'; |
254 |
|
$filter ||= 'all'; |
255 |
|
|
256 |
|
$logger->debug( __PACKAGE__ . "->getChildNodes($mode)" ); |
257 |
|
|
258 |
$logger->debug( __PACKAGE__ . "->getChildNodes()" ); |
if ($mode eq 'core') { |
259 |
|
|
260 |
# create new DBI - Data::Storage - object from already connected DBI::db - handle inside the current COREHANDLE |
my @nodes; |
261 |
#my $loc = new Data::Storage::Locator( type => "DBI", dbi => { db => $self->{COREHANDLE}->{db} }); |
|
262 |
#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 |
263 |
|
#my $loc = new Data::Storage::Locator( type => "DBI", dbi => { db => $self->{COREHANDLE}->{db} }); |
264 |
# todo: should we retrieve information from the schema here |
#my $loc = new Data::Storage::Locator( type => "DBI", COREHANDLE => $self->{COREHANDLE}->{db} ); |
265 |
# rather than poorly getting table names from underlying dbi? |
|
266 |
my $storage = $self->_getSubLayerHandle(); |
# todo: should we retrieve information from the schema here |
267 |
@nodes = @{$storage->getChildNodes()}; |
# rather than poorly getting table names from underlying dbi? |
268 |
#$storage->_configureCOREHANDLE(); |
my $storage = $self->_getSubLayerHandle(); |
269 |
#print "getchildnodes\n"; |
@nodes = @{$storage->getChildNodes()}; |
270 |
#print Dumper($self); |
#$storage->_configureCOREHANDLE(); |
271 |
#if (my $result = $self->sendCommand( 'SHOW TABLES;' ) ) { |
#print "getchildnodes\n"; |
272 |
|
#print Dumper($self); |
273 |
|
#if (my $result = $self->sendCommand( 'SHOW TABLES;' ) ) { |
274 |
|
|
275 |
|
# TODO: REVIEW |
276 |
|
#$storage->disconnect(); |
277 |
|
|
278 |
|
$self->{meta}->{childnodes} = \@nodes; |
279 |
|
|
280 |
|
return \@nodes; |
281 |
|
|
282 |
# TODO: REVIEW |
} elsif ($mode eq 'root') { |
283 |
#$storage->disconnect(); |
|
284 |
|
# FIXME: this will return *all* known classes to 'Class::Tangram', |
285 |
|
# which might not be what you expect since more than one instance |
286 |
|
# of Tangram may be in memory and Class::Tangram seems to |
287 |
|
# offer no methods to determine this or filter its result(s) according |
288 |
|
# to a specific database. |
289 |
|
my @object_names = Class::Tangram::known_classes(); |
290 |
|
my @concret_names; |
291 |
|
my $o_cnt; |
292 |
|
foreach (sort @object_names) { |
293 |
|
push @concret_names, $_ if (!Class::Tangram::class_is_abstract($_)); |
294 |
|
$o_cnt++; |
295 |
|
} |
296 |
|
|
297 |
|
if ($filter eq 'all') { |
298 |
|
return \@object_names; |
299 |
|
} elsif ($filter eq 'concrete') { |
300 |
|
return \@concret_names; |
301 |
|
} |
302 |
|
|
303 |
$self->{meta}->{childnodes} = \@nodes; |
} |
304 |
|
|
|
return \@nodes; |
|
305 |
|
|
306 |
} |
} |
307 |
|
|
|
|
|
308 |
sub testIntegrity { |
sub testIntegrity { |
309 |
|
|
310 |
my $self = shift; |
my $self = shift; |
378 |
$logger->debug( __PACKAGE__ . "->configureCOREHANDLE" ); |
$logger->debug( __PACKAGE__ . "->configureCOREHANDLE" ); |
379 |
|
|
380 |
#my $subLayer = $self->_getSubLayerHandle(); |
#my $subLayer = $self->_getSubLayerHandle(); |
381 |
|
#print Dumper($self); |
382 |
|
#exit; |
383 |
|
|
384 |
# apply configured modifications |
# apply configured modifications |
385 |
if (exists $self->{dbi}->{trace_level} && exists $self->{dbi}->{trace_file}) { |
if (exists $self->{dbi}->{trace_level} && exists $self->{dbi}->{trace_file}) { |
445 |
return $ok; |
return $ok; |
446 |
} |
} |
447 |
|
|
448 |
sub rebuildDbAndSchema { |
sub rebuildDb { |
449 |
my $self = shift; |
my $self = shift; |
450 |
$logger->info( __PACKAGE__ . "->rebuildDbAndSchema()" ); |
$logger->info( __PACKAGE__ . "->rebuildDb()" ); |
451 |
my @results; |
my @results; |
452 |
|
|
453 |
# sum up results (bool (0/1)) in array |
# sum up results (bool (0/1)) in array |
487 |
my @results; |
my @results; |
488 |
$logger->debug( __PACKAGE__ . "->getListFiltered( nodename => '" . $nodename . "' )" ); |
$logger->debug( __PACKAGE__ . "->getListFiltered( nodename => '" . $nodename . "' )" ); |
489 |
|
|
490 |
#print Dumper($filters); |
#print Dumper($filters); |
491 |
|
|
492 |
my @tfilters; |
my @tfilters; |
493 |
|
|
509 |
# objects => $objects, |
# objects => $objects, |
510 |
# ); |
# ); |
511 |
|
|
512 |
# HACK: build eval-string (sorry) to get filtered list - please give advice here |
# TODO: is_op? |
513 |
push @tfilters, '$remote->{' . $filter->{key} . '}' . " $filter->{op} '$filter->{val}'"; |
# dispatch un-common operators if exists |
514 |
|
if($filter->{op} eq "ref") { |
515 |
|
push @tfilters, 'ref($remote->{' . $filter->{key} . '})' . " eq '$filter->{val}'"; |
516 |
|
} else { |
517 |
|
# HACK: build eval-string (sorry) to get filtered list - please give advice here |
518 |
|
push @tfilters, '$remote->{' . $filter->{key} . '}' . " $filter->{op} '$filter->{val}'"; |
519 |
|
} |
520 |
|
|
521 |
} |
} |
522 |
|
|
532 |
# 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 |
533 |
my $evalstring = 'return $self->{_COREHANDLE}->select($remote, ' . $tfilter . ');'; |
my $evalstring = 'return $self->{_COREHANDLE}->select($remote, ' . $tfilter . ');'; |
534 |
|
|
535 |
|
#print "eval: $evalstring", "\n"; |
536 |
|
|
537 |
# get filtered list/set |
# get filtered list/set |
538 |
@results = eval($evalstring); |
@results = eval($evalstring); |
539 |
die $@ if $@; |
die $@ if $@; |
569 |
sub sendQuery { |
sub sendQuery { |
570 |
my $self = shift; |
my $self = shift; |
571 |
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); |
|
572 |
|
|
573 |
#print Dumper($query); |
#print Dumper($query); |
574 |
|
|
575 |
# HACK: special case: querying by id does not translate into a common tangram query |
# type = ITEM|LIST|TRANSPARENT |
576 |
# just load the object by given id(ent) |
my $type = ''; |
577 |
if ($query->{criterias}->[0]->{key} eq 'id' && $query->{criterias}->[0]->{op} eq 'eq') { |
# mode = OID|SPECIAL |
578 |
#print "LOAD!!!", "\n"; |
my $mode = ''; |
579 |
#exit; |
my $ident = ''; |
580 |
#return Set::Object->new( $self->{COREHANDLE}->load($query->{criterias}->[0]->{val}) ); |
my $crud = ''; |
581 |
my $ident = $query->{criterias}->[0]->{val}; |
|
582 |
#print "load obj", "\n"; |
|
583 |
#return $self->createSet() if $ident == 5; |
# dispatch type and mode |
584 |
$self->{_COREHANDLE}->unload($ident); |
|
585 |
my $object = $self->{_COREHANDLE}->load($ident); |
# defaults - 1 |
586 |
#print "get id", "\n"; |
if ($query->{options}) { |
587 |
my $oid = $self->{_COREHANDLE}->id($object); |
$crud = $query->{options}->{crud}; |
588 |
#print Dumper($object); |
$crud ||= $query->{options}->{action}; |
589 |
#print "oid: $oid", "\n"; |
} |
590 |
return $self->createSet($object); |
|
591 |
#return $self->createSet( $self->{COREHANDLE}->load('300090018') ); |
# defaults - 2 |
592 |
} |
$type ||= 'TRANSPARENT'; |
593 |
|
$crud ||= 'RETRIEVE'; |
594 |
die("This should not be reached for now - redirect to \$self->getListFiltered() here!"); |
|
595 |
|
if ($query->{options}->{OID}) { |
596 |
# TODO: do a common tangram query here |
$type = 'ITEM'; |
597 |
|
$mode = 'OID'; |
598 |
my @crits; |
$ident = $query->{options}->{OID}; |
599 |
foreach (@{$query->{criterias}}) { |
|
600 |
my $op = ''; |
} elsif (my $guid = $query->{options}->{GUID}) { |
601 |
$op = '=' if lc $_->{op} eq 'eq'; |
$type = 'TRANSPARENT'; |
602 |
push @crits, "$_->{key}$op'$_->{val}'"; |
$query->{criterias} = [ { key => 'guid', op => 'eq', val => $guid } ]; |
603 |
} |
|
604 |
my $subnodes = {}; |
# if operator is different (dispatcher for 'getListFiltered') |
605 |
map { $subnodes->{$_}++ } @{$query->{subnodes}}; |
} elsif (my $op = $query->{options}->{op}) { |
606 |
# HACK: this is hardcoded ;( expand possibilities! |
$type = 'TRANSPARENT'; |
607 |
#my $crit = join(' AND ', @crits); |
$query->{criterias} = [ { key => $query->{options}->{meta_label}, op => $op, val => $query->{options}->{meta_value} } ]; |
608 |
#my $sql = hash2Sql($query->{node}, $subnodes, 'SELECT', $crit); |
|
609 |
#return $self->sendCommand($sql); |
} |
610 |
#my $h = $self->{COREHANDLE}->remote($query->{node}); |
|
611 |
#my $res = $self->{COREHANDLE}->select($h, $h->{); |
# HACK: special case: querying by id does not translate into a common tangram query |
612 |
return $self->createCursor($query->{node}); |
# just load the object by given identifier (OID) named 'id' - this is required by Data::Transfer::Sync! |
613 |
|
if ($query->{criterias} && ($query->{criterias}->[0]->{key} eq 'id' && $query->{criterias}->[0]->{op} eq 'eq')) { |
614 |
|
$type = 'ITEM'; |
615 |
|
$mode = 'SPECIAL.SYNC'; |
616 |
|
$ident = $query->{criterias}->[0]->{val}; |
617 |
|
} |
618 |
|
|
619 |
|
|
620 |
|
# execute query |
621 |
|
my $result; |
622 |
|
|
623 |
|
if ($type eq 'ITEM' && $ident) { |
624 |
|
|
625 |
|
if ($mode eq 'OID') { |
626 |
|
# TODO: review this case! |
627 |
|
$result = $self->getObject($ident, $query->{options}); |
628 |
|
|
629 |
|
} elsif ($mode eq 'SPECIAL.SYNC') { |
630 |
|
|
631 |
|
# V1 - failed |
632 |
|
#return Set::Object->new( $self->{COREHANDLE}->load($query->{criterias}->[0]->{val}) ); |
633 |
|
|
634 |
|
# hmm.... |
635 |
|
#return $self->createSet() if $ident == 5; |
636 |
|
|
637 |
|
# Unload single object before doing any further operations to |
638 |
|
# expect a "fresh" object from orm when performing the next calls. |
639 |
|
$self->{_COREHANDLE}->unload($ident); |
640 |
|
|
641 |
|
# Load object from orm. |
642 |
|
my $object = $self->{_COREHANDLE}->load($ident); |
643 |
|
|
644 |
|
# determine object identifier (OID) |
645 |
|
my $oid = $self->{_COREHANDLE}->id($object); |
646 |
|
|
647 |
|
# encapsulate into result/response container and return this one |
648 |
|
$result = $self->createSet($object); |
649 |
|
|
650 |
|
# debugging |
651 |
|
#$result = $self->createSet( $self->{COREHANDLE}->load('300090018') ); |
652 |
|
|
653 |
|
} |
654 |
|
|
655 |
|
|
656 |
|
} elsif ($type eq 'TRANSPARENT') { |
657 |
|
|
658 |
|
if ($crud eq 'RETRIEVE') { |
659 |
|
|
660 |
|
my $list = $self->getListFiltered($query->{node}, $query->{criterias}); |
661 |
|
#return $self->createSet($object); |
662 |
|
#return $self->createSet($list); |
663 |
|
return $self->createSet(@$list); |
664 |
|
|
665 |
|
#die("This should not be reached for now - redirect to \$self->getListFiltered() here!"); |
666 |
|
|
667 |
|
# try a generic tangram query here |
668 |
|
# TODO: try to place an oql on top of that (search.cpan.org!) |
669 |
|
my @crits; |
670 |
|
foreach (@{$query->{criterias}}) { |
671 |
|
my $op = ''; |
672 |
|
$op = '=' if lc $_->{op} eq 'eq'; |
673 |
|
push @crits, "$_->{key}$op'$_->{val}'"; |
674 |
|
} |
675 |
|
my $subnodes = {}; |
676 |
|
map { $subnodes->{$_}++ } @{$query->{subnodes}}; |
677 |
|
# HACK: this is hardcoded ;( expand possibilities! |
678 |
|
#my $crit = join(' AND ', @crits); |
679 |
|
#my $sql = hash2Sql($query->{node}, $subnodes, 'SELECT', $crit); |
680 |
|
#return $self->sendCommand($sql); |
681 |
|
#my $h = $self->{COREHANDLE}->remote($query->{node}); |
682 |
|
#my $res = $self->{COREHANDLE}->select($h, $h->{); |
683 |
|
$result = $self->createCursor($query->{node}); |
684 |
|
|
685 |
|
} elsif ($crud eq 'UPDATE') { |
686 |
|
|
687 |
|
# Patch current query to be a loader (e.g. change action, remove payload) ... |
688 |
|
my $childquery = deep_copy($query); |
689 |
|
$childquery->{options}->{crud} = 'RETRIEVE'; |
690 |
|
delete $childquery->{payload}; |
691 |
|
|
692 |
|
# ... to use it to fetch a fresh object using ourselves (sendQuery). |
693 |
|
my $cursor = $self->sendQuery($childquery); |
694 |
|
my $status = $cursor->getStatus(); |
695 |
|
my $object = $cursor->getNextEntry(); |
696 |
|
|
697 |
|
# Merge values and apply value modifiers. |
698 |
|
my $options = { utf8 => 1, php => 1 }; |
699 |
|
merge_to($object, $query->{payload}, $options); |
700 |
|
|
701 |
|
# Execute update operation at orm. |
702 |
|
$self->update($object); |
703 |
|
|
704 |
|
} elsif ($crud eq 'DELETE') { |
705 |
|
|
706 |
|
# Patch current query to be a loader (e.g. change action) ... |
707 |
|
my $childquery = deep_copy($query); |
708 |
|
$childquery->{options}->{crud} = 'RETRIEVE'; |
709 |
|
|
710 |
|
# ... to use it to fetch a fresh object using ourselves (sendQuery). |
711 |
|
my $cursor = $self->sendQuery($childquery); |
712 |
|
my $status = $cursor->getStatus(); |
713 |
|
my $object = $cursor->getNextEntry(); |
714 |
|
|
715 |
|
$self->erase($object); |
716 |
|
|
717 |
|
} |
718 |
|
|
719 |
|
} |
720 |
|
|
721 |
|
return $result; |
722 |
|
|
723 |
} |
} |
724 |
|
|
725 |
sub eraseAll { |
sub eraseAll { |
755 |
return $object if $object; |
return $object if $object; |
756 |
} |
} |
757 |
|
|
758 |
sub getObjectByGuid { |
sub getObjectByGuid_old { |
759 |
my $self = shift; |
my $self = shift; |
760 |
my $guid = shift; |
my $guid = shift; |
761 |
my $options = shift; |
my $options = shift; |
762 |
|
|
763 |
# Guid and Classname is needed |
# Guid and Classname is needed |
764 |
if(!$guid || !$options->{classname}) { |
if(!$guid || !$options->{classname}) { |
765 |
|
$logger->error( __PACKAGE__ . "->getObjectByGuid: No 'guid' OR no Classname in options hash was given but needed!" ); |
766 |
return; |
return; |
767 |
} |
} |
768 |
|
|
771 |
$self->{_COREHANDLE}->unload() if ($options->{destroy}); |
$self->{_COREHANDLE}->unload() if ($options->{destroy}); |
772 |
|
|
773 |
# search for object with given Classname and Guid |
# search for object with given Classname and Guid |
774 |
my $obj_tmp = $self->{_COREHANDLE}->remote($classname); |
my $obj_tmp = $self->{_COREHANDLE}->remote($options->{classname}); |
775 |
my @result = $self->{_COREHANDLE}->select($obj_tmp, $obj_tmp->{guid} eq $guid); |
my @result = $self->{_COREHANDLE}->select($obj_tmp, $obj_tmp->{guid} eq $guid); |
776 |
|
|
777 |
# we searched for global unique identifer of some object, |
# we searched for global unique identifer of some object, |
778 |
# so it think we can trust there would be only one result |
# so I think we can trust there would be only one result |
779 |
if($result[0]) { |
if($result[0]) { |
780 |
return $result[0]; |
return $result[0]; |
781 |
} else { |
} else { |
782 |
return "No Object with Classname $classname and GUID $options->{guid} found!"; |
$logger->error( __PACKAGE__ . "->getObjectByGuid: No Object with Classname $options->{classname} and GUID $guid found!" ); |
783 |
|
return; |
784 |
} |
} |
785 |
|
|
786 |
} |
} |
787 |
|
|
788 |
sub getObjectAsHash { |
sub getObjectAsHash_old { |
789 |
my $self = shift; |
my $self = shift; |
790 |
my $oid = shift; |
my $oid = shift; |
791 |
my $options = shift; |
my $options = shift; |
800 |
# build options (a callback to unload autovivified objects) for 'expand' |
# build options (a callback to unload autovivified objects) for 'expand' |
801 |
# TODO: use $logger to write to debug here! |
# TODO: use $logger to write to debug here! |
802 |
my $cb; # = sub {}; |
my $cb; # = sub {}; |
803 |
|
|
804 |
|
# deactivated way to get rid of used instances, if requested |
805 |
=pod |
=pod |
806 |
if ($options->{destroy}) { |
if ($options->{destroy}) { |
807 |
$options->{cb}->{destroy} = sub { |
$options->{cb}->{destroy} = sub { |
808 |
print "================ DESTROY", "\n"; |
print "================ DESTROY", "\n"; |
809 |
my $object = shift; |
my $object = shift; |
810 |
#print Dumper($object); |
#print Dumper($object); |
811 |
$self->{_COREHANDLE}->unload($object); |
$self->{_COREHANDLE}->unload($object); |
812 |
#undef($object); |
#undef($object); |
813 |
}; |
}; |
814 |
} |
} |
815 |
=cut |
=cut |
816 |
|
|
817 |
my $hash = object2hash($obj, $options); |
my $hash = expand($obj, $options); |
818 |
#$options->{cb}->{destroy}->($obj); |
|
819 |
#$self->{_COREHANDLE}->unload($obj); |
# old (unsuccessful) attempts to get rid of used instances, if requested |
820 |
|
|
821 |
# convert values in hash to utf8 to be ready for (e.g.) encapsulation in XML |
# V1: |
822 |
# now done in object2hash |
#$options->{cb}->{destroy}->($obj); |
823 |
#var2utf8($hash) if ($options->{utf8}); |
#$self->{_COREHANDLE}->unload($obj); |
824 |
|
|
825 |
# old (wrong) attempts to get rid of used instances, if requested |
# V2: |
826 |
#$obj->clear_refs; |
#$obj->clear_refs; |
827 |
#$self->{COREHANDLE}->unload($obj) if($options->{destroy}); |
#$self->{COREHANDLE}->unload($obj) if($options->{destroy}); |
828 |
#$obj->DESTROY; |
#$obj->DESTROY; |
840 |
return $self->{_COREHANDLE}; |
return $self->{_COREHANDLE}; |
841 |
} |
} |
842 |
|
|
843 |
|
sub dropDb { |
844 |
|
my $self = shift; |
845 |
|
my $storage = $self->_getSubLayerHandle(); |
846 |
|
return $storage->dropDb(); |
847 |
|
} |
848 |
|
|
849 |
|
sub testAvailability { |
850 |
|
my $self = shift; |
851 |
|
my $storage = $self->_getSubLayerHandle(); |
852 |
|
return $storage->testAvailability(); |
853 |
|
} |
854 |
|
|
855 |
|
sub disconnect2 { |
856 |
|
my $self = shift; |
857 |
|
my $storage = $self->_getSubLayerHandle(); |
858 |
|
print "DISC!", "\n"; |
859 |
|
|
860 |
|
my $storage_ll = $storage->{_COREHANDLE}; |
861 |
|
$storage_ll->disconnect(); |
862 |
|
|
863 |
|
print Dumper($storage); |
864 |
|
exit; |
865 |
|
|
866 |
|
#$self->{_COREHANDLE} |
867 |
|
#$storage->disconnect(); |
868 |
|
$self->{dataStorageLayer}->disconnect(); |
869 |
|
} |
870 |
|
|
871 |
1; |
1; |
872 |
|
__END__ |