Dataquay::Connection Class Reference

Provides a connection interface to a transactional store, in a manner intended to be familiar to users of SQL database connection interfaces. More...

#include <dataquay/Connection.h>

Inherits Dataquay::Store.

List of all members.

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.
void commit ()
 Commit the outstanding Transaction, if any.
void rollback ()
 Roll back the outstanding Transaction, if any, and prepare to begin a new Transaction the next time a modifying function is called.
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.
Triple matchFirst (Triple t) const
 Return the first triple to match the given wildcard triple.
Node queryFirst (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.
QUrl getUniqueUri (QString prefix) const
 Get a new URI, starting with the given prefix, that does not currently exist within this store.
QUrl expand (QString uri) const
 Expand the given URI (which may use local namespaces) and prefix-expand it, returning the result as a QUrl.


Detailed Description

Provides a connection interface to a transactional store, in a manner intended to be familiar to users of SQL database connection interfaces.

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.


Constructor & Destructor Documentation

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.

Definition at line 183 of file Connection.cpp.

Dataquay::Connection::~Connection (  ) 

Destroy the Connection, first committing any outstanding transaction.

Definition at line 188 of file Connection.cpp.


Member Function Documentation

void Dataquay::Connection::commit (  ) 

Commit the outstanding Transaction, if any.

Definition at line 260 of file Connection.cpp.

void Dataquay::Connection::rollback (  ) 

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

Definition at line 266 of file Connection.cpp.

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

Add a triple to the store.

Prefix expansion is performed on URI nodes in the triple. Return false if the triple was already in the store. (Although Redland permits duplicate triples in a store, Dataquay doesn't.) Throw RDFException if the triple can not be added for some other reason.

Implements Dataquay::Store.

Definition at line 194 of file Connection.cpp.

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

Remove a triple from the store.

Prefix expansion is performed on URI nodes in the triple. 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.

Definition at line 200 of file Connection.cpp.

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.

Definition at line 206 of file Connection.cpp.

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.

Definition at line 212 of file Connection.cpp.

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

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

Prefix expansion is performed on URI nodes in the triple. Throw RDFException if the triple is not complete or if the test failed for any other reason.

Implements Dataquay::Store.

Definition at line 218 of file Connection.cpp.

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. Prefix expansion is performed on URI nodes in the triple. Return an empty list if there are no matches; may throw RDFException if matching fails in some other way.

Implements Dataquay::Store.

Definition at line 224 of file Connection.cpp.

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.

Definition at line 230 of file Connection.cpp.

Triple Dataquay::Connection::matchFirst ( Triple  t  )  const [virtual]

Return the first triple to match the given wildcard triple.

A node of type Nothing in any part of the triple matches any node in the data store. Prefix expansion is performed on URI nodes in the triple. Return an empty triple (three Nothing nodes) if there are no matches. May throw RDFException.

Implements Dataquay::Store.

Definition at line 236 of file Connection.cpp.

Node Dataquay::Connection::queryFirst ( 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.

Definition at line 242 of file Connection.cpp.

QUrl Dataquay::Connection::getUniqueUri ( QString  prefix  )  const [virtual]

Get a new URI, starting with the given prefix, that does not currently exist within this store.

The URI will be prefix expanded.

Implements Dataquay::Store.

Definition at line 248 of file Connection.cpp.

QUrl 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 QUrl.

(The QUrl class is not suitable for storing URIs that use namespaces, particularly local ones.)

Implements Dataquay::Store.

Definition at line 254 of file Connection.cpp.


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

Generated on Thu Sep 24 23:19:48 2009 for Dataquay by  doxygen 1.5.7.1