/[cvs]/nfo/perl/libs/Data/Storage/Container.pm
ViewVC logotype

Diff of /nfo/perl/libs/Data/Storage/Container.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.2 by joko, Sun Dec 1 07:08:35 2002 UTC revision 1.5 by joko, Sun Jan 19 02:39:57 2003 UTC
# Line 3  Line 3 
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  #  Revision 1.2  2002/12/01 07:08:35  joko
18  #  + needs to "use Data::Storage;"  #  + needs to "use Data::Storage;"
19  #  #
# Line 24  use warnings; Line 35  use warnings;
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;  use Data::Storage;
45  #use Data::Storage::Locator;  #use Data::Storage::Locator;
46    
# Line 39  sub new { Line 54  sub new {
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 {
# Line 87  sub initLocator { Line 109  sub initLocator {
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
# Line 108  sub initLocator { Line 131  sub initLocator {
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});
# Line 133  sub initStorage { Line 157  sub initStorage {
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    
# Line 159  sub initStorage { Line 178  sub initStorage {
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
# Line 188  sub initStorage { Line 208  sub initStorage {
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;
# Line 197  sub initStorage { Line 218  sub initStorage {
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  }  }

Legend:
Removed from v.1.2  
changed lines
  Added in v.1.5

MailToCvsAdmin">MailToCvsAdmin
ViewVC Help
Powered by ViewVC 1.1.26 RSS 2.0 feed