NakedTable.pm 3.05 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11
=pod 

=head1 NAME

  Bio::EnsEMBL::Hive::NakedTable

=head1 DESCRIPTION

    A data container object that links together an adaptor, a table and a preferred insertion method (insert/insert-ignore/replace).
    This object is generated from specially designed datalow URLs.

12 13
=head1 LICENSE

14
    Copyright [1999-2015] Wellcome Trust Sanger Institute and the EMBL-European Bioinformatics Institute
Brandon Walts's avatar
Brandon Walts committed
15
    Copyright [2016-2020] EMBL-European Bioinformatics Institute
16 17 18 19 20 21 22 23 24 25

    Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.
    You may obtain a copy of the License at

         http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software distributed under the License
    is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and limitations under the License.

26 27
=head1 CONTACT

28
  Please subscribe to the Hive mailing list:  http://listserver.ebi.ac.uk/mailman/listinfo/ehive-users  to discuss Hive-related questions or to be notified of our updates
29 30 31

=cut

32

33 34 35
package Bio::EnsEMBL::Hive::NakedTable;

use strict;
36
use warnings;
37

38
use base ( 'Bio::EnsEMBL::Hive::Storable' );
39

40

41 42 43 44 45 46 47 48 49
sub table_name {
    my $self = shift @_;

    if(@_) {
        $self->{'_table_name'} = shift @_;
    }
    return $self->{'_table_name'};
}

50

51 52 53 54 55 56
sub insertion_method {
    my $self = shift @_;

    if(@_) {
        $self->{'_insertion_method'} = shift @_;
    }
57
    return $self->{'_insertion_method'} || 'INSERT_IGNORE';
58 59
}

60

61
sub url {
62
    my ($self, $ref_dba) = @_;  # if reference dba is the same as 'my' dba, a shorter url is generated
63

64 65
    my $my_dba = $self->adaptor && $self->adaptor->db;
    return ( ($my_dba and $my_dba ne ($ref_dba//'') ) ? $my_dba->dbc->url : ':///' )
66 67 68 69 70
        . '/' . $self->table_name . '?insertion_method=' . $self->insertion_method;
}


sub display_name {
71
    my ($self, $ref_dba) = @_;  # if reference dba is the same as 'my' dba, a shorter display_name is generated
72

73 74
    my $my_dba = $self->adaptor && $self->adaptor->db;
    return ( ($my_dba and $my_dba ne ($ref_dba//'') ) ? $my_dba->dbc->dbname.'/' : '') . $self->table_name;
75 76
}

77

78
sub dataflow {
79
    my ( $self, $output_ids, $emitting_job ) = @_;
80

81 82 83 84 85 86 87
        # we have to do this the ugly way
        # because Registry code currently prevents us from passing arguments to adaptors' new() methods
        # (and by caching guarantees there is only one instance of each adaptor per DBAdaptor)
    my $adaptor = $self->adaptor();
    $adaptor->table_name( $self->table_name() );
    $adaptor->insertion_method( $self->insertion_method() );

88 89 90 91 92 93 94 95 96 97 98
    my @column_names = keys %{$self->adaptor->column_set};
    my @rows = ();

    foreach my $output_id (@$output_ids) {
        my %row_hash = ();
        foreach my $column (@column_names) {
            $row_hash{ $column } = $emitting_job->_param_possibly_overridden($column, $output_id);
        }
        push @rows, \%row_hash;
    }
    $adaptor->store( \@rows );
99 100 101 102
}

1;