--- nfo/perl/libs/Data/Storage.pm 2002/11/09 01:04:58 1.6 +++ nfo/perl/libs/Data/Storage.pm 2002/11/17 06:07:18 1.7 @@ -1,4 +1,4 @@ -# $Id: Storage.pm,v 1.6 2002/11/09 01:04:58 joko Exp $ +# $Id: Storage.pm,v 1.7 2002/11/17 06:07:18 joko Exp $ # # Copyright (c) 2002 Andreas Motl # @@ -7,6 +7,10 @@ ################################# # # $Log: Storage.pm,v $ +# Revision 1.7 2002/11/17 06:07:18 joko +# + creating the handler is easier than proposed first - for now :-) +# + sub testAvailability +# # Revision 1.6 2002/11/09 01:04:58 joko # + updated pod # @@ -92,6 +96,7 @@ use warnings; use Data::Storage::Locator; +use Data::Dumper; # TODO: actually implement level (integrate with Log::Dispatch) my $TRACELEVEL = 0; @@ -103,13 +108,14 @@ my $invocant = shift; my $class = ref($invocant) || $invocant; #my @args = normalizeArgs(@_); - + my $arg_locator = shift; my $arg_options = shift; - + #my $self = { STORAGEHANDLE => undef, @_ }; my $self = { STORAGEHANDLE => undef, locator => $arg_locator, options => $arg_options }; - $logger->debug( __PACKAGE__ . "[$self->{locator}->{type}]" . "->new(@_)" ); + #$logger->debug( __PACKAGE__ . "[$self->{locator}->{type}]" . "->new(@_)" ); + $logger->debug( __PACKAGE__ . "[$arg_locator->{type}]" . "->new(@_)" ); return bless $self, $class; } @@ -144,10 +150,12 @@ # e.g. "Data::Storage[Tangram]->insert(SystemEvent=HASH(0x5c0034c)) (AUTOLOAD)" # but that would be way too specific as long as we don't have an abstract handler for this ;) $logger->debug( $logstring ); + #print join('; ', @_); } # filtering AUTOLOAD calls if ($self->_filter_AUTOLOAD($method)) { + #print "_accessStorage\n"; $self->_accessStorage(); $self->{STORAGEHANDLE}->$method(@_); } @@ -188,33 +196,27 @@ sub _createStorageHandle { my $self = shift; - my $type = $self->{locator}->{type}; $logger->debug( __PACKAGE__ . "[$type]" . "->_createStorageHandle()" ); my $pkg = "Data::Storage::Handler::" . $type . ""; - # propagate args to handler - # needs some more thoughts! (not only "dbi" to Tangram, when (in future) db is not more the common case) - if ($type eq 'DBI') { - use Data::Storage::Handler::DBI; - #my @args = %{$self->{locator}->{dbi}}; - my @args = %{$self->{locator}}; - # create new storage handle - $self->{STORAGEHANDLE} = $pkg->new( @args ); - } - if ($type eq 'Tangram') { - use Data::Storage::Handler::Tangram; - #$self->{STORAGEHANDLE} = $pkg->new( dsn => $self->{locator}->{dbi}->{dsn} ); - #my @args = %{$self->{locator}->{dbi}}; - my @args = %{$self->{locator}}; - # create new storage handle - $self->{STORAGEHANDLE} = $pkg->new( @args ); - - #$self->{STORAGEHANDLE_UNDERLYING} = $self->{STORAGEHANDLE}->getUnderlyingStorage(); - #$self->{STORAGEHANDLE_UNDERLYING}->_configureCOREHANDLE(); + # try to load perl module at runtime + my $evalstr = "use $pkg;"; + eval($evalstr); + if ($@) { + $logger->error( __PACKAGE__ . "[$type]" . "->_createStorageHandle(): $@" ); + return; } + # build up some additional arguments to pass on + #my @args = %{$self->{locator}}; + my @args = (); + + # create new storage handle object, propagate arguments to handler + # pass locator by reference to be able to store status information in it + $self->{STORAGEHANDLE} = $pkg->new( locator => $self->{locator}, @args ); + } sub addLogDispatchHandler { @@ -273,10 +275,17 @@ $dbh->disconnect(); return 1; } else { - $logger->error( __PACKAGE__ . "[$self->{locator}->{type}]" . "->testDsn(): " . "DBI-error: " . $DBI::errstr ); + $logger->warning( __PACKAGE__ . "[$self->{locator}->{type}]" . "->testDsn(): " . "DBI-error: " . $DBI::errstr ); } } +sub testAvailability { + my $self = shift; + my $status = $self->testDsn(); + $self->{locator}->{status}->{available} = $status; + return $status; +} + sub createDb { my $self = shift; my $dsn = $self->{locator}->{dbi}->{dsn};