BioPerl-DB
view release on metacpan or search on metacpan
lib/Bio/DB/BioSQL/RelationshipAdaptor.pm view on Meta::CPAN
$obj_term->foreign_key_slot(ref($self) ."::object");
$pred_term->foreign_key_slot(ref($self) ."::predicate");
# and the ontology FK
$ont = $obj->ontology();
}
$ont = "Bio::Ontology::OntologyI" unless $ont;
$subj_term = "Bio::Ontology::TermI::subject" unless $subj_term;
$pred_term = "Bio::Ontology::TermI::predicate" unless $pred_term;
$obj_term = "Bio::Ontology::TermI::object" unless $obj_term;
return ($subj_term,$pred_term,$obj_term,$ont);
}
=head2 attach_foreign_key_objects
Title : attach_foreign_key_objects
Usage :
Function: Attaches foreign key objects to the given object as far as
necessary.
This method is called after find_by_XXX() queries, not for INSERTs
or UPDATEs.
Example :
Returns : TRUE on success, and FALSE otherwise.
Args : The object to which to attach foreign key objects.
A reference to an array of foreign key values, in the order of
foreign keys returned by get_foreign_key_objects().
=cut
sub attach_foreign_key_objects{
my ($self,$obj,$fks) = @_;
my $ok = 1;
if($fks && @$fks) {
# we expect to find 4 foreign keys: subject, predicate, object, and
# namespace (ontology)
my $i = 0;
foreach my $meth ("subject_term", "predicate_term", "object_term") {
next unless $fks->[$i]; # this actually always be defined
my $term = $self->_term_adaptor->find_by_primary_key($fks->[$i]);
$ok = defined($term) && $ok;
$obj->$meth($term) if $term;
$i++;
}
# foreign key to ontology
if($fks->[$i]) {
my $ont = $self->_ont_adaptor->find_by_primary_key($fks->[$i]);
$ok = defined($ont) && $ok;
$obj->ontology($ont) if $ont;
}
}
return $ok;
}
=head2 remove_children
Title : remove_children
Usage :
Function: This method is to cascade deletes in maintained objects.
We just return TRUE here.
Example :
Returns : TRUE on success and FALSE otherwise
Args : The persistent object that was just removed from the database.
Additional (named) parameter, as passed to remove().
=cut
sub remove_children{
return 1;
}
=head2 instantiate_from_row
Title : instantiate_from_row
Usage :
Function: Instantiates the class this object is an adaptor for, and populates
it with values from columns of the row.
This implementation call populate_from_row() to do the real job.
Example :
Returns : An object, or undef, if the row contains no values
Args : A reference to an array of column values. The first column is the
primary key, the other columns are expected to be in the order
returned by get_persistent_slots().
Optionally, the object factory to be used for instantiating the
proper class. The adaptor must be able to instantiate a default
class if this value is undef.
=cut
sub instantiate_from_row{
my ($self,$row,$fact) = @_;
my $obj;
if($row && @$row) {
if($fact) {
$obj = $fact->create_object();
} else {
$obj = Bio::Ontology::Relationship->new();
}
$self->populate_from_row($obj, $row);
}
return $obj;
}
=head2 populate_from_row
Title : populate_from_row
Usage :
Function: Instantiates the class this object is an adaptor for, and populates
it with values from columns of the row.
Example :
Returns : An object, or undef, if the row contains no values
Args : The object to be populated.
( run in 0.666 second using v1.01-cache-2.11-cpan-364913b4093 )