--- nfo/perl/libs/Data/Storage/Handler/Abstract.pm 2002/10/10 03:44:07 1.1 +++ nfo/perl/libs/Data/Storage/Handler/Abstract.pm 2002/12/03 15:52:24 1.6 @@ -1,8 +1,24 @@ ################################# # -# $Id: Abstract.pm,v 1.1 2002/10/10 03:44:07 cvsjoko Exp $ +# $Id: Abstract.pm,v 1.6 2002/12/03 15:52:24 joko Exp $ # # $Log: Abstract.pm,v $ +# Revision 1.6 2002/12/03 15:52:24 joko +# + fix/feature: if dispatching to deep core method fails (is not declared), try method at Data::Storage - level +# +# Revision 1.5 2002/12/01 22:19:33 joko +# + just disconnect if COREHANDLE exists +# +# Revision 1.4 2002/12/01 04:45:38 joko +# + sub eraseAll +# + sub createDb +# +# Revision 1.3 2002/11/29 04:58:20 joko +# + Storage::Result now uses the same dispatching mechanism like Storage::Handler +# +# Revision 1.2 2002/10/17 00:08:07 joko +# + bugfixes regarding "deep recursion" stuff +# # Revision 1.1 2002/10/10 03:44:07 cvsjoko # + new # @@ -26,20 +42,24 @@ my $class = ref($invocant) || $invocant; # logging info about the actual handler called - $logger->debug( __PACKAGE__ . "->" . "new()" ); $logger->debug( "$invocant->new( @_ )" ); + #$logger->debug( __PACKAGE__ . "->" . "new()" ); + + # arguments become properties + my $self = { @_ }; + # create object from blessed hash-reference + bless $self, $class; # handle meta data - my $metainfo = _getMetaInfo($class); + #my $metainfo = $self->getMetaInfo($class); + my $metainfo = $self->getMetaInfo(); if (!$metainfo->{disconnectMethod}) { $metainfo->{disconnectMethod} = 'disconnect'; } # type? $invocant =~ s/Data::Storage::Handler:://; $metainfo->{type} = $invocant; - # create object from blessed hash-reference # direct accessible (non-protected) properties ( was: my $self = { }; ) - my $self = { metainfo => $metainfo, @_ }; - bless $self, $class; + $self->{metainfo} = $metainfo; return $self; } @@ -56,7 +76,7 @@ # - why: debug-messages are on a very low level including every data-operation to "Data::Storage(::Handler::X)", # so e.g. a "$storage->insert" would trigger another "$storage->insert" itself # which leads to a infinite recursion loop (deep recursion) - # - solution: locks! (by Hack or via Perl "local"s) + # - solution: locks! (by Hack or (maybe) via Perl "local"s) my $self = shift; @@ -77,7 +97,10 @@ # test for COREHANDLE if (!$self->{COREHANDLE}) { - $logger->error( __PACKAGE__ . "[$self->{metainfo}->{type}]" . ": " . "COREHANDLE is undefined while trying to execute method \"$methodname\"" ); + #print "no COREHANDLE", "\n"; + if (!$self->{lock_info}->{log_lock}) { + $logger->error( __PACKAGE__ . "[$self->{metainfo}->{type}]" . ": " . "COREHANDLE is undefined while trying to execute method \"$methodname\"" ); + } return; } @@ -100,7 +123,12 @@ } #$lock_AUTOLOAD = 0; #$logger->log( level => 'debug', message => __PACKAGE__ . "->" . $methodname . " (AUTOLOAD)" ); + + # method calls doing it until here will get dispatched to the proper handler return $self->{COREHANDLE}->$methodname(@_); + + } elsif ($self->can($methodname)) { + return $self->$methodname(@_); } } @@ -114,7 +142,7 @@ # call "disconnect" or alike on COREHANDLE # was: $self->{COREHANDLE}->disconnect(); - $disconnectMethod && ( $self->{COREHANDLE}->$disconnectMethod() ); + $disconnectMethod && $self->{COREHANDLE} && ( $self->{COREHANDLE}->$disconnectMethod() ); undef $self->{COREHANDLE}; } @@ -135,31 +163,22 @@ eval("use Data::Storage::$type;"); } -sub _getMetaInfo { - my $packagename = shift; - #return $self->$metainfo; - - my $ns = '$' . $packagename . "::metainfo"; - $logger->debug( __PACKAGE__ . "->" . "_getMetaInfo()" . " " . "[$ns]" ); - return eval($ns); -} - # ==================================================== # PUBLIC METHODS # ==================================================== - # TODO: abstract "abstract methods" to list/hash to be used in AUTOLOAD - # e.g.: my @ABSTRACT_METHODS = (qw( connect sendCommand getChildNodes )); - - sub connect { - + sub existsChildNode { my $self = shift; - $self->_abstract_function('connect'); - return; - - $logger->debug( "\"connect\" has to be implemented by handler!" ); - return; + my $nodename = shift; + #$nodename = 'TransactionRoutingTable'; + $logger->debug( __PACKAGE__ . "->getChildNode( nodename $nodename )" ); + $self->getChildNodes() unless $self->{meta}->{childnodes}; + my $result = grep(m/$nodename/i, @{$self->{meta}->{childnodes}}); # TODO: use "/i" only on win32-systems! + return $result; + } + + sub connect_tmp { # my $self = shift; # my $connectionString = shift; @@ -168,6 +187,18 @@ } + +# ==================================================== +# CONCRETE METHOD DUMMIES (croaking via "$logger" by calling "_abstract_function") +# ==================================================== + + # TODO: + # - abstract "abstract methods" to list/hash to be used in AUTOLOAD + # e.g.: my @ABSTRACT_METHODS = (qw( connect sendCommand getChildNodes )); + # use Class::XYZ (Construct) + # - build them via anonymous subs + # - introduce them via symbols + sub sendCommand { my $self = shift; $self->_abstract_function('sendCommand'); @@ -183,4 +214,58 @@ $self->_abstract_function('configureCOREHANDLE'); } -1; \ No newline at end of file + sub getMetaInfo { + my $self = shift; + $self->_abstract_function('getMetaInfo'); + return; + } + + sub getListUnfiltered { + my $self = shift; + $self->_abstract_function('getListUnfiltered'); + return; + } + + sub getListFiltered { + my $self = shift; + $self->_abstract_function('getListFiltered'); + return; + } + + sub sendQuery { + my $self = shift; + $self->_abstract_function('sendQuery'); + return; + } + + sub connect { + my $self = shift; + $self->_abstract_function('connect'); + return; + } + + sub testIntegrity { + my $self = shift; + $self->_abstract_function('testIntegrity'); + return; + } + + sub quoteSql { + my $self = shift; + $self->_abstract_function('quoteSql'); + return; + } + + sub eraseAll { + my $self = shift; + $self->_abstract_function('eraseAll'); + return; + } + + sub createDb { + my $self = shift; + $self->_abstract_function('createDb'); + return; + } + +1;