[tracker/binary-log-2: 35/44] libtracker-data: Make sure to use the right IDs when replaying journal
- From: Jürg Billeter <juergbi src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [tracker/binary-log-2: 35/44] libtracker-data: Make sure to use the right IDs when replaying journal
- Date: Mon, 11 Jan 2010 17:55:19 +0000 (UTC)
commit e3855eb33065e74fc2c66ab19838cca31f94aac2
Author: Jürg Billeter <j bitron ch>
Date: Thu Jan 7 14:35:44 2010 +0100
libtracker-data: Make sure to use the right IDs when replaying journal
src/libtracker-data/tracker-data-manager.c | 143 +++++++++++++---------------
1 files changed, 66 insertions(+), 77 deletions(-)
---
diff --git a/src/libtracker-data/tracker-data-manager.c b/src/libtracker-data/tracker-data-manager.c
index c82eb1b..9dc2b75 100644
--- a/src/libtracker-data/tracker-data-manager.c
+++ b/src/libtracker-data/tracker-data-manager.c
@@ -67,9 +67,11 @@ static gboolean in_journal_replay;
static void
load_ontology_statement (const gchar *ontology_file,
+ guint32 subject_id,
const gchar *subject,
const gchar *predicate,
- const gchar *object)
+ const gchar *object,
+ guint32 *max_id)
{
if (g_strcmp0 (predicate, RDF_TYPE) == 0) {
if (g_strcmp0 (object, RDFS_CLASS) == 0) {
@@ -80,9 +82,15 @@ load_ontology_statement (const gchar *ontology_file,
return;
}
+ if (max_id) {
+ subject_id = ++(*max_id);
+ }
+
class = tracker_class_new ();
tracker_class_set_uri (class, subject);
+ tracker_class_set_id (class, subject_id);
tracker_ontology_add_class (class);
+ tracker_ontology_add_id_uri_pair (subject_id, subject);
g_object_unref (class);
} else if (g_strcmp0 (object, RDF_PROPERTY) == 0) {
TrackerProperty *property;
@@ -92,9 +100,15 @@ load_ontology_statement (const gchar *ontology_file,
return;
}
+ if (max_id) {
+ subject_id = ++(*max_id);
+ }
+
property = tracker_property_new ();
tracker_property_set_uri (property, subject);
+ tracker_property_set_id (property, subject_id);
tracker_ontology_add_property (property);
+ tracker_ontology_add_id_uri_pair (subject_id, subject);
g_object_unref (property);
} else if (g_strcmp0 (object, NRL_INVERSE_FUNCTIONAL_PROPERTY) == 0) {
TrackerProperty *property;
@@ -259,7 +273,8 @@ load_ontology_statement (const gchar *ontology_file,
}
static void
-load_ontology_file_from_path (const gchar *ontology_file)
+load_ontology_file_from_path (const gchar *ontology_file,
+ guint32 *max_id)
{
TrackerTurtleReader *reader;
GError *error = NULL;
@@ -278,7 +293,7 @@ load_ontology_file_from_path (const gchar *ontology_file)
predicate = tracker_turtle_reader_get_predicate (reader);
object = tracker_turtle_reader_get_object (reader);
- load_ontology_statement (ontology_file, subject, predicate, object);
+ load_ontology_statement (ontology_file, 0, subject, predicate, object, max_id);
}
g_object_unref (reader);
@@ -290,12 +305,13 @@ load_ontology_file_from_path (const gchar *ontology_file)
}
static void
-load_ontology_file (const gchar *filename)
+load_ontology_file (const gchar *filename,
+ guint32 *max_id)
{
gchar *ontology_file;
ontology_file = g_build_filename (ontologies_dir, filename, NULL);
- load_ontology_file_from_path (ontology_file);
+ load_ontology_file_from_path (ontology_file, max_id);
g_free (ontology_file);
}
@@ -335,10 +351,12 @@ load_ontology_from_journal (void)
subject = g_hash_table_lookup (id_uri_map, GUINT_TO_POINTER (subject_id));
predicate = g_hash_table_lookup (id_uri_map, GUINT_TO_POINTER (predicate_id));
- load_ontology_statement ("journal", subject, predicate, object);
+ load_ontology_statement ("journal", subject_id, subject, predicate, object, NULL);
}
}
+ g_hash_table_unref (id_uri_map);
+
return id_uri_map;
}
@@ -691,14 +709,11 @@ db_get_static_data (TrackerDBInterface *iface)
static void
-insert_uri_in_resource_table (TrackerDBInterface *iface,
- const gchar *uri,
- gint *max_id,
- TrackerClass *class,
- TrackerProperty *property)
+insert_uri_in_resource_table (TrackerDBInterface *iface,
+ const gchar *uri,
+ guint32 id)
{
TrackerDBStatement *stmt;
- gint id = ++(*max_id);
GError *error = NULL;
stmt = tracker_db_interface_create_statement (iface,
@@ -721,14 +736,6 @@ insert_uri_in_resource_table (TrackerDBInterface *iface,
tracker_db_journal_append_resource (id, uri);
}
- tracker_ontology_add_id_uri_pair (id, uri);
-
- if (class)
- tracker_class_set_id (class, id);
-
- if (property)
- tracker_property_set_id (property, id);
-
g_object_unref (stmt);
}
@@ -938,6 +945,40 @@ create_fts_table (TrackerDBInterface *iface)
g_free (query);
}
+static void
+import_ontology_into_db (void)
+{
+ TrackerDBInterface *iface;
+
+ TrackerClass **classes;
+ TrackerProperty **properties;
+ guint i, n_props, n_classes;
+
+ iface = tracker_db_manager_get_db_interface ();
+
+ classes = tracker_ontology_get_classes (&n_classes);
+ properties = tracker_ontology_get_properties (&n_props);
+
+ /* create tables */
+ for (i = 0; i < n_classes; i++) {
+ create_decomposed_metadata_tables (iface, classes[i]);
+ }
+
+ create_fts_table (iface);
+
+ /* insert classes into rdfs:Resource table */
+ for (i = 0; i < n_classes; i++) {
+ insert_uri_in_resource_table (iface, tracker_class_get_uri (classes[i]),
+ tracker_class_get_id (classes[i]));
+ }
+
+ /* insert properties into rdfs:Resource table */
+ for (i = 0; i < n_props; i++) {
+ insert_uri_in_resource_table (iface, tracker_property_get_uri (properties[i]),
+ tracker_property_get_id (properties[i]));
+ }
+}
+
gboolean
tracker_data_manager_init (TrackerDBManagerFlags flags,
const gchar *test_schema,
@@ -978,41 +1019,13 @@ tracker_data_manager_init (TrackerDBManagerFlags flags,
}
if (read_journal) {
- TrackerClass **classes;
- TrackerProperty **properties;
- gint max_id = 0;
- guint i, n_props, n_classes;
-
in_journal_replay = TRUE;
/* load ontology from journal into memory */
- /*id_uri_map =*/ load_ontology_from_journal ();
-
- classes = tracker_ontology_get_classes (&n_classes);
+ load_ontology_from_journal ();
tracker_data_begin_replay_transaction ();
-
- /* create tables */
- for (i = 0; i < n_classes; i++) {
- create_decomposed_metadata_tables (iface, classes[i]);
- }
-
- create_fts_table (iface);
-
- /* insert classes into rdfs:Resource table */
- for (i = 0; i < n_classes; i++) {
- insert_uri_in_resource_table (iface, tracker_class_get_uri (classes[i]),
- &max_id, classes[i], NULL);
- }
-
- /* insert properties into rdfs:Resource table */
- properties = tracker_ontology_get_properties (&n_props);
-
- for (i = 0; i < n_props; i++) {
- insert_uri_in_resource_table (iface, tracker_property_get_uri (properties[i]),
- &max_id, NULL, properties[i]);
- }
-
+ import_ontology_into_db ();
tracker_data_commit_transaction ();
tracker_db_journal_reader_shutdown ();
@@ -1024,14 +1037,11 @@ tracker_data_manager_init (TrackerDBManagerFlags flags,
/* open journal for writing */
tracker_db_journal_init (NULL);
} else if (is_first_time_index) {
- TrackerClass **classes;
- TrackerProperty **properties;
gint max_id = 0;
GList *sorted = NULL, *l;
gchar *test_schema_path = NULL;
const gchar *env_path;
GError *error = NULL;
- guint i, n_props, n_classes;
env_path = g_getenv ("TRACKER_DB_ONTOLOGIES_DIR");
@@ -1077,40 +1087,19 @@ tracker_data_manager_init (TrackerDBManagerFlags flags,
/* load ontology from files into memory */
for (l = sorted; l; l = l->next) {
g_debug ("Loading ontology %s", (char *) l->data);
- load_ontology_file (l->data);
+ load_ontology_file (l->data, &max_id);
}
if (test_schema) {
g_debug ("Loading ontology:'%s' (TEST ONTOLOGY)", test_schema_path);
- load_ontology_file_from_path (test_schema_path);
+ load_ontology_file_from_path (test_schema_path, &max_id);
}
- classes = tracker_ontology_get_classes (&n_classes);
-
tracker_data_begin_transaction ();
tracker_db_journal_start_transaction ();
- /* create tables */
- for (i = 0; i < n_classes; i++) {
- create_decomposed_metadata_tables (iface, classes[i]);
- }
-
- create_fts_table (iface);
-
- /* insert classes into rdfs:Resource table */
- for (i = 0; i < n_classes; i++) {
- insert_uri_in_resource_table (iface, tracker_class_get_uri (classes[i]),
- &max_id, classes[i], NULL);
- }
-
- /* insert properties into rdfs:Resource table */
- properties = tracker_ontology_get_properties (&n_props);
-
- for (i = 0; i < n_props; i++) {
- insert_uri_in_resource_table (iface, tracker_property_get_uri (properties[i]),
- &max_id, NULL, properties[i]);
- }
+ import_ontology_into_db ();
/* store ontology in database */
for (l = sorted; l; l = l->next) {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]