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