/[cvs]/nfo/perl/libs/App/Process.pm
ViewVC logotype

Diff of /nfo/perl/libs/App/Process.pm

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

revision 1.2 by joko, Thu Mar 27 15:43:05 2003 UTC revision 1.3 by joko, Fri Jun 6 03:14:16 2003 UTC
# Line 2  Line 2 
2  ##  $Id$  ##  $Id$
3  ## ----------------------------------------------------------------------  ## ----------------------------------------------------------------------
4  ##  $Log$  ##  $Log$
5    ##  Revision 1.3  2003/06/06 03:14:16  joko
6    ##  enhanced database connection bootstrapping:
7    ##    - boot default ones
8    ##    - boot-on-demand
9    ##    - protection for multiple redundant connections
10    ##
11  ##  Revision 1.2  2003/03/27 15:43:05  joko  ##  Revision 1.2  2003/03/27 15:43:05  joko
12  ##  minor fix: new comment/remark  ##  minor fix: new comment/remark
13  ##  ##
# Line 11  Line 17 
17  ## ----------------------------------------------------------------------  ## ----------------------------------------------------------------------
18    
19    
20    =pod
21    
22      This could also be called App::Component, App::Bean or whatever.
23      Since it conducts various things of the OEF framework,
24      it should probably be better renamed to OEF::App::Xyz, hmmm!?
25      OEF::App::Bean? OEF::App::Bimbo? Yakka and Bimbo...
26    
27    =cut
28    
29    
30  package App::Process;  package App::Process;
31    
32  use strict;  use strict;
# Line 114  sub getGuid { Line 130  sub getGuid {
130    
131  sub _bootDatabases {  sub _bootDatabases {
132    my $self = shift;    my $self = shift;
 #print Dumper($self->{config}->{databases});  
   
   #print Dumper($self);  
   #exit;  
   
   #my $dbkeys = shift;  
   my $dbkeys;  
133    
134      # re-enabled as of 2003-05-16: Now accepts db-keys via method-args again!
135      my $dbkeys = shift;
136      
137      #my $dbkeys;
138    my $dbcfg;    my $dbcfg;
139        
140    # CACHE THIS! JUST BOOT STORAGES INTO CONTAINER IF NOT ALREADY DONE!    # A - Build list of db-keys to boot
   my $container = DesignPattern::Object->fromPackage('Data::Storage::Container');  
141        
142    if (my $dbkey_raw = $self->{app}->{use_databases}) {    # FIXME: CACHE THIS! JUST BOOT STORAGES INTO CONTAINER IF NOT ALREADY DONE!
143      if (ref $dbkey_raw eq 'ARRAY') {    # WATCH OUT FOR GLOBAL USED RESOURCES!
144        $dbkeys = $dbkey_raw;    $self->{DSC} ||= DesignPattern::Object->fromPackage('Data::Storage::Container');
145      } else {    
146        #$self->{app}->{instance}->_bootDatabases();    # Check if database keys were specified explicitely
147        my @dbkeys = split(/,\s|,/, $dbkey_raw);    # as default inside the application container ...
148        #$self->_bootDatabases(\@dbkeys);    # new of 2003-05-16: Just do this if no dbkeys have been passed in via args.
149        $dbkeys = \@dbkeys;    $dbkeys ||= $self->_get_dbkeys_app_defaults();
     }  
   }  
150    
151    # just boot specified databases    # ... if yes, just boot specified databases...
152    if ($dbkeys) {    if ($dbkeys) {
153      $self->log("Using Database(s): " . join(', ', @{$dbkeys}), 'info');    
154        $self->log("Using database(s): " . join(', ', @{$dbkeys}), 'info');
155      foreach (@$dbkeys) {      foreach (@$dbkeys) {
156        $dbcfg->{$_} = $self->{app}->{config}->{databases}->{$_};        $dbcfg->{$_} = $self->{app}->{config}->{databases}->{$_};
157      }      }
158            
159    # boot all databases    # ... otherwise boot all databases.
160    } else {    } else {
161        $self->log("Using all databases.", 'info');
162      $dbcfg = $self->{app}->{config}->{databases};      $dbcfg = $self->{app}->{config}->{databases};
163    }    }
164    
   foreach (keys %$dbcfg) {  
     $container->addConfig($_, $dbcfg->{$_});  
   }  
165    
166    $container->initLocators();    # B - Propagate stuff to application -config and -resource slots etc.
167    $container->initStorages();    # TODO: refactor: abstract this out
168    
169    foreach (keys %{$container->{storage}}) {    # B.1 - Initialize config
170      $self->{app}->{storage}->{$_} = $container->{storage}->{$_};    foreach (keys %$dbcfg) {
171        $self->{DSC}->addConfig($_, $dbcfg->{$_});
172    }    }
173    
174      # B.2 - Initialize resources
175      $self->{DSC}->initLocators();
176      $self->{DSC}->initStorages();
177        
178    # trace    # B.3 - Establish symbols inside the application container
179      #print Dumper($self);    # as references to the storage handle instances inside the
180      # storage container singleton.
181      # In other words: spread the refs
182      # FIXME: This should be cleared up somehow!    ;-)
183      foreach (keys %{$self->{DSC}->{storage}}) {
184        $self->{app}->{storage}->{$_} = $self->{DSC}->{storage}->{$_};
185      }
186        
187  }  }
188    
189    sub _get_dbkeys_app_defaults {
190      my $self = shift;
191      my $dbkeys;
192      if (my $dbkey_raw = $self->{app}->{use_databases}) {
193        if (ref $dbkey_raw eq 'ARRAY') {
194          $dbkeys = $dbkey_raw;
195        } else {
196          #$self->{app}->{instance}->_bootDatabases();
197          my @dbkeys = split(/,\s|,/, $dbkey_raw);
198          #$self->_bootDatabases(\@dbkeys);
199          $dbkeys = \@dbkeys;
200        }
201      }
202      return $dbkeys;
203    }
204    
205  sub _shutdownDatabases {  sub _shutdownDatabases {
206    my $self = shift;    my $self = shift;
207    foreach my $dbkey (keys %{$self->{app}->{storage}}) {    foreach my $dbkey (keys %{$self->{app}->{storage}}) {
208      #print "SHUTDOWN $dbkey", "\n";      #print "SHUTDOWN $dbkey", "\n";
209      $self->{app}->{storage}->{$dbkey}->disconnect();      #print Dumper($self->{app}->{storage}->{$dbkey});
210        my $handle = $self->{app}->{storage}->{$dbkey};
211        #print ref $handle, "\n";
212        #next if not $handle or not ref $handle or ref($handle) =~ m/(ARRAY|HASH)/;
213        next if not $handle or not ref $handle or ref($handle) !~ m/(Data::Storage|DBI)/;
214        $handle->disconnect();
215    }    }
216  }  }
217    
218  =pod  #=pod
219  sub DESTROY {  sub DESTROY {
220    my $self = shift;    my $self = shift;
221    $self->_shutdownDatabases();    $self->_shutdownDatabases();
222  }  }
223  =cut  #=cut
224    
225    
226    sub activate_resources {
227      my $self = shift;
228      my $args = shift;
229      $self->_bootDatabases($args);
230    }
231    
232    sub resource_is_active {
233      my $self = shift;
234      my $key = shift;
235      # FIXME: Enhance this!
236      #print "key: $key", "\n";
237      #print Dumper($self->{DSC}->{storage});
238      return 1 if exists $self->{DSC}->{storage}->{$key};
239    }
240    
241  1;  1;
242  __END__  __END__

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

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