| 3 |
# $Id$ |
# $Id$ |
| 4 |
# |
# |
| 5 |
# $Log$ |
# $Log$ |
| 6 |
|
# Revision 1.28 2003/02/20 20:20:26 joko |
| 7 |
|
# tried to get auto-disconnect working again - failed with that |
| 8 |
|
# |
| 9 |
|
# Revision 1.27 2003/01/31 06:30:59 joko |
| 10 |
|
# + enabled 'sendQuery' |
| 11 |
|
# |
| 12 |
|
# Revision 1.26 2003/01/30 22:29:47 joko |
| 13 |
|
# + fixed module usage (removed dependency on 'libp.pm') |
| 14 |
|
# |
| 15 |
|
# Revision 1.25 2003/01/19 02:30:05 joko |
| 16 |
|
# + fix: modified call to '_initSchema' |
| 17 |
|
# |
| 18 |
|
# Revision 1.24 2002/12/22 14:13:01 joko |
| 19 |
|
# + sub dropDb |
| 20 |
|
# |
| 21 |
|
# Revision 1.23 2002/12/19 16:31:53 joko |
| 22 |
|
# +- renamed sub to 'rebuildDb' |
| 23 |
|
# |
| 24 |
|
# Revision 1.22 2002/12/18 22:28:16 jonen |
| 25 |
|
# + added extended logging at 'getObjectByGuid()' |
| 26 |
|
# |
| 27 |
# Revision 1.21 2002/12/16 22:20:49 jonen |
# Revision 1.21 2002/12/16 22:20:49 jonen |
| 28 |
# + fixed bug at 'getObjectByGuid()' |
# + fixed bug at 'getObjectByGuid()' |
| 29 |
# |
# |
| 44 |
# + fix: encapsulated object-loading inside an 'eval' |
# + fix: encapsulated object-loading inside an 'eval' |
| 45 |
# |
# |
| 46 |
# Revision 1.15 2002/12/05 13:55:21 joko |
# Revision 1.15 2002/12/05 13:55:21 joko |
| 47 |
# + now utilizing 'object2hash' instead of 'var_deref' |
# + now utilizing 'expand' instead of 'var_deref' |
| 48 |
# + played around with having fresh-objects - no progress.... |
# + played around with having fresh-objects - no progress.... |
| 49 |
# |
# |
| 50 |
# Revision 1.14 2002/12/05 09:40:30 jonen |
# Revision 1.14 2002/12/05 09:40:30 jonen |
| 117 |
use base ("Data::Storage::Handler"); |
use base ("Data::Storage::Handler"); |
| 118 |
use base ("Data::Storage::Handler::Abstract"); |
use base ("Data::Storage::Handler::Abstract"); |
| 119 |
|
|
| 120 |
use Tangram; |
|
| 121 |
use Data::Dumper; |
use Data::Dumper; |
| 122 |
use libp qw( getNewPerlObjectByPkgName ); |
use Tangram; |
| 123 |
|
|
| 124 |
|
use DesignPattern::Object; |
| 125 |
use Data::Storage::Result::Tangram; |
use Data::Storage::Result::Tangram; |
| 126 |
use Data::Compare::Struct qw( isEmpty ); |
use Data::Compare::Struct qw( isEmpty ); |
| 127 |
use Data::Transform::Deep qw( object2hash ); |
use Data::Transform::Deep qw( expand ); |
| 128 |
use Data::Transform::Encode qw( var2utf8 ); |
#use Data::Transform::Encode qw( var2utf8 ); |
|
|
|
| 129 |
|
|
| 130 |
# get logger instance |
# get logger instance |
| 131 |
my $logger = Log::Dispatch::Config->instance; |
my $logger = Log::Dispatch::Config->instance; |
| 146 |
my $self = shift; |
my $self = shift; |
| 147 |
$logger->debug( __PACKAGE__ . "->_initSchema()" ); |
$logger->debug( __PACKAGE__ . "->_initSchema()" ); |
| 148 |
#if (!$schema_tangram) { |
#if (!$schema_tangram) { |
| 149 |
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} } ); |
| 150 |
|
my $obj = DesignPattern::Object->fromPackage($self->{locator}->{schema}, { 'EXPORT_OBJECTS' => $self->{locator}->{classnames}, 'want_transactions' => $self->{locator}->{want_transactions} } ); |
| 151 |
$schema_tangram = $obj->getSchema(); |
$schema_tangram = $obj->getSchema(); |
| 152 |
#} |
#} |
| 153 |
if (!$schema_tangram) { |
if (!$schema_tangram) { |
| 180 |
my $self = shift; |
my $self = shift; |
| 181 |
|
|
| 182 |
my $dsn = shift; |
my $dsn = shift; |
| 183 |
|
|
| 184 |
|
#print Dumper($self); |
| 185 |
|
#exit; |
| 186 |
|
|
| 187 |
|
# TODO: re-enable |
| 188 |
$dsn ||= $self->{locator}->{dbi}->{dsn}; |
$dsn ||= $self->{locator}->{dbi}->{dsn}; |
|
|
|
| 189 |
$logger->debug( __PACKAGE__ . "->connect( dsn $dsn )" ); |
$logger->debug( __PACKAGE__ . "->connect( dsn $dsn )" ); |
| 190 |
|
|
| 191 |
#my $storage = Tangram::Relational->connect( $schema, $dsn ); |
#my $storage = Tangram::Relational->connect( $schema, $dsn ); |
| 197 |
# return; |
# return; |
| 198 |
# } |
# } |
| 199 |
|
|
| 200 |
return unless $self->_initSchema(); |
#return unless $self->_initSchema(); |
| 201 |
|
$self->_initSchema(); |
| 202 |
|
|
| 203 |
# create the main tangram storage object |
# create the main tangram storage object |
| 204 |
#$self->{COREHANDLE} = Tangram::Relational->connect( $schema, $dsn ); |
#$self->{COREHANDLE} = Tangram::Relational->connect( $schema, $dsn ); |
| 325 |
$logger->debug( __PACKAGE__ . "->configureCOREHANDLE" ); |
$logger->debug( __PACKAGE__ . "->configureCOREHANDLE" ); |
| 326 |
|
|
| 327 |
#my $subLayer = $self->_getSubLayerHandle(); |
#my $subLayer = $self->_getSubLayerHandle(); |
| 328 |
|
#print Dumper($self); |
| 329 |
|
#exit; |
| 330 |
|
|
| 331 |
# apply configured modifications |
# apply configured modifications |
| 332 |
if (exists $self->{dbi}->{trace_level} && exists $self->{dbi}->{trace_file}) { |
if (exists $self->{dbi}->{trace_level} && exists $self->{dbi}->{trace_file}) { |
| 392 |
return $ok; |
return $ok; |
| 393 |
} |
} |
| 394 |
|
|
| 395 |
sub rebuildDbAndSchema { |
sub rebuildDb { |
| 396 |
my $self = shift; |
my $self = shift; |
| 397 |
$logger->info( __PACKAGE__ . "->rebuildDbAndSchema()" ); |
$logger->info( __PACKAGE__ . "->rebuildDb()" ); |
| 398 |
my @results; |
my @results; |
| 399 |
|
|
| 400 |
# sum up results (bool (0/1)) in array |
# sum up results (bool (0/1)) in array |
| 434 |
my @results; |
my @results; |
| 435 |
$logger->debug( __PACKAGE__ . "->getListFiltered( nodename => '" . $nodename . "' )" ); |
$logger->debug( __PACKAGE__ . "->getListFiltered( nodename => '" . $nodename . "' )" ); |
| 436 |
|
|
| 437 |
#print Dumper($filters); |
#print Dumper($filters); |
| 438 |
|
|
| 439 |
my @tfilters; |
my @tfilters; |
| 440 |
|
|
| 473 |
# 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 |
| 474 |
my $evalstring = 'return $self->{_COREHANDLE}->select($remote, ' . $tfilter . ');'; |
my $evalstring = 'return $self->{_COREHANDLE}->select($remote, ' . $tfilter . ');'; |
| 475 |
|
|
| 476 |
|
#print "eval: $evalstring", "\n"; |
| 477 |
|
|
| 478 |
# get filtered list/set |
# get filtered list/set |
| 479 |
@results = eval($evalstring); |
@results = eval($evalstring); |
| 480 |
die $@ if $@; |
die $@ if $@; |
| 534 |
#return $self->createSet( $self->{COREHANDLE}->load('300090018') ); |
#return $self->createSet( $self->{COREHANDLE}->load('300090018') ); |
| 535 |
} |
} |
| 536 |
|
|
| 537 |
die("This should not be reached for now - redirect to \$self->getListFiltered() here!"); |
my $list = $self->getListFiltered($query->{node}, $query->{criterias}); |
| 538 |
|
#return $self->createSet($object); |
| 539 |
|
#return $self->createSet($list); |
| 540 |
|
return $self->createSet(@$list); |
| 541 |
|
|
| 542 |
|
#die("This should not be reached for now - redirect to \$self->getListFiltered() here!"); |
| 543 |
|
|
|
# TODO: do a common tangram query here |
|
| 544 |
|
|
| 545 |
|
|
| 546 |
|
|
| 547 |
|
# try a generic tangram query here |
| 548 |
|
# TODO: try to place an oql on top of that (search.cpan.org!) |
| 549 |
my @crits; |
my @crits; |
| 550 |
foreach (@{$query->{criterias}}) { |
foreach (@{$query->{criterias}}) { |
| 551 |
my $op = ''; |
my $op = ''; |
| 603 |
|
|
| 604 |
# Guid and Classname is needed |
# Guid and Classname is needed |
| 605 |
if(!$guid || !$options->{classname}) { |
if(!$guid || !$options->{classname}) { |
| 606 |
|
$logger->error( __PACKAGE__ . "->getObjectByGuid: No 'guid' OR no Classname in options hash was given but needed!" ); |
| 607 |
return; |
return; |
| 608 |
} |
} |
| 609 |
|
|
| 616 |
my @result = $self->{_COREHANDLE}->select($obj_tmp, $obj_tmp->{guid} eq $guid); |
my @result = $self->{_COREHANDLE}->select($obj_tmp, $obj_tmp->{guid} eq $guid); |
| 617 |
|
|
| 618 |
# we searched for global unique identifer of some object, |
# we searched for global unique identifer of some object, |
| 619 |
# so it think we can trust there would be only one result |
# so I think we can trust there would be only one result |
| 620 |
if($result[0]) { |
if($result[0]) { |
| 621 |
return $result[0]; |
return $result[0]; |
| 622 |
} else { |
} else { |
| 623 |
return "No Object with Classname $options->{classname} and GUID $options->{guid} found!"; |
$logger->error( __PACKAGE__ . "->getObjectByGuid: No Object with Classname $options->{classname} and GUID $guid found!" ); |
| 624 |
|
return; |
| 625 |
} |
} |
| 626 |
|
|
| 627 |
} |
} |
| 653 |
} |
} |
| 654 |
=cut |
=cut |
| 655 |
|
|
| 656 |
my $hash = object2hash($obj, $options); |
my $hash = expand($obj, $options); |
| 657 |
#$options->{cb}->{destroy}->($obj); |
#$options->{cb}->{destroy}->($obj); |
| 658 |
#$self->{_COREHANDLE}->unload($obj); |
#$self->{_COREHANDLE}->unload($obj); |
| 659 |
|
|
| 660 |
# convert values in hash to utf8 to be ready for (e.g.) encapsulation in XML |
# convert values in hash to utf8 to be ready for (e.g.) encapsulation in XML |
| 661 |
# now done in object2hash |
# now done in expand |
| 662 |
#var2utf8($hash) if ($options->{utf8}); |
#var2utf8($hash) if ($options->{utf8}); |
| 663 |
|
|
| 664 |
# old (wrong) attempts to get rid of used instances, if requested |
# old (wrong) attempts to get rid of used instances, if requested |
| 679 |
return $self->{_COREHANDLE}; |
return $self->{_COREHANDLE}; |
| 680 |
} |
} |
| 681 |
|
|
| 682 |
|
sub dropDb { |
| 683 |
|
my $self = shift; |
| 684 |
|
my $storage = $self->_getSubLayerHandle(); |
| 685 |
|
return $storage->dropDb(); |
| 686 |
|
} |
| 687 |
|
|
| 688 |
|
sub testAvailability { |
| 689 |
|
my $self = shift; |
| 690 |
|
my $storage = $self->_getSubLayerHandle(); |
| 691 |
|
return $storage->testAvailability(); |
| 692 |
|
} |
| 693 |
|
|
| 694 |
|
sub disconnect2 { |
| 695 |
|
my $self = shift; |
| 696 |
|
my $storage = $self->_getSubLayerHandle(); |
| 697 |
|
print "DISC!", "\n"; |
| 698 |
|
|
| 699 |
|
my $storage_ll = $storage->{_COREHANDLE}; |
| 700 |
|
$storage_ll->disconnect(); |
| 701 |
|
|
| 702 |
|
print Dumper($storage); |
| 703 |
|
exit; |
| 704 |
|
|
| 705 |
|
#$self->{_COREHANDLE} |
| 706 |
|
#$storage->disconnect(); |
| 707 |
|
$self->{dataStorageLayer}->disconnect(); |
| 708 |
|
} |
| 709 |
|
|
| 710 |
1; |
1; |
| 711 |
|
__END__ |