Commit 9e93c173 authored by Leo Gordon's avatar Leo Gordon
Browse files

store() now only has 1 argument, checks moved into store_or_update_one()

parent 8fa361aa
......@@ -53,9 +53,11 @@ sub default_table_name {
sub store_if_needed {
my ($self, $data) = @_;
my ($stored_hash) = $self->store({'data'=> $data}, 1);
my $storable_hash = {'data'=> $data};
return '_extended_data_id ' . $stored_hash->{'analysis_data_id'};
$self->store_or_update_one( $storable_hash );
return '_extended_data_id ' . $storable_hash->{'analysis_data_id'};
}
1;
......@@ -96,7 +96,7 @@ sub store_jobs_and_adjust_counters {
# avoid deadlocks when dataflowing under transactional mode (used in Ortheus Runnable for example):
$dbc->do( "SELECT 1 FROM job WHERE job_id=$semaphored_job_id FOR UPDATE" ) if($need_to_increase_semaphore_count and ($dbc->driver ne 'sqlite'));
my ($job, $stored_this_time) = $self->store( $job, 0 );
my ($job, $stored_this_time) = $self->store( $job );
if($stored_this_time) {
if($need_to_increase_semaphore_count) { # if we are not creating a new semaphore (where dependent jobs have already been counted),
......
......@@ -235,7 +235,7 @@ sub _table_info_loader {
if( $is_ai # careful! This is only supported by DBD::mysql and will not work with other drivers
or ($column_name eq $table_name.'_id')
or ($table_name eq 'analysis_base' and $column_name eq 'analysis_id') ) { # a special case (historical)
$autoinc_id = $column_name; # careful! This is only supported by DBD::mysql and will not work with other drivers
$autoinc_id = $column_name;
}
}
$sth->finish;
......@@ -396,6 +396,23 @@ sub update { # update (some or all) non_primary columns from the primary
$sth->finish();
}
sub store_or_update_one {
my ($self, $object) = @_;
if(UNIVERSAL::can($object, 'adaptor') and $object->adaptor and $object->adaptor==$self) { # looks like it has been previously stored
if(@{ $self->primary_key() }) { # updatable ?
$self->update( $object );
# warn "store_or_update_one: updated [".$object->toString."]\n";
}
} elsif( my $present = $self->check_object_present_in_db( $object ) ) {
$self->mark_stored($object, $present);
# warn "store_or_update_one: found [".$object->toString."] in db by content\n";
} else {
$self->store( $object );
# warn "store_or_update_one: stored [".$object->toString."]\n";
}
}
sub check_object_present_in_db { # return autoinc_id/undef if the table has autoinc_id or just 1/undef if not
my ( $self, $object ) = @_;
......@@ -422,7 +439,7 @@ sub check_object_present_in_db { # return autoinc_id/undef if the table has a
sub store {
my ($self, $object_or_list, $check_presence_in_db_first) = @_;
my ($self, $object_or_list) = @_;
my $objects = (ref($object_or_list) eq 'ARRAY') # ensure we get an array of objects to store
? $object_or_list
......@@ -446,9 +463,6 @@ sub store {
my $stored_this_time = 0;
foreach my $object (@$objects) {
if($check_presence_in_db_first and my $present = $self->check_object_present_in_db($object)) {
$self->mark_stored($object, $present);
} else {
my ($columns_being_stored, $column_key) = (ref($object) eq 'HASH') ? $self->keys_to_columns($object) : ($all_storable_columns, '*all*');
# warn "COLUMN_KEY='$column_key'\n";
......@@ -474,7 +488,6 @@ sub store {
$self->mark_stored($object, $liid );
++$stored_this_time;
}
}
}
foreach my $sth (values %hashed_sth) {
......
......@@ -727,21 +727,15 @@ sub run {
my $dataflow_rule_adaptor = $hive_dba->get_DataflowRuleAdaptor;
foreach my $resource_class ( $all_rc_coll->list ) {
unless( $resource_class->adaptor ) {
$resource_class_adaptor->store( $resource_class );
}
foreach my $resource_description ( $all_rd_coll->find_all_by('resource_class', $resource_class) ) { # code is simplified due to 'REPLACE' mode of the adaptor (NB: not portable!)
$resource_description_adaptor->store( $resource_description );
$resource_class_adaptor->store_or_update_one( $resource_class );
foreach my $resource_description (@{ $all_rd_coll->find_all_by('resource_class', $resource_class) }) {
$resource_description_adaptor->store_or_update_one( $resource_description );
}
}
foreach my $analysis ( $all_analyses_coll->list ) {
my $stats = $analysis->stats; # should be taking the value cached previously
unless( $analysis->adaptor ) { # TODO: check a more thorough condition if moving analyses around, etc
$analysis_adaptor->store( $analysis );
$analysis_stats_adaptor->store( $stats );
}
$analysis_adaptor->store_or_update_one( $analysis );
$analysis_stats_adaptor->store_or_update_one( $analysis->stats ); # should be taking the value cached previously
if(my $our_jobs = $analysis->jobs_collection ) {
$job_adaptor->store_jobs_and_adjust_counters( $our_jobs );
......@@ -751,11 +745,11 @@ sub run {
foreach my $analysis ( $all_analyses_coll->list ) {
foreach my $c_rule (@{ $analysis->control_rules_collection }) {
$ctrl_rule_adaptor->store( $c_rule, 1 );
$ctrl_rule_adaptor->store_or_update_one( $c_rule );
warn $c_rule->toString."\n";
}
foreach my $df_rule (@{ $analysis->dataflow_rules_collection }) {
$dataflow_rule_adaptor->store( $df_rule, 1 );
$dataflow_rule_adaptor->store_or_update_one( $df_rule );
warn $df_rule->toString."\n";
}
}
......
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