BioPerl-DB
view release on metacpan or search on metacpan
lib/Bio/DB/BioSQL/BasePersistenceAdaptor.pm view on Meta::CPAN
$self->{'_dbh'} = undef;
}
# reset the cache of statement handles
delete $self->{'_sth'};
# reset the object cache if any
delete $self->{'_obj_cache'} if $self->{'_obj_cache'};
# done
}
=head2 DESTROY
Title : DESTROY
Usage :
Function: We override this here to call finish().
Example :
Returns :
Args :
=cut
sub DESTROY {
my ($self) = @_;
$self->finish();
$self->SUPER::DESTROY();
}
=head1 Abstract Methods
Almost all of the following methods MUST be overridden by a
derived class. For some methods there is an implementation here
that assumes "no action" is the right thing, but for many adaptors
this won't be right. There is no way this base implementation can
make any meaningful guesses at the correct values for those.
=cut
=head2 get_persistent_slots
Title : get_persistent_slots
Usage :
Function: Get the slots of the object that map to attributes in its
respective entity in the datastore.
Slot name generally refers to a method name, but is not
required to do so, since determining the values is under
the control of get_persistent_slot_values().
This is a strictly abstract method. A derived class MUST
override it to return something meaningful.
Example :
Returns : an array of method names constituting the serializable slots
Args : the object about to be inserted or updated
=cut
sub get_persistent_slots{
shift->throw_not_implemented();
}
=head2 get_persistent_slot_values
Title : get_persistent_slot_values
Usage :
Function: Obtain the values for the slots returned by get_persistent_slots(),
in exactly that order.
The reason this method is here is that sometimes the actual
slot values need to be post-processed to yield the value
that gets actually stored in the database. E.g., slots
holding arrays will need some kind of join function
applied. Another example is if the method call needs
additional arguments. Supposedly the adaptor for a specific
interface knows exactly what to do here.
Since there is also populate_from_row() the adaptor has
full control over mapping values to a version that is
actually stored.
This is a strictly abstract method and it MUST be
overridden by a derived class.
Example :
Returns : A reference to an array of values for the persistent slots of this
object. Individual values may be undef.
Args : The object about to be serialized.
A reference to an array of foreign key objects if not retrievable
from the object itself.
=cut
sub get_persistent_slot_values {
my ($self,@args) = @_;
$self->throw_not_implemented();
}
=head2 get_foreign_key_objects
Title : get_foreign_key_objects
Usage :
Function: Gets the objects referenced by this object, and which therefore need
to be referenced as foreign keys in the datastore.
Note that the objects are expected to implement
Bio::DB::PersistentObjectI.
An implementation may obtain the values either through the object
to be serialized, or through the additional arguments. An
implementation should also make sure that the order of foreign key
objects returned is always the same.
Note also that in order to indicate a NULL value for a nullable
foreign key, either put an object returning undef from
primary_key(), or put the name of the class instead. DO NOT SIMPLY
LEAVE IT OUT.
This implementation assumes a default of no foreign keys and returns
an empty array.
Example :
Returns : an array of Bio::DB::PersistentObjectI implementing objects
Args : The object about to be inserted or updated, or undef if the call
is for a SELECT query. In the latter case return class or interface
names that are mapped to the foreign key tables.
Optionally, additional named parameters. A common parameter will
be -fkobjs, with a reference to an array of foreign key objects
that are not retrievable from the persistent object itself.
=cut
sub get_foreign_key_objects{
return ();
}
=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.
This implementation assumes there are no foreign keys that need to
be retrieved and instantiated. You MUST override this method
in order to have foreign key objects taken care of upon SELECTs.
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
lib/Bio/DB/BioSQL/BasePersistenceAdaptor.pm view on Meta::CPAN
sub store_children{
return 1;
}
=head2 attach_children
Title : attach_children
Usage :
Function: Possibly retrieve and attach child objects of the given object.
This is needed when whole object trees are supposed to be built
when a base object is queried for and returned. An example would
be Bio::SeqI objects and all the annotation objects that hang off
of it.
This is called by the find_by_XXXX() methods once the base object
has been built.
This implementation will do nothing unless it is overridden. Whether
to override it or not will depend on which of the children shall be
loaded instantly instead of lazily.
Example :
Returns : TRUE on success, and FALSE otherwise.
Args : The object for which to find and to which to attach the child
objects.
=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.
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{
shift->throw_not_implemented();
}
=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.
Usually a derived class will instantiate the proper class and pass
it on to populate_from_row().
This implementation assumes that the object factory is provided,
uses it to instantiate a new object, and then passes on to
populate_from_row(). If this is not appropriate the method must be
overridden by a derived object.
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) {
$self->throw("No object factory provided. Override this method ".
"in ".ref($self).
" if you know a good default way to go.");
}
$obj = $fact->create_object();
$self->populate_from_row($obj, $row);
}
return $obj;
}
=head2 populate_from_row
Title : populate_from_row
Usage :
Function: Populates the given object with values from columns of the row.
This method is strictly abstract and MUST be overridden by a
derived object.
Example :
Returns : The object populated, or undef, if the row contains no values
Args : The object to be populated.
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().
=cut
sub populate_from_row{
my ($self,@args) = @_;
$self->throw_not_implemented();
}
=head2 get_unique_key_query
Title : get_unique_key_query
Usage :
Function: Obtain the suitable unique key slots and values as
determined by the attribute values of the given object and
the additional foreign key objects, in case foreign keys
participate in a UK.
This method embodies the knowledge about which properties
constitute the alternative keys for an object (entity) and
how to obtain the values of those properties from the
object. Therefore, unless there is no alternative key for
an entity, the respective (derived) adaptor must override
this method.
If there are multiple alternative keys for an entity, the
overriding implementation may choose to determine at
runtime the best alternative key given the object and then
return only a single alternative key, or it may choose to
return an array of (supposedly equally suitable)
alternative keys. Note that if every alternative key
returned will be searched for until a match is found
(short-cut evaluation), so returning partially populated
alternative keys is usually not wise.
This implementation assumes there are no unique keys
defined for the entity adapted by this class and hence
returns an empty hash ref. Instead of overriding this
method a derived class may choose to override
find_by_unique_key() instead, as that one calls this
method.
See the documentation of find_by_unique_key() for further
information on what the return value is used for and what
the implications are.
Example :
Returns : One or more references to hash(es) where each hash
represents one unique key, and the keys of each hash
represent the names of the object's slots that are part of
the particular unique key and their values are the values
of those slots as suitable for the key.
Args : The object with those attributes set that constitute the chosen
unique key (note that the class of the object will be suitable for
the adaptor).
A reference to an array of foreign key objects if not retrievable
from the object itself.
=cut
sub get_unique_key_query{
return {};
}
1;
( run in 0.738 second using v1.01-cache-2.11-cpan-39bf76dae61 )