Bio-Das-ProServer
view release on metacpan or search on metacpan
lib/Bio/Das/ProServer/SourceHydra/dbi.pm view on Meta::CPAN
if($self->transport->dbh->{Driver}->{Name} ne 'mysql') {
return;
}
my $now = time;
my $basename = $self->config->{'basename'};
#########
# flush the timestamp cache *at most* once every $CACHE_TIMEOUT
# This may need signal triggering to have immediate support
#
if($now > ($self->{'_lastmodified_timestamp'} || 0)+$CACHE_TIMEOUT) {
$self->{'debug'} and carp qq(Flushing last-modified cache for hydra $self->{'dsn'});
$self->{'_lastmodified_timestamp'} = $now;
my $server_text = [sort { $b cmp $a } ## no critic
map { $_->{Update_time} }
@{ $self->transport()->query(q(SHOW TABLE STATUS),{Update_time=>1}) }
]->[0]; # server local time
my $server_unix = $self->transport()->query(q(SELECT UNIX_TIMESTAMP(?) as 'unix'), $server_text)->[0]{unix}; # sec since epoch
$self->{'_lastmodified'} = $server_unix;
}
return $self->{'_lastmodified'};
}
1;
__END__
=head1 NAME
Bio::Das::ProServer::SourceHydra::dbi - A database-backed implementation of B::D::P::SourceHydra
=head1 VERSION
$Revision: 687 $
=head1 AUTHOR
Roger Pettett <rmp@sanger.ac.uk>.
=head1 LICENSE AND COPYRIGHT
Copyright (c) 2007 The Sanger Institute
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself. See DISCLAIMER.txt for
disclaimers of warranty.
=head1 DESCRIPTION
=head1 SYNOPSIS
my $dbiHydra = Bio::Das::ProServer::SourceHydra::dbi->new();
=head1 SUBROUTINES/METHODS
=head2 sources : DBI sources
Effectively returns the results of a SHOW TABLES LIKE '$basename%'
query. In Oracle I guess this would need changing to table_name from
all_tables where like '$basename%' or something.
my @sources = $dbihydra->sources();
$basename comes from $self->config->{'basename'};
This routine caches results for $CACHE_TIMEOUT as show tables can be
slow for a few thousand sources.
=head2 last_modified : machine time of last data change
Gets the most recent update time for any of the hydra's tables.
Only knows how to do this for MySQL databases.
my $unixtime = $dbihydra->last_modified();
=head1 DIAGNOSTICS
Run ProServer with the -debug flag.
=head1 CONFIGURATION AND ENVIRONMENT
[mysimplehydra]
adaptor = simpledb # SourceAdaptor to clone
hydra = dbi # Hydra implementation to use
transport = dbi
basename = hydra # dbi: basename for db tables containing servable data
dbname = proserver
dbhost = mysql.example.com
dbuser = proserverro
dbpass = topsecret
=head1 DEPENDENCIES
Bio::Das::ProServer::SourceHydra
=head1 INCOMPATIBILITIES
=head1 BUGS AND LIMITATIONS
The last_modified method only works for MySQL databases.
=cut
( run in 1.935 second using v1.01-cache-2.11-cpan-39bf76dae61 )