NakedTable.pm 2.31 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
=pod 

=head1 NAME

  Bio::EnsEMBL::Hive::NakedTable

=head1 SYNOPSIS

=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.

=head1 CONTACT

  Please contact ehive-users@ebi.ac.uk mailing list with questions/suggestions.

=cut

package Bio::EnsEMBL::Hive::NakedTable;

use strict;
23 24
use Scalar::Util ('weaken');

25
use Bio::EnsEMBL::Utils::Argument ('rearrange');
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41

sub new {
    my $class = shift @_;

    my $self = bless {}, $class;

    my ($adaptor, $table_name, $insertion_method) = 
         rearrange([qw(adaptor table_name insertion_method) ], @_);

    $self->adaptor($adaptor)                    if(defined($adaptor));
    $self->table_name($table_name)              if(defined($table_name));
    $self->insertion_method($insertion_method)  if(defined($insertion_method));

    return $self;
}

42

43 44 45 46 47
sub adaptor {
    my $self = shift @_;

    if(@_) {
        $self->{'_adaptor'} = shift @_;
48
        weaken $self->{'_adaptor'};
49
    }
50

51 52 53
    return $self->{'_adaptor'};
}

54

55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
sub table_name {
    my $self = shift @_;

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

sub insertion_method {
    my $self = shift @_;

    if(@_) {
        $self->{'_insertion_method'} = shift @_;
    }
70
    return $self->{'_insertion_method'} || 'INSERT_IGNORE';
71 72 73 74 75 76 77
}

sub url {
    my $self    = shift @_;
    my $ref_dba = shift @_;     # if reference dba is the same as 'our' dba, a shorter url can be generated

    if(my $adaptor = $self->adaptor) {
78
        my $conn_prefix = ($adaptor->db == $ref_dba) ? ':///' : $adaptor->db->dbc->url();
79 80 81 82 83 84 85
        return $conn_prefix .'/'. $self->table_name() . '?insertion_method=' . $self->insertion_method();
    } else {
        return;
    }
}

sub dataflow {
86
    my ( $self, $output_ids ) = @_;
87

88 89 90 91 92 93 94 95
        # 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() );

    $adaptor->store( $output_ids );
96 97 98 99 100
}


1;