3 |
# $Id$ |
# $Id$ |
4 |
# |
# |
5 |
# $Log$ |
# $Log$ |
6 |
|
# Revision 1.5 2003/01/19 02:39:57 joko |
7 |
|
# + moved 'deep_copy' from module 'libp' to module 'Data::Transform::Deep' |
8 |
|
# + preserved order for hashes '$self->{config}' and '$self->{locator}' by using Tie::IxHash |
9 |
|
# |
10 |
|
# Revision 1.4 2002/12/04 07:38:07 jonen |
11 |
|
# + deep copy |
12 |
|
# |
13 |
|
# Revision 1.3 2002/12/01 22:18:28 joko |
14 |
|
# - no interactive implicit deploy |
15 |
|
# + only test integrity if storage available |
16 |
|
# |
17 |
|
# Revision 1.2 2002/12/01 07:08:35 joko |
18 |
|
# + needs to "use Data::Storage;" |
19 |
|
# |
20 |
# Revision 1.1 2002/11/29 04:54:54 joko |
# Revision 1.1 2002/11/29 04:54:54 joko |
21 |
# + initial check-in |
# + initial check-in |
22 |
# |
# |
35 |
# get logger instance |
# get logger instance |
36 |
my $logger = Log::Dispatch::Config->instance; |
my $logger = Log::Dispatch::Config->instance; |
37 |
|
|
38 |
use libp qw( deep_copy ); |
|
39 |
|
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - main |
40 |
|
use Tie::IxHash; |
41 |
use Data::Dumper; |
use Data::Dumper; |
42 |
|
|
43 |
|
use Data::Transform::Deep qw( deep_copy ); |
44 |
|
use Data::Storage; |
45 |
|
#use Data::Storage::Locator; |
46 |
|
|
47 |
sub new { |
sub new { |
48 |
my $invocant = shift; |
my $invocant = shift; |
54 |
$logger->debug( __PACKAGE__ . "->new( @args )" ); |
$logger->debug( __PACKAGE__ . "->new( @args )" ); |
55 |
|
|
56 |
my $self = { @_ }; |
my $self = { @_ }; |
57 |
return bless $self, $class; |
bless $self, $class; |
58 |
|
|
59 |
|
# preserve order of configuration variables |
60 |
|
#$self->{config} = {}; |
61 |
|
tie %{$self->{config}}, 'Tie::IxHash'; |
62 |
|
tie %{$self->{locator}}, 'Tie::IxHash'; |
63 |
|
|
64 |
|
return $self; |
65 |
} |
} |
66 |
|
|
67 |
sub addConfig { |
sub addConfig { |
109 |
$cfg_locator->{name} = $name; |
$cfg_locator->{name} = $name; |
110 |
|
|
111 |
# merge in specific settings |
# merge in specific settings |
112 |
foreach (keys %$db_config) { |
my $specific = deep_copy($db_config); |
113 |
$cfg_locator->{$_} = $db_config->{$_}; |
foreach (keys %$specific) { |
114 |
|
$cfg_locator->{$_} = $specific->{$_}; |
115 |
} |
} |
116 |
|
|
117 |
# HACK: transfer dsn from main to dbi settings |
# HACK: transfer dsn from main to dbi settings |
131 |
sub initLocators { |
sub initLocators { |
132 |
my $self = shift; |
my $self = shift; |
133 |
foreach (keys %{$self->{config}}) { |
foreach (keys %{$self->{config}}) { |
134 |
|
#print $_, "\n"; |
135 |
$self->initLocator($_, $self->{config}->{$_}) if !/^_/; |
$self->initLocator($_, $self->{config}->{$_}) if !/^_/; |
136 |
} |
} |
137 |
#print "locs: ", Dumper($self->{locator}); |
#print "locs: ", Dumper($self->{locator}); |
157 |
|
|
158 |
# should we test availability of the storage before using it? |
# should we test availability of the storage before using it? |
159 |
if ($locator->{test_availability}) { |
if ($locator->{test_availability}) { |
160 |
|
$locator->{status}->{availability} = $storage->testAvailability(); |
161 |
if ( !$storage->testAvailability() ) { |
if ( !$storage->testAvailability() ) { |
162 |
$logger->error( "$log_prefix is not available" ); |
$logger->error( "$log_prefix: testAvailability failed" ); |
|
return; |
|
163 |
} |
} |
164 |
} |
} |
165 |
|
|
166 |
# should we test integrity of the storage before using it? |
# should we test integrity of the storage before using it? |
167 |
if ($locator->{test_integrity}) { |
if ($locator->{status}->{availability} && $locator->{test_integrity}) { |
168 |
#return unless $storage->testIntegrity(); |
#return unless $storage->testIntegrity(); |
169 |
$locator->{status}->{integrity} = $storage->testIntegrity(); |
$locator->{status}->{integrity} = $storage->testIntegrity(); |
170 |
# actions if integrity fails |
# actions if integrity fails |
171 |
if (!$locator->{status}->{integrity}) { |
if (!$locator->{status}->{integrity}) { |
172 |
$logger->error( "testIntegrity failed on $log_prefix" ); |
$logger->error( "$log_prefix: testIntegrity failed" ); |
|
print "Try a $locator->{name}.deploySchema()? (y/n) "; |
|
|
my $res = <STDIN>; |
|
|
if ($res =~ m/y/i) { |
|
|
$storage->deploySchema(); |
|
|
} |
|
173 |
} |
} |
174 |
} |
} |
175 |
|
|
178 |
# don't connect right here, do an implicit connect on (later) usage |
# don't connect right here, do an implicit connect on (later) usage |
179 |
# maybe set ->{meta}->{connectmethod} = "connect" here |
# maybe set ->{meta}->{connectmethod} = "connect" here |
180 |
#return unless $storage->connect(); |
#return unless $storage->connect(); |
181 |
$storage->connect(); |
$storage->connect() if $locator->{status}->{integrity}; |
182 |
|
|
183 |
# should we check emptyness? |
# should we check emptyness? |
184 |
if ( $locator->{test_emptyness} && $locator->{status}->{integrity} ) { |
if ($locator->{status}->{availability} && $locator->{test_emptyness}) { |
185 |
|
#print "test empty", "\n"; |
186 |
if ( !@{$storage->getChildNodes()} ) { |
if ( !@{$storage->getChildNodes()} ) { |
187 |
$locator->{status}->{empty} = 1; |
$locator->{status}->{empty} = 1; |
188 |
$logger->warning( "$log_prefix is empty"); |
$logger->warning( "$log_prefix: Storage is empty."); |
189 |
#return; |
#return; |
190 |
} |
} |
191 |
} |
} |
192 |
|
|
193 |
# expand logging? |
# expand logging? |
194 |
if ( $locator->{logger} && $locator->{status}->{integrity} ) { |
if ( $locator->{status}->{integrity} && $locator->{logger} ) { |
195 |
# expand logging (to Tangram-Database) |
# expand logging (to Tangram-Database) |
196 |
# TODO: |
# TODO: |
197 |
# - move configuration data from this code to db_config somehow |
# - move configuration data from this code to db_config somehow |
208 |
} |
} |
209 |
|
|
210 |
#$self->{storage}->{$name} = $storage; |
#$self->{storage}->{$name} = $storage; |
211 |
|
#print "add storage: $name", "\n"; |
212 |
$self->addStorage($name, $storage); |
$self->addStorage($name, $storage); |
213 |
|
|
214 |
return 1; |
return 1; |
218 |
sub initStorages { |
sub initStorages { |
219 |
my $self = shift; |
my $self = shift; |
220 |
foreach (keys %{$self->{locator}}) { |
foreach (keys %{$self->{locator}}) { |
221 |
|
#print $_, "\n"; |
222 |
$self->initStorage($_); |
$self->initStorage($_); |
223 |
} |
} |
224 |
} |
} |