--- nfo/perl/libs/Data/Storage.pm 2003/01/30 21:42:22 1.17 +++ nfo/perl/libs/Data/Storage.pm 2003/06/25 22:51:51 1.20 @@ -1,6 +1,6 @@ ## ------------------------------------------------------------------------ ## -## $Id: Storage.pm,v 1.17 2003/01/30 21:42:22 joko Exp $ +## $Id: Storage.pm,v 1.20 2003/06/25 22:51:51 joko Exp $ ## ## Copyright (c) 2002 Andreas Motl ## @@ -9,6 +9,15 @@ ## ------------------------------------------------------------------------ ## ## $Log: Storage.pm,v $ +## Revision 1.20 2003/06/25 22:51:51 joko +## + sub get_locator_type & Co. +## +## Revision 1.19 2003/02/18 19:22:11 joko +## + fixed logging +## +## Revision 1.18 2003/01/30 22:12:17 joko +## - removed/refactored old code: ->Data::Storage::Handler::Tangram|DBI +## ## Revision 1.17 2003/01/30 21:42:22 joko ## + minor update: renamed method ## @@ -108,16 +117,20 @@ my $arg_locator = shift; my $arg_options = shift; + #my @args = @_; + #@args ||= (); if (!$arg_locator) { $logger->critical( __PACKAGE__ . "->new: No locator passed in!" ); return; } + + #print Dumper($arg_locator); #my $self = { STORAGEHANDLE => undef, @_ }; my $self = { STORAGEHANDLE => undef, locator => $arg_locator, options => $arg_options }; #$logger->debug( __PACKAGE__ . "[$self->{locator}->{type}]" . "->new(@_)" ); - $logger->debug( __PACKAGE__ . "[$arg_locator->{type}]" . "->new(@_)" ); + $logger->debug( __PACKAGE__ . "[$arg_locator->{type}]" . "->new()" ); return bless $self, $class; } @@ -139,10 +152,16 @@ my $method = $AUTOLOAD; $method =~ s/^.*:://; + #print __PACKAGE__, "\n"; + #print $method, "\n"; + #print $self->{locator}, "\n"; + + my $locator_type = $self->get_locator_type(); + # advanced logging of AUTOLOAD calls ... # ... nice but do it only when TRACING (TODO) is enabled my $logstring = ""; - $logstring .= __PACKAGE__ . "[$self->{locator}->{type}]" . "->" . $method; + $logstring .= __PACKAGE__ . "[$locator_type]" . "->" . $method; #print "count: ", $#_, "\n"; #$logstring .= Dumper(@_) if ($#_ != -1); my $tabcount = int( (80 - length($logstring)) / 10 ); @@ -162,7 +181,9 @@ if ($self->{STORAGEHANDLE}) { return $self->{STORAGEHANDLE}->$method(@_); } else { - $logger->critical( __PACKAGE__ . "->AUTOLOAD: ERROR: " . $logstring ); + my $msg = __PACKAGE__ . "->AUTOLOAD: ERROR: " . $logstring; + $logger->critical( $msg ) if $logger; + print STDERR $msg if not $logger; return; } } @@ -181,15 +202,6 @@ } -sub normalizeArgs { - my %args = @_; - if (!$args{dsn} && $args{meta}{dsn}) { - $args{dsn} = $args{meta}{dsn}; - } - my @result = %args; - return @result; -} - sub _accessStorageHandle { my $self = shift; # TODO: to some tracelevel! @@ -230,7 +242,11 @@ sub _createStorageHandle { my $self = shift; - my $type = $self->{locator}->{type}; + + # 2003-06-18: protection against storagehandles w/o locators + return if not defined $self->{locator}; + + my $type = $self->get_locator_type(); $logger->debug( __PACKAGE__ . "[$type]" . "->_createStorageHandle()" ); #print Dumper($self); @@ -297,45 +313,12 @@ $logger->remove($name); } -=pod -sub getDbName { - my $self = shift; - my $dsn = $self->{locator}->{dbi}->{dsn}; - $dsn =~ m/database=(.+?);/; - my $database_name = $1; - return $database_name; -} - -sub testAvailability { +sub get_locator_type { my $self = shift; - my $status = $self->testDsn(); - $self->{locator}->{status}->{available} = $status; - return $status; + my $locator_type = ''; + $locator_type = $self->{locator}->{type} if defined $self->{locator}; + return $locator_type; } -sub isConnected { - my $self = shift; - # TODO: REVIEW! - return 1 if $self->{STORAGEHANDLE}; -} - -sub testDsn { - my $self = shift; - my $dsn = $self->{locator}->{dbi}->{dsn}; - my $result; - if ( my $dbh = DBI->connect($dsn, '', '', { - PrintError => 0, - } ) ) { - - # TODO: REVIEW - $dbh->disconnect(); - - return 1; - } else { - $logger->warning( __PACKAGE__ . "[$self->{locator}->{type}]" . "->testDsn(): " . "DBI-error: " . $DBI::errstr ); - } -} -=cut - 1; __END__