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