9 |
## ------------------------------------------------------------------------ |
## ------------------------------------------------------------------------ |
10 |
## |
## |
11 |
## $Log$ |
## $Log$ |
12 |
|
## Revision 1.17 2003/01/30 21:42:22 joko |
13 |
|
## + minor update: renamed method |
14 |
|
## |
15 |
|
## Revision 1.16 2003/01/20 16:52:13 joko |
16 |
|
## + now using 'DesignPattern::Object' to create a new 'Data::Storage::Handler::Xyz' on demand - before we did this in a hand-rolled fashion |
17 |
|
## |
18 |
## Revision 1.15 2003/01/19 03:12:59 joko |
## Revision 1.15 2003/01/19 03:12:59 joko |
19 |
## + modified header |
## + modified header |
20 |
## - removed pod-documentation - now in 'Storage.pod' |
## - removed pod-documentation - now in 'Storage.pod' |
87 |
use strict; |
use strict; |
88 |
use warnings; |
use warnings; |
89 |
|
|
|
use Data::Storage::Locator; |
|
90 |
use Data::Dumper; |
use Data::Dumper; |
91 |
|
# FIXME: wipe out! |
|
# TODO: wipe out! |
|
92 |
use DBI; |
use DBI; |
93 |
|
|
94 |
|
use Data::Storage::Locator; |
95 |
|
use DesignPattern::Object; |
96 |
|
|
97 |
|
|
98 |
# TODO: actually implement level (integrate with Log::Dispatch) |
# TODO: actually implement level (integrate with Log::Dispatch) |
99 |
my $TRACELEVEL = 0; |
my $TRACELEVEL = 0; |
100 |
|
|
141 |
|
|
142 |
# advanced logging of AUTOLOAD calls ... |
# advanced logging of AUTOLOAD calls ... |
143 |
# ... nice but do it only when TRACING (TODO) is enabled |
# ... nice but do it only when TRACING (TODO) is enabled |
|
if ($TRACELEVEL) { |
|
144 |
my $logstring = ""; |
my $logstring = ""; |
145 |
$logstring .= __PACKAGE__ . "[$self->{locator}->{type}]" . "->" . $method; |
$logstring .= __PACKAGE__ . "[$self->{locator}->{type}]" . "->" . $method; |
146 |
#print "count: ", $#_, "\n"; |
#print "count: ", $#_, "\n"; |
150 |
# TODO: only ok if logstring doesn't contain |
# TODO: only ok if logstring doesn't contain |
151 |
# e.g. "Data::Storage[Tangram]->insert(SystemEvent=HASH(0x5c0034c)) (AUTOLOAD)" |
# e.g. "Data::Storage[Tangram]->insert(SystemEvent=HASH(0x5c0034c)) (AUTOLOAD)" |
152 |
# but that would be _way_ too specific as long as we don't have an abstract handler for this ;) |
# but that would be _way_ too specific as long as we don't have an abstract handler for this ;) |
153 |
|
if ($TRACELEVEL) { |
154 |
$logger->debug( $logstring ); |
$logger->debug( $logstring ); |
155 |
#print join('; ', @_); |
#print join('; ', @_); |
156 |
} |
} |
157 |
|
|
158 |
# filtering AUTOLOAD calls and first-time-touch of the actual storage impl |
# filtering AUTOLOAD calls and first-time-touch of the actual storage impl |
159 |
if ($self->_filter_AUTOLOAD($method)) { |
if ($self->_filter_AUTOLOAD($method)) { |
160 |
#print "_accessStorage\n"; |
#print "=== FILTER!", "\n"; |
161 |
$self->_accessStorage(); |
$self->_accessStorageHandle(); |
162 |
return $self->{STORAGEHANDLE}->$method(@_); |
if ($self->{STORAGEHANDLE}) { |
163 |
|
return $self->{STORAGEHANDLE}->$method(@_); |
164 |
|
} else { |
165 |
|
$logger->critical( __PACKAGE__ . "->AUTOLOAD: ERROR: " . $logstring ); |
166 |
|
return; |
167 |
|
} |
168 |
} |
} |
169 |
|
|
170 |
} |
} |
190 |
return @result; |
return @result; |
191 |
} |
} |
192 |
|
|
193 |
sub _accessStorage { |
sub _accessStorageHandle { |
194 |
my $self = shift; |
my $self = shift; |
195 |
# TODO: to some tracelevel! |
# TODO: to some tracelevel! |
196 |
|
#print "=========== _accessStorage", "\n"; |
197 |
if ($TRACELEVEL) { |
if ($TRACELEVEL) { |
198 |
$logger->debug( __PACKAGE__ . "[$self->{locator}->{type}]" . "->_accessStorage()" ); |
$logger->debug( __PACKAGE__ . "[$self->{locator}->{type}]" . "->_accessStorageHandle()" ); |
199 |
} |
} |
200 |
if (!$self->{STORAGEHANDLE}) { |
if (!$self->{STORAGEHANDLE}) { |
201 |
$self->_createStorageHandle(); |
return $self->_createStorageHandle(); |
202 |
} |
} |
203 |
} |
} |
204 |
|
|
205 |
|
sub _createStorageHandle1 { |
206 |
|
my $self = shift; |
207 |
|
my $type = $self->{locator}->{type}; |
208 |
|
$logger->debug( __PACKAGE__ . "[$type]" . "->_createStorageHandle()" ); |
209 |
|
|
210 |
|
my $pkg = "Data::Storage::Handler::" . $type . ""; |
211 |
|
|
212 |
|
# try to load perl module at runtime |
213 |
|
my $evalstr = "use $pkg;"; |
214 |
|
eval($evalstr); |
215 |
|
if ($@) { |
216 |
|
$logger->error( __PACKAGE__ . "[$type]" . "->_createStorageHandle(): $@" ); |
217 |
|
return; |
218 |
|
} |
219 |
|
|
220 |
|
# build up some additional arguments to pass on |
221 |
|
#my @args = %{$self->{locator}}; |
222 |
|
my @args = (); |
223 |
|
|
224 |
|
# - create new storage handle object |
225 |
|
# - propagate arguments to handler |
226 |
|
# - pass locator by reference to be able to store status- or meta-information in it |
227 |
|
$self->{STORAGEHANDLE} = $pkg->new( locator => $self->{locator}, @args ); |
228 |
|
|
229 |
|
} |
230 |
|
|
231 |
sub _createStorageHandle { |
sub _createStorageHandle { |
232 |
my $self = shift; |
my $self = shift; |
233 |
my $type = $self->{locator}->{type}; |
my $type = $self->{locator}->{type}; |
234 |
$logger->debug( __PACKAGE__ . "[$type]" . "->_createStorageHandle()" ); |
$logger->debug( __PACKAGE__ . "[$type]" . "->_createStorageHandle()" ); |
235 |
|
|
236 |
|
#print Dumper($self); |
237 |
|
#exit; |
238 |
|
|
239 |
my $pkg = "Data::Storage::Handler::" . $type . ""; |
my $pkg = "Data::Storage::Handler::" . $type . ""; |
240 |
|
|
241 |
# try to load perl module at runtime |
# try to load perl module at runtime |
242 |
|
=pod |
243 |
my $evalstr = "use $pkg;"; |
my $evalstr = "use $pkg;"; |
244 |
eval($evalstr); |
eval($evalstr); |
245 |
if ($@) { |
if ($@) { |
255 |
# - propagate arguments to handler |
# - propagate arguments to handler |
256 |
# - pass locator by reference to be able to store status- or meta-information in it |
# - pass locator by reference to be able to store status- or meta-information in it |
257 |
$self->{STORAGEHANDLE} = $pkg->new( locator => $self->{locator}, @args ); |
$self->{STORAGEHANDLE} = $pkg->new( locator => $self->{locator}, @args ); |
258 |
|
=cut |
259 |
|
|
260 |
|
$self->{STORAGEHANDLE} = DesignPattern::Object->fromPackage( $pkg, locator => $self->{locator} ); |
261 |
|
return 1; |
262 |
|
|
263 |
} |
} |
264 |
|
|
297 |
$logger->remove($name); |
$logger->remove($name); |
298 |
} |
} |
299 |
|
|
300 |
|
=pod |
301 |
sub getDbName { |
sub getDbName { |
302 |
my $self = shift; |
my $self = shift; |
303 |
my $dsn = $self->{locator}->{dbi}->{dsn}; |
my $dsn = $self->{locator}->{dbi}->{dsn}; |
335 |
$logger->warning( __PACKAGE__ . "[$self->{locator}->{type}]" . "->testDsn(): " . "DBI-error: " . $DBI::errstr ); |
$logger->warning( __PACKAGE__ . "[$self->{locator}->{type}]" . "->testDsn(): " . "DBI-error: " . $DBI::errstr ); |
336 |
} |
} |
337 |
} |
} |
338 |
|
=cut |
339 |
|
|
340 |
1; |
1; |
341 |
__END__ |
__END__ |