Bio-MAGETAB

 view release on metacpan or  search on metacpan

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

 });
 
 my $db = Bio::MAGETAB::Util::Persistence->new({
     dbparams => ["dbi:SQLite:$db_file"],
 });
 
 # If this is a new database, deploy the schema.
 unless ( -e $db_file ) {
     $db->deploy();
 }
 
 # Connect to the database.
 $db->connect();
 
 my $builder = Bio::MAGETAB::Util::DBLoader->new({
     database => $db,
 });
 
 $reader->set_builder( $builder );
 
 # Read objects into the database.
 $reader->parse();

=head1 DESCRIPTION

DBLoader is a Builder subclass which uses a relational database
backend to track object creation, rather than the simple hash
reference mechanism used by Builder. See the
L<Persistence|Bio::MAGETAB::Util::Persistence> class and the Tangram module
documentation for more information on supported database engines.

=head1 ATTRIBUTES

See the L<Builder|Bio::MAGETAB::Util::Builder> class for documentation on the superclass
attributes.

=over 2

=item database

The internal store to use for object lookups. This must be a
Bio::MAGETAB::Util::Persistence object.

=back

=head1 METHODS

See the L<Builder|Bio::MAGETAB::Util::Builder> class for documentation on the superclass
methods.

=head1 CAVEATS

Objects when modified are not automatically updated in the
database. You should use the C<update> method to do this (see
L<METHODS|Bio::MAGETAB::Util::Builder/METHODS> in the Builder class). In particular, it is
important to bear in mind that there are places in the Bio::MAGETAB
model where relationships between objects are being maintained behind
the scenes (this allows certain relationships to be navigable in both
directions). When modifying these objects, you must also call
C<update> on their target objects to ensure the database is kept
synchronized with the objects held in memory. For example:

 # SDRFRow to Nodes is a reciprocal relationship:
 my $row = $loader->create_sdrf_row({
    nodes => \@nodes,
 });
 
 # @nodes now know about $row, but the database doesn't know this:
 $loader->update( @nodes );

 # Similarly, with Edges and Nodes:
 my $edge = $loader->find_or_create_edge({
    inputNode  => $in,
    outputNode => $out,
 });
 
 # Again, $in and $out know about $edge, but the database does not:
 $loader->update( $in, $out );

=head1 KNOWN BUGS

When used with SQLite or MySQL (and possibly others), the Tangram
modules incorrectly modify any C<select> statements containing the '%'
character, so that this character is replaced with '%%'. This means
that while values are correctly inserted into the database they are
not retrieved correctly, and this may result in errors or duplicate
entries when working with objects whose identifying fields contains a
'%' character. See the L<Builder|Bio::MAGETAB::Util::Builder> class for a discussion on
object identity, and
L<http://rt.cpan.org/Public/Bug/Display.html?id=29133> for a possible
quick fix for this Tangram bug.

=head1 SEE ALSO

L<Bio::MAGETAB::Util::Reader>
L<Bio::MAGETAB::Util::Builder>
L<Bio::MAGETAB::Util::Persistence>

=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 1.669 second using v1.01-cache-2.11-cpan-39bf76dae61 )