| 1 |
## -------------------------------------------------------------------------------- |
## ------------------------------------------------------------------------ |
| 2 |
## $Id$ |
## $Id$ |
| 3 |
## -------------------------------------------------------------------------------- |
## ------------------------------------------------------------------------ |
| 4 |
## $Log$ |
## $Log$ |
| 5 |
|
## Revision 1.13 2003/01/30 22:27:05 joko |
| 6 |
|
## + added new abstract methods |
| 7 |
|
## |
| 8 |
|
## Revision 1.12 2003/01/30 21:46:32 joko |
| 9 |
|
## + fixed behaviour of AUTOLOAD-method |
| 10 |
|
## |
| 11 |
|
## Revision 1.11 2003/01/20 16:43:18 joko |
| 12 |
|
## + better argument-property merging |
| 13 |
|
## + debugging-output !!! |
| 14 |
|
## + abstract-dummy 'sub createChildNode' |
| 15 |
|
## |
| 16 |
|
## Revision 1.10 2003/01/19 02:31:51 joko |
| 17 |
|
## + fix to 'sub AUTOLOAD' |
| 18 |
|
## |
| 19 |
## Revision 1.9 2002/12/19 16:30:23 joko |
## Revision 1.9 2002/12/19 16:30:23 joko |
| 20 |
## + added 'sub dropDb' and 'sub rebuildDb' as croakers for concrete implementations of methods in proper handlers |
## + added 'sub dropDb' and 'sub rebuildDb' as croakers for concrete implementations of methods in proper handlers |
| 21 |
## |
## |
| 44 |
## |
## |
| 45 |
## Revision 1.1 2002/10/10 03:44:07 cvsjoko |
## Revision 1.1 2002/10/10 03:44:07 cvsjoko |
| 46 |
## + new |
## + new |
| 47 |
## -------------------------------------------------------------------------------- |
## ------------------------------------------------------------------------ |
| 48 |
|
|
| 49 |
|
|
| 50 |
package Data::Storage::Handler::Abstract; |
package Data::Storage::Handler::Abstract; |
| 54 |
|
|
| 55 |
use base qw( DesignPattern::Object ); |
use base qw( DesignPattern::Object ); |
| 56 |
|
|
| 57 |
|
|
| 58 |
use Data::Dumper; |
use Data::Dumper; |
| 59 |
use Tie::SecureHash; |
use Tie::SecureHash; |
| 60 |
#use Data::Storage::Handler; |
#use Data::Storage::Handler; |
| 61 |
|
use Data::Transform::Deep qw( merge ); |
| 62 |
|
|
| 63 |
|
|
| 64 |
# get logger instance |
# get logger instance |
| 65 |
my $logger = Log::Dispatch::Config->instance; |
my $logger = Log::Dispatch::Config->instance; |
| 82 |
bless $self, $class; |
bless $self, $class; |
| 83 |
=cut |
=cut |
| 84 |
|
|
| 85 |
|
#=pod |
| 86 |
# V2 - maybe more convenient/secure? utilizing Damian Conway's Tie::SecureHash... |
# V2 - maybe more convenient/secure? utilizing Damian Conway's Tie::SecureHash... |
| 87 |
my $self = Tie::SecureHash->new( |
my $self = Tie::SecureHash->new( |
| 88 |
$class, |
$class, |
| 106 |
#_protected => , |
#_protected => , |
| 107 |
#__private => , |
#__private => , |
| 108 |
); |
); |
| 109 |
|
#=cut |
| 110 |
|
|
| 111 |
# 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 |
| 112 |
|
|
| 113 |
# mungle arguments from array into hash - perl does the job ;) |
# mungle arguments from array into hash - perl does the job ;) |
| 114 |
my %args = @_; |
#my %args = @_; |
| 115 |
|
#my %args = (); |
| 116 |
|
|
| 117 |
|
#print Dumper(@_); |
| 118 |
|
|
| 119 |
# merge attributes one-by-one |
# merge attributes one-by-one |
| 120 |
# TODO: deep_copy? / merge_deep? |
# TODO: deep_copy? / merge_deep? |
| 121 |
foreach (keys %args) { |
while (my $elemName = shift @_) { |
| 122 |
#print "key: $_", "\n"; |
#print "elemName: $elemName", "\n"; |
| 123 |
$self->{$_} = $args{$_}; |
if (my $elemValue = shift @_) { |
| 124 |
|
#print Dumper($elemValue); |
| 125 |
|
#print "elemName=$elemName, elemValue=$elemValue", "\n"; |
| 126 |
|
$self->{$elemName} = $elemValue; |
| 127 |
|
} |
| 128 |
|
#$self->{$_} = $args{$_}; |
| 129 |
|
#$self->{$_} = $args{$_}; |
| 130 |
} |
} |
| 131 |
|
|
| 132 |
# 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 |
| 150 |
} |
} |
| 151 |
|
|
| 152 |
|
|
| 153 |
|
# TODO: use NEXT.pm inside this mechanism (to avoid repetitions...) |
| 154 |
sub AUTOLOAD { |
sub AUTOLOAD { |
| 155 |
|
|
| 156 |
# recursion problem to be avoided here!!! |
# recursion problem to be avoided here!!! |
| 187 |
#if (!$self->exists('COREHANDLE')) { return; } |
#if (!$self->exists('COREHANDLE')) { return; } |
| 188 |
|
|
| 189 |
# handle locking (hack) |
# handle locking (hack) |
| 190 |
if ($self->exists('lock_info') && $self->{lock_info}->{last_method} && $methodname eq $self->{lock_info}->{last_method}) { |
if ($self->can('exists') && $self->exists('lock_info') && $self->{lock_info}->{last_method} && $methodname eq $self->{lock_info}->{last_method}) { |
| 191 |
$self->{lock_info}->{log_lock} = 1; |
$self->{lock_info}->{log_lock} = 1; |
| 192 |
} else { |
} else { |
| 193 |
$self->{lock_info}->{log_lock} = 0; |
$self->{lock_info}->{log_lock} = 0; |
| 208 |
#if (!$self->exists('_COREHANDLE')) { |
#if (!$self->exists('_COREHANDLE')) { |
| 209 |
#if (!$self->{_COREHANDLE}) { |
#if (!$self->{_COREHANDLE}) { |
| 210 |
if (!$core) { |
if (!$core) { |
| 211 |
my $err_msg_core = __PACKAGE__ . "[$self->{metainfo}->{type}]" . ": " . "COREHANDLE is undefined while trying to execute method \"$methodname\""; |
|
| 212 |
print $err_msg_core, "\n"; |
#print Dumper($self); |
| 213 |
if ($self->exists('lock_info') && !$self->{lock_info}->{log_lock}) { |
#exit; |
| 214 |
|
|
| 215 |
|
my $handlertype = $self->{metainfo}->{type}; |
| 216 |
|
$handlertype ||= ''; |
| 217 |
|
|
| 218 |
|
my $err_msg_core = __PACKAGE__ . "[$handlertype]" . ": " . "COREHANDLE is undefined while trying to execute method \"$methodname\""; |
| 219 |
|
|
| 220 |
|
#print $err_msg_core, "\n"; |
| 221 |
|
|
| 222 |
|
#if ($self->exists('lock_info') && !$self->{lock_info}->{log_lock}) { |
| 223 |
$logger->error( $err_msg_core ); |
$logger->error( $err_msg_core ); |
| 224 |
} |
#} |
| 225 |
|
|
| 226 |
return; |
return; |
| 227 |
|
|
| 228 |
} |
} |
| 229 |
#=cut |
#=cut |
| 230 |
|
|
| 265 |
|
|
| 266 |
#print "calling: $methodname", "\n"; |
#print "calling: $methodname", "\n"; |
| 267 |
|
|
| 268 |
# method calls doing it until here will get dispatched to the proper handler |
# method calls making it until here will get dispatched to the proper handler |
| 269 |
return $core->$methodname(@_); |
return $core->$methodname(@_); |
| 270 |
|
|
| 271 |
} elsif ($self->can($methodname)) { |
} elsif ($self->can($methodname)) { |
| 272 |
|
# try to call specified method inside our or inherited module(s) scope(s) |
| 273 |
return $self->$methodname(@_); |
return $self->$methodname(@_); |
| 274 |
} |
} |
| 275 |
|
|
| 306 |
my $self = shift; |
my $self = shift; |
| 307 |
my $nodename = shift; |
my $nodename = shift; |
| 308 |
#$nodename = 'TransactionRoutingTable'; |
#$nodename = 'TransactionRoutingTable'; |
| 309 |
$logger->debug( __PACKAGE__ . "->getChildNode( nodename $nodename )" ); |
$logger->debug( __PACKAGE__ . "->existsChildNode( nodename $nodename )" ); |
| 310 |
$self->getChildNodes() unless $self->{meta}->{childnodes}; |
$self->getChildNodes() unless $self->{meta}->{childnodes}; |
| 311 |
my $result = grep(m/$nodename/i, @{$self->{meta}->{childnodes}}); # TODO: use "/i" only on win32-systems! |
my $result = grep(m/$nodename/i, @{$self->{meta}->{childnodes}}); # TODO: use "/i" only on win32-systems! |
| 312 |
return $result; |
return $result; |
| 343 |
$self->_abstract_function('sendCommand'); |
$self->_abstract_function('sendCommand'); |
| 344 |
} |
} |
| 345 |
|
|
| 346 |
|
sub createChildNode { |
| 347 |
|
my $self = shift; |
| 348 |
|
$self->_abstract_function('createChildNode'); |
| 349 |
|
} |
| 350 |
|
|
| 351 |
sub existsChildNode_tmp { |
sub existsChildNode_tmp { |
| 352 |
my $self = shift; |
my $self = shift; |
| 353 |
$self->_abstract_function('existsChildNode'); |
$self->_abstract_function('existsChildNode'); |
| 429 |
return; |
return; |
| 430 |
} |
} |
| 431 |
|
|
| 432 |
|
sub getDbName { |
| 433 |
|
my $self = shift; |
| 434 |
|
$self->_abstract_function('getDbName'); |
| 435 |
|
return; |
| 436 |
|
} |
| 437 |
|
|
| 438 |
|
sub testAvailability { |
| 439 |
|
my $self = shift; |
| 440 |
|
$self->_abstract_function('testAvailability'); |
| 441 |
|
return; |
| 442 |
|
} |
| 443 |
|
|
| 444 |
|
sub isConnected { |
| 445 |
|
my $self = shift; |
| 446 |
|
$self->_abstract_function('isConnected'); |
| 447 |
|
return; |
| 448 |
|
} |
| 449 |
|
|
| 450 |
|
sub testDsn { |
| 451 |
|
my $self = shift; |
| 452 |
|
$self->_abstract_function('testDsn'); |
| 453 |
|
return; |
| 454 |
|
} |
| 455 |
|
|
| 456 |
1; |
1; |