3 |
# $Id$ |
# $Id$ |
4 |
# |
# |
5 |
# $Log$ |
# $Log$ |
6 |
|
# Revision 1.19 2002/12/16 06:46:09 joko |
7 |
|
# + attempt to introduce a generic '_patchSchema' - cancelled! |
8 |
|
# |
9 |
|
# Revision 1.18 2002/12/13 21:48:07 joko |
10 |
|
# + fix to 'sub sendQuery' |
11 |
|
# |
12 |
|
# Revision 1.17 2002/12/12 02:51:09 joko |
13 |
|
# + cosmetics |
14 |
|
# |
15 |
|
# Revision 1.16 2002/12/11 06:54:10 joko |
16 |
|
# + fix: encapsulated object-loading inside an 'eval' |
17 |
|
# |
18 |
|
# Revision 1.15 2002/12/05 13:55:21 joko |
19 |
|
# + now utilizing 'object2hash' instead of 'var_deref' |
20 |
|
# + played around with having fresh-objects - no progress.... |
21 |
|
# |
22 |
|
# Revision 1.14 2002/12/05 09:40:30 jonen |
23 |
|
# + added option->{destroy} at getObject for unloading all instance |
24 |
|
# |
25 |
# Revision 1.13 2002/12/05 07:59:04 joko |
# Revision 1.13 2002/12/05 07:59:04 joko |
26 |
# + now using Tie::SecureHash as a base for the COREHANDLE |
# + now using Tie::SecureHash as a base for the COREHANDLE |
27 |
# + former public COREHANDLE becomes private _COREHANDLE now |
# + former public COREHANDLE becomes private _COREHANDLE now |
94 |
use libp qw( getNewPerlObjectByPkgName ); |
use libp qw( getNewPerlObjectByPkgName ); |
95 |
use Data::Storage::Result::Tangram; |
use Data::Storage::Result::Tangram; |
96 |
use Data::Compare::Struct qw( isEmpty ); |
use Data::Compare::Struct qw( isEmpty ); |
97 |
use Data::Transform::Deep qw( var_deref ); |
use Data::Transform::Deep qw( object2hash ); |
98 |
use Data::Transform::Encode qw( var2utf8 ); |
use Data::Transform::Encode qw( var2utf8 ); |
99 |
|
|
100 |
|
|
124 |
$logger->error( __PACKAGE__ . "->_initSchema: No Schema available for $self->{schema}" ); |
$logger->error( __PACKAGE__ . "->_initSchema: No Schema available for $self->{schema}" ); |
125 |
return 0; |
return 0; |
126 |
} |
} |
127 |
|
#$self->_patchSchema(); |
128 |
return 1; |
return 1; |
129 |
} |
} |
130 |
|
|
131 |
|
sub _patchSchema { |
132 |
|
my $self = shift; |
133 |
|
foreach (keys %{$schema_tangram->{classes}}) { |
134 |
|
next if $schema_tangram->{classes}->{$_}->{abstract}; |
135 |
|
#next if ($_ ne 'TsBankAccount'); |
136 |
|
#$_ ne 'AbstractAccount' && |
137 |
|
print "class: $_", "\n"; |
138 |
|
#print Dumper($schema_tangram->{classes}->{$_}); |
139 |
|
# create new string property named 'guid' |
140 |
|
my $tstring = Tangram::String->new(); |
141 |
|
$tstring->{name} = $tstring->{col} = 'guid'; |
142 |
|
# inject property into schema |
143 |
|
#$schema_tangram->{classes}->{$_}->{root}->{SPECS}->[0]->{fields}->{string}->{$tstring->{name}} = $tstring; |
144 |
|
print Dumper($schema_tangram->{classes}->{$_}->{root}->{SPECS}->[0]->{fields}); |
145 |
|
} |
146 |
|
} |
147 |
|
|
148 |
sub connect { |
sub connect { |
149 |
|
|
150 |
my $self = shift; |
my $self = shift; |
453 |
|
|
454 |
sub createSet { |
sub createSet { |
455 |
my $self = shift; |
my $self = shift; |
456 |
|
#print "-" x 80, "\n"; |
457 |
|
#print Dumper(@_); |
458 |
my @objects = @_; |
my @objects = @_; |
459 |
my $rh = Set::Object->new(); |
my $rh = Set::Object->new(); |
460 |
foreach (@objects) { |
foreach (@objects) { |
461 |
#print Dumper($_); |
if (!isEmpty($_)) { |
462 |
$rh->insert($_) if !isEmpty($_); |
#print Dumper($_); |
463 |
|
$rh->insert($_); |
464 |
|
} |
465 |
} |
} |
466 |
#print Dumper($rh->members()); |
#print Dumper($rh->members()); |
467 |
my $result = Data::Storage::Result::Tangram->new( RESULTHANDLE => $rh ); |
my $result = Data::Storage::Result::Tangram->new( RESULTHANDLE => $rh ); |
485 |
my $ident = $query->{criterias}->[0]->{val}; |
my $ident = $query->{criterias}->[0]->{val}; |
486 |
#print "load obj", "\n"; |
#print "load obj", "\n"; |
487 |
#return $self->createSet() if $ident == 5; |
#return $self->createSet() if $ident == 5; |
488 |
|
$self->{_COREHANDLE}->unload($ident); |
489 |
my $object = $self->{_COREHANDLE}->load($ident); |
my $object = $self->{_COREHANDLE}->load($ident); |
490 |
#print "get id", "\n"; |
#print "get id", "\n"; |
491 |
my $oid = $self->{_COREHANDLE}->id($object); |
my $oid = $self->{_COREHANDLE}->id($object); |
492 |
|
#print Dumper($object); |
493 |
|
#print "oid: $oid", "\n"; |
494 |
return $self->createSet($object); |
return $self->createSet($object); |
495 |
#return $self->createSet( $self->{COREHANDLE}->load('300090018') ); |
#return $self->createSet( $self->{COREHANDLE}->load('300090018') ); |
496 |
} |
} |
533 |
sub getObject { |
sub getObject { |
534 |
my $self = shift; |
my $self = shift; |
535 |
my $oid = shift; |
my $oid = shift; |
536 |
|
my $options = shift; |
537 |
|
|
538 |
|
# TODO: create a deep_unload method (currently _all_ objects are unloaded) |
539 |
|
# unload($oid) will only unload object, not deep object hashes |
540 |
|
$self->{_COREHANDLE}->unload() if ($options->{destroy}); |
541 |
|
|
542 |
# TODO: review this |
# TODO: review this |
543 |
#if (!$self->{COREHANDLE}) { return; } |
#if (!$self->{COREHANDLE}) { return; } |
544 |
return $self->{_COREHANDLE}->load($oid); |
|
545 |
|
# TODO: review this |
546 |
|
my $object = eval('$self->{_COREHANDLE}->load($oid);'); |
547 |
|
print $@, "\n" if $@; |
548 |
|
|
549 |
|
return $object if $object; |
550 |
} |
} |
551 |
|
|
552 |
sub getObjectAsHash { |
sub getObjectAsHash { |
553 |
my $self = shift; |
my $self = shift; |
554 |
my $oid = shift; |
my $oid = shift; |
555 |
my $options = shift; |
my $options = shift; |
556 |
my $obj = $self->getObject($oid); |
my $obj = $self->getObject($oid, $options); |
557 |
my $deref = var_deref($obj); |
|
558 |
var2utf8($deref) if ($options->{utf8}); |
# build options (a callback to unload autovivified objects) for 'expand' |
559 |
undef($obj) if($options->{destroy}); |
# TODO: use $logger to write to debug here! |
560 |
return $deref; |
my $cb; # = sub {}; |
561 |
|
=pod |
562 |
|
if ($options->{destroy}) { |
563 |
|
$options->{cb}->{destroy} = sub { |
564 |
|
print "================ DESTROY", "\n"; |
565 |
|
my $object = shift; |
566 |
|
#print Dumper($object); |
567 |
|
$self->{_COREHANDLE}->unload($object); |
568 |
|
#undef($object); |
569 |
|
}; |
570 |
|
} |
571 |
|
=cut |
572 |
|
|
573 |
|
my $hash = object2hash($obj, $options); |
574 |
|
#$options->{cb}->{destroy}->($obj); |
575 |
|
#$self->{_COREHANDLE}->unload($obj); |
576 |
|
|
577 |
|
# convert values in hash to utf8 to be ready for (e.g.) encapsulation in XML |
578 |
|
# now done in object2hash |
579 |
|
#var2utf8($hash) if ($options->{utf8}); |
580 |
|
|
581 |
|
# old (wrong) attempts to get rid of used instances, if requested |
582 |
|
#$obj->clear_refs; |
583 |
|
#$self->{COREHANDLE}->unload($obj) if($options->{destroy}); |
584 |
|
#$obj->DESTROY; |
585 |
|
#undef($obj) if($options->{destroy}); |
586 |
|
|
587 |
|
return $hash; |
588 |
} |
} |
589 |
|
|
590 |
sub getSchema { |
sub getSchema { |