--- nfo/perl/libs/Data/Storage/Container.pm 2002/11/29 04:54:54 1.1 +++ nfo/perl/libs/Data/Storage/Container.pm 2003/01/19 02:39:57 1.5 @@ -1,8 +1,22 @@ ################################################ # -# $Id: Container.pm,v 1.1 2002/11/29 04:54:54 joko Exp $ +# $Id: Container.pm,v 1.5 2003/01/19 02:39:57 joko Exp $ # # $Log: Container.pm,v $ +# Revision 1.5 2003/01/19 02:39:57 joko +# + moved 'deep_copy' from module 'libp' to module 'Data::Transform::Deep' +# + preserved order for hashes '$self->{config}' and '$self->{locator}' by using Tie::IxHash +# +# Revision 1.4 2002/12/04 07:38:07 jonen +# + deep copy +# +# Revision 1.3 2002/12/01 22:18:28 joko +# - no interactive implicit deploy +# + only test integrity if storage available +# +# Revision 1.2 2002/12/01 07:08:35 joko +# + needs to "use Data::Storage;" +# # Revision 1.1 2002/11/29 04:54:54 joko # + initial check-in # @@ -21,9 +35,14 @@ # get logger instance my $logger = Log::Dispatch::Config->instance; -use libp qw( deep_copy ); + +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - main +use Tie::IxHash; use Data::Dumper; +use Data::Transform::Deep qw( deep_copy ); +use Data::Storage; +#use Data::Storage::Locator; sub new { my $invocant = shift; @@ -35,7 +54,14 @@ $logger->debug( __PACKAGE__ . "->new( @args )" ); my $self = { @_ }; - return bless $self, $class; + bless $self, $class; + + # preserve order of configuration variables + #$self->{config} = {}; + tie %{$self->{config}}, 'Tie::IxHash'; + tie %{$self->{locator}}, 'Tie::IxHash'; + + return $self; } sub addConfig { @@ -83,8 +109,9 @@ $cfg_locator->{name} = $name; # merge in specific settings - foreach (keys %$db_config) { - $cfg_locator->{$_} = $db_config->{$_}; + my $specific = deep_copy($db_config); + foreach (keys %$specific) { + $cfg_locator->{$_} = $specific->{$_}; } # HACK: transfer dsn from main to dbi settings @@ -104,6 +131,7 @@ sub initLocators { my $self = shift; foreach (keys %{$self->{config}}) { + #print $_, "\n"; $self->initLocator($_, $self->{config}->{$_}) if !/^_/; } #print "locs: ", Dumper($self->{locator}); @@ -129,24 +157,19 @@ # should we test availability of the storage before using it? if ($locator->{test_availability}) { + $locator->{status}->{availability} = $storage->testAvailability(); if ( !$storage->testAvailability() ) { - $logger->error( "$log_prefix is not available" ); - return; + $logger->error( "$log_prefix: testAvailability failed" ); } } # should we test integrity of the storage before using it? - if ($locator->{test_integrity}) { + if ($locator->{status}->{availability} && $locator->{test_integrity}) { #return unless $storage->testIntegrity(); $locator->{status}->{integrity} = $storage->testIntegrity(); # actions if integrity fails if (!$locator->{status}->{integrity}) { - $logger->error( "testIntegrity failed on $log_prefix" ); - print "Try a $locator->{name}.deploySchema()? (y/n) "; - my $res = ; - if ($res =~ m/y/i) { - $storage->deploySchema(); - } + $logger->error( "$log_prefix: testIntegrity failed" ); } } @@ -155,19 +178,20 @@ # don't connect right here, do an implicit connect on (later) usage # maybe set ->{meta}->{connectmethod} = "connect" here #return unless $storage->connect(); - $storage->connect(); + $storage->connect() if $locator->{status}->{integrity}; # should we check emptyness? - if ( $locator->{test_emptyness} && $locator->{status}->{integrity} ) { + if ($locator->{status}->{availability} && $locator->{test_emptyness}) { + #print "test empty", "\n"; if ( !@{$storage->getChildNodes()} ) { $locator->{status}->{empty} = 1; - $logger->warning( "$log_prefix is empty"); + $logger->warning( "$log_prefix: Storage is empty."); #return; } } # expand logging? - if ( $locator->{logger} && $locator->{status}->{integrity} ) { + if ( $locator->{status}->{integrity} && $locator->{logger} ) { # expand logging (to Tangram-Database) # TODO: # - move configuration data from this code to db_config somehow @@ -184,6 +208,7 @@ } #$self->{storage}->{$name} = $storage; + #print "add storage: $name", "\n"; $self->addStorage($name, $storage); return 1; @@ -193,6 +218,7 @@ sub initStorages { my $self = shift; foreach (keys %{$self->{locator}}) { + #print $_, "\n"; $self->initStorage($_); } }