Commit 13f462ad authored by Leo Gordon's avatar Leo Gordon
Browse files

moved loading/saving of the collections into DBAdaptor module

parent 6e8b91eb
...@@ -67,55 +67,14 @@ use Bio::EnsEMBL::Hive::Utils::Collection; ...@@ -67,55 +67,14 @@ use Bio::EnsEMBL::Hive::Utils::Collection;
our %hash_of_collections; our %hash_of_collections;
sub collection { sub collection {
my $key = pop @_; my $class = shift @_;
my $key = shift @_;
return $hash_of_collections{$key} ||= Bio::EnsEMBL::Hive::Utils::Collection->new(); if(@_) {
} $hash_of_collections{$key} = shift @_;
sub load_collections_from_dba {
my $hive_dba = pop @_;
foreach my $AdaptorType ('Meta', 'MetaContainer') {
my $adaptor = $hive_dba->get_adaptor( $AdaptorType );
$hash_of_collections{$AdaptorType} = $adaptor->get_param_hash();
}
foreach my $AdaptorType ('ResourceClass', 'ResourceDescription', 'Analysis', 'AnalysisStats', 'AnalysisCtrlRule', 'DataflowRule') {
my $adaptor = $hive_dba->get_adaptor( $AdaptorType );
$hash_of_collections{$AdaptorType} = Bio::EnsEMBL::Hive::Utils::Collection->new( $adaptor->fetch_all );
}
}
sub save_collections_to_dba {
my $hive_dba = pop @_;
foreach my $AdaptorType ('Meta', 'MetaContainer') {
my $adaptor = $hive_dba->get_adaptor( $AdaptorType );
while(my ($meta_key, $meta_value) = each %{ $hash_of_collections{$AdaptorType} } ) {
$adaptor->remove_all_by_meta_key($meta_key); # make sure the previous values are gone
$adaptor->store_pair( $meta_key, $meta_value );
}
} }
foreach my $AdaptorType ('ResourceClass', 'ResourceDescription', 'Analysis', 'AnalysisStats', 'AnalysisCtrlRule', 'DataflowRule') { return $hash_of_collections{$key} ||= Bio::EnsEMBL::Hive::Utils::Collection->new();
my $adaptor = $hive_dba->get_adaptor( $AdaptorType );
foreach my $storable_object ( Bio::EnsEMBL::Hive->collection( $AdaptorType )->list ) {
$adaptor->store_or_update_one( $storable_object );
# warn "Stored/updated ".$storable_object->toString()."\n";
}
}
my $job_adaptor = $hive_dba->get_AnalysisJobAdaptor;
foreach my $analysis ( Bio::EnsEMBL::Hive->collection('Analysis')->list ) {
if(my $our_jobs = $analysis->jobs_collection ) {
$job_adaptor->store( $our_jobs );
foreach my $job (@$our_jobs) {
# warn "Stored ".$job->toString()."\n";
}
}
}
} }
1; 1;
......
...@@ -36,9 +36,11 @@ package Bio::EnsEMBL::Hive::DBSQL::DBAdaptor; ...@@ -36,9 +36,11 @@ package Bio::EnsEMBL::Hive::DBSQL::DBAdaptor;
use strict; use strict;
use Bio::EnsEMBL::Hive::Utils ('throw'); use Bio::EnsEMBL::Hive;
use Bio::EnsEMBL::Hive::DBSQL::DBConnection; use Bio::EnsEMBL::Hive::DBSQL::DBConnection;
use Bio::EnsEMBL::Hive::DBSQL::SqlSchemaAdaptor; use Bio::EnsEMBL::Hive::DBSQL::SqlSchemaAdaptor;
use Bio::EnsEMBL::Hive::Utils ('throw');
use Bio::EnsEMBL::Hive::Utils::Collection;
sub new { sub new {
...@@ -253,5 +255,51 @@ sub AUTOLOAD { ...@@ -253,5 +255,51 @@ sub AUTOLOAD {
return $self->get_adaptor($type, @_); return $self->get_adaptor($type, @_);
} }
sub load_collections {
my $self = shift @_;
foreach my $AdaptorType ('Meta', 'MetaContainer') {
my $adaptor = $self->get_adaptor( $AdaptorType );
Bio::EnsEMBL::Hive->collection( $AdaptorType, $adaptor->get_param_hash() );
}
foreach my $AdaptorType ('ResourceClass', 'ResourceDescription', 'Analysis', 'AnalysisStats', 'AnalysisCtrlRule', 'DataflowRule') {
my $adaptor = $self->get_adaptor( $AdaptorType );
Bio::EnsEMBL::Hive->collection( $AdaptorType, Bio::EnsEMBL::Hive::Utils::Collection->new( $adaptor->fetch_all ) );
}
}
sub save_collections {
my $self = shift @_;
foreach my $AdaptorType ('Meta', 'MetaContainer') {
my $adaptor = $self->get_adaptor( $AdaptorType );
while(my ($meta_key, $meta_value) = each %{ Bio::EnsEMBL::Hive->collection( $AdaptorType ) } ) {
$adaptor->remove_all_by_meta_key($meta_key); # make sure the previous values are gone
$adaptor->store_pair( $meta_key, $meta_value );
}
}
foreach my $AdaptorType ('ResourceClass', 'ResourceDescription', 'Analysis', 'AnalysisStats', 'AnalysisCtrlRule', 'DataflowRule') {
my $adaptor = $self->get_adaptor( $AdaptorType );
foreach my $storable_object ( Bio::EnsEMBL::Hive->collection( $AdaptorType )->list ) {
$adaptor->store_or_update_one( $storable_object );
# warn "Stored/updated ".$storable_object->toString()."\n";
}
}
my $job_adaptor = $self->get_AnalysisJobAdaptor;
foreach my $analysis ( Bio::EnsEMBL::Hive->collection('Analysis')->list ) {
if(my $our_jobs = $analysis->jobs_collection ) {
$job_adaptor->store( $our_jobs );
foreach my $job (@$our_jobs) {
# warn "Stored ".$job->toString()."\n";
}
}
}
}
1; 1;
...@@ -15,7 +15,6 @@ BEGIN { ...@@ -15,7 +15,6 @@ BEGIN {
use Getopt::Long qw(:config pass_through no_auto_abbrev); use Getopt::Long qw(:config pass_through no_auto_abbrev);
use Pod::Usage; use Pod::Usage;
use Bio::EnsEMBL::Hive;
use Bio::EnsEMBL::Hive::DBSQL::DBAdaptor; use Bio::EnsEMBL::Hive::DBSQL::DBAdaptor;
use Bio::EnsEMBL::Hive::Utils ('script_usage', 'load_file_or_module'); use Bio::EnsEMBL::Hive::Utils ('script_usage', 'load_file_or_module');
use Bio::EnsEMBL::Hive::Utils::Graph; use Bio::EnsEMBL::Hive::Utils::Graph;
...@@ -72,7 +71,7 @@ sub main { ...@@ -72,7 +71,7 @@ sub main {
-no_sql_schema_version_check => $self->{'nosqlvc'}, -no_sql_schema_version_check => $self->{'nosqlvc'},
); );
Bio::EnsEMBL::Hive->load_collections_from_dba( $self->{'dba'} ); $self->{'dba'}->load_collections();
} }
if($self->{'pipeconfig'}) { if($self->{'pipeconfig'}) {
......
...@@ -42,11 +42,11 @@ sub main { ...@@ -42,11 +42,11 @@ sub main {
my $hive_dba = Bio::EnsEMBL::Hive::DBSQL::DBAdaptor->new( -url => $pipeconfig_object->pipeline_url(), -no_sql_schema_version_check => 1 ); my $hive_dba = Bio::EnsEMBL::Hive::DBSQL::DBAdaptor->new( -url => $pipeconfig_object->pipeline_url(), -no_sql_schema_version_check => 1 );
Bio::EnsEMBL::Hive->load_collections_from_dba( $hive_dba ); $hive_dba->load_collections();
$pipeconfig_object->add_objects_from_config(); $pipeconfig_object->add_objects_from_config();
Bio::EnsEMBL::Hive->save_collections_to_dba( $hive_dba ); $hive_dba->save_collections();
$pipeconfig_object->show_useful_commands(); $pipeconfig_object->show_useful_commands();
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment