9 |
## ------------------------------------------------------------------------ |
## ------------------------------------------------------------------------ |
10 |
## |
## |
11 |
## $Log$ |
## $Log$ |
12 |
|
## Revision 1.19 2003/02/18 19:22:11 joko |
13 |
|
## + fixed logging |
14 |
|
## |
15 |
|
## Revision 1.18 2003/01/30 22:12:17 joko |
16 |
|
## - removed/refactored old code: ->Data::Storage::Handler::Tangram|DBI |
17 |
|
## |
18 |
|
## Revision 1.17 2003/01/30 21:42:22 joko |
19 |
|
## + minor update: renamed method |
20 |
|
## |
21 |
## Revision 1.16 2003/01/20 16:52:13 joko |
## Revision 1.16 2003/01/20 16:52:13 joko |
22 |
## + now using 'DesignPattern::Object' to create a new 'Data::Storage::Handler::Xyz' on demand - before we did this in a hand-rolled fashion |
## + now using 'DesignPattern::Object' to create a new 'Data::Storage::Handler::Xyz' on demand - before we did this in a hand-rolled fashion |
23 |
## |
## |
114 |
|
|
115 |
my $arg_locator = shift; |
my $arg_locator = shift; |
116 |
my $arg_options = shift; |
my $arg_options = shift; |
117 |
|
#my @args = @_; |
118 |
|
#@args ||= (); |
119 |
|
|
120 |
if (!$arg_locator) { |
if (!$arg_locator) { |
121 |
$logger->critical( __PACKAGE__ . "->new: No locator passed in!" ); |
$logger->critical( __PACKAGE__ . "->new: No locator passed in!" ); |
122 |
return; |
return; |
123 |
} |
} |
124 |
|
|
125 |
|
#print Dumper($arg_locator); |
126 |
|
|
127 |
#my $self = { STORAGEHANDLE => undef, @_ }; |
#my $self = { STORAGEHANDLE => undef, @_ }; |
128 |
my $self = { STORAGEHANDLE => undef, locator => $arg_locator, options => $arg_options }; |
my $self = { STORAGEHANDLE => undef, locator => $arg_locator, options => $arg_options }; |
129 |
#$logger->debug( __PACKAGE__ . "[$self->{locator}->{type}]" . "->new(@_)" ); |
#$logger->debug( __PACKAGE__ . "[$self->{locator}->{type}]" . "->new(@_)" ); |
130 |
$logger->debug( __PACKAGE__ . "[$arg_locator->{type}]" . "->new(@_)" ); |
$logger->debug( __PACKAGE__ . "[$arg_locator->{type}]" . "->new()" ); |
131 |
return bless $self, $class; |
return bless $self, $class; |
132 |
} |
} |
133 |
|
|
167 |
|
|
168 |
# filtering AUTOLOAD calls and first-time-touch of the actual storage impl |
# filtering AUTOLOAD calls and first-time-touch of the actual storage impl |
169 |
if ($self->_filter_AUTOLOAD($method)) { |
if ($self->_filter_AUTOLOAD($method)) { |
170 |
$self->_accessStorage(); |
#print "=== FILTER!", "\n"; |
171 |
|
$self->_accessStorageHandle(); |
172 |
if ($self->{STORAGEHANDLE}) { |
if ($self->{STORAGEHANDLE}) { |
173 |
return $self->{STORAGEHANDLE}->$method(@_); |
return $self->{STORAGEHANDLE}->$method(@_); |
174 |
} else { |
} else { |
191 |
} |
} |
192 |
|
|
193 |
|
|
194 |
sub normalizeArgs { |
sub _accessStorageHandle { |
|
my %args = @_; |
|
|
if (!$args{dsn} && $args{meta}{dsn}) { |
|
|
$args{dsn} = $args{meta}{dsn}; |
|
|
} |
|
|
my @result = %args; |
|
|
return @result; |
|
|
} |
|
|
|
|
|
sub _accessStorage { |
|
195 |
my $self = shift; |
my $self = shift; |
196 |
# TODO: to some tracelevel! |
# TODO: to some tracelevel! |
197 |
|
#print "=========== _accessStorage", "\n"; |
198 |
if ($TRACELEVEL) { |
if ($TRACELEVEL) { |
199 |
$logger->debug( __PACKAGE__ . "[$self->{locator}->{type}]" . "->_accessStorage()" ); |
$logger->debug( __PACKAGE__ . "[$self->{locator}->{type}]" . "->_accessStorageHandle()" ); |
200 |
} |
} |
201 |
if (!$self->{STORAGEHANDLE}) { |
if (!$self->{STORAGEHANDLE}) { |
202 |
return $self->_createStorageHandle(); |
return $self->_createStorageHandle(); |
298 |
$logger->remove($name); |
$logger->remove($name); |
299 |
} |
} |
300 |
|
|
|
=pod |
|
|
sub getDbName { |
|
|
my $self = shift; |
|
|
my $dsn = $self->{locator}->{dbi}->{dsn}; |
|
|
$dsn =~ m/database=(.+?);/; |
|
|
my $database_name = $1; |
|
|
return $database_name; |
|
|
} |
|
|
|
|
|
sub testAvailability { |
|
|
my $self = shift; |
|
|
my $status = $self->testDsn(); |
|
|
$self->{locator}->{status}->{available} = $status; |
|
|
return $status; |
|
|
} |
|
|
|
|
|
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 |
|
301 |
|
|
302 |
1; |
1; |
303 |
__END__ |
__END__ |