--- nfo/perl/libs/Data/Storage/Handler/Abstract.pm 2002/12/05 07:57:48 1.7 +++ nfo/perl/libs/Data/Storage/Handler/Abstract.pm 2003/02/09 05:12:28 1.14 @@ -1,7 +1,30 @@ -## -------------------------------------------------------------------------------- -## $Id: Abstract.pm,v 1.7 2002/12/05 07:57:48 joko Exp $ -## -------------------------------------------------------------------------------- +## ------------------------------------------------------------------------ +## $Id: Abstract.pm,v 1.14 2003/02/09 05:12:28 joko Exp $ +## ------------------------------------------------------------------------ ## $Log: Abstract.pm,v $ +## Revision 1.14 2003/02/09 05:12:28 joko +## + quoting of strings used in sql-queries! +## +## Revision 1.13 2003/01/30 22:27:05 joko +## + added new abstract methods +## +## Revision 1.12 2003/01/30 21:46:32 joko +## + fixed behaviour of AUTOLOAD-method +## +## Revision 1.11 2003/01/20 16:43:18 joko +## + better argument-property merging +## + debugging-output !!! +## + abstract-dummy 'sub createChildNode' +## +## Revision 1.10 2003/01/19 02:31:51 joko +## + fix to 'sub AUTOLOAD' +## +## Revision 1.9 2002/12/19 16:30:23 joko +## + added 'sub dropDb' and 'sub rebuildDb' as croakers for concrete implementations of methods in proper handlers +## +## Revision 1.8 2002/12/13 21:48:35 joko +## + sub _abstract_function +## ## Revision 1.7 2002/12/05 07:57:48 joko ## + now using Tie::SecureHash as a base for the COREHANDLE ## + former public COREHANDLE becomes private _COREHANDLE now @@ -24,7 +47,7 @@ ## ## Revision 1.1 2002/10/10 03:44:07 cvsjoko ## + new -## -------------------------------------------------------------------------------- +## ------------------------------------------------------------------------ package Data::Storage::Handler::Abstract; @@ -32,9 +55,14 @@ use strict; use warnings; +use base qw( DesignPattern::Object ); + + use Data::Dumper; use Tie::SecureHash; #use Data::Storage::Handler; +use Data::Transform::Deep qw( merge ); + # get logger instance my $logger = Log::Dispatch::Config->instance; @@ -57,7 +85,7 @@ bless $self, $class; =cut - +#=pod # V2 - maybe more convenient/secure? utilizing Damian Conway's Tie::SecureHash... my $self = Tie::SecureHash->new( $class, @@ -81,18 +109,27 @@ #_protected => , #__private => , ); - +#=cut # merge passed-in arguments to constructor as properties into already blessed secure object - + # mungle arguments from array into hash - perl does the job ;) - my %args = @_; - + #my %args = @_; + #my %args = (); + +#print Dumper(@_); + # merge attributes one-by-one # TODO: deep_copy? / merge_deep? - foreach (keys %args) { - #print "key: $_", "\n"; - $self->{$_} = $args{$_}; + while (my $elemName = shift @_) { + #print "elemName: $elemName", "\n"; + if (my $elemValue = shift @_) { + #print Dumper($elemValue); + #print "elemName=$elemName, elemValue=$elemValue", "\n"; + $self->{$elemName} = $elemValue; + } + #$self->{$_} = $args{$_}; + #$self->{$_} = $args{$_}; } # V3 - rolling our own security (just for {COREHANDLE} - nothing else) - nope, Tie::SecureHash works wonderful @@ -116,6 +153,7 @@ } +# TODO: use NEXT.pm inside this mechanism (to avoid repetitions...) sub AUTOLOAD { # recursion problem to be avoided here!!! @@ -152,7 +190,7 @@ #if (!$self->exists('COREHANDLE')) { return; } # handle locking (hack) - 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}) { $self->{lock_info}->{log_lock} = 1; } else { $self->{lock_info}->{log_lock} = 0; @@ -173,12 +211,23 @@ #if (!$self->exists('_COREHANDLE')) { #if (!$self->{_COREHANDLE}) { if (!$core) { - my $err_msg_core = __PACKAGE__ . "[$self->{metainfo}->{type}]" . ": " . "COREHANDLE is undefined while trying to execute method \"$methodname\""; -print $err_msg_core, "\n"; - if ($self->exists('lock_info') && !$self->{lock_info}->{log_lock}) { + +#print Dumper($self); +#exit; + + my $handlertype = $self->{metainfo}->{type}; + $handlertype ||= ''; + + my $err_msg_core = __PACKAGE__ . "[$handlertype]" . ": " . "COREHANDLE is undefined while trying to execute method \"$methodname\""; + +#print $err_msg_core, "\n"; + + #if ($self->exists('lock_info') && !$self->{lock_info}->{log_lock}) { $logger->error( $err_msg_core ); - } + #} + return; + } #=cut @@ -219,10 +268,11 @@ #print "calling: $methodname", "\n"; - # 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 return $core->$methodname(@_); } elsif ($self->can($methodname)) { + # try to call specified method inside our or inherited module(s) scope(s) return $self->$methodname(@_); } @@ -244,18 +294,6 @@ } } - -sub _abstract_function { - my $self = shift; - my $fName = shift; - my $class = ref($self); - # was: - # $logger->error( __PACKAGE__ . ": function \"$fName\" is an abstract method, please implement it in \"$class\""); - # is: - die( __PACKAGE__ . ": function \"$fName\" is an abstract method, please implement it in \"$class\""); - #exit; -} - sub _typeCheck2 { my $type = shift; print "type: $type"; @@ -270,10 +308,23 @@ sub existsChildNode { my $self = shift; my $nodename = shift; - #$nodename = 'TransactionRoutingTable'; - $logger->debug( __PACKAGE__ . "->getChildNode( nodename $nodename )" ); + + # TODO: don't use $self->{meta}->{childnodes} directly in here + # get it returned from $self->getChildNodes()!!! + + $logger->debug( __PACKAGE__ . "->existsChildNode( nodename=$nodename )" ); $self->getChildNodes() unless $self->{meta}->{childnodes}; - my $result = grep(m/$nodename/i, @{$self->{meta}->{childnodes}}); # TODO: use "/i" only on win32-systems! + + # quote this, it might contain meta characters which don't work in a regex + $nodename = quotemeta($nodename); + + # trace + #print Dumper($self->{meta}); + #print "nodename: $nodename", "\n"; + + # FIXME: use "/i" only on win32-systems! + my $result = grep(m/$nodename/i, @{$self->{meta}->{childnodes}}); + return $result; } @@ -308,6 +359,11 @@ $self->_abstract_function('sendCommand'); } + sub createChildNode { + my $self = shift; + $self->_abstract_function('createChildNode'); + } + sub existsChildNode_tmp { my $self = shift; $self->_abstract_function('existsChildNode'); @@ -377,4 +433,40 @@ return; } + sub dropDb { + my $self = shift; + $self->_abstract_function('dropDb'); + return; + } + + sub rebuildDb { + my $self = shift; + $self->_abstract_function('rebuildDb'); + return; + } + + sub getDbName { + my $self = shift; + $self->_abstract_function('getDbName'); + return; + } + + sub testAvailability { + my $self = shift; + $self->_abstract_function('testAvailability'); + return; + } + + sub isConnected { + my $self = shift; + $self->_abstract_function('isConnected'); + return; + } + + sub testDsn { + my $self = shift; + $self->_abstract_function('testDsn'); + return; + } + 1;