Difference between revisions of "Projects/Nepomuk/BulkChanges"

Jump to: navigation, search
(Added examples)
(Marked this version for translation)
 
(One intermediate revision by one user not shown)
Line 1: Line 1:
Quite often one needs to apply some changes to a large number of resources. Instead of using the <code>Resource</code> class which is synchronous. They are easier ways, which are asynchronous.
+
<languages />
 +
<translate>
 +
== Making Bulk Changes == <!--T:1-->
  
With KDE 4.9 the [http://api.kde.org/4.x-api/kdelibs-apidocs/nepomuk-core/html/group__nepomuk__datamanagement.html Nepomuk Datamanagement libraries] finally became public and allow clients to make large bulk changes to Nepomuk. In fact they are now the defacto method of modifying data. All other client libraries are now built on top of the Data Management library.
+
<!--T:2-->
 +
Quite often one needs to apply some changes to a large number of resources. Instead of using the <tt>Resource</tt> class which is synchronous. They are easier ways, which are asynchronous.
  
= Includes and Libraries =
+
<!--T:3-->
 +
With KDE 4.9 the [http://api.kde.org/4.x-api/kdelibs-apidocs/nepomuk-core/html/group__nepomuk__datamanagement.html Nepomuk Datamanagement libraries] finally became public and allow clients to make large bulk changes to '''Nepomuk'''. In fact they are now the de facto method of modifying data. All other client libraries are now built on top of the Data Management library.
 +
 
 +
== Includes and Libraries == <!--T:4-->
 
Since the datamanagement libraries are so prevalent, they come bundled together with the NepomukCore library.
 
Since the datamanagement libraries are so prevalent, they come bundled together with the NepomukCore library.
  
The appropriate functions are included in the [http://api.kde.org/4.x-api/kdelibs-apidocs/nepomuk-core/html/group__nepomuk__datamanagement.html <code>Nepomuk/DataManagement</code>] include file.
+
<!--T:5-->
 +
The appropriate functions are included in the [http://api.kde.org/4.x-api/kdelibs-apidocs/nepomuk-core/html/group__nepomuk__datamanagement.html <tt>Nepomuk/DataManagement</tt>] include file.
  
=Jobs=
+
== Jobs == <!--T:6-->
  
Each Datamanagement function returns a <code>KJob</code> which performs the jobs and returns a signal on completion. These jobs are automatically started, and like all other <code>KJob</code>s they are automatically deleted on completion.
+
<!--T:7-->
 +
Each Datamanagement function returns a <tt>KJob</tt> which performs the jobs and returns a signal on completion. These jobs are automatically started, and like all other <tt>KJob</tt>s they are automatically deleted on completion.
  
=== Errors ===
+
=== Errors === <!--T:8-->
  
While these jobs are quite easy to use, they have inbuilt error checking that verifies the domain, range and cardinality of the properties that are being changed. Therefore it is important to check the error code of the job when it returns. A better error message can be received via <code>KJob::errorString</code>
+
<!--T:9-->
 +
While these jobs are quite easy to use, they have inbuilt error checking that verifies the domain, range and cardinality of the properties that are being changed. Therefore it is important to check the error code of the job when it returns. A better error message can be received via <tt>KJob::errorString</tt>
  
= Examples =
+
== Examples == <!--T:10-->
  
 +
<!--T:11-->
 
Setting the tags for a large number of resources -
 
Setting the tags for a large number of resources -
 
<syntaxhighlight lang="cpp-qt">
 
<syntaxhighlight lang="cpp-qt">
Line 23: Line 33:
 
     QVariantList tagResources;
 
     QVariantList tagResources;
  
     KJob* job = setProperty( resourceList, NAO::hasTag(), tagResources );
+
     <!--T:12-->
 +
KJob* job = setProperty( resourceList, NAO::hasTag(), tagResources );
 
     connect( job, SIGNAL(result(KJob*)), this, SLOT(slotTagUpdateDone()) );
 
     connect( job, SIGNAL(result(KJob*)), this, SLOT(slotTagUpdateDone()) );
 
</syntaxhighlight>
 
</syntaxhighlight>
  
  
 +
<!--T:13-->
 
This can also be done synchronously by running an event loop in the background -
 
This can also be done synchronously by running an event loop in the background -
 
<syntaxhighlight lang="cpp-qt">
 
<syntaxhighlight lang="cpp-qt">
Line 35: Line 47:
 
         kError() << job->errorString();
 
         kError() << job->errorString();
 
</syntaxhighlight>
 
</syntaxhighlight>
 +
 +
<!--T:14-->
 +
[[Category:Documentation]]
 +
[[Category:Development]]
 +
[[Category:Tutorials]]
 +
</translate>

Latest revision as of 15:06, 11 December 2012

Other languages:English 100%

Contents

[edit] Making Bulk Changes

Quite often one needs to apply some changes to a large number of resources. Instead of using the Resource class which is synchronous. They are easier ways, which are asynchronous.

With KDE 4.9 the Nepomuk Datamanagement libraries finally became public and allow clients to make large bulk changes to Nepomuk. In fact they are now the de facto method of modifying data. All other client libraries are now built on top of the Data Management library.

[edit] Includes and Libraries

Since the datamanagement libraries are so prevalent, they come bundled together with the NepomukCore library.

The appropriate functions are included in the Nepomuk/DataManagement include file.

[edit] Jobs

Each Datamanagement function returns a KJob which performs the jobs and returns a signal on completion. These jobs are automatically started, and like all other KJobs they are automatically deleted on completion.

[edit] Errors

While these jobs are quite easy to use, they have inbuilt error checking that verifies the domain, range and cardinality of the properties that are being changed. Therefore it is important to check the error code of the job when it returns. A better error message can be received via KJob::errorString

[edit] Examples

Setting the tags for a large number of resources -

    QList<QUrl> resourceList;
    QVariantList tagResources;
 
    KJob* job = setProperty( resourceList, NAO::hasTag(), tagResources );
    connect( job, SIGNAL(result(KJob*)), this, SLOT(slotTagUpdateDone()) );


This can also be done synchronously by running an event loop in the background -

    KJob* job = setProperty( resourceList, NAO::hasTag(), tagResources );
    job->exec();
    if( job->error() )
        kError() << job->errorString();

This page was last modified on 11 December 2012, at 15:06. This page has been accessed 1,555 times. Content is available under Creative Commons License SA 3.0 as well as the GNU Free Documentation License 1.2.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V.Legal