AnalysisDataAdaptor.pm 1.95 KB
Newer Older
1 2 3 4 5 6 7 8 9
# Perl module for Bio::EnsEMBL::Hive::DBSQL::AnalysisDataAdaptor
#
# Date of creation: 22.03.2004
# Original Creator : Jessica Severin <jessica@ebi.ac.uk>
#
# Copyright EMBL-EBI 2004
#
# You may distribute this module under the same terms as perl itself

10
=pod
11 12

=head1 NAME
13

14 15 16
  Bio::EnsEMBL::Hive::DBSQL::AnalysisDataAdaptor

=head1 SYNOPSIS
17

18 19 20
  $dataDBA = $db_adaptor->get_AnalysisDataAdaptor;

=head1 DESCRIPTION
21

22 23 24 25 26 27
   analysis_data table holds LONGTEXT data for use by the analysis system.
   This data is general purpose and it's up to each analysis to
   determine how to use it.
   This Adaptor module is used to access/store this data.

=head1 CONTACT
28 29

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

=head1 APPENDIX
32

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

=cut



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

use strict;

Leo Gordon's avatar
Leo Gordon committed
44 45
use base ('Bio::EnsEMBL::DBSQL::BaseAdaptor');

46 47 48 49

sub fetch_by_dbID {
  my ($self, $data_id) = @_;

Jessica Severin's avatar
Jessica Severin committed
50
  my $sql = "SELECT data FROM analysis_data WHERE analysis_data_id = ?";
51
  my $sth = $self->prepare($sql);
Jessica Severin's avatar
Jessica Severin committed
52
  $sth->execute($data_id);
53

Jessica Severin's avatar
Jessica Severin committed
54
  my ($data) = $sth->fetchrow_array();
55
  $sth->finish();
Jessica Severin's avatar
Jessica Severin committed
56
  return $data;
57 58 59 60 61 62 63 64 65 66
}

#
# STORE METHODS
#
################

sub store {
  my ($self, $data) = @_;
  
67 68
  return 0 unless($data);
  
Leo Gordon's avatar
a typo  
Leo Gordon committed
69 70
  my $sth = $self->prepare("INSERT INTO analysis_data (data) VALUES (?)");
  $sth->execute($data);
Leo Gordon's avatar
Leo Gordon committed
71
  my $data_id = $self->dbc->db_handle->last_insert_id(undef, undef, 'analysis_data', 'analysis_data_id');
Leo Gordon's avatar
a typo  
Leo Gordon committed
72
  $sth->finish;
73 74 75 76 77 78 79 80 81

  return $data_id;
}


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

82 83 84 85
  return 0 unless($data);

  my $sth = $self->prepare("SELECT analysis_data_id FROM analysis_data WHERE data = ?");
  $sth->execute($data);
Jessica Severin's avatar
Jessica Severin committed
86
  ($data_id) = $sth->fetchrow_array();
87 88 89
  $sth->finish;

  if($data_id) {
Jessica Severin's avatar
Jessica Severin committed
90
    # print("data already stored as id $data_id\n");
91 92 93
    return $data_id;
  }

94
  return $self->store($data);
95 96 97 98 99 100 101 102
}

1;