3 |
# $Id$ |
# $Id$ |
4 |
# |
# |
5 |
# $Log$ |
# $Log$ |
6 |
|
# Revision 1.3 2002/12/01 22:18:28 joko |
7 |
|
# - no interactive implicit deploy |
8 |
|
# + only test integrity if storage available |
9 |
|
# |
10 |
|
# Revision 1.2 2002/12/01 07:08:35 joko |
11 |
|
# + needs to "use Data::Storage;" |
12 |
|
# |
13 |
# Revision 1.1 2002/11/29 04:54:54 joko |
# Revision 1.1 2002/11/29 04:54:54 joko |
14 |
# + initial check-in |
# + initial check-in |
15 |
# |
# |
30 |
|
|
31 |
use libp qw( deep_copy ); |
use libp qw( deep_copy ); |
32 |
use Data::Dumper; |
use Data::Dumper; |
33 |
|
use Data::Storage; |
34 |
|
#use Data::Storage::Locator; |
35 |
|
|
36 |
sub new { |
sub new { |
37 |
my $invocant = shift; |
my $invocant = shift; |
137 |
|
|
138 |
# should we test availability of the storage before using it? |
# should we test availability of the storage before using it? |
139 |
if ($locator->{test_availability}) { |
if ($locator->{test_availability}) { |
140 |
|
$locator->{status}->{availability} = $storage->testAvailability(); |
141 |
if ( !$storage->testAvailability() ) { |
if ( !$storage->testAvailability() ) { |
142 |
$logger->error( "$log_prefix is not available" ); |
$logger->error( "$log_prefix: testAvailability failed" ); |
|
return; |
|
143 |
} |
} |
144 |
} |
} |
145 |
|
|
146 |
# should we test integrity of the storage before using it? |
# should we test integrity of the storage before using it? |
147 |
if ($locator->{test_integrity}) { |
if ($locator->{status}->{availability} && $locator->{test_integrity}) { |
148 |
#return unless $storage->testIntegrity(); |
#return unless $storage->testIntegrity(); |
149 |
$locator->{status}->{integrity} = $storage->testIntegrity(); |
$locator->{status}->{integrity} = $storage->testIntegrity(); |
150 |
# actions if integrity fails |
# actions if integrity fails |
151 |
if (!$locator->{status}->{integrity}) { |
if (!$locator->{status}->{integrity}) { |
152 |
$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(); |
|
|
} |
|
153 |
} |
} |
154 |
} |
} |
155 |
|
|
158 |
# don't connect right here, do an implicit connect on (later) usage |
# don't connect right here, do an implicit connect on (later) usage |
159 |
# maybe set ->{meta}->{connectmethod} = "connect" here |
# maybe set ->{meta}->{connectmethod} = "connect" here |
160 |
#return unless $storage->connect(); |
#return unless $storage->connect(); |
161 |
$storage->connect(); |
$storage->connect() if $locator->{status}->{integrity}; |
162 |
|
|
163 |
# should we check emptyness? |
# should we check emptyness? |
164 |
if ( $locator->{test_emptyness} && $locator->{status}->{integrity} ) { |
if ($locator->{status}->{availability} && $locator->{test_emptyness}) { |
165 |
|
#print "test empty", "\n"; |
166 |
if ( !@{$storage->getChildNodes()} ) { |
if ( !@{$storage->getChildNodes()} ) { |
167 |
$locator->{status}->{empty} = 1; |
$locator->{status}->{empty} = 1; |
168 |
$logger->warning( "$log_prefix is empty"); |
$logger->warning( "$log_prefix: Storage is empty."); |
169 |
#return; |
#return; |
170 |
} |
} |
171 |
} |
} |
172 |
|
|
173 |
# expand logging? |
# expand logging? |
174 |
if ( $locator->{logger} && $locator->{status}->{integrity} ) { |
if ( $locator->{status}->{integrity} && $locator->{logger} ) { |
175 |
# expand logging (to Tangram-Database) |
# expand logging (to Tangram-Database) |
176 |
# TODO: |
# TODO: |
177 |
# - move configuration data from this code to db_config somehow |
# - move configuration data from this code to db_config somehow |
188 |
} |
} |
189 |
|
|
190 |
#$self->{storage}->{$name} = $storage; |
#$self->{storage}->{$name} = $storage; |
191 |
|
#print "add storage: $name", "\n"; |
192 |
$self->addStorage($name, $storage); |
$self->addStorage($name, $storage); |
193 |
|
|
194 |
return 1; |
return 1; |