3 |
# $Id$ |
# $Id$ |
4 |
# |
# |
5 |
# $Log$ |
# $Log$ |
6 |
|
# Revision 1.18 2002/12/13 21:48:07 joko |
7 |
|
# + fix to 'sub sendQuery' |
8 |
|
# |
9 |
|
# Revision 1.17 2002/12/12 02:51:09 joko |
10 |
|
# + cosmetics |
11 |
|
# |
12 |
|
# Revision 1.16 2002/12/11 06:54:10 joko |
13 |
|
# + fix: encapsulated object-loading inside an 'eval' |
14 |
|
# |
15 |
|
# Revision 1.15 2002/12/05 13:55:21 joko |
16 |
|
# + now utilizing 'object2hash' instead of 'var_deref' |
17 |
|
# + played around with having fresh-objects - no progress.... |
18 |
|
# |
19 |
|
# Revision 1.14 2002/12/05 09:40:30 jonen |
20 |
|
# + added option->{destroy} at getObject for unloading all instance |
21 |
|
# |
22 |
# Revision 1.13 2002/12/05 07:59:04 joko |
# Revision 1.13 2002/12/05 07:59:04 joko |
23 |
# + now using Tie::SecureHash as a base for the COREHANDLE |
# + now using Tie::SecureHash as a base for the COREHANDLE |
24 |
# + former public COREHANDLE becomes private _COREHANDLE now |
# + former public COREHANDLE becomes private _COREHANDLE now |
91 |
use libp qw( getNewPerlObjectByPkgName ); |
use libp qw( getNewPerlObjectByPkgName ); |
92 |
use Data::Storage::Result::Tangram; |
use Data::Storage::Result::Tangram; |
93 |
use Data::Compare::Struct qw( isEmpty ); |
use Data::Compare::Struct qw( isEmpty ); |
94 |
use Data::Transform::Deep qw( var_deref ); |
use Data::Transform::Deep qw( object2hash ); |
95 |
use Data::Transform::Encode qw( var2utf8 ); |
use Data::Transform::Encode qw( var2utf8 ); |
96 |
|
|
97 |
|
|
432 |
|
|
433 |
sub createSet { |
sub createSet { |
434 |
my $self = shift; |
my $self = shift; |
435 |
|
#print "-" x 80, "\n"; |
436 |
|
#print Dumper(@_); |
437 |
my @objects = @_; |
my @objects = @_; |
438 |
my $rh = Set::Object->new(); |
my $rh = Set::Object->new(); |
439 |
foreach (@objects) { |
foreach (@objects) { |
440 |
#print Dumper($_); |
if (!isEmpty($_)) { |
441 |
$rh->insert($_) if !isEmpty($_); |
#print Dumper($_); |
442 |
|
$rh->insert($_); |
443 |
|
} |
444 |
} |
} |
445 |
#print Dumper($rh->members()); |
#print Dumper($rh->members()); |
446 |
my $result = Data::Storage::Result::Tangram->new( RESULTHANDLE => $rh ); |
my $result = Data::Storage::Result::Tangram->new( RESULTHANDLE => $rh ); |
464 |
my $ident = $query->{criterias}->[0]->{val}; |
my $ident = $query->{criterias}->[0]->{val}; |
465 |
#print "load obj", "\n"; |
#print "load obj", "\n"; |
466 |
#return $self->createSet() if $ident == 5; |
#return $self->createSet() if $ident == 5; |
467 |
|
$self->{_COREHANDLE}->unload($ident); |
468 |
my $object = $self->{_COREHANDLE}->load($ident); |
my $object = $self->{_COREHANDLE}->load($ident); |
469 |
#print "get id", "\n"; |
#print "get id", "\n"; |
470 |
my $oid = $self->{_COREHANDLE}->id($object); |
my $oid = $self->{_COREHANDLE}->id($object); |
471 |
|
#print Dumper($object); |
472 |
|
#print "oid: $oid", "\n"; |
473 |
return $self->createSet($object); |
return $self->createSet($object); |
474 |
#return $self->createSet( $self->{COREHANDLE}->load('300090018') ); |
#return $self->createSet( $self->{COREHANDLE}->load('300090018') ); |
475 |
} |
} |
512 |
sub getObject { |
sub getObject { |
513 |
my $self = shift; |
my $self = shift; |
514 |
my $oid = shift; |
my $oid = shift; |
515 |
|
my $options = shift; |
516 |
|
|
517 |
|
# TODO: create a deep_unload method (currently _all_ objects are unloaded) |
518 |
|
# unload($oid) will only unload object, not deep object hashes |
519 |
|
$self->{_COREHANDLE}->unload() if ($options->{destroy}); |
520 |
|
|
521 |
# TODO: review this |
# TODO: review this |
522 |
#if (!$self->{COREHANDLE}) { return; } |
#if (!$self->{COREHANDLE}) { return; } |
523 |
return $self->{_COREHANDLE}->load($oid); |
|
524 |
|
# TODO: review this |
525 |
|
my $object = eval('$self->{_COREHANDLE}->load($oid);'); |
526 |
|
print $@, "\n" if $@; |
527 |
|
|
528 |
|
return $object if $object; |
529 |
} |
} |
530 |
|
|
531 |
sub getObjectAsHash { |
sub getObjectAsHash { |
532 |
my $self = shift; |
my $self = shift; |
533 |
my $oid = shift; |
my $oid = shift; |
534 |
my $options = shift; |
my $options = shift; |
535 |
my $obj = $self->getObject($oid); |
my $obj = $self->getObject($oid, $options); |
536 |
my $deref = var_deref($obj); |
|
537 |
var2utf8($deref) if ($options->{utf8}); |
# build options (a callback to unload autovivified objects) for 'expand' |
538 |
undef($obj) if($options->{destroy}); |
# TODO: use $logger to write to debug here! |
539 |
return $deref; |
my $cb; # = sub {}; |
540 |
|
=pod |
541 |
|
if ($options->{destroy}) { |
542 |
|
$options->{cb}->{destroy} = sub { |
543 |
|
print "================ DESTROY", "\n"; |
544 |
|
my $object = shift; |
545 |
|
#print Dumper($object); |
546 |
|
$self->{_COREHANDLE}->unload($object); |
547 |
|
#undef($object); |
548 |
|
}; |
549 |
|
} |
550 |
|
=cut |
551 |
|
|
552 |
|
my $hash = object2hash($obj, $options); |
553 |
|
#$options->{cb}->{destroy}->($obj); |
554 |
|
#$self->{_COREHANDLE}->unload($obj); |
555 |
|
|
556 |
|
# convert values in hash to utf8 to be ready for (e.g.) encapsulation in XML |
557 |
|
# now done in object2hash |
558 |
|
#var2utf8($hash) if ($options->{utf8}); |
559 |
|
|
560 |
|
# old (wrong) attempts to get rid of used instances, if requested |
561 |
|
#$obj->clear_refs; |
562 |
|
#$self->{COREHANDLE}->unload($obj) if($options->{destroy}); |
563 |
|
#$obj->DESTROY; |
564 |
|
#undef($obj) if($options->{destroy}); |
565 |
|
|
566 |
|
return $hash; |
567 |
} |
} |
568 |
|
|
569 |
sub getSchema { |
sub getSchema { |