| 7 |
################################# |
################################# |
| 8 |
# |
# |
| 9 |
# $Log$ |
# $Log$ |
| 10 |
|
# Revision 1.7 2002/11/17 06:07:18 joko |
| 11 |
|
# + creating the handler is easier than proposed first - for now :-) |
| 12 |
|
# + sub testAvailability |
| 13 |
|
# |
| 14 |
# Revision 1.6 2002/11/09 01:04:58 joko |
# Revision 1.6 2002/11/09 01:04:58 joko |
| 15 |
# + updated pod |
# + updated pod |
| 16 |
# |
# |
| 96 |
use warnings; |
use warnings; |
| 97 |
|
|
| 98 |
use Data::Storage::Locator; |
use Data::Storage::Locator; |
| 99 |
|
use Data::Dumper; |
| 100 |
|
|
| 101 |
# TODO: actually implement level (integrate with Log::Dispatch) |
# TODO: actually implement level (integrate with Log::Dispatch) |
| 102 |
my $TRACELEVEL = 0; |
my $TRACELEVEL = 0; |
| 108 |
my $invocant = shift; |
my $invocant = shift; |
| 109 |
my $class = ref($invocant) || $invocant; |
my $class = ref($invocant) || $invocant; |
| 110 |
#my @args = normalizeArgs(@_); |
#my @args = normalizeArgs(@_); |
| 111 |
|
|
| 112 |
my $arg_locator = shift; |
my $arg_locator = shift; |
| 113 |
my $arg_options = shift; |
my $arg_options = shift; |
| 114 |
|
|
| 115 |
#my $self = { STORAGEHANDLE => undef, @_ }; |
#my $self = { STORAGEHANDLE => undef, @_ }; |
| 116 |
my $self = { STORAGEHANDLE => undef, locator => $arg_locator, options => $arg_options }; |
my $self = { STORAGEHANDLE => undef, locator => $arg_locator, options => $arg_options }; |
| 117 |
$logger->debug( __PACKAGE__ . "[$self->{locator}->{type}]" . "->new(@_)" ); |
#$logger->debug( __PACKAGE__ . "[$self->{locator}->{type}]" . "->new(@_)" ); |
| 118 |
|
$logger->debug( __PACKAGE__ . "[$arg_locator->{type}]" . "->new(@_)" ); |
| 119 |
return bless $self, $class; |
return bless $self, $class; |
| 120 |
} |
} |
| 121 |
|
|
| 150 |
# e.g. "Data::Storage[Tangram]->insert(SystemEvent=HASH(0x5c0034c)) (AUTOLOAD)" |
# e.g. "Data::Storage[Tangram]->insert(SystemEvent=HASH(0x5c0034c)) (AUTOLOAD)" |
| 151 |
# but that would be way too specific as long as we don't have an abstract handler for this ;) |
# but that would be way too specific as long as we don't have an abstract handler for this ;) |
| 152 |
$logger->debug( $logstring ); |
$logger->debug( $logstring ); |
| 153 |
|
#print join('; ', @_); |
| 154 |
} |
} |
| 155 |
|
|
| 156 |
# filtering AUTOLOAD calls |
# filtering AUTOLOAD calls |
| 157 |
if ($self->_filter_AUTOLOAD($method)) { |
if ($self->_filter_AUTOLOAD($method)) { |
| 158 |
|
#print "_accessStorage\n"; |
| 159 |
$self->_accessStorage(); |
$self->_accessStorage(); |
| 160 |
$self->{STORAGEHANDLE}->$method(@_); |
$self->{STORAGEHANDLE}->$method(@_); |
| 161 |
} |
} |
| 196 |
|
|
| 197 |
sub _createStorageHandle { |
sub _createStorageHandle { |
| 198 |
my $self = shift; |
my $self = shift; |
|
|
|
| 199 |
my $type = $self->{locator}->{type}; |
my $type = $self->{locator}->{type}; |
| 200 |
$logger->debug( __PACKAGE__ . "[$type]" . "->_createStorageHandle()" ); |
$logger->debug( __PACKAGE__ . "[$type]" . "->_createStorageHandle()" ); |
| 201 |
|
|
| 202 |
my $pkg = "Data::Storage::Handler::" . $type . ""; |
my $pkg = "Data::Storage::Handler::" . $type . ""; |
| 203 |
|
|
| 204 |
# propagate args to handler |
# try to load perl module at runtime |
| 205 |
# needs some more thoughts! (not only "dbi" to Tangram, when (in future) db is not more the common case) |
my $evalstr = "use $pkg;"; |
| 206 |
if ($type eq 'DBI') { |
eval($evalstr); |
| 207 |
use Data::Storage::Handler::DBI; |
if ($@) { |
| 208 |
#my @args = %{$self->{locator}->{dbi}}; |
$logger->error( __PACKAGE__ . "[$type]" . "->_createStorageHandle(): $@" ); |
| 209 |
my @args = %{$self->{locator}}; |
return; |
|
# 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(); |
|
| 210 |
} |
} |
| 211 |
|
|
| 212 |
|
# build up some additional arguments to pass on |
| 213 |
|
#my @args = %{$self->{locator}}; |
| 214 |
|
my @args = (); |
| 215 |
|
|
| 216 |
|
# create new storage handle object, propagate arguments to handler |
| 217 |
|
# pass locator by reference to be able to store status information in it |
| 218 |
|
$self->{STORAGEHANDLE} = $pkg->new( locator => $self->{locator}, @args ); |
| 219 |
|
|
| 220 |
} |
} |
| 221 |
|
|
| 222 |
sub addLogDispatchHandler { |
sub addLogDispatchHandler { |
| 275 |
$dbh->disconnect(); |
$dbh->disconnect(); |
| 276 |
return 1; |
return 1; |
| 277 |
} else { |
} else { |
| 278 |
$logger->error( __PACKAGE__ . "[$self->{locator}->{type}]" . "->testDsn(): " . "DBI-error: " . $DBI::errstr ); |
$logger->warning( __PACKAGE__ . "[$self->{locator}->{type}]" . "->testDsn(): " . "DBI-error: " . $DBI::errstr ); |
| 279 |
} |
} |
| 280 |
} |
} |
| 281 |
|
|
| 282 |
|
sub testAvailability { |
| 283 |
|
my $self = shift; |
| 284 |
|
my $status = $self->testDsn(); |
| 285 |
|
$self->{locator}->{status}->{available} = $status; |
| 286 |
|
return $status; |
| 287 |
|
} |
| 288 |
|
|
| 289 |
sub createDb { |
sub createDb { |
| 290 |
my $self = shift; |
my $self = shift; |
| 291 |
my $dsn = $self->{locator}->{dbi}->{dsn}; |
my $dsn = $self->{locator}->{dbi}->{dsn}; |