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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1 - (show annotations)
Thu Feb 20 18:41:48 2003 UTC (21 years, 3 months ago) by joko
Branch: MAIN
+ initial commit

1 ## ----------------------------------------------------------------------
2 ## $Id: Ref.pm,v 1.1 2003/01/22 17:59:22 root Exp $
3 ## ----------------------------------------------------------------------
4 ## $Log: Ref.pm,v $
5 ## ----------------------------------------------------------------------
6
7
8 package App::Process;
9
10 use strict;
11 use warnings;
12
13 use base qw(
14 DesignPattern::Object
15 DesignPattern::Logger
16 );
17
18 use Data::Dumper;
19
20 use shortcuts qw( now );
21
22
23 # --------------------------------------------------- main ------------
24 DesignPattern::Object->log_basic("Package " . __PACKAGE__ . " loaded.");
25
26
27 sub constructor {
28 my $self = shift;
29
30 $self->log( __PACKAGE__ . "->constructor", 'info');
31 #$self->log( "INIT", 'info');
32
33 # trace
34 #print Dumper($self);
35 #exit;
36
37 # just boot database called "oefcore"
38 # TODO: REVIEW: just boot if not booted yet.....
39 # FIXME: this is hardcoded!
40 #$self->{boot} = BizWorks::Boot->new( use_databases => [qw( oefcore )] );
41 #$self->{app}->{use_databases} =|| [qw( oefcore )];
42 $self->_bootDatabases();
43
44 # if no "guid" is given ....
45 if (!$self->{guid}) {
46
47 # ... create fresh task-object, ...
48 $self->{TASK} = Task->new(
49 stamp => now(),
50 #context => ,
51 );
52 $self->{app}->{storage}->{oefcore}->insert($self->{TASK});
53
54 =pod
55 # ... create fresh report-object, ...
56 $self->{REPORT} = Report->new(
57 stamp => now(),
58 #context => ,
59 );
60 $self->{app}->{storage}->{oefcore}->insert($self->{REPORT});
61
62 # ... link them together
63 =cut
64
65 # ... and (finally) assign the Task's GUID to an object attribute here
66 $self->{guid} = $self->{TASK}->{guid};
67
68 } else {
69
70 # load context from (resumed) task
71 # FIXME: move this to OEF::Component::Task::Persistable
72 my $task = $self->{app}->{storage}->{oefcore}->getObjectByGuid($self->{guid}, { classname => 'Task' });
73 $self->{_context_raw} = $task->{context};
74
75 }
76
77
78 }
79
80
81 sub _check {
82 my $self = shift;
83 if (!$self->getGuid()) {
84 return 1;
85 }
86 }
87
88 sub perform {
89 my $self = shift;
90
91 return if ($self->skip("task has no guid", $self->_check()));
92
93 #print Dumper($self);
94 #exit;
95
96 $self->log("task " . $self->getGuid() . " starting.");
97 $self->{TASK}->{begin} = now();
98 $self->run() if $self->can('run');
99 #$self->_run();
100 $self->{TASK}->{end} = now();
101 $self->log("task " . $self->getGuid() . " finished.");
102 }
103
104 sub getGuid {
105 my $self = shift;
106 return $self->{guid};
107 }
108
109 sub _bootDatabases {
110 my $self = shift;
111 #print Dumper($self->{config}->{databases});
112
113 #print Dumper($self);
114 #exit;
115
116 #my $dbkeys = shift;
117 my $dbkeys;
118
119 my $dbcfg;
120 my $container = DesignPattern::Object->fromPackage('Data::Storage::Container');
121
122 if (my $dbkey_raw = $self->{app}->{use_databases}) {
123 if (ref $dbkey_raw eq 'ARRAY') {
124 $dbkeys = $dbkey_raw;
125 } else {
126 #$self->{app}->{instance}->_bootDatabases();
127 my @dbkeys = split(/,\s|,/, $dbkey_raw);
128 #$self->_bootDatabases(\@dbkeys);
129 $dbkeys = \@dbkeys;
130 }
131 }
132
133 # just boot specified databases
134 if ($dbkeys) {
135 $self->log("Using Database(s): " . join(', ', @{$dbkeys}), 'info');
136 foreach (@$dbkeys) {
137 $dbcfg->{$_} = $self->{app}->{config}->{databases}->{$_};
138 }
139
140 # boot all databases
141 } else {
142 $dbcfg = $self->{app}->{config}->{databases};
143 }
144
145 foreach (keys %$dbcfg) {
146 $container->addConfig($_, $dbcfg->{$_});
147 }
148
149 $container->initLocators();
150 $container->initStorages();
151
152 foreach (keys %{$container->{storage}}) {
153 $self->{app}->{storage}->{$_} = $container->{storage}->{$_};
154 }
155
156 # trace
157 #print Dumper($self);
158
159 }
160
161 sub _shutdownDatabases {
162 my $self = shift;
163 foreach my $dbkey (keys %{$self->{app}->{storage}}) {
164 #print "SHUTDOWN $dbkey", "\n";
165 $self->{app}->{storage}->{$dbkey}->disconnect();
166 }
167 }
168
169 =pod
170 sub DESTROY {
171 my $self = shift;
172 $self->_shutdownDatabases();
173 }
174 =cut
175
176 1;
177 __END__

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