Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

file 289 lines (224 sloc) 8.583 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289
# $Id$
#
# BioPerl module for Bio::DB::BioSQL::Oracle::TermAdaptorDriver
#
# Please direct questions and support issues to <bioperl-l@bioperl.org>
#
# Cared for by Hilmar Lapp <hlapp at gmx.net>
#
# Copyright Hilmar Lapp
#

#
# (c) Hilmar Lapp, hlapp at gmx.net, 2003.
# (c) GNF, Genomics Institute of the Novartis Research Foundation, 2003.
#
# You may distribute this module under the same terms as perl itself.
# Refer to the Perl Artistic License (see the license accompanying this
# software package, or see http://www.perl.com/language/misc/Artistic.html)
# for the terms under which you may use, modify, and redistribute this module.
#
# THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
# WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
# MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
#

# POD documentation - main docs before the code

=head1 NAME

Bio::DB::BioSQL::Oracle::TermAdaptorDriver - DESCRIPTION of Object

=head1 SYNOPSIS

Give standard usage here

=head1 DESCRIPTION

Describe the object here

=head1 FEEDBACK

=head2 Mailing Lists

User feedback is an integral part of the evolution of this and other
Bioperl modules. Send your comments and suggestions preferably to
the Bioperl mailing list. Your participation is much appreciated.

bioperl-l@bioperl.org - General discussion
http://bioperl.org/wiki/Mailing_lists - About the mailing lists

=head2 Support
Please direct usage questions or support issues to the mailing list:
L<bioperl-l@bioperl.org>
rather than to the module maintainer directly. Many experienced and
reponsive experts will be able look at the problem and quickly
address it. Please include a thorough description of the problem
with code and data examples if at all possible.

=head2 Reporting Bugs

Report bugs to the Bioperl bug tracking system to help us keep track
of the bugs and their resolution. Bug reports can be submitted via
the web:

http://bugzilla.open-bio.org/

=head1 AUTHOR - Hilmar Lapp

Email hlapp at gmx.net

=head1 CONTRIBUTORS

Additional contributors names and emails here

=head1 APPENDIX

The rest of the documentation details each of the object methods.
Internal methods are usually preceded with a _

=cut


# Let the code begin...


package Bio::DB::BioSQL::Oracle::TermAdaptorDriver;
use vars qw(@ISA);
use strict;

use Bio::DB::BioSQL::Oracle::BasePersistenceAdaptorDriver;

@ISA = qw(Bio::DB::BioSQL::Oracle::BasePersistenceAdaptorDriver);


=head2 remove_synonyms

Title : remove_synonyms
Usage :
Function: Removes all synonyms for an ontology term.
Example :
Returns : TRUE on success, and FALSE otherwise.
Args : The calling persistence adaptor.

The persistent term object for which to remove the synonyms
(a Bio::DB::PersistentObjectI compliant object with defined
primary key).


=cut

sub remove_synonyms{
    my ($self,$adp,$obj) = @_;

    # delete statement cached?
    my $cachekey = "DELETE SYNONYMS";
    my $sth = $adp->sth($cachekey);
    # if not we need to build it
    if(! $sth) {
# we need table name and foreign key
my $table = $self->table_name("TermSynonym");
my $fkname = $self->foreign_key_name($obj->obj);
# build, prepare, and cache the SQL statement
$sth = $self->_build_sth($adp, $cachekey,
                                 "DELETE FROM $table WHERE $fkname = ?");
    }
    # bind parameters and execute insert
    my $dbgmsg = "executing with values (".
$obj->primary_key().") (FK to ".ref($obj->obj).")";
    $adp->debug("$cachekey: $dbgmsg\n");
    my $rv = $sth->execute($obj->primary_key());
    if(! $rv) {
        $self->warn("failed to remove term synonyms (".ref($adp)
                    .") with values (".$obj->primary_key()
                    .") (FK to ".ref($obj->obj)."):\n".$sth->errstr());
    }
    return $rv;
}

=head2 store_synonym

Title : store_synonym
Usage :
Function: Stores a synonym for an ontology term.
Example :
Returns : TRUE on success, and FALSE otherwise.
Args : The calling persistence adaptor.

The persistent term object for which to store the synonym
(a Bio::DB::PersistentObjectI compliant object with defined
primary key).

The synonym to store (a scalar).


=cut

sub store_synonym{
    my ($self,$adp,$obj,$syn) = @_;

    # insert and look-up statements cached?
    my $icachekey = "INSERT SYNONYM";
    my $isth = $adp->sth($icachekey);
    # if not we need to build them
    if(! $isth) {
# we need table name, foreign key, and slot map
my $table = $self->table_name("TermSynonym");
my $fkname = $self->foreign_key_name($obj->obj);
my $colmap = $self->slot_attribute_map($table);
# build, prepare, and cache the SQL statements
$isth = $self->_build_sth($adp, $icachekey,
"INSERT INTO $table (".
join(", ", $colmap->{'synonym'}, $fkname).
") VALUES (?, ?)");
    }
    # bind parameters and execute insert
    my $dbgmsg = "executing with values ($syn, ".
$obj->primary_key().") (synonym, FK to ".ref($obj->obj).")";
    $adp->debug("$icachekey: $dbgmsg\n");
    my $rv = $isth->execute($syn, $obj->primary_key());
    if(! $rv) {
# this might be a UK failure, not a bad statement error
        if (index($isth->errstr(), "ORA-00001") >= 0) {
            # we actually don't need to execute a look-up here because the
            # synonym is not an object and hence has no primary key itself
            $rv = "0E0"; # evaluates to TRUE, but numerically equals zero
        } else {
            $self->warn("failed to store term synonym (".ref($adp)
                        .") with values ($syn) (FK ".$obj->primary_key()
                        ." to ".ref($obj->obj)."):\n"
                        .$isth->errstr());
        }
    }
    return $rv;
}

sub _build_sth{
    my ($self,$adp,$cachekey,$sql) = @_;
    # prepare and cache
    $adp->debug("$cachekey: preparing: $sql\n");
    my $sth = $adp->dbh->prepare($sql);
    $self->throw("failed to prepare \"$sql\": ".$adp->dbh->errstr)
unless $sth;
    $adp->sth($cachekey,$sth);
    return $sth;
}

=head2 get_synonyms

Title : get_synonyms
Usage :
Function: Retrieves the synonyms for an ontology term and adds them
the term's synonyms.
Example :
Returns : TRUE on success, and FALSE otherwise.
Args : The calling persistence adaptor.

The persistent term object for which to retrieve the
synonyms (a Bio::DB::PersistentObjectI compliant object
with defined primary key).


=cut

sub get_synonyms{
    my ($self,$adp,$obj) = @_;

    # look-up statement cached?
    my $cachekey = "SELECT SYNONYMS";
    my $sth = $adp->sth($cachekey);
    # if not we need to build it
    if(! $sth) {
# we need table name, foreign key, and slot map
my $table = $self->table_name("TermSynonym");
my $fkname = $self->foreign_key_name($obj->obj);
my $colmap = $self->slot_attribute_map($table);
# build, prepare, and cache the SQL statement
$sth = $self->_build_sth($adp, $cachekey,
"SELECT ".$colmap->{'synonym'}.
" FROM $table WHERE $fkname = ?");
    }
    # bind parameters and execute select
    my $dbgmsg = "executing with values (".
$obj->primary_key().") (FK to ".ref($obj->obj).")";
    $adp->debug("$cachekey: $dbgmsg\n");
    my $rv = $sth->execute($obj->primary_key());
    $self->warn("failed to execute $cachekey: ".$sth->errstr) unless $rv;
    while(my $row = $sth->fetchrow_arrayref()) {
$obj->add_synonym($row->[0]);
    }
    return $rv;
}

=head2 bind_param

Title : bind_param
Usage :
Function: Binds a parameter value to a prepared statement.

We override this in order to possibly truncate term
definitions longer than 4000 characters, the limit of
Oracle's VARCHAR2 data type. Note that this problem does
not exist with Pg's and mysql's text types.

Example :
Returns : the return value of the DBI::bind_param() call
Args : the DBI statement handle to bind to
the index of the column (1-based)
the value to bind
additional arguments to be passed to the sth->bind_param call


=cut

sub bind_param{
    my ($self,$sth,$i,$val,@bindargs) = @_;
    
    # definition is the 3rd value to bind
    if (($i == 3) && defined($val) && (length($val) > 4000)) {
        $self->warn("term definition is "
                    .length($val)." chars long, need to truncate to 4000");
        $val = substr($val,0,4000);
    }
    return $self->SUPER::bind_param($sth,$i,$val,@bindargs);
}

1;
Something went wrong with that request. Please try again.