3 |
# $Id$ |
# $Id$ |
4 |
# |
# |
5 |
# $Log$ |
# $Log$ |
6 |
|
# Revision 1.24 2002/12/22 14:13:01 joko |
7 |
|
# + sub dropDb |
8 |
|
# |
9 |
|
# Revision 1.23 2002/12/19 16:31:53 joko |
10 |
|
# +- renamed sub to 'rebuildDb' |
11 |
|
# |
12 |
|
# Revision 1.22 2002/12/18 22:28:16 jonen |
13 |
|
# + added extended logging at 'getObjectByGuid()' |
14 |
|
# |
15 |
|
# Revision 1.21 2002/12/16 22:20:49 jonen |
16 |
|
# + fixed bug at 'getObjectByGuid()' |
17 |
|
# |
18 |
|
# Revision 1.20 2002/12/16 20:49:17 jonen |
19 |
|
# + added sub 'getObjectByGuid()' |
20 |
|
# + added functionality to use 'getObjectByGuid' at 'getObjectAsHash()' |
21 |
|
# |
22 |
|
# Revision 1.19 2002/12/16 06:46:09 joko |
23 |
|
# + attempt to introduce a generic '_patchSchema' - cancelled! |
24 |
|
# |
25 |
|
# Revision 1.18 2002/12/13 21:48:07 joko |
26 |
|
# + fix to 'sub sendQuery' |
27 |
|
# |
28 |
|
# Revision 1.17 2002/12/12 02:51:09 joko |
29 |
|
# + cosmetics |
30 |
|
# |
31 |
|
# Revision 1.16 2002/12/11 06:54:10 joko |
32 |
|
# + fix: encapsulated object-loading inside an 'eval' |
33 |
|
# |
34 |
|
# Revision 1.15 2002/12/05 13:55:21 joko |
35 |
|
# + now utilizing 'object2hash' instead of 'var_deref' |
36 |
|
# + played around with having fresh-objects - no progress.... |
37 |
|
# |
38 |
# Revision 1.14 2002/12/05 09:40:30 jonen |
# Revision 1.14 2002/12/05 09:40:30 jonen |
39 |
# + added option->{destroy} at getObject for unloading all instance |
# + added option->{destroy} at getObject for unloading all instance |
40 |
# |
# |
110 |
use libp qw( getNewPerlObjectByPkgName ); |
use libp qw( getNewPerlObjectByPkgName ); |
111 |
use Data::Storage::Result::Tangram; |
use Data::Storage::Result::Tangram; |
112 |
use Data::Compare::Struct qw( isEmpty ); |
use Data::Compare::Struct qw( isEmpty ); |
113 |
use Data::Transform::Deep qw( var_deref ); |
use Data::Transform::Deep qw( object2hash ); |
114 |
use Data::Transform::Encode qw( var2utf8 ); |
use Data::Transform::Encode qw( var2utf8 ); |
115 |
|
|
116 |
|
|
140 |
$logger->error( __PACKAGE__ . "->_initSchema: No Schema available for $self->{schema}" ); |
$logger->error( __PACKAGE__ . "->_initSchema: No Schema available for $self->{schema}" ); |
141 |
return 0; |
return 0; |
142 |
} |
} |
143 |
|
#$self->_patchSchema(); |
144 |
return 1; |
return 1; |
145 |
} |
} |
146 |
|
|
147 |
|
sub _patchSchema { |
148 |
|
my $self = shift; |
149 |
|
foreach (keys %{$schema_tangram->{classes}}) { |
150 |
|
next if $schema_tangram->{classes}->{$_}->{abstract}; |
151 |
|
#next if ($_ ne 'TsBankAccount'); |
152 |
|
#$_ ne 'AbstractAccount' && |
153 |
|
print "class: $_", "\n"; |
154 |
|
#print Dumper($schema_tangram->{classes}->{$_}); |
155 |
|
# create new string property named 'guid' |
156 |
|
my $tstring = Tangram::String->new(); |
157 |
|
$tstring->{name} = $tstring->{col} = 'guid'; |
158 |
|
# inject property into schema |
159 |
|
#$schema_tangram->{classes}->{$_}->{root}->{SPECS}->[0]->{fields}->{string}->{$tstring->{name}} = $tstring; |
160 |
|
print Dumper($schema_tangram->{classes}->{$_}->{root}->{SPECS}->[0]->{fields}); |
161 |
|
} |
162 |
|
} |
163 |
|
|
164 |
sub connect { |
sub connect { |
165 |
|
|
166 |
my $self = shift; |
my $self = shift; |
371 |
return $ok; |
return $ok; |
372 |
} |
} |
373 |
|
|
374 |
sub rebuildDbAndSchema { |
sub rebuildDb { |
375 |
my $self = shift; |
my $self = shift; |
376 |
$logger->info( __PACKAGE__ . "->rebuildDbAndSchema()" ); |
$logger->info( __PACKAGE__ . "->rebuildDb()" ); |
377 |
my @results; |
my @results; |
378 |
|
|
379 |
# sum up results (bool (0/1)) in array |
# sum up results (bool (0/1)) in array |
469 |
|
|
470 |
sub createSet { |
sub createSet { |
471 |
my $self = shift; |
my $self = shift; |
472 |
|
#print "-" x 80, "\n"; |
473 |
|
#print Dumper(@_); |
474 |
my @objects = @_; |
my @objects = @_; |
475 |
my $rh = Set::Object->new(); |
my $rh = Set::Object->new(); |
476 |
foreach (@objects) { |
foreach (@objects) { |
477 |
#print Dumper($_); |
if (!isEmpty($_)) { |
478 |
$rh->insert($_) if !isEmpty($_); |
#print Dumper($_); |
479 |
|
$rh->insert($_); |
480 |
|
} |
481 |
} |
} |
482 |
#print Dumper($rh->members()); |
#print Dumper($rh->members()); |
483 |
my $result = Data::Storage::Result::Tangram->new( RESULTHANDLE => $rh ); |
my $result = Data::Storage::Result::Tangram->new( RESULTHANDLE => $rh ); |
501 |
my $ident = $query->{criterias}->[0]->{val}; |
my $ident = $query->{criterias}->[0]->{val}; |
502 |
#print "load obj", "\n"; |
#print "load obj", "\n"; |
503 |
#return $self->createSet() if $ident == 5; |
#return $self->createSet() if $ident == 5; |
504 |
|
$self->{_COREHANDLE}->unload($ident); |
505 |
my $object = $self->{_COREHANDLE}->load($ident); |
my $object = $self->{_COREHANDLE}->load($ident); |
506 |
#print "get id", "\n"; |
#print "get id", "\n"; |
507 |
my $oid = $self->{_COREHANDLE}->id($object); |
my $oid = $self->{_COREHANDLE}->id($object); |
508 |
|
#print Dumper($object); |
509 |
|
#print "oid: $oid", "\n"; |
510 |
return $self->createSet($object); |
return $self->createSet($object); |
511 |
#return $self->createSet( $self->{COREHANDLE}->load('300090018') ); |
#return $self->createSet( $self->{COREHANDLE}->load('300090018') ); |
512 |
} |
} |
550 |
my $self = shift; |
my $self = shift; |
551 |
my $oid = shift; |
my $oid = shift; |
552 |
my $options = shift; |
my $options = shift; |
553 |
# TODO: create a deep_unload method |
|
554 |
|
# TODO: create a deep_unload method (currently _all_ objects are unloaded) |
555 |
# unload($oid) will only unload object, not deep object hashes |
# unload($oid) will only unload object, not deep object hashes |
556 |
$self->{_COREHANDLE}->unload() if($options->{destroy}); |
$self->{_COREHANDLE}->unload() if ($options->{destroy}); |
557 |
|
|
558 |
# TODO: review this |
# TODO: review this |
559 |
#if (!$self->{COREHANDLE}) { return; } |
#if (!$self->{COREHANDLE}) { return; } |
560 |
return $self->{_COREHANDLE}->load($oid); |
|
561 |
|
# TODO: review this |
562 |
|
my $object = eval('$self->{_COREHANDLE}->load($oid);'); |
563 |
|
print $@, "\n" if $@; |
564 |
|
|
565 |
|
return $object if $object; |
566 |
|
} |
567 |
|
|
568 |
|
sub getObjectByGuid { |
569 |
|
my $self = shift; |
570 |
|
my $guid = shift; |
571 |
|
my $options = shift; |
572 |
|
|
573 |
|
# Guid and Classname is needed |
574 |
|
if(!$guid || !$options->{classname}) { |
575 |
|
$logger->error( __PACKAGE__ . "->getObjectByGuid: No 'guid' OR no Classname in options hash was given but needed!" ); |
576 |
|
return; |
577 |
|
} |
578 |
|
|
579 |
|
# TODO: create a deep_unload method (currently _all_ objects are unloaded) |
580 |
|
# unload($oid) will only unload object, not deep object hashes |
581 |
|
$self->{_COREHANDLE}->unload() if ($options->{destroy}); |
582 |
|
|
583 |
|
# search for object with given Classname and Guid |
584 |
|
my $obj_tmp = $self->{_COREHANDLE}->remote($options->{classname}); |
585 |
|
my @result = $self->{_COREHANDLE}->select($obj_tmp, $obj_tmp->{guid} eq $guid); |
586 |
|
|
587 |
|
# we searched for global unique identifer of some object, |
588 |
|
# so I think we can trust there would be only one result |
589 |
|
if($result[0]) { |
590 |
|
return $result[0]; |
591 |
|
} else { |
592 |
|
$logger->error( __PACKAGE__ . "->getObjectByGuid: No Object with Classname $options->{classname} and GUID $guid found!" ); |
593 |
|
return; |
594 |
|
} |
595 |
|
|
596 |
} |
} |
597 |
|
|
598 |
sub getObjectAsHash { |
sub getObjectAsHash { |
599 |
my $self = shift; |
my $self = shift; |
600 |
my $oid = shift; |
my $oid = shift; |
601 |
my $options = shift; |
my $options = shift; |
602 |
my $obj = $self->getObject($oid, $options); |
my $obj; |
603 |
my $deref = var_deref($obj); |
|
604 |
var2utf8($deref) if ($options->{utf8}); |
if($options->{guid}) { |
605 |
#$obj->clear_refs; |
$obj = $self->getObjectByGuid($oid, $options); |
606 |
#$self->{COREHANDLE}->unload($obj) if($options->{destroy}); |
} else { |
607 |
#$obj->DESTROY; |
$obj = $self->getObject($oid, $options); |
608 |
#undef($obj) if($options->{destroy}); |
} |
609 |
return $deref; |
|
610 |
|
# build options (a callback to unload autovivified objects) for 'expand' |
611 |
|
# TODO: use $logger to write to debug here! |
612 |
|
my $cb; # = sub {}; |
613 |
|
=pod |
614 |
|
if ($options->{destroy}) { |
615 |
|
$options->{cb}->{destroy} = sub { |
616 |
|
print "================ DESTROY", "\n"; |
617 |
|
my $object = shift; |
618 |
|
#print Dumper($object); |
619 |
|
$self->{_COREHANDLE}->unload($object); |
620 |
|
#undef($object); |
621 |
|
}; |
622 |
|
} |
623 |
|
=cut |
624 |
|
|
625 |
|
my $hash = object2hash($obj, $options); |
626 |
|
#$options->{cb}->{destroy}->($obj); |
627 |
|
#$self->{_COREHANDLE}->unload($obj); |
628 |
|
|
629 |
|
# convert values in hash to utf8 to be ready for (e.g.) encapsulation in XML |
630 |
|
# now done in object2hash |
631 |
|
#var2utf8($hash) if ($options->{utf8}); |
632 |
|
|
633 |
|
# old (wrong) attempts to get rid of used instances, if requested |
634 |
|
#$obj->clear_refs; |
635 |
|
#$self->{COREHANDLE}->unload($obj) if($options->{destroy}); |
636 |
|
#$obj->DESTROY; |
637 |
|
#undef($obj) if($options->{destroy}); |
638 |
|
|
639 |
|
return $hash; |
640 |
} |
} |
641 |
|
|
642 |
sub getSchema { |
sub getSchema { |
648 |
return $self->{_COREHANDLE}; |
return $self->{_COREHANDLE}; |
649 |
} |
} |
650 |
|
|
651 |
|
sub dropDb { |
652 |
|
my $self = shift; |
653 |
|
my $storage = $self->_getSubLayerHandle(); |
654 |
|
return $storage->dropDb(); |
655 |
|
} |
656 |
|
|
657 |
1; |
1; |