<commit_before>=head1 LICENSE

  Copyright (c) 1999-2013 The European Bioinformatics Institute and
  Genome Research Limited.  All rights reserved.

  This software is distributed under a modified Apache license.
  For license details, please see

    http://www.ensembl.org/info/about/code_licence.html

=head1 CONTACT

  Please email comments or questions to the public Ensembl
  developers list at <<EMAIL>>.

  Questions may also be sent to the Ensembl help desk at
  <<EMAIL>>.

=head1 NAME

Bio::EnsEMBL::Compara::DBSQL::BaseFullCacheAdaptor

=head1 DESCRIPTION

This adaptor extends the Compara BaseAdaptor and adds convenient
methods to build a full cache of the data

=head1 APPENDIX

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

=cut


package Bio::EnsEMBL::Compara::DBSQL::BaseFullCacheAdaptor;

use strict;

use base ('Bio::EnsEMBL::Compara::DBSQL::BaseAdaptor');


=head2 _id_cache

  Description: Overwritten from Bio::EnsEMBL::DBSQL::BaseAdaptor.
               [Meaning changed]: Now returns the hash by itself,
               instead of an instance of BaseCache
  Caller     : Bio::EnsEMBL::DBSQL::BaseAdaptor

=cut

sub _id_cache {
    my $self = shift;

    $self->_build_id_cache unless exists $self->{_id_cache};
    return $self->{_id_cache};
}


=head2 _build_id_cache

  Description: Overwritten from Bio::EnsEMBL::DBSQL::BaseAdaptor.
               Returns a new instance of a FullIdCache.
  Caller     : Bio::EnsEMBL::DBSQL::BaseAdaptor

=cut

sub _build_id_cache {
    my $self = shift;

    $self->{_id_cache} = {};
    my $objs = $self->generic_fetch();
    foreach my $obj (@{$objs}) {
        $self->_add_to_cache($obj);
    }

    # If there are tags, load them all
    if ($self->isa('Bio::EnsEMBL::Compara::DBSQL::TagAdaptor')) {
        $self->_load_tagvalues_multiple(-ALL_OBJECTS => 1, @{$objs});
    }
}


=head2 fetch_by_dbID

  Description: Returns the object identified by its dbID
  Caller     : general

=cut

sub fetch_by_dbID {
    my $self = shift;
    my $id = shift;
    return $self->_id_cache->{$id};
}


sub fetch_all_by_dbID_list {
    my $self = shift;
    my $id_list = shift;
    my $_id_cache = $self->_id_cache;
    return [map {$_id_cache->{$_}} @{$id_list}];
}

=head2 fetch_all

  Description: Returns all the objects stored in the cache
  Caller     : general

=cut

sub fetch_all {
    my ($self) = @_;

    return [ values %{ $self->_id_cache() } ];
}


=head2 _add_to_cache

  Description: Adds the entry to the cache
  Caller     : Any derived adaptor (usually, its store() method)

=cut

sub _add_to_cache {
    my ($self, $object) = @_;

    $self->{_id_cache}->{$object->dbID()} = $object;
}


=head2 _remove_from_cache

  Description: Removes an entry from the cache<commit_msg>docfix BaseFullCacheAdaptor.pm<commit_after>=head1 LICENSE

  Copyright (c) 1999-2013 The European Bioinformatics Institute and
  Genome Research Limited.  All rights reserved.

  This software is distributed under a modified Apache license.
  For license details, please see

    http://www.ensembl.org/info/about/code_licence.html

=head1 CONTACT

  Please email comments or questions to the public Ensembl
  developers list at <<EMAIL>>.

  Questions may also be sent to the Ensembl help desk at
  <<EMAIL>>.

=head1 NAME

Bio::EnsEMBL::Compara::DBSQL::BaseFullCacheAdaptor

=head1 DESCRIPTION

This adaptor extends the Compara BaseAdaptor and adds convenient
methods to build a full cache of the data

=head1 APPENDIX

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

=cut


package Bio::EnsEMBL::Compara::DBSQL::BaseFullCacheAdaptor;

use strict;

use base ('Bio::EnsEMBL::Compara::DBSQL::BaseAdaptor');


=head2 _id_cache

  Description: Overwritten from Bio::EnsEMBL::DBSQL::BaseAdaptor.
               [Meaning changed]: Now returns the hash by itself,
               instead of an instance of BaseCache
  Caller     : Bio::EnsEMBL::DBSQL::BaseAdaptor

=cut

sub _id_cache {
    my $self = shift;

    $self->_build_id_cache unless exists $self->{_id_cache};
    return $self->{_id_cache};
}


=head2 _build_id_cache

  Description: Overwritten from Bio::EnsEMBL::DBSQL::BaseAdaptor.
               Returns a new instance of a FullIdCache.
  Caller     : Bio::EnsEMBL::DBSQL::BaseAdaptor

=cut

sub _build_id_cache {
    my $self = shift;

    $self->{_id_cache} = {};
    my $objs = $self->generic_fetch();
    foreach my $obj (@{$objs}) {
        $self->_add_to_cache($obj);
    }

    # If there are tags, load them all
    if ($self->isa('Bio::EnsEMBL::Compara::DBSQL::TagAdaptor')) {
        $self->_load_tagvalues_multiple(-ALL_OBJECTS => 1, @{$objs});
    }
}


=head2 fetch_by_dbID

  Arg [1]    : int $id
               The unique database identifier for the object to be obtained
  Example    : $human_gdb = $genomedb_adpator->fetch_by_dbID(90);
  Description: Returns the object identified by its dbID
  Caller     : general

=cut

sub fetch_by_dbID {
    my $self = shift;
    my $id = shift;
    return $self->_id_cache->{$id};
}


=head2 fetch_all_by_dbID_list

  Arg[1]     : listref of integers $id_list
               The unique database identifiers for the features to be obtained
  Description: Returns an array-ref of all the objects with a matching dbID
  Caller     : general

=cut

sub fetch_all_by_dbID_list {
    my $self = shift;
    my $id_list = shift;
    my $_id_cache = $self->_id_cache;
    return [map {$_id_cache->{$_}} @{$id_list}];
}


=head2 fetch_all

  Description: Returns all the objects from this adaptor
  Caller     : general

=cut

sub fetch_all {
    my ($self) = @_;

    return [ values %{ $self->_id_cache() } ];
}


=head2 _add_to_cache

  Description: Adds the entry to the cache
  Caller     : Any derived adaptor (usually, its store() method)

=cut

sub _add_to_cache {
    my ($self, $object) = @_;

    $self->{_id_cache}->{$object->dbID()} = $object;
}


=head2 _remove_from_cache

  Description: Removes an entry from the cache
{'fraction_non_alphanumeric': 0.1058784785114441, 'fraction_numerical': 0.007409846863164828, 'mean_word_length': 3.492603550295858, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 46, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5625880', 'n_tokens_mistral': 2113, 'n_tokens_neox': 2023, 'n_words': 604}