Dataquay 0.8
Dataquay::Connection Class Reference

Connection provides a connection interface to TransactionalStore, allowing it to be used in a convenient manner familiar to programmers working with SQL databases. More...

#include <dataquay/Connection.h>

Inheritance diagram for Dataquay::Connection:

Public Types

enum  ImportDuplicatesMode { ImportIgnoreDuplicates , ImportFailOnDuplicates , ImportPermitDuplicates }
 ImportDuplicatesMode determines the outcome when an import operation encounters a triple in the imported data set that already exists in the store. More...
 
enum  Feature { ModifyFeature , QueryFeature , RemoteImportFeature }
 Feature defines the set of optional features a Store implementation may support. More...
 
typedef QSet< FeatureFeatures
 

Public Slots

void commit ()
 Commit the outstanding Transaction, if any.
 
ChangeSet commitAndObtain ()
 Commit the outstanding Transaction, if any, and return the changes committed.
 
void rollback ()
 Roll back the outstanding Transaction, if any, and prepare to begin a new Transaction the next time a modifying function is called.
 

Signals

void transactionCommitted (const ChangeSet &)
 Forwarded from TransactionalStore.
 
void transactionCommitted ()
 Forwarded from TransactionalStore.
 

Public Member Functions

 Connection (TransactionalStore *ts)
 Construct a Connection to the given TransactionalStore, through which a series of transactions may be made in a single processing thread.
 
 ~Connection ()
 Destroy the Connection, first committing any outstanding transaction.
 
bool add (Triple t)
 Add a triple to the store.
 
bool remove (Triple t)
 Remove a triple from the store.
 
void change (ChangeSet changes)
 Atomically apply the sequence of add/remove changes described in the given ChangeSet.
 
void revert (ChangeSet changes)
 Atomically apply the sequence of add/remove changes described in the given ChangeSet, in reverse (ie removing adds and adding removes, in reverse order).
 
bool contains (Triple t) const
 Return true if the store contains the given triple, false otherwise.
 
Triples match (Triple t) const
 Return all triples matching the given wildcard triple.
 
ResultSet query (QString sparql) const
 Run a SPARQL query against the store and return its results.
 
Node complete (Triple t) const
 Given a triple in which any two nodes are specified and the other is a wildcard node of type Nothing, return a node that can be substituted for the Nothing node in order to complete a triple that exists in the store.
 
Triple matchOnce (Triple t) const
 Return a triple from the store that matches the given wildcard triple, or the empty triple if none matches.
 
Node queryOnce (QString sparql, QString bindingName) const
 Run a SPARQL query against the store and return the node of the first result for the given query binding.
 
Uri getUniqueUri (QString prefix) const
 Get a new URI, starting with the given prefix (e.g.
 
Node addBlankNode ()
 Create and return a new blank node.
 
Uri expand (QString uri) const
 Expand the given URI (which may use local namespaces) and prefix-expand it, returning the result as a Uri.
 
void save (QString filename) const
 Export the store to an RDF/TTL file with the given filename.
 
void import (QUrl url, ImportDuplicatesMode idm, QString format="")
 Import the RDF document found at the given URL into the current store (in addition to its existing contents).
 
void importString (QString encodedRdf, Uri uri, ImportDuplicatesMode idm, QString format="")
 Import the RDF document encoded in the given string into the current store (in addition to its existing contents).
 
Features getSupportedFeatures () const
 Retrieve the set of optional features supported by this Store implementation.
 

Detailed Description

Connection provides a connection interface to TransactionalStore, allowing it to be used in a convenient manner familiar to programmers working with SQL databases.

Each processing thread may construct a Connection to a central TransactionalStore. The Connection will start a new Transaction on the store when the first modifying function (add, remove, change or revert) is called and will continue to use this Transaction for all accesses to the store until either commit() or rollback() is called on the Connection.

Any read-only functions called on this class between a commit() or rollback() and the next modifying function will be passed directly to the store without any transaction. Read-only functions called while a transaction is in progress will be passed through the current transaction, and so will read the effective state of the store with the partial transaction in force.

The Connection commits any active Transaction when it is deleted. To avoid this, call rollback() before deletion. No other auto-commit functionality is provided – if you want auto-commit, use the TransactionalStore's own interface in AutoTransaction mode.

Each Connection should be used in a single processing thread only. Connection is not thread-safe.

Definition at line 74 of file Connection.h.

Member Typedef Documentation

◆ Features

Definition at line 290 of file Store.h.

Member Enumeration Documentation

◆ ImportDuplicatesMode

ImportDuplicatesMode determines the outcome when an import operation encounters a triple in the imported data set that already exists in the store.

ImportIgnoreDuplicates: Any duplicate of a triple that is already in the store is discarded without comment.

ImportFailOnDuplicates: Import will fail with an RDFDuplicateImportException if any duplicate of a triple already in the store is found, and nothing will be imported.

ImportPermitDuplicates: No tests for duplicate triples will be carried out, and the behaviour when duplicates are imported will depend on the underlying store implementation (which may merge them or store them as separate duplicate triples). This is usually inadvisable: besides its unpredictability, this class does not generally handle duplicate triples well in other contexts.

Enumerator
ImportIgnoreDuplicates 
ImportFailOnDuplicates 
ImportPermitDuplicates 

Definition at line 222 of file Store.h.

◆ Feature

enum Dataquay::Store::Feature
inherited

Feature defines the set of optional features a Store implementation may support.

Code that uses Store should check that the features it requires are available before trying to make use of them.

ModifyFeature: The store can be modified (triples can be added to it). All current Store implementations support this feature.

QueryFeature: The store supports SPARQL queries through the query and queryOnce methods. A store that does not support queries will throw RDFUnsupportedError when these functions are called.

RemoteImportFeature: The store can import URLs that represent network resources as well as URLs referring to files on the local disc. The extent to which this feature is actually available may also depend on the configuration of the underlying RDF library. A store that does not support remote URLs will fail as if the resource was absent, when asked to load one.

Enumerator
ModifyFeature 
QueryFeature 
RemoteImportFeature 

Definition at line 284 of file Store.h.

Constructor & Destructor Documentation

◆ Connection()

Dataquay::Connection::Connection ( TransactionalStore * ts)

Construct a Connection to the given TransactionalStore, through which a series of transactions may be made in a single processing thread.

◆ ~Connection()

Dataquay::Connection::~Connection ( )

Destroy the Connection, first committing any outstanding transaction.

If you do not want any outstanding transaction to be committed, call rollback() first.

Member Function Documentation

◆ add()

bool Dataquay::Connection::add ( Triple t)
virtual

Add a triple to the store.

Return false if the triple was already in the store. (Dataquay does not permit duplicate triples in a store.) Throw RDFException if the triple can not be added for some other reason.

Implements Dataquay::Store.

◆ remove()

bool Dataquay::Connection::remove ( Triple t)
virtual

Remove a triple from the store.

If some nodes in the triple are Nothing nodes, remove all matching triples. Return false if no matching triple was found in the store. Throw RDFException if removal failed for some other reason.

Implements Dataquay::Store.

◆ change()

void Dataquay::Connection::change ( ChangeSet changes)
virtual

Atomically apply the sequence of add/remove changes described in the given ChangeSet.

Throw RDFException if any operation fails for any reason (including duplication etc).

Implements Dataquay::Store.

◆ revert()

void Dataquay::Connection::revert ( ChangeSet changes)
virtual

Atomically apply the sequence of add/remove changes described in the given ChangeSet, in reverse (ie removing adds and adding removes, in reverse order).

Throw RDFException if any operation fails for any reason (including duplication etc).

Implements Dataquay::Store.

◆ contains()

bool Dataquay::Connection::contains ( Triple t) const
virtual

Return true if the store contains the given triple, false otherwise.

Throw RDFException if the triple is not complete or if the test failed for any other reason.

Implements Dataquay::Store.

◆ match()

Triples Dataquay::Connection::match ( Triple t) const
virtual

Return all triples matching the given wildcard triple.

A node of type Nothing in any part of the triple matches any node in the data store. Return an empty list if there are no matches; may throw RDFException if matching fails in some other way.

Implements Dataquay::Store.

◆ query()

ResultSet Dataquay::Connection::query ( QString sparql) const
virtual

Run a SPARQL query against the store and return its results.

Any prefixes added previously using addQueryPrefix will be available in this query without needing to be declared in the SPARQL given here (equivalent to writing "PREFIX prefix: <uri>" for each prefix,uri pair set with addPrefix).

May throw RDFException.

Note that the RDF store must have an absolute base URI (rather than the default "#") in order to perform queries, as relative URIs in the query will be interpreted relative to the query base rather than the store and without a proper base URI there is no way to override that internally.

Implements Dataquay::Store.

◆ complete()

Node Dataquay::Connection::complete ( Triple t) const
virtual

Given a triple in which any two nodes are specified and the other is a wildcard node of type Nothing, return a node that can be substituted for the Nothing node in order to complete a triple that exists in the store.

If no matching triple can be found, return a null node. If more than one triple matches, the returned value may arbitrarily be from any of them. May throw RDFException.

Implements Dataquay::Store.

◆ matchOnce()

Triple Dataquay::Connection::matchOnce ( Triple t) const
virtual

Return a triple from the store that matches the given wildcard triple, or the empty triple if none matches.

A node of type Nothing in any part of the triple matches any node in the data store. If more than one triple matches, the returned value may arbitrarily be any of them. May throw RDFException.

Implements Dataquay::Store.

◆ queryOnce()

Node Dataquay::Connection::queryOnce ( QString sparql,
QString bindingName ) const
virtual

Run a SPARQL query against the store and return the node of the first result for the given query binding.

This is a shorthand for use with queries that are only expected to have one result. May throw RDFException.

Implements Dataquay::Store.

◆ getUniqueUri()

Uri Dataquay::Connection::getUniqueUri ( QString prefix) const
virtual

Get a new URI, starting with the given prefix (e.g.

":event_"), that does not currently exist within this store. The URI will be prefix expanded.

Implements Dataquay::Store.

◆ addBlankNode()

Node Dataquay::Connection::addBlankNode ( )
virtual

Create and return a new blank node.

This node can only be referred to using the given Node object, and only during its lifetime within this instance of the store.

Implements Dataquay::Store.

◆ expand()

Uri Dataquay::Connection::expand ( QString uri) const
virtual

Expand the given URI (which may use local namespaces) and prefix-expand it, returning the result as a Uri.

(The Uri class cannot be used to store URIs that have unexpanded namespace prefixes.)

The set of available prefixes for expansion depends on the subclass implementation. See, for example, BasicStore::addPrefix.

Implements Dataquay::Store.

◆ save()

void Dataquay::Connection::save ( QString filename) const
virtual

Export the store to an RDF/TTL file with the given filename.

If the file already exists, it will if possible be overwritten. May throw RDFException, FileOperationFailed, FailedToOpenFile, etc.

Note that unlike import (which takes a URL argument), save takes a simple filename with no file:// prefix.

Implements Dataquay::Store.

◆ import()

void Dataquay::Connection::import ( QUrl url,
ImportDuplicatesMode idm,
QString format = "" )
virtual

Import the RDF document found at the given URL into the current store (in addition to its existing contents).

Its behaviour when a triple is encountered that already exists in the store is controlled by the ImportDuplicatesMode.

May throw RDFException or RDFDuplicateImportException.

Note that the URL must be a URL, not just a filename (i.e. local files need the file: prefix).

If format is specified, it will be taken as the RDF parse format (e.g. ntriples). The set of supported format strings depends on the underlying RDF library configuration. The default is to guess the format if possible.

Implements Dataquay::Store.

◆ importString()

void Dataquay::Connection::importString ( QString encodedRdf,
Uri baseUri,
ImportDuplicatesMode idm,
QString format = "" )
virtual

Import the RDF document encoded in the given string into the current store (in addition to its existing contents).

Its behaviour when a triple is encountered that already exists in the store is controlled by the ImportDuplicatesMode.

May throw RDFException or RDFDuplicateImportException.

If format is specified, it will be taken as the RDF parse format (e.g. ntriples). The set of supported format strings depends on the underlying RDF library configuration. The default is to guess the format if possible.

Implements Dataquay::Store.

◆ getSupportedFeatures()

Features Dataquay::Connection::getSupportedFeatures ( ) const
virtual

Retrieve the set of optional features supported by this Store implementation.

Implements Dataquay::Store.

◆ commit

void Dataquay::Connection::commit ( )
slot

Commit the outstanding Transaction, if any.

◆ commitAndObtain

ChangeSet Dataquay::Connection::commitAndObtain ( )
slot

Commit the outstanding Transaction, if any, and return the changes committed.

◆ rollback

void Dataquay::Connection::rollback ( )
slot

Roll back the outstanding Transaction, if any, and prepare to begin a new Transaction the next time a modifying function is called.

◆ transactionCommitted [1/2]

void Dataquay::Connection::transactionCommitted ( const ChangeSet & )
signal

Forwarded from TransactionalStore.

◆ transactionCommitted [2/2]

void Dataquay::Connection::transactionCommitted ( )
signal

Forwarded from TransactionalStore.


The documentation for this class was generated from the following file: