AnalysisDataAdaptor.pm 3.12 KB
Newer Older
1
=pod
2 3

=head1 NAME
4

5
    Bio::EnsEMBL::Hive::DBSQL::AnalysisDataAdaptor
6 7

=head1 SYNOPSIS
8

9
    $dataDBA = $db_adaptor->get_AnalysisDataAdaptor;
10 11

=head1 DESCRIPTION
12

13 14 15 16 17
   analysis_data table holds LONGTEXT data that is currently used as an extension of some fixed-width fields of 'job' table.
   It is no longer general-purpose. Please avoid accessing this table directly or via the adaptor.

=head1 LICENSE

18
    Copyright [1999-2015] Wellcome Trust Sanger Institute and the EMBL-European Bioinformatics Institute
nwillhoft's avatar
nwillhoft committed
19
    Copyright [2016-2021] EMBL-European Bioinformatics Institute
20 21 22 23 24 25 26 27 28

    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.
29 30

=head1 CONTACT
31

32
    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
33 34

=head1 APPENDIX
35

36 37
    The rest of the documentation details each of the object methods.
    Internal methods are preceded with a _
38 39 40 41

=cut


Jessica Severin's avatar
Jessica Severin committed
42
package Bio::EnsEMBL::Hive::DBSQL::AnalysisDataAdaptor;
43 44

use strict;
45
use warnings;
46

47 48
use Digest::MD5 qw(md5_hex);

49
use base ('Bio::EnsEMBL::Hive::DBSQL::NakedTableAdaptor');
Leo Gordon's avatar
Leo Gordon committed
50

51

52 53
sub default_table_name {
    return 'analysis_data';
54 55
}

56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
=head2 fetch_by_data_to_analysis_data_id

  Arg [1]    : String $input_id
  Example    : $ext_data_id = $analysis_data_adaptor->fetch_by_data_to_analysis_data_id( $input_id );
  Description: Attempts to find an entry in the analysis_data table by its content (data + MD5 checksum)
  Returntype : Integer (dbID of the analysis_data table)

=cut

sub fetch_by_data_to_analysis_data_id {     # It is a special case not covered by AUTOLOAD; note the lowercase _to_
    my ($self, $input_id) = @_;

    my $md5sum = md5_hex($input_id);
    return $self->fetch_by_data_AND_md5sum_TO_analysis_data_id($input_id, $md5sum);
}

72 73

sub store_if_needed {
74
    my ($self, $data) = @_;
75

76
    my $storable_hash = {'data' => $data, 'md5sum' => md5_hex($data)};
77

78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
    $self->store( $storable_hash );

    # We now need to check for collisions ourselves since there is no
    # UNIQUE KEY in the table definition.
    # This is very similar to check_object_present_in_db_by_content()
    # but it returns the *first* analysis_data_id that's been stored
    my $sql = 'SELECT MIN(analysis_data_id) FROM analysis_data WHERE md5sum = ? AND data = ?';
    my $sth = $self->prepare( $sql );
    $sth->execute( $storable_hash->{md5sum}, $data );
    my ($first_dbID) = $sth->fetchrow_array();
    $sth->finish;
    if ($first_dbID != $storable_hash->{analysis_data_id}) {
        # Our row duplicates a previous one, so we need to clean up
        $self->remove($storable_hash);
    }
    return '_extended_data_id ' . $first_dbID;
94 95 96
}

1;