| 3 |
# $Id$ |
# $Id$ |
| 4 |
# |
# |
| 5 |
# $Log$ |
# $Log$ |
| 6 |
|
# Revision 1.8 2003/02/18 19:19:47 joko |
| 7 |
|
# + modified locator handling |
| 8 |
|
# |
| 9 |
|
# Revision 1.7 2003/01/30 22:21:52 joko |
| 10 |
|
# + changed 'connect'-behaviour back to old state |
| 11 |
|
# + renamed log-output (now using 'initializing' instead of 'booting' - corresponding to 'initStorage') |
| 12 |
|
# |
| 13 |
|
# Revision 1.6 2003/01/30 21:44:00 joko |
| 14 |
|
# + temporary fix: (FIXME) now connecting to storage on storagehandle-instantiation |
| 15 |
|
# |
| 16 |
# Revision 1.5 2003/01/19 02:39:57 joko |
# Revision 1.5 2003/01/19 02:39:57 joko |
| 17 |
# + moved 'deep_copy' from module 'libp' to module 'Data::Transform::Deep' |
# + moved 'deep_copy' from module 'libp' to module 'Data::Transform::Deep' |
| 18 |
# + preserved order for hashes '$self->{config}' and '$self->{locator}' by using Tie::IxHash |
# + preserved order for hashes '$self->{config}' and '$self->{locator}' by using Tie::IxHash |
| 50 |
use Tie::IxHash; |
use Tie::IxHash; |
| 51 |
use Data::Dumper; |
use Data::Dumper; |
| 52 |
|
|
|
use Data::Transform::Deep qw( deep_copy ); |
|
| 53 |
use Data::Storage; |
use Data::Storage; |
| 54 |
#use Data::Storage::Locator; |
use Data::Storage::Locator; |
| 55 |
|
use Data::Transform::Deep qw( deep_copy ); |
| 56 |
|
use Data::Compare::Struct qw( isEmpty ); |
| 57 |
|
|
| 58 |
sub new { |
sub new { |
| 59 |
my $invocant = shift; |
my $invocant = shift; |
| 105 |
my $self = shift; |
my $self = shift; |
| 106 |
my $name = shift; |
my $name = shift; |
| 107 |
my $db_config = $self->{config}->{$name}; |
my $db_config = $self->{config}->{$name}; |
| 108 |
|
$db_config ||= {}; |
| 109 |
|
|
| 110 |
$logger->debug( __PACKAGE__ . "->initLocator( db_config $db_config )" ); |
$logger->debug( __PACKAGE__ . "->initLocator( name='$name' )" ); |
| 111 |
|
|
| 112 |
my $cfg_locator = {}; |
my $cfg_locator = {}; |
| 113 |
|
|
| 117 |
$cfg_locator->{$_} = $default->{$_}; |
$cfg_locator->{$_} = $default->{$_}; |
| 118 |
} |
} |
| 119 |
|
|
|
# name it |
|
|
$cfg_locator->{name} = $name; |
|
|
|
|
| 120 |
# merge in specific settings |
# merge in specific settings |
| 121 |
my $specific = deep_copy($db_config); |
my $specific = deep_copy($db_config); |
| 122 |
foreach (keys %$specific) { |
foreach (keys %$specific) { |
| 132 |
# HACK: set errorhandler if dbi settings are present |
# HACK: set errorhandler if dbi settings are present |
| 133 |
$cfg_locator->{dbi}->{HandleError} = \&_dbErrorHandler if $cfg_locator->{dbi}; |
$cfg_locator->{dbi}->{HandleError} = \&_dbErrorHandler if $cfg_locator->{dbi}; |
| 134 |
|
|
| 135 |
|
# trace |
| 136 |
|
#print "locator:", "\n"; |
| 137 |
|
#print Dumper($cfg_locator); |
| 138 |
|
|
| 139 |
|
# check locator metadata |
| 140 |
|
if (isEmpty($cfg_locator)) { |
| 141 |
|
$logger->warning( __PACKAGE__ . "->initLocator( name='$name' ): Metadata was empty. Please check configuration." ); |
| 142 |
|
return; |
| 143 |
|
} |
| 144 |
|
|
| 145 |
|
# name it |
| 146 |
|
$cfg_locator->{name} = $name; |
| 147 |
|
|
| 148 |
# create new locator object |
# create new locator object |
| 149 |
$self->{locator}->{$name} = Data::Storage::Locator->new( $cfg_locator ); |
$self->{locator}->{$name} = Data::Storage::Locator->new( $cfg_locator ); |
| 150 |
|
|
| 170 |
my $name = shift; |
my $name = shift; |
| 171 |
|
|
| 172 |
my $locator = $self->getLocator($name); |
my $locator = $self->getLocator($name); |
| 173 |
$logger->info( __PACKAGE__ . " is booting storage declared by locator \"$name\"" ); |
$logger->info( __PACKAGE__ . " is initializing storage declared by locator \"$name\"" ); |
| 174 |
|
|
| 175 |
my $storage = Data::Storage->new($locator); |
my $storage = Data::Storage->new($locator); |
| 176 |
|
|
| 177 |
|
# TODO: do below (after 'testAvailability' and 'testIntegrity') again!!! |
| 178 |
|
#$storage->connect(); |
| 179 |
|
|
| 180 |
my $log_prefix = __PACKAGE__ . "->initStorage: "; |
my $log_prefix = __PACKAGE__ . "->initStorage: "; |
| 181 |
$log_prefix .= "dsn=\"$self->{locator}->{$name}->{dsn}\"" if $self->{locator}->{$name}->{dsn}; |
$log_prefix .= "dsn=\"$self->{locator}->{$name}->{dsn}\"" if $self->{locator}->{$name}->{dsn}; |