| 1 |
## -------------------------------------------------------------------------------- |
## ------------------------------------------------------------------------ |
| 2 |
## $Id$ |
## $Id$ |
| 3 |
## -------------------------------------------------------------------------------- |
## ------------------------------------------------------------------------ |
| 4 |
## $Log$ |
## $Log$ |
| 5 |
|
## Revision 1.19 2003/06/25 22:53:58 joko |
| 6 |
|
## don't disconnect automagically |
| 7 |
|
## |
| 8 |
|
## Revision 1.18 2003/06/06 03:40:57 joko |
| 9 |
|
## disabled autovivifying of arguments as attributes |
| 10 |
|
## |
| 11 |
|
## Revision 1.17 2003/05/13 07:58:49 joko |
| 12 |
|
## fix: die if methodname is empty |
| 13 |
|
## fixes to log-string |
| 14 |
|
## |
| 15 |
|
## Revision 1.16 2003/04/18 16:07:53 joko |
| 16 |
|
## just use logger if instantiation successed |
| 17 |
|
## |
| 18 |
|
## Revision 1.15 2003/02/20 20:19:13 joko |
| 19 |
|
## tried to get auto-disconnect working again - failed with that |
| 20 |
|
## |
| 21 |
|
## Revision 1.14 2003/02/09 05:12:28 joko |
| 22 |
|
## + quoting of strings used in sql-queries! |
| 23 |
|
## |
| 24 |
|
## Revision 1.13 2003/01/30 22:27:05 joko |
| 25 |
|
## + added new abstract methods |
| 26 |
|
## |
| 27 |
|
## Revision 1.12 2003/01/30 21:46:32 joko |
| 28 |
|
## + fixed behaviour of AUTOLOAD-method |
| 29 |
|
## |
| 30 |
|
## Revision 1.11 2003/01/20 16:43:18 joko |
| 31 |
|
## + better argument-property merging |
| 32 |
|
## + debugging-output !!! |
| 33 |
|
## + abstract-dummy 'sub createChildNode' |
| 34 |
|
## |
| 35 |
## Revision 1.10 2003/01/19 02:31:51 joko |
## Revision 1.10 2003/01/19 02:31:51 joko |
| 36 |
## + fix to 'sub AUTOLOAD' |
## + fix to 'sub AUTOLOAD' |
| 37 |
## |
## |
| 63 |
## |
## |
| 64 |
## Revision 1.1 2002/10/10 03:44:07 cvsjoko |
## Revision 1.1 2002/10/10 03:44:07 cvsjoko |
| 65 |
## + new |
## + new |
| 66 |
## -------------------------------------------------------------------------------- |
## ------------------------------------------------------------------------ |
| 67 |
|
|
| 68 |
|
|
| 69 |
package Data::Storage::Handler::Abstract; |
package Data::Storage::Handler::Abstract; |
| 73 |
|
|
| 74 |
use base qw( DesignPattern::Object ); |
use base qw( DesignPattern::Object ); |
| 75 |
|
|
| 76 |
|
|
| 77 |
use Data::Dumper; |
use Data::Dumper; |
| 78 |
use Tie::SecureHash; |
use Tie::SecureHash; |
| 79 |
#use Data::Storage::Handler; |
#use Data::Storage::Handler; |
| 80 |
|
use Hash::Merge qw( merge ); |
| 81 |
|
|
| 82 |
|
#use Log::Dispatch::Config; |
| 83 |
|
#Log::Dispatch::Config->configure(); |
| 84 |
|
|
| 85 |
# get logger instance |
# get logger instance |
| 86 |
my $logger = Log::Dispatch::Config->instance; |
my $logger; |
| 87 |
|
eval('$logger = Log::Dispatch::Config->instance;'); |
| 88 |
|
|
| 89 |
#our $lock_info; |
#our $lock_info; |
| 90 |
|
|
| 93 |
my $class = ref($invocant) || $invocant; |
my $class = ref($invocant) || $invocant; |
| 94 |
|
|
| 95 |
# logging info about the actual handler called |
# logging info about the actual handler called |
| 96 |
$logger->debug( "$invocant->new( @_ )" ); |
$logger->debug( "$invocant->new( @_ )" ) if $logger; |
| 97 |
#$logger->debug( __PACKAGE__ . "->" . "new()" ); |
#$logger->debug( __PACKAGE__ . "->" . "new()" ); |
| 98 |
|
|
| 99 |
# V1 - arguments become properties automagically / normal perl mode blessing |
# V1 - arguments become properties automagically / normal perl mode blessing |
| 131 |
#=cut |
#=cut |
| 132 |
|
|
| 133 |
# merge passed-in arguments to constructor as properties into already blessed secure object |
# merge passed-in arguments to constructor as properties into already blessed secure object |
| 134 |
|
|
| 135 |
# mungle arguments from array into hash - perl does the job ;) |
# mungle arguments from array into hash - perl does the job ;) |
| 136 |
my %args = @_; |
#my %args = @_; |
| 137 |
|
#my %args = (); |
| 138 |
|
|
| 139 |
|
#print Dumper(@_); |
| 140 |
|
|
| 141 |
# merge attributes one-by-one |
# merge attributes one-by-one |
| 142 |
# TODO: deep_copy? / merge_deep? |
# TODO: deep_copy? / merge_deep? |
| 143 |
foreach (keys %args) { |
while (my $elemName = shift @_) { |
| 144 |
#print "key: $_", "\n"; |
#print "elemName: $elemName", "\n"; |
| 145 |
$self->{$_} = $args{$_}; |
if (my $elemValue = shift @_) { |
| 146 |
|
#print Dumper($elemValue); |
| 147 |
|
#print "elemName=$elemName, elemValue=$elemValue", "\n"; |
| 148 |
|
$self->{$elemName} = $elemValue; |
| 149 |
|
} |
| 150 |
|
#$self->{$_} = $args{$_}; |
| 151 |
|
#$self->{$_} = $args{$_}; |
| 152 |
} |
} |
| 153 |
|
|
| 154 |
# V3 - rolling our own security (just for {COREHANDLE} - nothing else) - nope, Tie::SecureHash works wonderful |
# V3 - rolling our own security (just for {COREHANDLE} - nothing else) - nope, Tie::SecureHash works wonderful |
| 160 |
# handle meta data |
# handle meta data |
| 161 |
#my $metainfo = $self->getMetaInfo($class); |
#my $metainfo = $self->getMetaInfo($class); |
| 162 |
my $metainfo = $self->getMetaInfo(); |
my $metainfo = $self->getMetaInfo(); |
| 163 |
if (!$metainfo->{disconnectMethod}) { $metainfo->{disconnectMethod} = 'disconnect'; } |
#if (!$metainfo->{disconnectMethod}) { $metainfo->{disconnectMethod} = 'disconnect'; } |
| 164 |
# type? |
# type? |
| 165 |
$invocant =~ s/Data::Storage::Handler:://; |
$invocant =~ s/Data::Storage::Handler:://; |
| 166 |
$metainfo->{type} = $invocant; |
$metainfo->{type} = $invocant; |
| 238 |
$handlertype ||= ''; |
$handlertype ||= ''; |
| 239 |
|
|
| 240 |
my $err_msg_core = __PACKAGE__ . "[$handlertype]" . ": " . "COREHANDLE is undefined while trying to execute method \"$methodname\""; |
my $err_msg_core = __PACKAGE__ . "[$handlertype]" . ": " . "COREHANDLE is undefined while trying to execute method \"$methodname\""; |
| 241 |
print $err_msg_core, "\n"; |
|
| 242 |
if ($self->exists('lock_info') && !$self->{lock_info}->{log_lock}) { |
#print $err_msg_core, "\n"; |
| 243 |
|
|
| 244 |
|
#if ($self->exists('lock_info') && !$self->{lock_info}->{log_lock}) { |
| 245 |
$logger->error( $err_msg_core ); |
$logger->error( $err_msg_core ); |
| 246 |
} |
#} |
| 247 |
|
|
| 248 |
return; |
return; |
| 249 |
|
|
| 250 |
} |
} |
| 251 |
#=cut |
#=cut |
| 252 |
|
|
| 253 |
|
=pod |
| 254 |
|
if (!$methodname) { |
| 255 |
|
die("Methodname is not defined!"); |
| 256 |
|
return; |
| 257 |
|
} |
| 258 |
|
=cut |
| 259 |
|
|
| 260 |
#print "$methodname - 3", "\n"; |
#print "$methodname - 3", "\n"; |
| 261 |
|
|
| 262 |
# try to dispatch method-call to Storage::Handler::* |
# try to dispatch method-call to Storage::Handler::* |
| 285 |
#$lock_AUTOLOAD = 1 if ($methodname eq 'insert'); |
#$lock_AUTOLOAD = 1 if ($methodname eq 'insert'); |
| 286 |
if (!$self->{lock_info}->{log_lock}) { |
if (!$self->{lock_info}->{log_lock}) { |
| 287 |
#print "method: $methodname", "\n"; |
#print "method: $methodname", "\n"; |
| 288 |
$logger->debug( __PACKAGE__ . "[$self->{metainfo}->{type}]" . "->" . $methodname . "(@_)" ); |
my $type = $self->{metainfo}->{type}; |
| 289 |
|
$type ||= ''; |
| 290 |
|
# FIXME! |
| 291 |
|
#$logger->debug( __PACKAGE__ . "[$type]" . "->" . $methodname . "(@_)" ); |
| 292 |
|
$logger->debug( __PACKAGE__ . "[$type]" . "->" . $methodname ); |
| 293 |
} else { |
} else { |
| 294 |
# AUTOLOAD - sub is locked to prevent deep recursions if (e.g.) db-inserts cause log-actions to same db itself |
# AUTOLOAD - sub is locked to prevent deep recursions if (e.g.) db-inserts cause log-actions to same db itself |
| 295 |
} |
} |
| 310 |
|
|
| 311 |
sub DESTROY { |
sub DESTROY { |
| 312 |
my $self = shift; |
my $self = shift; |
| 313 |
#if ($self->{COREHANDLE}) { |
|
| 314 |
if ($self->exists('_COREHANDLE')) { |
return; |
| 315 |
|
|
| 316 |
|
$logger->debug( __PACKAGE__ . "[$self->{metainfo}->{type}]" . "->DESTROY" ); |
| 317 |
|
|
| 318 |
|
my $disconnectMethod = $self->{metainfo}->{disconnectMethod}; |
| 319 |
|
print "meth: ", $disconnectMethod, "\n"; |
| 320 |
|
|
| 321 |
|
#$disconnectMethod && $self->{_COREHANDLE} && ( $self->{_COREHANDLE}->$disconnectMethod() ); |
| 322 |
|
$self->{_COREHANDLE}->$disconnectMethod(); |
| 323 |
|
#$self->$disconnectMethod(); |
| 324 |
|
|
| 325 |
|
#my $core1 = $self->getCOREHANDLE() if $self->can('getCOREHANDLE'); |
| 326 |
|
#$core1->$disconnectMethod(); |
| 327 |
|
|
| 328 |
|
return; |
| 329 |
|
|
| 330 |
|
print "DESTROY-1", "\n"; |
| 331 |
|
#if ($self->{__COREHANDLE}) { |
| 332 |
|
#if ($self->exists('_COREHANDLE')) { |
| 333 |
|
|
| 334 |
|
# get corehandle instance from underlying handler |
| 335 |
|
my $core; |
| 336 |
|
$core = $self->getCOREHANDLE() if $self->can('getCOREHANDLE'); |
| 337 |
|
|
| 338 |
|
#if ($self->{STORAGEHANDLE}) { |
| 339 |
|
if ($core) { |
| 340 |
|
print "DESTROY-2", "\n"; |
| 341 |
$logger->debug( __PACKAGE__ . "[$self->{metainfo}->{type}]" . "->DESTROY" ); |
$logger->debug( __PACKAGE__ . "[$self->{metainfo}->{type}]" . "->DESTROY" ); |
| 342 |
|
|
| 343 |
my $disconnectMethod = $self->{metainfo}->{disconnectMethod}; |
my $disconnectMethod = $self->{metainfo}->{disconnectMethod}; |
| 364 |
sub existsChildNode { |
sub existsChildNode { |
| 365 |
my $self = shift; |
my $self = shift; |
| 366 |
my $nodename = shift; |
my $nodename = shift; |
| 367 |
#$nodename = 'TransactionRoutingTable'; |
|
| 368 |
$logger->debug( __PACKAGE__ . "->existsChildNode( nodename $nodename )" ); |
# TODO: don't use $self->{meta}->{childnodes} directly in here |
| 369 |
|
# get it returned from $self->getChildNodes()!!! |
| 370 |
|
|
| 371 |
|
$logger->debug( __PACKAGE__ . "->existsChildNode( nodename=$nodename )" ); |
| 372 |
$self->getChildNodes() unless $self->{meta}->{childnodes}; |
$self->getChildNodes() unless $self->{meta}->{childnodes}; |
| 373 |
my $result = grep(m/$nodename/i, @{$self->{meta}->{childnodes}}); # TODO: use "/i" only on win32-systems! |
|
| 374 |
|
# quote this, it might contain meta characters which don't work in a regex |
| 375 |
|
$nodename = quotemeta($nodename); |
| 376 |
|
|
| 377 |
|
# trace |
| 378 |
|
#print Dumper($self->{meta}); |
| 379 |
|
#print "nodename: $nodename", "\n"; |
| 380 |
|
|
| 381 |
|
# FIXME: use "/i" only on win32-systems! |
| 382 |
|
my $result = grep(m/$nodename/i, @{$self->{meta}->{childnodes}}); |
| 383 |
|
|
| 384 |
return $result; |
return $result; |
| 385 |
} |
} |
| 386 |
|
|
| 415 |
$self->_abstract_function('sendCommand'); |
$self->_abstract_function('sendCommand'); |
| 416 |
} |
} |
| 417 |
|
|
| 418 |
|
sub createChildNode { |
| 419 |
|
my $self = shift; |
| 420 |
|
$self->_abstract_function('createChildNode'); |
| 421 |
|
} |
| 422 |
|
|
| 423 |
sub existsChildNode_tmp { |
sub existsChildNode_tmp { |
| 424 |
my $self = shift; |
my $self = shift; |
| 425 |
$self->_abstract_function('existsChildNode'); |
$self->_abstract_function('existsChildNode'); |
| 501 |
return; |
return; |
| 502 |
} |
} |
| 503 |
|
|
| 504 |
|
sub getDbName { |
| 505 |
|
my $self = shift; |
| 506 |
|
$self->_abstract_function('getDbName'); |
| 507 |
|
return; |
| 508 |
|
} |
| 509 |
|
|
| 510 |
|
sub testAvailability { |
| 511 |
|
my $self = shift; |
| 512 |
|
$self->_abstract_function('testAvailability'); |
| 513 |
|
return; |
| 514 |
|
} |
| 515 |
|
|
| 516 |
|
sub isConnected { |
| 517 |
|
my $self = shift; |
| 518 |
|
$self->_abstract_function('isConnected'); |
| 519 |
|
return; |
| 520 |
|
} |
| 521 |
|
|
| 522 |
|
sub testDsn { |
| 523 |
|
my $self = shift; |
| 524 |
|
$self->_abstract_function('testDsn'); |
| 525 |
|
return; |
| 526 |
|
} |
| 527 |
|
|
| 528 |
1; |
1; |