| 3 |
# $Id$ |
# $Id$ |
| 4 |
# |
# |
| 5 |
# $Log$ |
# $Log$ |
| 6 |
|
# Revision 1.9 2003/03/27 15:31:08 joko |
| 7 |
|
# fixes to modules regarding new namespace(s) below Data::Mungle::* |
| 8 |
|
# |
| 9 |
|
# Revision 1.8 2003/02/18 19:19:47 joko |
| 10 |
|
# + modified locator handling |
| 11 |
|
# |
| 12 |
|
# Revision 1.7 2003/01/30 22:21:52 joko |
| 13 |
|
# + changed 'connect'-behaviour back to old state |
| 14 |
|
# + renamed log-output (now using 'initializing' instead of 'booting' - corresponding to 'initStorage') |
| 15 |
|
# |
| 16 |
|
# Revision 1.6 2003/01/30 21:44:00 joko |
| 17 |
|
# + temporary fix: (FIXME) now connecting to storage on storagehandle-instantiation |
| 18 |
|
# |
| 19 |
|
# Revision 1.5 2003/01/19 02:39:57 joko |
| 20 |
|
# + moved 'deep_copy' from module 'libp' to module 'Data.Transform.Deep' |
| 21 |
|
# + preserved order for hashes '$self->{config}' and '$self->{locator}' by using Tie::IxHash |
| 22 |
|
# |
| 23 |
|
# Revision 1.4 2002/12/04 07:38:07 jonen |
| 24 |
|
# + deep copy |
| 25 |
|
# |
| 26 |
# Revision 1.3 2002/12/01 22:18:28 joko |
# Revision 1.3 2002/12/01 22:18:28 joko |
| 27 |
# - no interactive implicit deploy |
# - no interactive implicit deploy |
| 28 |
# + only test integrity if storage available |
# + only test integrity if storage available |
| 48 |
# get logger instance |
# get logger instance |
| 49 |
my $logger = Log::Dispatch::Config->instance; |
my $logger = Log::Dispatch::Config->instance; |
| 50 |
|
|
| 51 |
use libp qw( deep_copy ); |
|
| 52 |
|
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - main |
| 53 |
|
use Tie::IxHash; |
| 54 |
use Data::Dumper; |
use Data::Dumper; |
| 55 |
|
|
| 56 |
use Data::Storage; |
use Data::Storage; |
| 57 |
#use Data::Storage::Locator; |
use Data::Storage::Locator; |
| 58 |
|
use Data::Mungle::Transform::Deep qw( deep_copy ); |
| 59 |
|
use Data::Mungle::Compare::Struct qw( isEmpty ); |
| 60 |
|
|
| 61 |
sub new { |
sub new { |
| 62 |
my $invocant = shift; |
my $invocant = shift; |
| 68 |
$logger->debug( __PACKAGE__ . "->new( @args )" ); |
$logger->debug( __PACKAGE__ . "->new( @args )" ); |
| 69 |
|
|
| 70 |
my $self = { @_ }; |
my $self = { @_ }; |
| 71 |
return bless $self, $class; |
bless $self, $class; |
| 72 |
|
|
| 73 |
|
# preserve order of configuration variables |
| 74 |
|
#$self->{config} = {}; |
| 75 |
|
tie %{$self->{config}}, 'Tie::IxHash'; |
| 76 |
|
tie %{$self->{locator}}, 'Tie::IxHash'; |
| 77 |
|
|
| 78 |
|
return $self; |
| 79 |
} |
} |
| 80 |
|
|
| 81 |
sub addConfig { |
sub addConfig { |
| 108 |
my $self = shift; |
my $self = shift; |
| 109 |
my $name = shift; |
my $name = shift; |
| 110 |
my $db_config = $self->{config}->{$name}; |
my $db_config = $self->{config}->{$name}; |
| 111 |
|
$db_config ||= {}; |
| 112 |
|
|
| 113 |
$logger->debug( __PACKAGE__ . "->initLocator( db_config $db_config )" ); |
$logger->debug( __PACKAGE__ . "->initLocator( name='$name' )" ); |
| 114 |
|
|
| 115 |
my $cfg_locator = {}; |
my $cfg_locator = {}; |
| 116 |
|
|
| 120 |
$cfg_locator->{$_} = $default->{$_}; |
$cfg_locator->{$_} = $default->{$_}; |
| 121 |
} |
} |
| 122 |
|
|
|
# name it |
|
|
$cfg_locator->{name} = $name; |
|
|
|
|
| 123 |
# merge in specific settings |
# merge in specific settings |
| 124 |
foreach (keys %$db_config) { |
my $specific = deep_copy($db_config); |
| 125 |
$cfg_locator->{$_} = $db_config->{$_}; |
foreach (keys %$specific) { |
| 126 |
|
$cfg_locator->{$_} = $specific->{$_}; |
| 127 |
} |
} |
| 128 |
|
|
| 129 |
# HACK: transfer dsn from main to dbi settings |
# HACK: transfer dsn from main to dbi settings |
| 135 |
# HACK: set errorhandler if dbi settings are present |
# HACK: set errorhandler if dbi settings are present |
| 136 |
$cfg_locator->{dbi}->{HandleError} = \&_dbErrorHandler if $cfg_locator->{dbi}; |
$cfg_locator->{dbi}->{HandleError} = \&_dbErrorHandler if $cfg_locator->{dbi}; |
| 137 |
|
|
| 138 |
|
# trace |
| 139 |
|
#print "locator:", "\n"; |
| 140 |
|
#print Dumper($cfg_locator); |
| 141 |
|
|
| 142 |
|
# check locator metadata |
| 143 |
|
if (isEmpty($cfg_locator)) { |
| 144 |
|
$logger->warning( __PACKAGE__ . "->initLocator( name='$name' ): Metadata was empty. Please check configuration." ); |
| 145 |
|
return; |
| 146 |
|
} |
| 147 |
|
|
| 148 |
|
# name it |
| 149 |
|
$cfg_locator->{name} = $name; |
| 150 |
|
|
| 151 |
# create new locator object |
# create new locator object |
| 152 |
$self->{locator}->{$name} = Data::Storage::Locator->new( $cfg_locator ); |
$self->{locator}->{$name} = Data::Storage::Locator->new( $cfg_locator ); |
| 153 |
|
|
| 156 |
sub initLocators { |
sub initLocators { |
| 157 |
my $self = shift; |
my $self = shift; |
| 158 |
foreach (keys %{$self->{config}}) { |
foreach (keys %{$self->{config}}) { |
| 159 |
|
#print $_, "\n"; |
| 160 |
$self->initLocator($_, $self->{config}->{$_}) if !/^_/; |
$self->initLocator($_, $self->{config}->{$_}) if !/^_/; |
| 161 |
} |
} |
| 162 |
#print "locs: ", Dumper($self->{locator}); |
#print "locs: ", Dumper($self->{locator}); |
| 173 |
my $name = shift; |
my $name = shift; |
| 174 |
|
|
| 175 |
my $locator = $self->getLocator($name); |
my $locator = $self->getLocator($name); |
| 176 |
$logger->info( __PACKAGE__ . " is booting storage declared by locator \"$name\"" ); |
$logger->info( __PACKAGE__ . " is initializing storage declared by locator \"$name\"" ); |
| 177 |
|
|
| 178 |
my $storage = Data::Storage->new($locator); |
my $storage = Data::Storage->new($locator); |
| 179 |
|
|
| 180 |
|
# TODO: do below (after 'testAvailability' and 'testIntegrity') again!!! |
| 181 |
|
#$storage->connect(); |
| 182 |
|
|
| 183 |
my $log_prefix = __PACKAGE__ . "->initStorage: "; |
my $log_prefix = __PACKAGE__ . "->initStorage: "; |
| 184 |
$log_prefix .= "dsn=\"$self->{locator}->{$name}->{dsn}\"" if $self->{locator}->{$name}->{dsn}; |
$log_prefix .= "dsn=\"$self->{locator}->{$name}->{dsn}\"" if $self->{locator}->{$name}->{dsn}; |
| 246 |
sub initStorages { |
sub initStorages { |
| 247 |
my $self = shift; |
my $self = shift; |
| 248 |
foreach (keys %{$self->{locator}}) { |
foreach (keys %{$self->{locator}}) { |
| 249 |
|
#print $_, "\n"; |
| 250 |
$self->initStorage($_); |
$self->initStorage($_); |
| 251 |
} |
} |
| 252 |
} |
} |