Development/Tutorials/Metadata/Nepomuk/StorageService: Difference between revisions

From KDE TechBase
(New page: {{TutorialBrowser| series=Nepomuk| name=Nepomuk Storage Service| pre=| next=OntologyLoader| reading=Nepomuk Services, [[../NepomukServer...)
 
m (Text replace - "</code>" to "</syntaxhighlight>")
 
(2 intermediate revisions by 2 users not shown)
Line 1: Line 1:
{{TutorialBrowser|
{{TutorialBrowser|
series=Nepomuk|
series=[[../|Nepomuk]]|
name=Nepomuk Storage Service|
name=Nepomuk Storage Service|
pre=|
pre=|
Line 15: Line 15:
1. Use [http://api.kde.org/kdesupport-api/kdesupport-apidocs/soprano/html/classSoprano_1_1Client_1_1DBusClient.html Soprano::Client::DBusClient] to create a connection to the Nepomuk Server:
1. Use [http://api.kde.org/kdesupport-api/kdesupport-apidocs/soprano/html/classSoprano_1_1Client_1_1DBusClient.html Soprano::Client::DBusClient] to create a connection to the Nepomuk Server:


<code cppqt>
<syntaxhighlight lang="cpp-qt">
Soprano::Client::DBusClient* client = new Soprano::Client::DBusClient( "org.kde.NepomukStorage" );
Soprano::Client::DBusClient* client = new Soprano::Client::DBusClient( "org.kde.NepomukStorage" );
Soprano::Model* model = client->createModel( "main" );
Soprano::Model* model = client->createModel( "main" );
</code>
</syntaxhighlight>


The Nepomuk Server registers as DBus service ''org.kde.NepomukStorage'' and the name of the main data repository is ''main''.
The Nepomuk Server registers as DBus service ''org.kde.NepomukStorage'' and the name of the main data repository is ''main''.
Line 24: Line 24:
2. Use the Nepomuk library, i.e. [http://api.kde.org/4.x-api/kdelibs-apidocs/nepomuk/html/classNepomuk_1_1ResourceManager.html ResourceManager] to access the main model:
2. Use the Nepomuk library, i.e. [http://api.kde.org/4.x-api/kdelibs-apidocs/nepomuk/html/classNepomuk_1_1ResourceManager.html ResourceManager] to access the main model:


<code cppqt>
<syntaxhighlight lang="cpp-qt">
Soprano::Model* model = Nepomuk::ResourceManager::instance()->mainModel();
Soprano::Model* model = Nepomuk::ResourceManager::instance()->mainModel();
</code>
</syntaxhighlight>


The advantage of the first version is that there is no need to link to libnepomuk. On the other hand the main model as provided by libnepomuk connects via a local socket if available which is faster. Also, it provides an automatic re-connect feature.
The advantage of the first version is that there is no need to link to libnepomuk. On the other hand the main model as provided by libnepomuk connects via a local socket if available which is faster. Also, it provides an automatic re-connect feature.
When implementing a Nepomuk service use [http://api.kde.org/4.x-api/kdelibs-apidocs/nepomuk/html/classNepomuk_1_1Service.html Service] to access the main repository:
When implementing a Nepomuk service use [http://api.kde.org/4.x-api/kdelibs-apidocs/nepomuk/html/classNepomuk_1_1Service.html Service] to access the main repository:


<code cppqt>
<syntaxhighlight lang="cpp-qt">
class MyService : public Nepomuk::Service {
class MyService : public Nepomuk::Service {
public:
public:
Line 38: Line 38:
     }
     }
};
};
</code>
</syntaxhighlight>


So all in all the easy way is also the recommended one: use ''libnepomuk'' and the [http://api.kde.org/4.x-api/kdelibs-apidocs/nepomuk/html/classNepomuk_1_1ResourceManager.html ResourceManager] or [http://api.kde.org/4.x-api/kdelibs-apidocs/nepomuk/html/classNepomuk_1_1Service.html Service] to access the data.
So all in all the easy way is also the recommended one: use ''libnepomuk'' and the [http://api.kde.org/4.x-api/kdelibs-apidocs/nepomuk/html/classNepomuk_1_1ResourceManager.html ResourceManager] or [http://api.kde.org/4.x-api/kdelibs-apidocs/nepomuk/html/classNepomuk_1_1Service.html Service] to access the data.

Latest revision as of 20:53, 29 June 2011

Nepomuk Storage Service
Tutorial Series   Nepomuk
Previous  
What's Next   OntologyLoader
Further Reading   Nepomuk Services, Nepomuk Server

Nepomuk Storage Service

The main repository is an RDF database using Soprano including a Soprano full text index. The interface of the repository is exported via DBus (The DBus interface is defined by Soprano). When using the Soprano DBus interface from within a KDE application there is no need to bother with QDBus. Soprano provides the Soprano::Client::DBusModel class which wraps all DBus communication into a nice Soprano::Model interface.

There are two ways to access this wrapper model:

1. Use Soprano::Client::DBusClient to create a connection to the Nepomuk Server:

Soprano::Client::DBusClient* client = new Soprano::Client::DBusClient( "org.kde.NepomukStorage" );
Soprano::Model* model = client->createModel( "main" );

The Nepomuk Server registers as DBus service org.kde.NepomukStorage and the name of the main data repository is main.

2. Use the Nepomuk library, i.e. ResourceManager to access the main model:

Soprano::Model* model = Nepomuk::ResourceManager::instance()->mainModel();

The advantage of the first version is that there is no need to link to libnepomuk. On the other hand the main model as provided by libnepomuk connects via a local socket if available which is faster. Also, it provides an automatic re-connect feature. When implementing a Nepomuk service use Service to access the main repository:

class MyService : public Nepomuk::Service {
public:
    MyService( QObject* parent ) : Service( parent ) {
       Soprano::Model* model = mainModel();
    }
};

So all in all the easy way is also the recommended one: use libnepomuk and the ResourceManager or Service to access the data.