Bio-MAGETAB

 view release on metacpan or  search on metacpan

lib/Bio/MAGETAB/Util/Persistence.pm  view on Meta::CPAN

        'Bio::MAGETAB::SDRFRow' => {
            bases  => [ 'Bio::MAGETAB::BaseClass' ],
            fields => {
                int   => [ qw( rowNumber ) ],
                array => { nodes        => 'Bio::MAGETAB::Node',
                           factorValues => 'Bio::MAGETAB::FactorValue', },
                ref   => [ qw( channel ) ],
            },
        },

        'Bio::MAGETAB::Sample' => {
            bases => [ 'Bio::MAGETAB::Material' ],
            table => 'Bio_MAGETAB_Material',
        },

        'Bio::MAGETAB::Source' => {
            bases  => [ 'Bio::MAGETAB::Material' ],
            table  => 'Bio_MAGETAB_Material',
            fields => {
                array  => { providers => 'Bio::MAGETAB::Contact' },
            },
        },

        'Bio::MAGETAB::TermSource' => {
            bases  => [ 'Bio::MAGETAB::BaseClass' ],
            fields => {
                string => [ qw( name
                                uri
                                version ) ],
            },
        },
    ],

    # Instantiation of persistent objects in the database needs to
    # circumvent the Moose type constraints during any
    # Tangram::Storage->select( $remote, $filter ) calls. This just
    # returns a blessed hashref; the final objects still obey the
    # original constraints, however.
    make_object => sub { my $class = shift; return bless {}, $class },

    };
}

has 'config'   => ( is       => 'rw',
                    isa      => HashRef,
                    required => 1,
                    default  => \&class_config, );

# We delegate quite a lot to the associated Tangram::Storage
# instance. We could delegate even more, although tests should then be
# written to ensure the delegated calls are functioning correctly.
has 'store'    => ( is       => 'rw',
                    isa      => 'Tangram::Storage',
                    handles  => [qw( insert
                                     select
                                     update
                                     erase
                                     id
                                     count
                                     sum
                                     cursor
                                     remote )] );

has 'dbparams' => ( is         => 'ro',
                    isa        => ArrayRef,
                    required   => 1,
                    auto_deref => 1, );

sub BUILD {

    my ( $self, $params ) = @_;

    unless ( defined $params->{ 'dbparams' }[0] ) {
        croak("Error: Database DSN must be specified.\n");
    }
}

sub deploy {

    my ( $self ) = @_;

    my $dbh = DBI->connect( $self->get_dbparams() );

    Tangram::Relational->deploy( $self->get_schema(), $dbh );

    $dbh->disconnect();

    return;
}

sub get_schema {

    my ( $self ) = @_;

    return Tangram::Relational->schema( $self->get_config() );
}

sub connect {

    my ( $self ) = @_;

    my $store = Tangram::Relational->connect( $self->get_schema(), $self->get_dbparams() );

    $self->set_store( $store );

    return;
}

# Make the classes immutable. In theory this speeds up object
# instantiation for a small compilation time cost.
__PACKAGE__->meta->make_immutable();

no Moose;

=head1 NAME

Bio::MAGETAB::Util::Persistence - A Tangram-based object persistence
class for MAGE-TAB.

=head1 SYNOPSIS

lib/Bio/MAGETAB/Util/Persistence.pm  view on Meta::CPAN

the Tangram modules.

=head1 ATTRIBUTES

=over 2

=item dbparams

A reference to an array containing database connection
parameters. This array is passed directly to C<DBI-E<gt>connect()>.

=item config

The Tangram schema definition used to create the database. This
attribute is read-only.

=item store

The underlying Tangram::Storage object used for most of the
interaction with the database.

=back

=head1 METHODS

=over 2

=item deploy

Connect to the database and deploy the schema. This only needs to be
done once to set up the database.

=item connect

Connect to the database. This must be done before using any of the
following methods.

=item get_schema

Returns the Tangram::Schema object created using the config attribute.

=item class_config

A class method which returns the config hash reference used to create
the Tangram::Schema object.

=item insert

=item select

=item update

=item erase

=item id

=item count

=item sum

=item cursor

=item remote

All these methods are delegated directly to the Tangram::Storage
object created by the C<connect> method, and contained within the
Persistence object. Please see the Tangram documentation for more
information on these methods.

=back

=head1 SEE ALSO

L<Bio::MAGETAB::DBLoader>
L<http://tangram.utsl.gen.nz/>

=head1 AUTHOR

Tim F. Rayner <tfrayner@gmail.com>

=head1 LICENSE

This library is released under version 2 of the GNU General Public
License (GPL).

=cut

1;



( run in 2.802 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )