| 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 |
# Revision 1.17 2002/12/12 02:51:09 joko |
| 29 |
# + cosmetics |
# + cosmetics |
| 30 |
# |
# |
| 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 |
} |
} |
| 565 |
return $object if $object; |
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 |
|
|
| 604 |
|
if($options->{guid}) { |
| 605 |
|
$obj = $self->getObjectByGuid($oid, $options); |
| 606 |
|
} else { |
| 607 |
|
$obj = $self->getObject($oid, $options); |
| 608 |
|
} |
| 609 |
|
|
| 610 |
# build options (a callback to unload autovivified objects) for 'expand' |
# build options (a callback to unload autovivified objects) for 'expand' |
| 611 |
# TODO: use $logger to write to debug here! |
# TODO: use $logger to write to debug here! |
| 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; |