Soprano  2.8.0
Public Slots | Signals | Public Member Functions | Static Public Member Functions
Soprano::Util::AsyncQuery Class Reference

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>

+ Inheritance diagram for Soprano::Util::AsyncQuery:

List of all members.

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
- Public Member Functions inherited from QObject
 QObject (QObject *parent=0)
 blockSignals (bool block)
 childEvent (QChildEvent *event)
 children ()
 connect (const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type=Qt::AutoCompatConnection)
 connect (const QObject *sender, const char *signal, const char *method, Qt::ConnectionType type=Qt::AutoCompatConnection)
 connectNotify (const char *signal)
 customEvent (QEvent *event)
 deleteLater ()
 destroyed (QObject *obj=0)
 disconnect (const QObject *sender, const char *signal, const QObject *receiver, const char *method)
 disconnect (const char *signal=0, const QObject *receiver=0, const char *method=0)
 disconnect (const QObject *receiver, const char *method=0)
 disconnectNotify (const char *signal)
 dumpObjectInfo ()
 dumpObjectTree ()
 dynamicPropertyNames ()
 event (QEvent *e)
 eventFilter (QObject *watched, QEvent *event)
 findChild (const QString &name=QString()
 findChildren (const QString &name=QString()
 findChildren (const QRegExp &regExp)
 inherits (const char *className)
 installEventFilter (QObject *filterObj)
 isWidgetType ()
 killTimer (int id)
 metaObject ()
 moveToThread (QThread *targetThread)
 parent ()
 property (const char *name)
 receivers (const char *signal)
 removeEventFilter (QObject *obj)
 sender ()
 setParent (QObject *parent)
 setProperty (const char *name, const QVariant &value)
 signalsBlocked ()
 startTimer (int interval)
 thread ()
 timerEvent (QTimerEvent *event)
 tr (const char *sourceText, const char *comment=0, int n=-1)
 trUtf8 (const char *sourceText, const char *comment=0, int n=-1)
 staticMetaObject
 QObject (QObject *parent, const char *name)
 checkConnectArgs (const char *signal, const QObject *object, const char *method)
 child (const char *objName, const char *inheritsClass=0, bool recursiveSearch=true)
 className ()
 insertChild (QObject *object)
 isA (const char *className)
 name ()
 name (const char *defaultName)
 normalizeSignalSlot (const char *signalSlot)
 removeChild (QObject *object)
 setName (const char *name)
- Public Member Functions inherited from Soprano::Error::ErrorCache
virtual ~ErrorCache ()
virtual Error lastError () const

Static Public Member Functions

static AsyncQueryexecuteQuery (Soprano::Model *model, const QString &query, Query::QueryLanguage language, const QString &userQueryLanguage=QString())

Additional Inherited Members

- Protected Member Functions inherited from Soprano::Error::ErrorCache
 ErrorCache ()
void clearError () const
void setError (const Error &) const
void setError (const QString &errorMessage, int code=ErrorUnknown) const

Detailed Description

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();
}
See also:
Soprano::Util::AsyncModel
Author:
Sebastian Trueg trueg.nosp@m.@kde.nosp@m..org
Since:
2.4

Definition at line 76 of file asyncquery.h.


Constructor & Destructor Documentation

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.

See also:
close()

Member Function Documentation

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.

Returns:
The result of a boolean query (SPARQL ASK).
See also:
isBool()
Node Soprano::Util::AsyncQuery::binding ( const QString name) const

Get the current binding for a variable.

Parameters:
nameThe name of the requested variable.

This method does only make sense for tuple queries.

Returns:
The binding for the requested variable or and invalid node if the bindings do not contain the variable.
Node Soprano::Util::AsyncQuery::binding ( int  offset) const

Get the current binding for a variable by index.

Parameters:
offsetThe index of the requested variable.

This method does only make sense for tuple queries.

Returns:
The binding for the requested variable or and invalid node if offset is out of bounds, i.e. bigger or equal to bindingCount().
int Soprano::Util::AsyncQuery::bindingCount ( ) const

The number of bindings in this query result.

This method does only make sense for tuple queries.

Returns:
The number of bindings.
QStringList Soprano::Util::AsyncQuery::bindingNames ( ) const

This method does only make sense for tuple queries.

Returns:
The names of the bound variables in this query result.
bool Soprano::Util::AsyncQuery::isGraph ( ) const

Check if this is a graph result.

Returns:
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.

Returns:
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.

Returns:
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.

Returns:
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

Emitted once the next value is ready when iterating the result via next(). Will be emitted automatically for the first element. The last call in a connected slot should be next() to trigger iteration to the next element.

Parameters:
queryThe query itself for convinience.
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.

Parameters:
queryThe 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.

Parameters:
modelThe model to execute the query on.
queryThe query to evaluate.
languageThe query language used to encode query.
userQueryLanguageIf language equals Query::QueryLanguageUser userQueryLanguage defines the language to use.
See also:
Model::executeQuery
Returns:
A new AsyncQuery instance which is ready to be used or 0 if 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.

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