--- nfo/perl/libs/Data/Storage/Handler/Abstract.pm 2003/01/30 21:46:32 1.12 +++ nfo/perl/libs/Data/Storage/Handler/Abstract.pm 2003/06/06 03:40:57 1.18 @@ -1,7 +1,26 @@ ## ------------------------------------------------------------------------ -## $Id: Abstract.pm,v 1.12 2003/01/30 21:46:32 joko Exp $ +## $Id: Abstract.pm,v 1.18 2003/06/06 03:40:57 joko Exp $ ## ------------------------------------------------------------------------ ## $Log: Abstract.pm,v $ +## Revision 1.18 2003/06/06 03:40:57 joko +## disabled autovivifying of arguments as attributes +## +## Revision 1.17 2003/05/13 07:58:49 joko +## fix: die if methodname is empty +## fixes to log-string +## +## Revision 1.16 2003/04/18 16:07:53 joko +## just use logger if instantiation successed +## +## Revision 1.15 2003/02/20 20:19:13 joko +## tried to get auto-disconnect working again - failed with that +## +## 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 ## @@ -55,11 +74,14 @@ use Data::Dumper; use Tie::SecureHash; #use Data::Storage::Handler; -use Data::Transform::Deep qw( merge ); +use Hash::Merge qw( merge ); +#use Log::Dispatch::Config; +#Log::Dispatch::Config->configure(); # get logger instance -my $logger = Log::Dispatch::Config->instance; +my $logger; +eval('$logger = Log::Dispatch::Config->instance;'); #our $lock_info; @@ -68,7 +90,7 @@ my $class = ref($invocant) || $invocant; # logging info about the actual handler called - $logger->debug( "$invocant->new( @_ )" ); + $logger->debug( "$invocant->new( @_ )" ) if $logger; #$logger->debug( __PACKAGE__ . "->" . "new()" ); # V1 - arguments become properties automagically / normal perl mode blessing @@ -225,6 +247,13 @@ } #=cut +=pod + if (!$methodname) { + die("Methodname is not defined!"); + return; + } +=cut + #print "$methodname - 3", "\n"; # try to dispatch method-call to Storage::Handler::* @@ -253,7 +282,11 @@ #$lock_AUTOLOAD = 1 if ($methodname eq 'insert'); if (!$self->{lock_info}->{log_lock}) { #print "method: $methodname", "\n"; - $logger->debug( __PACKAGE__ . "[$self->{metainfo}->{type}]" . "->" . $methodname . "(@_)" ); + my $type = $self->{metainfo}->{type}; + $type ||= ''; + # FIXME! + #$logger->debug( __PACKAGE__ . "[$type]" . "->" . $methodname . "(@_)" ); + $logger->debug( __PACKAGE__ . "[$type]" . "->" . $methodname ); } else { # AUTOLOAD - sub is locked to prevent deep recursions if (e.g.) db-inserts cause log-actions to same db itself } @@ -274,8 +307,34 @@ sub DESTROY { my $self = shift; - #if ($self->{COREHANDLE}) { - if ($self->exists('_COREHANDLE')) { + +return; + + $logger->debug( __PACKAGE__ . "[$self->{metainfo}->{type}]" . "->DESTROY" ); + + my $disconnectMethod = $self->{metainfo}->{disconnectMethod}; + print "meth: ", $disconnectMethod, "\n"; + + #$disconnectMethod && $self->{_COREHANDLE} && ( $self->{_COREHANDLE}->$disconnectMethod() ); + $self->{_COREHANDLE}->$disconnectMethod(); + #$self->$disconnectMethod(); + + #my $core1 = $self->getCOREHANDLE() if $self->can('getCOREHANDLE'); + #$core1->$disconnectMethod(); + +return; + + print "DESTROY-1", "\n"; + #if ($self->{__COREHANDLE}) { + #if ($self->exists('_COREHANDLE')) { + + # get corehandle instance from underlying handler + my $core; + $core = $self->getCOREHANDLE() if $self->can('getCOREHANDLE'); + + #if ($self->{STORAGEHANDLE}) { + if ($core) { + print "DESTROY-2", "\n"; $logger->debug( __PACKAGE__ . "[$self->{metainfo}->{type}]" . "->DESTROY" ); my $disconnectMethod = $self->{metainfo}->{disconnectMethod}; @@ -302,10 +361,23 @@ sub existsChildNode { my $self = shift; my $nodename = shift; - #$nodename = 'TransactionRoutingTable'; - $logger->debug( __PACKAGE__ . "->existsChildNode( 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; } @@ -426,4 +498,28 @@ 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;