[tracker/tracker-store-queue] Using insert_statement and delete_statement
- From: Philip Van Hoof <pvanhoof src gnome org>
- To: svn-commits-list gnome org
- Subject: [tracker/tracker-store-queue] Using insert_statement and delete_statement
- Date: Thu, 21 May 2009 11:29:53 -0400 (EDT)
commit d73e18a022ac21072cb95f8ba40776c336caf5bd
Author: Philip Van Hoof <philip codeminded be>
Date: Thu May 21 17:28:11 2009 +0200
Using insert_statement and delete_statement
I can't use SPARQL's INSERT because it's not possible to reliably know
whether object and predicate are either string formatted or URI
formatted. Feel free to remove the extra API and replace it back to
SPARQL INSERT and DELETE if you know how to quickly know how to format
the query correctly.
---
.../evolution/tracker-evolution-registrar.c | 10 +-
src/plugins/kmail/tracker-kmail-registrar.c | 10 +-
src/tracker-store/tracker-resources.c | 38 ++----
src/tracker-store/tracker-store-queue.c | 151 ++++++++++++++++++--
src/tracker-store/tracker-store-queue.h | 67 ++++++---
5 files changed, 200 insertions(+), 76 deletions(-)
diff --git a/src/plugins/evolution/tracker-evolution-registrar.c b/src/plugins/evolution/tracker-evolution-registrar.c
index 9ce612c..646942c 100644
--- a/src/plugins/evolution/tracker-evolution-registrar.c
+++ b/src/plugins/evolution/tracker-evolution-registrar.c
@@ -274,14 +274,8 @@ data_insert_statement (const gchar *subject,
const gchar *predicate,
const gchar *object)
{
- gchar *update = g_strdup_printf ("INSERT { <%s> %s \"%s\" }",
- subject,
- predicate,
- object);
-
- tracker_store_queue_batch_sparql_update (update, NULL, NULL, NULL);
-
- g_free (update);
+ tracker_store_queue_batch_insert_statement (subject, predicate, object,
+ NULL, NULL, NULL);
}
static void
diff --git a/src/plugins/kmail/tracker-kmail-registrar.c b/src/plugins/kmail/tracker-kmail-registrar.c
index b104cc8..7a5705e 100644
--- a/src/plugins/kmail/tracker-kmail-registrar.c
+++ b/src/plugins/kmail/tracker-kmail-registrar.c
@@ -160,14 +160,8 @@ data_insert_statement (const gchar *subject,
const gchar *predicate,
const gchar *object)
{
- gchar *update = g_strdup_printf ("INSERT { <%s> %s \"%s\" }",
- subject,
- predicate,
- object);
-
- tracker_store_queue_batch_sparql_update (update, NULL, NULL, NULL);
-
- g_free (update);
+ tracker_store_queue_batch_insert_statement (subject, predicate, object,
+ NULL, NULL, NULL);
}
static void
diff --git a/src/tracker-store/tracker-resources.c b/src/tracker-store/tracker-resources.c
index 8370938..551aa59 100644
--- a/src/tracker-store/tracker-resources.c
+++ b/src/tracker-store/tracker-resources.c
@@ -152,7 +152,6 @@ tracker_resources_insert (TrackerResources *self,
TrackerResourcesPrivate *priv;
guint request_id;
TrackerDBusMethodInfo *info;
- gchar *update;
request_id = tracker_dbus_get_next_request_id ();
@@ -187,12 +186,10 @@ tracker_resources_insert (TrackerResources *self,
info->request_id = request_id;
info->context = context;
- update = g_strdup_printf ("INSERT { <%s> %s \"%s\" }", subject, predicate, object);
+ tracker_store_queue_insert_statement (subject, predicate, object,
+ update_callback, info,
+ destroy_method_info);
- tracker_store_queue_sparql_update (update, update_callback, info,
- destroy_method_info);
-
- g_free (update);
}
@@ -207,7 +204,6 @@ tracker_resources_delete (TrackerResources *self,
TrackerResourcesPrivate *priv;
guint request_id;
TrackerDBusMethodInfo *info;
- gchar *update;
request_id = tracker_dbus_get_next_request_id ();
@@ -242,12 +238,9 @@ tracker_resources_delete (TrackerResources *self,
info->request_id = request_id;
info->context = context;
- update = g_strdup_printf ("DELETE { <%s> %s \"%s\" }", subject, predicate, object);
-
- tracker_store_queue_sparql_update (update, update_callback, info,
- destroy_method_info);
-
- g_free (update);
+ tracker_store_queue_delete_statement (subject, predicate, object,
+ update_callback, info,
+ destroy_method_info);
}
@@ -310,21 +303,14 @@ process_turtle_file_part (TrackerResources *object)
}
while (tracker_turtle_reader_next ()) {
-
- gchar *update = g_strdup_printf ("INSERT { <%s> %s \"%s\" }",
- tracker_turtle_reader_get_subject (),
- tracker_turtle_reader_get_predicate (),
- tracker_turtle_reader_get_object ());
-
- tracker_store_queue_batch_sparql_update (update,
- turtle_update_callback,
- g_object_ref (object),
- NULL);
-
- g_free (update);
+ tracker_store_queue_batch_insert_statement (tracker_turtle_reader_get_subject (),
+ tracker_turtle_reader_get_predicate (),
+ tracker_turtle_reader_get_object (),
+ turtle_update_callback,
+ g_object_ref (object),
+ NULL);
}
-
tracker_store_queue_batch_commit (turtle_commit_callback,
g_object_ref (object),
NULL);
diff --git a/src/tracker-store/tracker-store-queue.c b/src/tracker-store/tracker-store-queue.c
index 8ec4685..f19a6cd 100644
--- a/src/tracker-store/tracker-store-queue.c
+++ b/src/tracker-store/tracker-store-queue.c
@@ -38,14 +38,23 @@ typedef struct {
} TrackerStoreQueuePrivate;
typedef enum {
- TRACKER_STORE_QUEUE_TASK_TYPE_QUERY,
- TRACKER_STORE_QUEUE_TASK_TYPE_UPDATE,
- TRACKER_STORE_QUEUE_TASK_TYPE_COMMIT,
+ TRACKER_STORE_QUEUE_TASK_TYPE_QUERY = 0,
+ TRACKER_STORE_QUEUE_TASK_TYPE_UPDATE = 1,
+ TRACKER_STORE_QUEUE_TASK_TYPE_COMMIT = 2,
+ TRACKER_STORE_QUEUE_TASK_TYPE_INSERT_STATEMENT = 3,
+ TRACKER_STORE_QUEUE_TASK_TYPE_DELETE_STATEMENT = 4,
} TrackerStoreQueueTaskType;
typedef struct {
TrackerStoreQueueTaskType type;
- gchar *query;
+ union {
+ gchar *query;
+ struct {
+ gchar *subject;
+ gchar *predicate;
+ gchar *object;
+ } statement;
+ } data;
gpointer user_data;
gboolean in_batch;
GDestroyNotify destroy;
@@ -71,7 +80,13 @@ private_free (gpointer data)
static void
tracker_store_queue_task_free (TrackerStoreQueueTask *task)
{
- g_free (task->query);
+ if (task->type >= TRACKER_STORE_QUEUE_TASK_TYPE_INSERT_STATEMENT) {
+ g_free (task->data.statement.subject);
+ g_free (task->data.statement.predicate);
+ g_free (task->data.statement.predicate);
+ } else {
+ g_free (task->data.query);
+ }
g_slice_free (TrackerStoreQueueTask, task);
}
@@ -95,7 +110,7 @@ queue_idle_handler (gpointer user_data)
switch (task->type) {
case TRACKER_STORE_QUEUE_TASK_TYPE_QUERY:
- result_set = tracker_data_query_sparql (task->query, &error);
+ result_set = tracker_data_query_sparql (task->data.query, &error);
if (task->callback.query_callback) {
task->callback.query_callback (result_set, error,
task->user_data);
@@ -116,8 +131,28 @@ queue_idle_handler (gpointer user_data)
break;
+ case TRACKER_STORE_QUEUE_TASK_TYPE_INSERT_STATEMENT:
+ tracker_data_insert_statement (task->data.statement.subject,
+ task->data.statement.predicate,
+ task->data.statement.object);
+
+ if (task->callback.update_callback) {
+ task->callback.update_callback (error, task->user_data);
+ }
+ break;
+
+ case TRACKER_STORE_QUEUE_TASK_TYPE_DELETE_STATEMENT:
+ tracker_data_delete_statement (task->data.statement.subject,
+ task->data.statement.predicate,
+ task->data.statement.object);
+
+ if (task->callback.update_callback) {
+ task->callback.update_callback (error, task->user_data);
+ }
+ break;
+
case TRACKER_STORE_QUEUE_TASK_TYPE_UPDATE:
- tracker_data_update_sparql (task->query, &error);
+ tracker_data_update_sparql (task->data.query, &error);
if (task->callback.update_callback) {
task->callback.update_callback (error, task->user_data);
}
@@ -263,7 +298,7 @@ tracker_store_queue_batch_sparql_update (const gchar *sparql,
task = g_slice_new0 (TrackerStoreQueueTask);
task->type = TRACKER_STORE_QUEUE_TASK_TYPE_UPDATE;
- task->query = g_strdup (sparql);
+ task->data.query = g_strdup (sparql);
task->user_data = user_data;
task->callback.update_callback = callback;
task->in_batch = TRUE;
@@ -291,7 +326,7 @@ tracker_store_queue_sparql_update (const gchar *sparql,
task = g_slice_new0 (TrackerStoreQueueTask);
task->type = TRACKER_STORE_QUEUE_TASK_TYPE_UPDATE;
- task->query = g_strdup (sparql);
+ task->data.query = g_strdup (sparql);
task->user_data = user_data;
task->callback.update_callback = callback;
task->destroy = destroy;
@@ -318,7 +353,7 @@ tracker_store_queue_sparql_query (const gchar *sparql,
task = g_slice_new0 (TrackerStoreQueueTask);
task->type = TRACKER_STORE_QUEUE_TASK_TYPE_QUERY;
- task->query = g_strdup (sparql);
+ task->data.query = g_strdup (sparql);
task->user_data = user_data;
task->callback.query_callback = callback;
task->destroy = destroy;
@@ -330,3 +365,99 @@ tracker_store_queue_sparql_query (const gchar *sparql,
start_handler (private);
}
}
+
+void
+tracker_store_queue_batch_insert_statement (const gchar *subject,
+ const gchar *predicate,
+ const gchar *object,
+ TrackerStoreQueueSparqlUpdateCallback callback,
+ gpointer user_data,
+ GDestroyNotify destroy)
+{
+ TrackerStoreQueuePrivate *private;
+ TrackerStoreQueueTask *task;
+
+ private = g_static_private_get (&private_key);
+ g_return_if_fail (private != NULL);
+
+ task = g_slice_new0 (TrackerStoreQueueTask);
+ task->type = TRACKER_STORE_QUEUE_TASK_TYPE_INSERT_STATEMENT;
+ task->data.statement.subject = g_strdup (subject);
+ task->data.statement.predicate = g_strdup (predicate);
+ task->data.statement.object = g_strdup (object);
+ task->user_data = user_data;
+ task->callback.update_callback = callback;
+ task->in_batch = TRUE;
+ task->destroy = destroy;
+
+ g_queue_insert_sorted (private->queue, task,
+ queue_sorter, NULL);
+
+ if (!private->have_handler) {
+ start_handler (private);
+ }
+}
+
+
+void
+tracker_store_queue_insert_statement (const gchar *subject,
+ const gchar *predicate,
+ const gchar *object,
+ TrackerStoreQueueSparqlUpdateCallback callback,
+ gpointer user_data,
+ GDestroyNotify destroy)
+{
+ TrackerStoreQueuePrivate *private;
+ TrackerStoreQueueTask *task;
+
+ private = g_static_private_get (&private_key);
+ g_return_if_fail (private != NULL);
+
+ task = g_slice_new0 (TrackerStoreQueueTask);
+ task->type = TRACKER_STORE_QUEUE_TASK_TYPE_INSERT_STATEMENT;
+ task->data.statement.subject = g_strdup (subject);
+ task->data.statement.predicate = g_strdup (predicate);
+ task->data.statement.object = g_strdup (object);
+ task->user_data = user_data;
+ task->callback.update_callback = callback;
+ task->destroy = destroy;
+
+ g_queue_insert_sorted (private->queue, task,
+ queue_sorter, NULL);
+
+ if (!private->have_handler) {
+ start_handler (private);
+ }
+}
+
+void
+tracker_store_queue_delete_statement (const gchar *subject,
+ const gchar *predicate,
+ const gchar *object,
+ TrackerStoreQueueSparqlUpdateCallback callback,
+ gpointer user_data,
+ GDestroyNotify destroy)
+{
+ TrackerStoreQueuePrivate *private;
+ TrackerStoreQueueTask *task;
+
+ private = g_static_private_get (&private_key);
+ g_return_if_fail (private != NULL);
+
+ task = g_slice_new0 (TrackerStoreQueueTask);
+ task->type = TRACKER_STORE_QUEUE_TASK_TYPE_DELETE_STATEMENT;
+ task->data.statement.subject = g_strdup (subject);
+ task->data.statement.predicate = g_strdup (predicate);
+ task->data.statement.object = g_strdup (object);
+ task->user_data = user_data;
+ task->callback.update_callback = callback;
+ task->destroy = destroy;
+
+ g_queue_insert_sorted (private->queue, task,
+ queue_sorter, NULL);
+
+ if (!private->have_handler) {
+ start_handler (private);
+ }
+}
+
diff --git a/src/tracker-store/tracker-store-queue.h b/src/tracker-store/tracker-store-queue.h
index 38e6afd..fe435ba 100644
--- a/src/tracker-store/tracker-store-queue.h
+++ b/src/tracker-store/tracker-store-queue.h
@@ -32,30 +32,49 @@
G_BEGIN_DECLS
-typedef void (* TrackerStoreQueueSparqlUpdateCallback) (GError *error,
- gpointer user_data);
-typedef void (* TrackerStoreQueueCommitCallback) (gpointer user_data);
-typedef void (* TrackerStoreQueueSparqlQueryCallback) (TrackerDBResultSet *results,
- GError *error,
- gpointer user_data);
-
-void tracker_store_queue_init (void);
-void tracker_store_queue_shutdown (void);
-void tracker_store_queue_batch_commit (TrackerStoreQueueCommitCallback callback,
- gpointer user_data,
- GDestroyNotify destroy);
-void tracker_store_queue_batch_sparql_update (const gchar *sparql,
- TrackerStoreQueueSparqlUpdateCallback callback,
- gpointer user_data,
- GDestroyNotify destroy);
-void tracker_store_queue_sparql_update (const gchar *sparql,
- TrackerStoreQueueSparqlUpdateCallback callback,
- gpointer user_data,
- GDestroyNotify destroy);
-void tracker_store_queue_sparql_query (const gchar *sparql,
- TrackerStoreQueueSparqlQueryCallback callback,
- gpointer user_data,
- GDestroyNotify destroy);
+typedef void (* TrackerStoreQueueSparqlUpdateCallback) (GError *error,
+ gpointer user_data);
+typedef void (* TrackerStoreQueueCommitCallback) (gpointer user_data);
+typedef void (* TrackerStoreQueueSparqlQueryCallback) (TrackerDBResultSet *results,
+ GError *error,
+ gpointer user_data);
+
+void tracker_store_queue_init (void);
+void tracker_store_queue_shutdown (void);
+void tracker_store_queue_batch_commit (TrackerStoreQueueCommitCallback callback,
+ gpointer user_data,
+ GDestroyNotify destroy);
+void tracker_store_queue_batch_sparql_update (const gchar *sparql,
+ TrackerStoreQueueSparqlUpdateCallback callback,
+ gpointer user_data,
+ GDestroyNotify destroy);
+void tracker_store_queue_batch_insert_statement (const gchar *subject,
+ const gchar *predicate,
+ const gchar *object,
+ TrackerStoreQueueSparqlUpdateCallback callback,
+ gpointer user_data,
+ GDestroyNotify destroy);
+void tracker_store_queue_sparql_update (const gchar *sparql,
+ TrackerStoreQueueSparqlUpdateCallback callback,
+ gpointer user_data,
+ GDestroyNotify destroy);
+void tracker_store_queue_insert_statement (const gchar *subject,
+ const gchar *predicate,
+ const gchar *object,
+ TrackerStoreQueueSparqlUpdateCallback callback,
+ gpointer user_data,
+ GDestroyNotify destroy);
+void tracker_store_queue_delete_statement (const gchar *subject,
+ const gchar *predicate,
+ const gchar *object,
+ TrackerStoreQueueSparqlUpdateCallback callback,
+ gpointer user_data,
+ GDestroyNotify destroy);
+void tracker_store_queue_sparql_query (const gchar *sparql,
+ TrackerStoreQueueSparqlQueryCallback callback,
+ gpointer user_data,
+ GDestroyNotify destroy);
+
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]