/[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.1 by joko, Fri Nov 29 04:54:54 2002 UTC revision 1.8 by joko, Tue Feb 18 19:19:47 2003 UTC
# Line 3  Line 3 
3  #  $Id$  #  $Id$
4  #  #
5  #  $Log$  #  $Log$
6    #  Revision 1.8  2003/02/18 19:19:47  joko
7    #  + modified locator handling
8    #
9    #  Revision 1.7  2003/01/30 22:21:52  joko
10    #  + changed 'connect'-behaviour back to old state
11    #  + renamed log-output (now using 'initializing' instead of 'booting' - corresponding to 'initStorage')
12    #
13    #  Revision 1.6  2003/01/30 21:44:00  joko
14    #  + temporary fix: (FIXME) now connecting to storage on storagehandle-instantiation
15    #
16    #  Revision 1.5  2003/01/19 02:39:57  joko
17    #  + moved 'deep_copy' from module 'libp' to module 'Data::Transform::Deep'
18    #  + preserved order for hashes '$self->{config}' and '$self->{locator}' by using Tie::IxHash
19    #
20    #  Revision 1.4  2002/12/04 07:38:07  jonen
21    #  + deep copy
22    #
23    #  Revision 1.3  2002/12/01 22:18:28  joko
24    #  - no interactive implicit deploy
25    #  + only test integrity if storage available
26    #
27    #  Revision 1.2  2002/12/01 07:08:35  joko
28    #  + needs to "use Data::Storage;"
29    #
30  #  Revision 1.1  2002/11/29 04:54:54  joko  #  Revision 1.1  2002/11/29 04:54:54  joko
31  #  + initial check-in  #  + initial check-in
32  #  #
# Line 21  use warnings; Line 45  use warnings;
45  # get logger instance  # get logger instance
46  my $logger = Log::Dispatch::Config->instance;  my $logger = Log::Dispatch::Config->instance;
47    
48  use libp qw( deep_copy );  
49    # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -   main
50    use Tie::IxHash;
51  use Data::Dumper;  use Data::Dumper;
52    
53    use Data::Storage;
54    use Data::Storage::Locator;
55    use Data::Transform::Deep qw( deep_copy );
56    use Data::Compare::Struct qw( isEmpty );
57    
58  sub new {  sub new {
59    my $invocant = shift;    my $invocant = shift;
# Line 35  sub new { Line 65  sub new {
65    $logger->debug( __PACKAGE__ . "->new( @args )" );    $logger->debug( __PACKAGE__ . "->new( @args )" );
66    
67    my $self = { @_ };    my $self = { @_ };
68    return bless $self, $class;    bless $self, $class;
69      
70      # preserve order of configuration variables
71      #$self->{config} = {};
72      tie %{$self->{config}}, 'Tie::IxHash';
73      tie %{$self->{locator}}, 'Tie::IxHash';
74      
75      return $self;
76  }  }
77    
78  sub addConfig {  sub addConfig {
# Line 68  sub initLocator { Line 105  sub initLocator {
105    my $self = shift;    my $self = shift;
106    my $name = shift;    my $name = shift;
107    my $db_config = $self->{config}->{$name};    my $db_config = $self->{config}->{$name};
108      $db_config ||= {};
109    
110    $logger->debug( __PACKAGE__ . "->initLocator( db_config $db_config )" );    $logger->debug( __PACKAGE__ . "->initLocator( name='$name' )" );
111    
112    my $cfg_locator = {};    my $cfg_locator = {};
113        
# Line 79  sub initLocator { Line 117  sub initLocator {
117      $cfg_locator->{$_} = $default->{$_};      $cfg_locator->{$_} = $default->{$_};
118    }    }
119        
   # name it  
   $cfg_locator->{name} = $name;  
     
120    # merge in specific settings    # merge in specific settings
121    foreach (keys %$db_config) {    my $specific = deep_copy($db_config);
122      $cfg_locator->{$_} = $db_config->{$_};    foreach (keys %$specific) {
123        $cfg_locator->{$_} = $specific->{$_};
124    }    }
125        
126    # HACK: transfer dsn from main to dbi settings    # HACK: transfer dsn from main to dbi settings
# Line 96  sub initLocator { Line 132  sub initLocator {
132    # HACK: set errorhandler if dbi settings are present    # HACK: set errorhandler if dbi settings are present
133    $cfg_locator->{dbi}->{HandleError} = \&_dbErrorHandler if $cfg_locator->{dbi};    $cfg_locator->{dbi}->{HandleError} = \&_dbErrorHandler if $cfg_locator->{dbi};
134    
135      # trace
136        #print "locator:", "\n";
137        #print Dumper($cfg_locator);
138    
139      # check locator metadata
140      if (isEmpty($cfg_locator)) {
141        $logger->warning( __PACKAGE__ . "->initLocator( name='$name' ): Metadata was empty. Please check configuration." );
142        return;
143      }
144    
145      # name it
146      $cfg_locator->{name} = $name;
147    
148    # create new locator object    # create new locator object
149    $self->{locator}->{$name} = Data::Storage::Locator->new( $cfg_locator );    $self->{locator}->{$name} = Data::Storage::Locator->new( $cfg_locator );
150    
# Line 104  sub initLocator { Line 153  sub initLocator {
153  sub initLocators {  sub initLocators {
154    my $self = shift;    my $self = shift;
155    foreach (keys %{$self->{config}}) {    foreach (keys %{$self->{config}}) {
156        #print $_, "\n";
157      $self->initLocator($_, $self->{config}->{$_}) if !/^_/;      $self->initLocator($_, $self->{config}->{$_}) if !/^_/;
158    }    }
159    #print "locs: ", Dumper($self->{locator});    #print "locs: ", Dumper($self->{locator});
# Line 120  sub initStorage { Line 170  sub initStorage {
170    my $name = shift;    my $name = shift;
171    
172    my $locator = $self->getLocator($name);    my $locator = $self->getLocator($name);
173    $logger->info( __PACKAGE__ . " is booting storage declared by locator \"$name\"" );    $logger->info( __PACKAGE__ . " is initializing storage declared by locator \"$name\"" );
174    
175    my $storage = Data::Storage->new($locator);    my $storage = Data::Storage->new($locator);
176      
177      # TODO: do below (after 'testAvailability' and 'testIntegrity') again!!!
178      #$storage->connect();
179    
180    my $log_prefix = __PACKAGE__ . "->initStorage: ";    my $log_prefix = __PACKAGE__ . "->initStorage: ";
181    $log_prefix .= "dsn=\"$self->{locator}->{$name}->{dsn}\"" if $self->{locator}->{$name}->{dsn};    $log_prefix .= "dsn=\"$self->{locator}->{$name}->{dsn}\"" if $self->{locator}->{$name}->{dsn};
182    
183    # should we test availability of the storage before using it?    # should we test availability of the storage before using it?
184    if ($locator->{test_availability}) {    if ($locator->{test_availability}) {
185        $locator->{status}->{availability} = $storage->testAvailability();
186      if ( !$storage->testAvailability() ) {      if ( !$storage->testAvailability() ) {
187        $logger->error( "$log_prefix is not available" );        $logger->error( "$log_prefix: testAvailability failed" );
       return;  
188      }      }
189    }    }
190                        
191    # should we test integrity of the storage before using it?    # should we test integrity of the storage before using it?
192    if ($locator->{test_integrity}) {    if ($locator->{status}->{availability} && $locator->{test_integrity}) {
193      #return unless $storage->testIntegrity();      #return unless $storage->testIntegrity();
194      $locator->{status}->{integrity} = $storage->testIntegrity();      $locator->{status}->{integrity} = $storage->testIntegrity();
195      # actions if integrity fails      # actions if integrity fails
196      if (!$locator->{status}->{integrity}) {      if (!$locator->{status}->{integrity}) {
197        $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();  
       }  
198      }      }
199    }    }
200    
# Line 155  sub initStorage { Line 203  sub initStorage {
203    # don't connect right here, do an implicit connect on (later) usage    # don't connect right here, do an implicit connect on (later) usage
204    # maybe set ->{meta}->{connectmethod} = "connect" here    # maybe set ->{meta}->{connectmethod} = "connect" here
205    #return unless $storage->connect();    #return unless $storage->connect();
206    $storage->connect();    $storage->connect() if $locator->{status}->{integrity};
207    
208    # should we check emptyness?    # should we check emptyness?
209    if ( $locator->{test_emptyness} && $locator->{status}->{integrity} ) {    if ($locator->{status}->{availability} && $locator->{test_emptyness}) {
210        #print "test empty", "\n";
211      if ( !@{$storage->getChildNodes()} ) {      if ( !@{$storage->getChildNodes()} ) {
212        $locator->{status}->{empty} = 1;        $locator->{status}->{empty} = 1;
213        $logger->warning( "$log_prefix is empty");        $logger->warning( "$log_prefix: Storage is empty.");
214        #return;        #return;
215      }      }
216    }    }
217    
218    # expand logging?    # expand logging?
219    if ( $locator->{logger} && $locator->{status}->{integrity} ) {    if ( $locator->{status}->{integrity} && $locator->{logger} ) {
220      # expand logging (to Tangram-Database)      # expand logging (to Tangram-Database)
221      # TODO:      # TODO:
222      # - move configuration data from this code to db_config somehow      # - move configuration data from this code to db_config somehow
# Line 184  sub initStorage { Line 233  sub initStorage {
233    }    }
234    
235    #$self->{storage}->{$name} = $storage;    #$self->{storage}->{$name} = $storage;
236      #print "add storage: $name", "\n";
237    $self->addStorage($name, $storage);    $self->addStorage($name, $storage);
238    
239    return 1;    return 1;
# Line 193  sub initStorage { Line 243  sub initStorage {
243  sub initStorages {  sub initStorages {
244    my $self = shift;    my $self = shift;
245    foreach (keys %{$self->{locator}}) {    foreach (keys %{$self->{locator}}) {
246        #print $_, "\n";
247      $self->initStorage($_);      $self->initStorage($_);
248    }    }
249  }  }

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.8

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