9 |
## ------------------------------------------------------------------------ |
## ------------------------------------------------------------------------ |
10 |
## |
## |
11 |
## $Log$ |
## $Log$ |
12 |
|
## Revision 1.20 2003/06/25 22:51:51 joko |
13 |
|
## + sub get_locator_type & Co. |
14 |
|
## |
15 |
|
## Revision 1.19 2003/02/18 19:22:11 joko |
16 |
|
## + fixed logging |
17 |
|
## |
18 |
|
## Revision 1.18 2003/01/30 22:12:17 joko |
19 |
|
## - removed/refactored old code: ->Data::Storage::Handler::Tangram|DBI |
20 |
|
## |
21 |
## Revision 1.17 2003/01/30 21:42:22 joko |
## Revision 1.17 2003/01/30 21:42:22 joko |
22 |
## + minor update: renamed method |
## + minor update: renamed method |
23 |
## |
## |
117 |
|
|
118 |
my $arg_locator = shift; |
my $arg_locator = shift; |
119 |
my $arg_options = shift; |
my $arg_options = shift; |
120 |
|
#my @args = @_; |
121 |
|
#@args ||= (); |
122 |
|
|
123 |
if (!$arg_locator) { |
if (!$arg_locator) { |
124 |
$logger->critical( __PACKAGE__ . "->new: No locator passed in!" ); |
$logger->critical( __PACKAGE__ . "->new: No locator passed in!" ); |
125 |
return; |
return; |
126 |
} |
} |
127 |
|
|
128 |
|
#print Dumper($arg_locator); |
129 |
|
|
130 |
#my $self = { STORAGEHANDLE => undef, @_ }; |
#my $self = { STORAGEHANDLE => undef, @_ }; |
131 |
my $self = { STORAGEHANDLE => undef, locator => $arg_locator, options => $arg_options }; |
my $self = { STORAGEHANDLE => undef, locator => $arg_locator, options => $arg_options }; |
132 |
#$logger->debug( __PACKAGE__ . "[$self->{locator}->{type}]" . "->new(@_)" ); |
#$logger->debug( __PACKAGE__ . "[$self->{locator}->{type}]" . "->new(@_)" ); |
133 |
$logger->debug( __PACKAGE__ . "[$arg_locator->{type}]" . "->new(@_)" ); |
$logger->debug( __PACKAGE__ . "[$arg_locator->{type}]" . "->new()" ); |
134 |
return bless $self, $class; |
return bless $self, $class; |
135 |
} |
} |
136 |
|
|
152 |
my $method = $AUTOLOAD; |
my $method = $AUTOLOAD; |
153 |
$method =~ s/^.*:://; |
$method =~ s/^.*:://; |
154 |
|
|
155 |
|
#print __PACKAGE__, "\n"; |
156 |
|
#print $method, "\n"; |
157 |
|
#print $self->{locator}, "\n"; |
158 |
|
|
159 |
|
my $locator_type = $self->get_locator_type(); |
160 |
|
|
161 |
# advanced logging of AUTOLOAD calls ... |
# advanced logging of AUTOLOAD calls ... |
162 |
# ... nice but do it only when TRACING (TODO) is enabled |
# ... nice but do it only when TRACING (TODO) is enabled |
163 |
my $logstring = ""; |
my $logstring = ""; |
164 |
$logstring .= __PACKAGE__ . "[$self->{locator}->{type}]" . "->" . $method; |
$logstring .= __PACKAGE__ . "[$locator_type]" . "->" . $method; |
165 |
#print "count: ", $#_, "\n"; |
#print "count: ", $#_, "\n"; |
166 |
#$logstring .= Dumper(@_) if ($#_ != -1); |
#$logstring .= Dumper(@_) if ($#_ != -1); |
167 |
my $tabcount = int( (80 - length($logstring)) / 10 ); |
my $tabcount = int( (80 - length($logstring)) / 10 ); |
181 |
if ($self->{STORAGEHANDLE}) { |
if ($self->{STORAGEHANDLE}) { |
182 |
return $self->{STORAGEHANDLE}->$method(@_); |
return $self->{STORAGEHANDLE}->$method(@_); |
183 |
} else { |
} else { |
184 |
$logger->critical( __PACKAGE__ . "->AUTOLOAD: ERROR: " . $logstring ); |
my $msg = __PACKAGE__ . "->AUTOLOAD: ERROR: " . $logstring; |
185 |
|
$logger->critical( $msg ) if $logger; |
186 |
|
print STDERR $msg if not $logger; |
187 |
return; |
return; |
188 |
} |
} |
189 |
} |
} |
202 |
} |
} |
203 |
|
|
204 |
|
|
|
sub normalizeArgs { |
|
|
my %args = @_; |
|
|
if (!$args{dsn} && $args{meta}{dsn}) { |
|
|
$args{dsn} = $args{meta}{dsn}; |
|
|
} |
|
|
my @result = %args; |
|
|
return @result; |
|
|
} |
|
|
|
|
205 |
sub _accessStorageHandle { |
sub _accessStorageHandle { |
206 |
my $self = shift; |
my $self = shift; |
207 |
# TODO: to some tracelevel! |
# TODO: to some tracelevel! |
242 |
|
|
243 |
sub _createStorageHandle { |
sub _createStorageHandle { |
244 |
my $self = shift; |
my $self = shift; |
245 |
my $type = $self->{locator}->{type}; |
|
246 |
|
# 2003-06-18: protection against storagehandles w/o locators |
247 |
|
return if not defined $self->{locator}; |
248 |
|
|
249 |
|
my $type = $self->get_locator_type(); |
250 |
$logger->debug( __PACKAGE__ . "[$type]" . "->_createStorageHandle()" ); |
$logger->debug( __PACKAGE__ . "[$type]" . "->_createStorageHandle()" ); |
251 |
|
|
252 |
#print Dumper($self); |
#print Dumper($self); |
313 |
$logger->remove($name); |
$logger->remove($name); |
314 |
} |
} |
315 |
|
|
316 |
=pod |
sub get_locator_type { |
|
sub getDbName { |
|
|
my $self = shift; |
|
|
my $dsn = $self->{locator}->{dbi}->{dsn}; |
|
|
$dsn =~ m/database=(.+?);/; |
|
|
my $database_name = $1; |
|
|
return $database_name; |
|
|
} |
|
|
|
|
|
sub testAvailability { |
|
317 |
my $self = shift; |
my $self = shift; |
318 |
my $status = $self->testDsn(); |
my $locator_type = ''; |
319 |
$self->{locator}->{status}->{available} = $status; |
$locator_type = $self->{locator}->{type} if defined $self->{locator}; |
320 |
return $status; |
return $locator_type; |
321 |
} |
} |
322 |
|
|
|
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 |
|
|
|
|
323 |
1; |
1; |
324 |
__END__ |
__END__ |