3 # BioPerl module for Bio::DB::BioSQL::Oracle::TermAdaptorDriver
5 # Please direct questions and support issues to <bioperl-l@bioperl.org>
7 # Cared for by Hilmar Lapp <hlapp at gmx.net>
9 # Copyright Hilmar Lapp
13 # (c) Hilmar Lapp, hlapp at gmx.net, 2003.
14 # (c) GNF, Genomics Institute of the Novartis Research Foundation, 2003.
16 # You may distribute this module under the same terms as perl itself.
17 # Refer to the Perl Artistic License (see the license accompanying this
18 # software package, or see http://www.perl.com/language/misc/Artistic.html)
19 # for the terms under which you may use, modify, and redistribute this module.
21 # THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
22 # WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
23 # MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
26 # POD documentation - main docs before the code
30 Bio::DB::BioSQL::Oracle::TermAdaptorDriver - DESCRIPTION of Object
34 Give standard usage here
38 Describe the object here
44 User feedback is an integral part of the evolution of this and other
45 Bioperl modules. Send your comments and suggestions preferably to
46 the Bioperl mailing list. Your participation is much appreciated.
48 bioperl-l@bioperl.org - General discussion
49 http://bioperl.org/wiki/Mailing_lists - About the mailing lists
53 Please direct usage questions or support issues to the mailing list:
55 I<bioperl-l@bioperl.org>
57 rather than to the module maintainer directly. Many experienced and
58 reponsive experts will be able look at the problem and quickly
59 address it. Please include a thorough description of the problem
60 with code and data examples if at all possible.
64 Report bugs to the Bioperl bug tracking system to help us keep track
65 of the bugs and their resolution. Bug reports can be submitted via
68 http://redmine.open-bio.org/projects/bioperl/
70 =head1 AUTHOR - Hilmar Lapp
72 Email hlapp at gmx.net
76 Additional contributors names and emails here
80 The rest of the documentation details each of the object methods.
81 Internal methods are usually preceded with a _
86 # Let the code begin...
89 package Bio
::DB
::BioSQL
::Oracle
::TermAdaptorDriver
;
93 use Bio::DB::BioSQL::Oracle::BasePersistenceAdaptorDriver;
95 @ISA = qw(Bio::DB::BioSQL::Oracle::BasePersistenceAdaptorDriver);
98 =head2 remove_synonyms
100 Title : remove_synonyms
102 Function: Removes all synonyms for an ontology term.
104 Returns : TRUE on success, and FALSE otherwise.
105 Args : The calling persistence adaptor.
107 The persistent term object for which to remove the synonyms
108 (a Bio::DB::PersistentObjectI compliant object with defined
115 my ($self,$adp,$obj) = @_;
117 # delete statement cached?
118 my $cachekey = "DELETE SYNONYMS";
119 my $sth = $adp->sth($cachekey);
120 # if not we need to build it
122 # we need table name and foreign key
123 my $table = $self->table_name("TermSynonym");
124 my $fkname = $self->foreign_key_name($obj->obj);
125 # build, prepare, and cache the SQL statement
126 $sth = $self->_build_sth($adp, $cachekey,
127 "DELETE FROM $table WHERE $fkname = ?");
129 # bind parameters and execute insert
130 my $dbgmsg = "executing with values (".
131 $obj->primary_key().") (FK to ".ref($obj->obj).")";
132 $adp->debug("$cachekey: $dbgmsg\n");
133 my $rv = $sth->execute($obj->primary_key());
135 $self->warn("failed to remove term synonyms (".ref($adp)
136 .") with values (".$obj->primary_key()
137 .") (FK to ".ref($obj->obj)."):\n".$sth->errstr());
144 Title : store_synonym
146 Function: Stores a synonym for an ontology term.
148 Returns : TRUE on success, and FALSE otherwise.
149 Args : The calling persistence adaptor.
151 The persistent term object for which to store the synonym
152 (a Bio::DB::PersistentObjectI compliant object with defined
155 The synonym to store (a scalar).
161 my ($self,$adp,$obj,$syn) = @_;
163 # insert and look-up statements cached?
164 my $icachekey = "INSERT SYNONYM";
165 my $isth = $adp->sth($icachekey);
166 # if not we need to build them
168 # we need table name, foreign key, and slot map
169 my $table = $self->table_name("TermSynonym");
170 my $fkname = $self->foreign_key_name($obj->obj);
171 my $colmap = $self->slot_attribute_map($table);
172 # build, prepare, and cache the SQL statements
173 $isth = $self->_build_sth($adp, $icachekey,
174 "INSERT INTO $table (".
175 join(", ", $colmap->{'synonym'}, $fkname).
178 # bind parameters and execute insert
179 my $dbgmsg = "executing with values ($syn, ".
180 $obj->primary_key().") (synonym, FK to ".ref($obj->obj).")";
181 $adp->debug("$icachekey: $dbgmsg\n");
182 my $rv = $isth->execute($syn, $obj->primary_key());
184 # this might be a UK failure, not a bad statement error
185 if (index($isth->errstr(), "ORA-00001") >= 0) {
186 # we actually don't need to execute a look-up here because the
187 # synonym is not an object and hence has no primary key itself
188 $rv = "0E0"; # evaluates to TRUE, but numerically equals zero
190 $self->warn("failed to store term synonym (".ref($adp)
191 .") with values ($syn) (FK ".$obj->primary_key()
192 ." to ".ref($obj->obj)."):\n"
200 my ($self,$adp,$cachekey,$sql) = @_;
202 $adp->debug("$cachekey: preparing: $sql\n");
203 my $sth = $adp->dbh->prepare($sql);
204 $self->throw("failed to prepare \"$sql\": ".$adp->dbh->errstr)
206 $adp->sth($cachekey,$sth);
214 Function: Retrieves the synonyms for an ontology term and adds them
217 Returns : TRUE on success, and FALSE otherwise.
218 Args : The calling persistence adaptor.
220 The persistent term object for which to retrieve the
221 synonyms (a Bio::DB::PersistentObjectI compliant object
222 with defined primary key).
228 my ($self,$adp,$obj) = @_;
230 # look-up statement cached?
231 my $cachekey = "SELECT SYNONYMS";
232 my $sth = $adp->sth($cachekey);
233 # if not we need to build it
235 # we need table name, foreign key, and slot map
236 my $table = $self->table_name("TermSynonym");
237 my $fkname = $self->foreign_key_name($obj->obj);
238 my $colmap = $self->slot_attribute_map($table);
239 # build, prepare, and cache the SQL statement
240 $sth = $self->_build_sth($adp, $cachekey,
241 "SELECT ".$colmap->{'synonym'}.
242 " FROM $table WHERE $fkname = ?");
244 # bind parameters and execute select
245 my $dbgmsg = "executing with values (".
246 $obj->primary_key().") (FK to ".ref($obj->obj).")";
247 $adp->debug("$cachekey: $dbgmsg\n");
248 my $rv = $sth->execute($obj->primary_key());
249 $self->warn("failed to execute $cachekey: ".$sth->errstr) unless $rv;
250 while(my $row = $sth->fetchrow_arrayref()) {
251 $obj->add_synonym($row->[0]);
260 Function: Binds a parameter value to a prepared statement.
262 We override this in order to possibly truncate term
263 definitions longer than 4000 characters, the limit of
264 Oracle's VARCHAR2 data type. Note that this problem does
265 not exist with Pg's and mysql's text types.
268 Returns : the return value of the DBI::bind_param() call
269 Args : the DBI statement handle to bind to
270 the index of the column (1-based)
272 additional arguments to be passed to the sth->bind_param call
278 my ($self,$sth,$i,$val,@bindargs) = @_;
280 # definition is the 3rd value to bind
281 if (($i == 3) && defined($val) && (length($val) > 4000)) {
282 $self->warn("term definition is "
283 .length($val)." chars long, need to truncate to 4000");
284 $val = substr($val,0,4000);
286 return $self->SUPER::bind_param
($sth,$i,$val,@bindargs);