Soprano 2.6.0
|
A wrapper around Soprano::Model which executes a query in a separate thread and allows to iterate the results asyncroneously. More...
#include <Soprano/Util/AsyncQuery>
Public Slots | |
bool | next () |
void | close () |
Signals | |
void | nextReady (Soprano::Util::AsyncQuery *query) |
void | finished (Soprano::Util::AsyncQuery *query) |
Public Member Functions | |
~AsyncQuery () | |
Statement | currentStatement () const |
BindingSet | currentBindings () const |
bool | boolValue () const |
Node | binding (const QString &name) const |
Node | binding (int offset) const |
int | bindingCount () const |
QStringList | bindingNames () const |
bool | isGraph () const |
bool | isBinding () const |
bool | isBool () const |
Static Public Member Functions | |
static AsyncQuery * | executeQuery (Soprano::Model *model, const QString &query, Query::QueryLanguage language, const QString &userQueryLanguage=QString()) |
A wrapper around Soprano::Model which executes a query in a separate thread and allows to iterate the results asyncroneously.
In contrast to AsyncModel everything is asyncroneous, not only the execution of the query itself, but also the iteration.
For executing a query asyncroneously simply use the static executeQuery() method which will return a pointer to the newly created query object.
AsyncQuery objects will always delete themselves once the end of the iterator is reached and the finished signal has been emitted. This also means that boolean results need to be read in a slot connected to the finished() signal.
Typical usage would be to connect to the nextReady() signal, use one of the binding() methods or currentStatement() to get the current value, and then call next() in it to trigger async iteration to the next element:
void MyQueryHandler::slotNextReady( Soprano::Util::AsyncQuery* query ) { // do something with the current value addToSomeList( query->binding(0) ); // trigger async iteration to the next element query->next(); }
Definition at line 76 of file asyncquery.h.
Soprano::Util::AsyncQuery::~AsyncQuery | ( | ) |
Delete the query. This will cancel an unfinished query. Be aware that normally there is no need to delete the query object as it will auto-delete itself once finished.
Statement Soprano::Util::AsyncQuery::currentStatement | ( | ) | const |
Retrieve the current Statement after nextReady has been emitted. This method does only make sense for graph queries.
BindingSet Soprano::Util::AsyncQuery::currentBindings | ( | ) | const |
Convenience method that puts all current bindings into one map. This method does only make sense for tuple queries.
bool Soprano::Util::AsyncQuery::boolValue | ( | ) | const |
This method does only make sense for boolean queries.
Get the current binding for a variable.
name | The name of the requested variable. |
This method does only make sense for tuple queries.
Node Soprano::Util::AsyncQuery::binding | ( | int | offset | ) | const |
Get the current binding for a variable by index.
offset | The index of the requested variable. |
This method does only make sense for tuple queries.
int Soprano::Util::AsyncQuery::bindingCount | ( | ) | const |
The number of bindings in this query result.
This method does only make sense for tuple queries.
QStringList Soprano::Util::AsyncQuery::bindingNames | ( | ) | const |
This method does only make sense for tuple queries.
bool Soprano::Util::AsyncQuery::isGraph | ( | ) | const |
Check if this is a graph result.
true
if this result refers to a graph query, i.e. currentStatement() returns valid values. bool Soprano::Util::AsyncQuery::isBinding | ( | ) | const |
Check if this is a tuple result.
true
if this result refers to a tuple query, i.e. currentBindings(), binding(), bindingCount(), and bindingNames() return valid values. bool Soprano::Util::AsyncQuery::isBool | ( | ) | const |
Check if this is a boolean result.
There is no need to call next() for boolean results. However, for internal reasons backends need to always return true
for boolean queries.
true
if this result refers to a boolean query (SPARQL ASK), i.e. boolValue() returns a valid value. bool Soprano::Util::AsyncQuery::next | ( | ) | [slot] |
Trigger iteration to the next element once the current has been read via one of the binding() methods or currentStatement(). Be aware that this has not to be called for the first element which is emitted automatically. Once the next result has been retrieved the nextReady signal is emitted.
true
if successful, false
if the iteration reached the end. void Soprano::Util::AsyncQuery::close | ( | ) | [slot] |
Closes the query. This will cancel the query if it is not finished yet. Afterwards the query will delete itself. It has the same effect as deleting the query object manually.
finished() will always be emitted in case the query was not finished yet.
void Soprano::Util::AsyncQuery::nextReady | ( | Soprano::Util::AsyncQuery * | query | ) | [signal] |
void Soprano::Util::AsyncQuery::finished | ( | Soprano::Util::AsyncQuery * | query | ) | [signal] |
Emitted once the last element has been read and the internal iterator is finished after the last call to next() or if the result of a boolean query is available.
Once this signals has been emitted the query will delete itself. In a slot connected to this signal ErrorCache::lastError() can be used to retrieve information about the success of the query.
query | The query itself for convinience. |
static AsyncQuery* Soprano::Util::AsyncQuery::executeQuery | ( | Soprano::Model * | model, |
const QString & | query, | ||
Query::QueryLanguage | language, | ||
const QString & | userQueryLanguage = QString() |
||
) | [static] |
Create a new query object.
model | The model to execute the query on. |
query | The query to evaluate. |
language | The query language used to encode query . |
userQueryLanguage | If language equals Query::QueryLanguageUser userQueryLanguage defines the language to use. |
model
is 0. The query will delete itself once it is finished. It can also be deleted at any point in time to cancel the query.