view release on metacpan or search on metacpan
lib/Bio/DB/BioSQL/AnnotationCollectionAdaptor.pm view on Meta::CPAN
# return type
return $foundanything ?
Bio::DB::Query::PrebuiltResult->new(-objs => [$ac]) :
Bio::DB::Query::PrebuiltResult->new(-objs => []);
}
=head2 remove_children
Title : remove_children
Usage :
Function: This method is to cascade deletes in maintained objects.
We need to undefine the primary keys of all contained
children objects 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().
lib/Bio/DB/BioSQL/AnnotationCollectionAdaptor.pm view on Meta::CPAN
# get the annotation type map
my $annotmap = $self->_supported_annotation_map();
# check annotation for each key
foreach my $annkey ($ac->get_all_annotation_keys()) {
foreach my $ann ($ac->get_Annotations($annkey)) {
if($ann->isa("Bio::DB::PersistentObjectI")) {
# undef the PK if this is a child relationship by FK
my $key = $self->_annotation_map_key($annotmap,$ann);
if($annotmap->{$key}->{"link"} eq "child") {
$ann->primary_key(undef);
# cascade through in case the object needs it
$ann->adaptor->remove_children($ann);
}
}
}
}
# done
return 1;
}
=head1 Internal Methods
lib/Bio/DB/BioSQL/BaseDriver.pm view on Meta::CPAN
}
}
my $ifnull = $adp->dbcontext->dbi->ifnull_sqlfunc();
my $sql = "UPDATE $table SET " .
join(", ", map {"$_ = $ifnull\(?,$_\)";} @attrs) .
" WHERE " . $self->primary_key_name($table) . " = ?";
$adp->debug("preparing UPDATE statement: $sql\n");
return $self->prepare($adp->dbh(),$sql);
}
=head2 cascade_delete
Title : cascade_delete
Usage :
Function: Removes all persistent objects dependent from the given persistent
object from the database (foreign key integrity).
This implementation assumes that the underlying schema and RDBMS
support cascading deletes, and hence does nothing other than
returning TRUE.
Example :
Returns : TRUE on success, and FALSE otherwise
Args : The DBContextI implementing object for the database.
The object for which the dependent rows shall be deleted.
Optionally, additional (named) arguments.
=cut
sub cascade_delete{
# our default assumption is that the RDBMS does support cascading deletes
return 1;
}
=head2 insert_object
Title : insert_object
Usage :
Function:
Example :
lib/Bio/DB/BioSQL/BasePersistenceAdaptor.pm view on Meta::CPAN
my $foundobj;
if($self->caching_mode() &&
($foundobj = $self->find_by_unique_key($obj, @args))) {
$obj->primary_key($foundobj->primary_key);
# Should we return right here instead of storing children? Not sure.
#
# My take is that we shouldn't store the children for found objects,
# because it essentially would amount to updating dependent
# information, which is inconsistent with the fact that we don't
# update the object itself. So, leave it to the caller to physically
# trigger an update (which will cascade through to the children)
# instead of doing possibly unwanted magic here.
#
$skip_children = 1 unless defined($skip_children);
} else {
# either caching disabled or not found in cache
#
# insert and obtain primary key
my $pk = $self->dbd()->insert_object($self, $obj, \@fkobjs);
# if no primary key, it may be due to a UK violation (provided that
# caching is disabled)
lib/Bio/DB/BioSQL/BasePersistenceAdaptor.pm view on Meta::CPAN
if(! $sth) {
# need to create one
$sth = $self->dbd()->prepare_delete_sth($self, @args);
# and cache
$self->sth($cache_key, $sth);
}
# execute
my ($rv, $rv2);
$self->debug("DELETING ".ref($obj->obj())." object (pk=$pk)\n");
$rv = $sth->execute($pk);
# we may need to cascade in software -- ugly
$rv2 = $self->dbd()->cascade_delete($self->dbcontext(), $obj) if $rv;
# the caller should commit if necessary
#
# take care of the children (do this before undefining the primary key
# as something might have children that need this to locate them)
$rv = $self->remove_children($obj,@args) ? $rv : 0;
# undefine the objects primary key - it doesn't exist in the datastore any
# longer
$obj->primary_key(undef);
# done
return $rv;
lib/Bio/DB/BioSQL/BasePersistenceAdaptor.pm view on Meta::CPAN
=cut
sub attach_children{
return 1;
}
=head2 remove_children
Title : remove_children
Usage :
Function: This method is to cascade deletes in maintained objects.
Child records in the database will usually be cascaded by
the RDBMS. In order to cascade removals to persistent child
objects, you must override this method. Usually you will
need to undefine the primary key of child objects, and
possibly remove them from caches if they are cached.
Because failure to do so may result in serious and often
non-obvious bugs, there is no default provided here. You
*must* override this method in a derived adaptor as
evidence that you know what you are doing, even if all you
do is just return TRUE.
lib/Bio/DB/BioSQL/BioNamespaceAdaptor.pm view on Meta::CPAN
$uk_h->{'namespace'} = $obj->namespace();
}
return $uk_h;
}
=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
lib/Bio/DB/BioSQL/BiosequenceAdaptor.pm view on Meta::CPAN
=cut
sub attach_foreign_key_objects{
return 1;
}
=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
lib/Bio/DB/BioSQL/ClusterAdaptor.pm view on Meta::CPAN
-contexts =>["subject","object",undef]);
}
# done
return $ok;
}
=head2 remove_children
Title : remove_children
Usage :
Function: This method is to cascade deletes in maintained objects.
We need to undefine the primary keys of all contained
annotation objects 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().
lib/Bio/DB/BioSQL/CommentAdaptor.pm view on Meta::CPAN
=cut
sub attach_foreign_key_objects{
return 1;
}
=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
lib/Bio/DB/BioSQL/DBLinkAdaptor.pm view on Meta::CPAN
=cut
sub store_children{
return 1;
}
=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
lib/Bio/DB/BioSQL/LocationAdaptor.pm view on Meta::CPAN
sub store_children{
my ($self,$obj) = @_;
return 1;
}
=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
lib/Bio/DB/BioSQL/OntologyAdaptor.pm view on Meta::CPAN
my @vals = ($obj->name(),
$obj->definition()
);
return \@vals;
}
=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
lib/Bio/DB/BioSQL/Oracle/SpeciesAdaptorDriver.pm view on Meta::CPAN
=head2 prepare_delete_sth
Title : prepare_delete_sth
Usage :
Function: Creates a prepared statement with one placeholder variable
suitable to delete one row from the respective table the
given class maps to.
We override this here in order to delete from the taxon
node table, not the taxon name table. The node table will
cascade to the name table.
Example :
Returns : A DBI statement handle for a prepared statement with one placeholder
Args : The calling adaptor (basically, it needs to implement dbh()).
Optionally, additional arguments.
=cut
sub prepare_delete_sth{
lib/Bio/DB/BioSQL/Pg/SpeciesAdaptorDriver.pm view on Meta::CPAN
=head2 prepare_delete_sth
Title : prepare_delete_sth
Usage :
Function: Creates a prepared statement with one placeholder variable suitable
to delete one row from the respective table the given class maps to.
We override this here in order to delete from the taxon
node table, not the taxon name table. The node table will
cascade to the name table.
Example :
Returns : A DBI statement handle for a prepared statement with one placeholder
Args : The calling adaptor (basically, it needs to implement dbh()).
Optionally, additional arguments.
=cut
sub prepare_delete_sth{
lib/Bio/DB/BioSQL/PrimarySeqAdaptor.pm view on Meta::CPAN
my ($self,$obj) = @_;
# delegate to Biosequence adaptor
return $self->_bioseq_adaptor()->store($obj);
}
=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
lib/Bio/DB/BioSQL/ReferenceAdaptor.pm view on Meta::CPAN
=cut
sub store_children{
return 1;
}
=head2 remove_children
Title : remove_children
Usage :
Function: This method is to cascade deletes in maintained objects.
We just return TRUE here, because the dbxref child is only
virtual.
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().
lib/Bio/DB/BioSQL/RelationshipAdaptor.pm view on Meta::CPAN
$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
lib/Bio/DB/BioSQL/SeqAdaptor.pm view on Meta::CPAN
if($obj && $rows && @$rows && $obj->isa("Bio::Seq::RichSeqI")) {
$obj->division($rows->[6]) if $rows->[6];
}
return $obj;
}
=head2 remove_children
Title : remove_children
Usage :
Function: This method is to cascade deletes in maintained objects.
We need to undefine the primary keys of all contained
feature objects 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{
my $self = shift;
my $obj = shift;
# features
foreach my $feat ($obj->top_SeqFeatures()) {
if($feat->isa("Bio::DB::PersistentObjectI")) {
$feat->primary_key(undef);
# cascade to feature's children
$self->_feat_adaptor->remove_children($feat);
}
}
# annotation collection
my $ac = $obj->annotation();
if($ac->isa("Bio::DB::PersistentObjectI")) {
$ac->primary_key(undef);
$ac->adaptor()->remove_children($ac);
}
# done
lib/Bio/DB/BioSQL/SeqFeatureAdaptor.pm view on Meta::CPAN
# annotation adaptor added everything to the feature transparently
$qres->next_object(); # remove it from the stack, just to be sure
# done
return $ok;
}
=head2 remove_children
Title : remove_children
Usage :
Function: This method is to cascade deletes in maintained objects.
We need to undefine the primary keys of location objects
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().
lib/Bio/DB/BioSQL/SimpleValueAdaptor.pm view on Meta::CPAN
=cut
sub attach_children{
return 1;
}
=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
lib/Bio/DB/BioSQL/SpeciesAdaptor.pm view on Meta::CPAN
$uk_h->{'name_class'} = "scientific name";
}
return $uk_h;
}
=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
lib/Bio/DB/BioSQL/TermAdaptor.pm view on Meta::CPAN
# in bioperl - although they could be)
$ok = $self->get_synonyms($obj) && $ok;
# done
return $ok;
}
=head2 remove_children
Title : remove_children
Usage :
Function: This method is to cascade deletes in maintained objects.
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
lib/Bio/DB/BioSQL/mysql/SpeciesAdaptorDriver.pm view on Meta::CPAN
=head2 prepare_delete_sth
Title : prepare_delete_sth
Usage :
Function: Creates a prepared statement with one placeholder variable suitable
to delete one row from the respective table the given class maps to.
We override this here in order to delete from the taxon
node table, not the taxon name table. The node table will
cascade to the name table.
Example :
Returns : A DBI statement handle for a prepared statement with one placeholder
Args : The calling adaptor (basically, it needs to implement dbh()).
Optionally, additional arguments.
=cut
sub prepare_delete_sth{
lib/Bio/DB/DBD.pm view on Meta::CPAN
=cut
sub prepare_delete_sth{
my ($self,@args) = @_;
$self->throw_not_implemented();
}
=head2 cascade_delete
Title : cascade_delete
Usage :
Function: Removes all persistent objects dependent from the given persistent
object from the database (foreign key integrity).
The method may throw an exception, or the database calls
involved may throw an exception.
If the RDBMS supports cascading deletes, and the schema definition
enabled FK constraints with cascading deletes, then the
implementation won''t need to do anything.
Example :
Returns : TRUE on success, and FALSE otherwise
Args : The DBContextI implementing object for the database.
The object for which the dependent rows shall be deleted.
Optionally, additional (named) arguments.
=cut
sub cascade_delete{
my ($self,@args) = @_;
$self->throw_not_implemented();
}
1;