NAME

RDF::RDB2RDF::DirectMapping::Store - mapping-fu

SYNOPSIS

 my $mapper = RDF::RDB2RDF->new('DirectMapping',
   prefix => 'http://example.net/data/');
 my $store  = RDF::RDB2RDF::DirectMapping::Store->new($dbh, $mapper, %options);

DESCRIPTION

This is pretty experimental. It provides a RDF::Trine::Store based on a database handle and a RDF::RDB2RDF::DirectMapping map.

Some queries are super-optimised; others are somewhat slower.

A Read-Write Adventure!

As of 0.006, there is very experimental support for add_statement, remove_statement and remove_statements.

Because data is stored in the database in a relational manner rather than as triples, some statements cannot be added to the database because they don't fit within the database's existing set of relations (i.e. tables). These will croak, but you can customise the failure (e.g. ignore it) using a callback:

 my %opts = (
   on_croak => sub {
     my ($store, $action, $st, $reason) = @_;
     my $dbh     = $store->dbh;
     my $mapping = $store->mapping;
     # do stuff here
   },
 );
 $store->add_statement($st, $ctxt, \%opts);

The on_croak option can alternatively be passed to the constructor.

Generally speaking, if the add_statement or remove_statement methods fail, the database has probably been left unchanged. (But there are no guarantees - the database may have, say, a trigger set up which fires on SELECT.)

Certain statements will also generate a warning. These warnings can be silenced by setting an on_carp callback similarly.

Again because of the relational nature of the storage, many statements will be mutually exclusive. That is, adding one statement may automatically negate an existing statement (i.e. cause it to be removed). You may set the overwrite option to a false-but-defined value to prevent this happening.

 $store->add_statement($st, $ctxt, { overwrite => 0 });

Literal datatypes are essentially ignored when adding a statement because the mapping uses SQL datatypes to decide on RDF datatypes. Languages tags for plain literals will give a warning (which can be handled with on_carp) but will otherwise be ignored. When removing a statement, the datatype will not be ignored, because before the statement is removed, the store checks that the exact statement exists in the store.

remove_statement fails if it would alter part of the primary key for a table, but add_statement can alter part of the primary key.

In many RDF stores, the remove_statements method is a logical shortcut for calling get_statement and then looping through the results, removing each one from the store. (Though probably optimized.)

In this store though, remove_statements may succeed when individual calls to remove_statement would have succeeded.

BUGS

Please report any bugs to http://rt.cpan.org/Dist/Display.html?Queue=RDF-RDB2RDF.

SEE ALSO

RDF::Trine, RDF::RDB2RDF, RDF::RDB2RDF::DirectMapping, RDF::Trine::Store.

http://perlrdf.org/.

http://www.w3.org/TR/2012/WD-rdb-direct-mapping-20120529/.

AUTHOR

Toby Inkster <tobyink@cpan.org>.

COPYRIGHT

Copyright 2011-2013 Toby Inkster

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

DISCLAIMER OF WARRANTIES

THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.