--- nfo/perl/libs/App/Process.pm 2003/02/20 18:41:48 1.1 +++ nfo/perl/libs/App/Process.pm 2004/06/19 01:51:21 1.5 @@ -1,13 +1,38 @@ ## ---------------------------------------------------------------------- -## $Id: Process.pm,v 1.1 2003/02/20 18:41:48 joko Exp $ +## $Id: Process.pm,v 1.5 2004/06/19 01:51:21 joko Exp $ ## ---------------------------------------------------------------------- ## $Log: Process.pm,v $ +## Revision 1.5 2004/06/19 01:51:21 joko +## don't do any "Task"-handling (would require db "oefcore") +## +## Revision 1.4 2003/12/03 00:21:38 joko +## + minor fix to '_bootDatabases': instantiate the DSC-container if no ref to it exists +## +## Revision 1.3 2003/06/06 03:14:16 joko +## enhanced database connection bootstrapping: +## - boot default ones +## - boot-on-demand +## - protection for multiple redundant connections +## +## Revision 1.2 2003/03/27 15:43:05 joko +## minor fix: new comment/remark +## ## Revision 1.1 2003/02/20 18:41:48 joko ## + initial commit ## ## ---------------------------------------------------------------------- +=pod + + This could also be called App::Component, App::Bean or whatever. + Since it conducts various things of the OEF framework, + it should probably be better renamed to OEF::App::Xyz, hmmm!? + OEF::App::Bean? OEF::App::Bimbo? Yakka and Bimbo... + +=cut + + package App::Process; use strict; @@ -43,6 +68,8 @@ #$self->{boot} = BizWorks::Boot->new( use_databases => [qw( oefcore )] ); #$self->{app}->{use_databases} =|| [qw( oefcore )]; $self->_bootDatabases(); + + return; # if no "guid" is given .... if (!$self->{guid}) { @@ -111,70 +138,115 @@ sub _bootDatabases { my $self = shift; -#print Dumper($self->{config}->{databases}); - - #print Dumper($self); - #exit; - - #my $dbkeys = shift; - my $dbkeys; + # re-enabled as of 2003-05-16: Now accepts db-keys via method-args again! + my $dbkeys = shift; + + #my $dbkeys; my $dbcfg; - my $container = DesignPattern::Object->fromPackage('Data::Storage::Container'); - if (my $dbkey_raw = $self->{app}->{use_databases}) { - if (ref $dbkey_raw eq 'ARRAY') { - $dbkeys = $dbkey_raw; - } else { - #$self->{app}->{instance}->_bootDatabases(); - my @dbkeys = split(/,\s|,/, $dbkey_raw); - #$self->_bootDatabases(\@dbkeys); - $dbkeys = \@dbkeys; - } + # A - Build list of db-keys to boot + + # FIXME: CACHE THIS! JUST BOOT STORAGES INTO CONTAINER IF NOT ALREADY DONE! + # WATCH OUT FOR GLOBAL USED RESOURCES! + if (not ref $self->{DSC} eq 'Data::Storage::Container') { + $self->{DSC} = DesignPattern::Object->fromPackage('Data::Storage::Container'); } + + # Check if database keys were specified explicitely + # as default inside the application container ... + # new of 2003-05-16: Just do this if no dbkeys have been passed in via args. + $dbkeys ||= $self->_get_dbkeys_app_defaults(); - # just boot specified databases + # ... if yes, just boot specified databases... if ($dbkeys) { - $self->log("Using Database(s): " . join(', ', @{$dbkeys}), 'info'); + + $self->log("Using database(s): " . join(', ', @{$dbkeys}), 'info'); foreach (@$dbkeys) { $dbcfg->{$_} = $self->{app}->{config}->{databases}->{$_}; } - # boot all databases + # ... otherwise boot all databases. } else { + $self->log("Using all databases.", 'info'); $dbcfg = $self->{app}->{config}->{databases}; } - foreach (keys %$dbcfg) { - $container->addConfig($_, $dbcfg->{$_}); - } - $container->initLocators(); - $container->initStorages(); + # B - Propagate stuff to application -config and -resource slots etc. + # TODO: refactor: abstract this out - foreach (keys %{$container->{storage}}) { - $self->{app}->{storage}->{$_} = $container->{storage}->{$_}; + # B.1 - Initialize config + foreach (keys %$dbcfg) { + $self->{DSC}->addConfig($_, $dbcfg->{$_}); } + + # B.2 - Initialize resources + $self->{DSC}->initLocators(); + $self->{DSC}->initStorages(); - # trace - #print Dumper($self); + # B.3 - Establish symbols inside the application container + # as references to the storage handle instances inside the + # storage container singleton. + # In other words: spread the refs + # FIXME: This should be cleared up somehow! ;-) + foreach (keys %{$self->{DSC}->{storage}}) { + $self->{app}->{storage}->{$_} = $self->{DSC}->{storage}->{$_}; + } } +sub _get_dbkeys_app_defaults { + my $self = shift; + my $dbkeys; + if (my $dbkey_raw = $self->{app}->{use_databases}) { + if (ref $dbkey_raw eq 'ARRAY') { + $dbkeys = $dbkey_raw; + } else { + #$self->{app}->{instance}->_bootDatabases(); + my @dbkeys = split(/,\s|,/, $dbkey_raw); + #$self->_bootDatabases(\@dbkeys); + $dbkeys = \@dbkeys; + } + } + return $dbkeys; +} + sub _shutdownDatabases { my $self = shift; foreach my $dbkey (keys %{$self->{app}->{storage}}) { #print "SHUTDOWN $dbkey", "\n"; - $self->{app}->{storage}->{$dbkey}->disconnect(); + #print Dumper($self->{app}->{storage}->{$dbkey}); + my $handle = $self->{app}->{storage}->{$dbkey}; + #print ref $handle, "\n"; + #next if not $handle or not ref $handle or ref($handle) =~ m/(ARRAY|HASH)/; + next if not $handle or not ref $handle or ref($handle) !~ m/(Data::Storage|DBI)/; + $handle->disconnect(); } } -=pod +#=pod sub DESTROY { my $self = shift; $self->_shutdownDatabases(); } -=cut +#=cut + + +sub activate_resources { + my $self = shift; + my $args = shift; + $self->_bootDatabases($args); +} + +sub resource_is_active { + my $self = shift; + my $key = shift; + # FIXME: Enhance this! + #print "key: $key", "\n"; + #print Dumper($self->{DSC}->{storage}); + return 1 if exists $self->{DSC}->{storage}->{$key}; +} 1; __END__