| 3 |
# $Id$ |
# $Id$ |
| 4 |
# |
# |
| 5 |
# $Log$ |
# $Log$ |
| 6 |
|
# Revision 1.26 2003/01/30 22:29:47 joko |
| 7 |
|
# + fixed module usage (removed dependency on 'libp.pm') |
| 8 |
|
# |
| 9 |
|
# Revision 1.25 2003/01/19 02:30:05 joko |
| 10 |
|
# + fix: modified call to '_initSchema' |
| 11 |
|
# |
| 12 |
|
# Revision 1.24 2002/12/22 14:13:01 joko |
| 13 |
|
# + sub dropDb |
| 14 |
|
# |
| 15 |
|
# Revision 1.23 2002/12/19 16:31:53 joko |
| 16 |
|
# +- renamed sub to 'rebuildDb' |
| 17 |
|
# |
| 18 |
|
# Revision 1.22 2002/12/18 22:28:16 jonen |
| 19 |
|
# + added extended logging at 'getObjectByGuid()' |
| 20 |
|
# |
| 21 |
|
# Revision 1.21 2002/12/16 22:20:49 jonen |
| 22 |
|
# + fixed bug at 'getObjectByGuid()' |
| 23 |
|
# |
| 24 |
# Revision 1.20 2002/12/16 20:49:17 jonen |
# Revision 1.20 2002/12/16 20:49:17 jonen |
| 25 |
# + added sub 'getObjectByGuid()' |
# + added sub 'getObjectByGuid()' |
| 26 |
# + added functionality to use 'getObjectByGuid' at 'getObjectAsHash()' |
# + added functionality to use 'getObjectByGuid' at 'getObjectAsHash()' |
| 113 |
|
|
| 114 |
use Tangram; |
use Tangram; |
| 115 |
use Data::Dumper; |
use Data::Dumper; |
| 116 |
use libp qw( getNewPerlObjectByPkgName ); |
use DesignPattern::Object; |
| 117 |
use Data::Storage::Result::Tangram; |
use Data::Storage::Result::Tangram; |
| 118 |
use Data::Compare::Struct qw( isEmpty ); |
use Data::Compare::Struct qw( isEmpty ); |
| 119 |
use Data::Transform::Deep qw( object2hash ); |
use Data::Transform::Deep qw( object2hash ); |
| 120 |
use Data::Transform::Encode qw( var2utf8 ); |
use Data::Transform::Encode qw( var2utf8 ); |
| 121 |
|
|
|
|
|
| 122 |
# get logger instance |
# get logger instance |
| 123 |
my $logger = Log::Dispatch::Config->instance; |
my $logger = Log::Dispatch::Config->instance; |
| 124 |
|
|
| 138 |
my $self = shift; |
my $self = shift; |
| 139 |
$logger->debug( __PACKAGE__ . "->_initSchema()" ); |
$logger->debug( __PACKAGE__ . "->_initSchema()" ); |
| 140 |
#if (!$schema_tangram) { |
#if (!$schema_tangram) { |
| 141 |
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} } ); |
| 142 |
|
my $obj = DesignPattern::Object->fromPackage($self->{locator}->{schema}, { 'EXPORT_OBJECTS' => $self->{locator}->{classnames}, 'want_transactions' => $self->{locator}->{want_transactions} } ); |
| 143 |
$schema_tangram = $obj->getSchema(); |
$schema_tangram = $obj->getSchema(); |
| 144 |
#} |
#} |
| 145 |
if (!$schema_tangram) { |
if (!$schema_tangram) { |
| 172 |
my $self = shift; |
my $self = shift; |
| 173 |
|
|
| 174 |
my $dsn = shift; |
my $dsn = shift; |
| 175 |
|
|
| 176 |
|
#print Dumper($self); |
| 177 |
|
#exit; |
| 178 |
|
|
| 179 |
|
# TODO: re-enable |
| 180 |
$dsn ||= $self->{locator}->{dbi}->{dsn}; |
$dsn ||= $self->{locator}->{dbi}->{dsn}; |
|
|
|
| 181 |
$logger->debug( __PACKAGE__ . "->connect( dsn $dsn )" ); |
$logger->debug( __PACKAGE__ . "->connect( dsn $dsn )" ); |
| 182 |
|
|
| 183 |
#my $storage = Tangram::Relational->connect( $schema, $dsn ); |
#my $storage = Tangram::Relational->connect( $schema, $dsn ); |
| 189 |
# return; |
# return; |
| 190 |
# } |
# } |
| 191 |
|
|
| 192 |
return unless $self->_initSchema(); |
#return unless $self->_initSchema(); |
| 193 |
|
$self->_initSchema(); |
| 194 |
|
|
| 195 |
# create the main tangram storage object |
# create the main tangram storage object |
| 196 |
#$self->{COREHANDLE} = Tangram::Relational->connect( $schema, $dsn ); |
#$self->{COREHANDLE} = Tangram::Relational->connect( $schema, $dsn ); |
| 317 |
$logger->debug( __PACKAGE__ . "->configureCOREHANDLE" ); |
$logger->debug( __PACKAGE__ . "->configureCOREHANDLE" ); |
| 318 |
|
|
| 319 |
#my $subLayer = $self->_getSubLayerHandle(); |
#my $subLayer = $self->_getSubLayerHandle(); |
| 320 |
|
#print Dumper($self); |
| 321 |
|
#exit; |
| 322 |
|
|
| 323 |
# apply configured modifications |
# apply configured modifications |
| 324 |
if (exists $self->{dbi}->{trace_level} && exists $self->{dbi}->{trace_file}) { |
if (exists $self->{dbi}->{trace_level} && exists $self->{dbi}->{trace_file}) { |
| 384 |
return $ok; |
return $ok; |
| 385 |
} |
} |
| 386 |
|
|
| 387 |
sub rebuildDbAndSchema { |
sub rebuildDb { |
| 388 |
my $self = shift; |
my $self = shift; |
| 389 |
$logger->info( __PACKAGE__ . "->rebuildDbAndSchema()" ); |
$logger->info( __PACKAGE__ . "->rebuildDb()" ); |
| 390 |
my @results; |
my @results; |
| 391 |
|
|
| 392 |
# sum up results (bool (0/1)) in array |
# sum up results (bool (0/1)) in array |
| 585 |
|
|
| 586 |
# Guid and Classname is needed |
# Guid and Classname is needed |
| 587 |
if(!$guid || !$options->{classname}) { |
if(!$guid || !$options->{classname}) { |
| 588 |
|
$logger->error( __PACKAGE__ . "->getObjectByGuid: No 'guid' OR no Classname in options hash was given but needed!" ); |
| 589 |
return; |
return; |
| 590 |
} |
} |
| 591 |
|
|
| 594 |
$self->{_COREHANDLE}->unload() if ($options->{destroy}); |
$self->{_COREHANDLE}->unload() if ($options->{destroy}); |
| 595 |
|
|
| 596 |
# search for object with given Classname and Guid |
# search for object with given Classname and Guid |
| 597 |
my $obj_tmp = $self->{_COREHANDLE}->remote($classname); |
my $obj_tmp = $self->{_COREHANDLE}->remote($options->{classname}); |
| 598 |
my @result = $self->{_COREHANDLE}->select($obj_tmp, $obj_tmp->{guid} eq $guid); |
my @result = $self->{_COREHANDLE}->select($obj_tmp, $obj_tmp->{guid} eq $guid); |
| 599 |
|
|
| 600 |
# we searched for global unique identifer of some object, |
# we searched for global unique identifer of some object, |
| 601 |
# so it think we can trust there would be only one result |
# so I think we can trust there would be only one result |
| 602 |
if($result[0]) { |
if($result[0]) { |
| 603 |
return $result[0]; |
return $result[0]; |
| 604 |
} else { |
} else { |
| 605 |
return "No Object with Classname $classname and GUID $options->{guid} found!"; |
$logger->error( __PACKAGE__ . "->getObjectByGuid: No Object with Classname $options->{classname} and GUID $guid found!" ); |
| 606 |
|
return; |
| 607 |
} |
} |
| 608 |
|
|
| 609 |
} |
} |
| 661 |
return $self->{_COREHANDLE}; |
return $self->{_COREHANDLE}; |
| 662 |
} |
} |
| 663 |
|
|
| 664 |
|
sub dropDb { |
| 665 |
|
my $self = shift; |
| 666 |
|
my $storage = $self->_getSubLayerHandle(); |
| 667 |
|
return $storage->dropDb(); |
| 668 |
|
} |
| 669 |
|
|
| 670 |
|
sub testAvailability { |
| 671 |
|
my $self = shift; |
| 672 |
|
my $storage = $self->_getSubLayerHandle(); |
| 673 |
|
return $storage->testAvailability(); |
| 674 |
|
} |
| 675 |
|
|
| 676 |
1; |
1; |
| 677 |
|
__END__ |