[tracker/property-changes: 3/3] libtracker-data: Support for changing tracker:indexed in ontology
- From: Philip Van Hoof <pvanhoof src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker/property-changes: 3/3] libtracker-data: Support for changing tracker:indexed in ontology
- Date: Wed, 31 Mar 2010 13:24:29 +0000 (UTC)
commit 517ef1d01661ff99fd39307de4cd0171a2176491
Author: Philip Van Hoof <philip codeminded be>
Date: Wed Mar 31 14:30:18 2010 +0200
libtracker-data: Support for changing tracker:indexed in ontology
src/libtracker-data/tracker-data-manager.c | 109 ++++++++++++++++++++--------
1 files changed, 78 insertions(+), 31 deletions(-)
---
diff --git a/src/libtracker-data/tracker-data-manager.c b/src/libtracker-data/tracker-data-manager.c
index f4f9388..0aa2516 100644
--- a/src/libtracker-data/tracker-data-manager.c
+++ b/src/libtracker-data/tracker-data-manager.c
@@ -75,10 +75,52 @@ static gboolean initialized;
static gboolean in_journal_replay;
static void
-notify_and_writeback_helper (const gchar *kind,
- const gchar *subject,
- const gchar *predicate,
- const gchar *object)
+set_index_for_single_value_property (TrackerDBInterface *iface,
+ const gchar *service_name,
+ const gchar *field_name,
+ gboolean enabled)
+{
+ if (enabled) {
+ tracker_db_interface_execute_query (iface, NULL,
+ "CREATE INDEX \"%s_%s\" ON \"%s\" (\"%s\")",
+ service_name,
+ field_name,
+ service_name,
+ field_name);
+ } else {
+ tracker_db_interface_execute_query (iface, NULL,
+ "DROP INDEX IF EXISTS \"%s_%s\"",
+ service_name,
+ field_name);
+ }
+}
+
+static void
+set_index_for_multi_value_property (TrackerDBInterface *iface,
+ const gchar *service_name,
+ const gchar *field_name,
+ gboolean enabled)
+{
+ if (enabled) {
+ tracker_db_interface_execute_query (iface, NULL,
+ "CREATE INDEX \"%s_%s_ID\" ON \"%s_%s\" (ID)",
+ service_name,
+ field_name,
+ service_name,
+ field_name);
+ } else {
+ tracker_db_interface_execute_query (iface, NULL,
+ "DROP INDEX IF EXISTS \"%s_%s_ID\"",
+ service_name,
+ field_name);
+ }
+}
+
+static gboolean
+update_property_value (const gchar *kind,
+ const gchar *subject,
+ const gchar *predicate,
+ const gchar *object)
{
GError *error = NULL;
TrackerDBResultSet *result_set;
@@ -86,7 +128,7 @@ notify_and_writeback_helper (const gchar *kind,
gboolean needed = TRUE;
query = g_strdup_printf ("SELECT ?old_value WHERE { "
- "<%s> tracker:%s ?old_value "
+ "<%s> %s ?old_value "
"}", subject, kind);
result_set = tracker_data_query_sparql (query, &error);
@@ -122,6 +164,8 @@ notify_and_writeback_helper (const gchar *kind,
kind, subject, error->message);
g_error_free (error);
}
+
+ return needed;
}
void
@@ -251,7 +295,6 @@ tracker_data_ontology_load_statement (const gchar *ontology_path,
tracker_class_add_super_class (class, super_class);
} else if (g_strcmp0 (predicate, TRACKER_PREFIX "notify") == 0) {
TrackerClass *class;
- gboolean wanted_value;
class = tracker_ontologies_get_class_by_uri (subject);
if (class == NULL) {
@@ -259,17 +302,12 @@ tracker_data_ontology_load_statement (const gchar *ontology_path,
return;
}
- if (strcmp (object, "true") == 0) {
- wanted_value = TRUE;
- }
-
if (tracker_class_get_is_new (class) != in_update) {
- notify_and_writeback_helper ("notify", subject, predicate, object);
+ update_property_value ("tracker:notify", subject, predicate, object);
}
} else if (g_strcmp0 (predicate, TRACKER_PREFIX "writeback") == 0) {
TrackerProperty *property;
- gboolean wanted_value;
property = tracker_ontologies_get_property_by_uri (subject);
if (property == NULL) {
@@ -277,14 +315,11 @@ tracker_data_ontology_load_statement (const gchar *ontology_path,
return;
}
- if (strcmp (object, "true") == 0) {
- wanted_value = TRUE;
- }
-
if (tracker_property_get_is_new (property) != in_update) {
- notify_and_writeback_helper ("writeback", subject, predicate, object);
+ update_property_value ("tracker:writeback", subject, predicate, object);
}
+
} else if (g_strcmp0 (predicate, RDFS_SUB_PROPERTY_OF) == 0) {
TrackerProperty *property, *super_property;
@@ -365,6 +400,7 @@ tracker_data_ontology_load_statement (const gchar *ontology_path,
}
} else if (g_strcmp0 (predicate, TRACKER_PREFIX "indexed") == 0) {
TrackerProperty *property;
+ gboolean enabled;
property = tracker_ontologies_get_property_by_uri (subject);
if (property == NULL) {
@@ -372,11 +408,31 @@ tracker_data_ontology_load_statement (const gchar *ontology_path,
return;
}
+ enabled = (strcmp (object, "true") == 0);
+
if (tracker_property_get_is_new (property) != in_update) {
- return;
+
+ if (update_property_value ("tracker:indexed", subject, predicate, object)) {
+ TrackerDBInterface *iface;
+ TrackerClass *class;
+ const gchar *service_name;
+ const gchar *field_name;
+
+ iface = tracker_db_manager_get_db_interface ();
+
+ class = tracker_property_get_domain (property);
+ field_name = tracker_property_get_name (property);
+ service_name = tracker_class_get_name (class);
+
+ if (tracker_property_get_multiple_values (property)) {
+ set_index_for_multi_value_property (iface, service_name, field_name, enabled);
+ } else {
+ set_index_for_single_value_property (iface, service_name, field_name, enabled);
+ }
+ }
}
- if (strcmp (object, "true") == 0) {
+ if (enabled) {
tracker_property_set_indexed (property, TRUE);
}
} else if (g_strcmp0 (predicate, TRACKER_PREFIX "transient") == 0) {
@@ -1194,12 +1250,8 @@ create_decomposed_metadata_property_table (TrackerDBInterface *iface,
sql->str,
field_name);
- tracker_db_interface_execute_query (iface, NULL,
- "CREATE INDEX \"%s_%s_ID\" ON \"%s_%s\" (ID)",
- service_name,
- field_name,
- service_name,
- field_name);
+ set_index_for_multi_value_property (iface, service_name, field_name, TRUE);
+
} else {
/* we still have to include the property value in
* the unique index for proper constraints */
@@ -1361,12 +1413,7 @@ create_decomposed_metadata_tables (TrackerDBInterface *iface,
if (!tracker_property_get_multiple_values (field)
&& tracker_property_get_indexed (field)) {
field_name = tracker_property_get_name (field);
- tracker_db_interface_execute_query (iface, NULL,
- "CREATE INDEX \"%s_%s\" ON \"%s\" (\"%s\")",
- service_name,
- field_name,
- service_name,
- field_name);
+ set_index_for_single_value_property (iface, service_name, field_name, TRUE);
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]