[tracker/ontology-cope: 5/9] libtracker-common, -data: distinguish between entities that are in_update
- From: Philip Van Hoof <pvanhoof src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker/ontology-cope: 5/9] libtracker-common, -data: distinguish between entities that are in_update
- Date: Thu, 18 Feb 2010 21:39:52 +0000 (UTC)
commit 49d2a2a86a4f57f753d711ed9ba5692afa82ea5e
Author: Philip Van Hoof <philip codeminded be>
Date: Wed Feb 17 16:01:51 2010 +0100
libtracker-common, -data: distinguish between entities that are in_update
src/libtracker-common/tracker-class.c | 43 ++++-
src/libtracker-common/tracker-class.h | 3 +
src/libtracker-common/tracker-namespace.c | 43 ++++-
src/libtracker-common/tracker-namespace.h | 20 +-
src/libtracker-common/tracker-ontologies.c | 1 -
src/libtracker-common/tracker-ontologies.h | 1 -
src/libtracker-common/tracker-ontology.c | 43 ++++-
src/libtracker-common/tracker-ontology.h | 4 +
src/libtracker-common/tracker-property.c | 43 ++++-
src/libtracker-common/tracker-property.h | 3 +
src/libtracker-data/tracker-data-manager.c | 356 ++++++++++++++++++++++++----
src/libtracker-data/tracker-data-update.c | 16 +-
src/libtracker-data/tracker-data-update.h | 1 +
13 files changed, 504 insertions(+), 73 deletions(-)
---
diff --git a/src/libtracker-common/tracker-class.c b/src/libtracker-common/tracker-class.c
index 4cf73ae..1ecbf58 100644
--- a/src/libtracker-common/tracker-class.c
+++ b/src/libtracker-common/tracker-class.c
@@ -38,6 +38,7 @@ struct _TrackerClassPriv {
gchar *name;
gint count;
gint id;
+ gboolean is_new;
GArray *super_classes;
};
@@ -57,7 +58,8 @@ enum {
PROP_URI,
PROP_NAME,
PROP_COUNT,
- PROP_ID
+ PROP_ID,
+ PROP_IS_NEW
};
G_DEFINE_TYPE (TrackerClass, tracker_class, G_TYPE_OBJECT);
@@ -103,6 +105,13 @@ tracker_class_class_init (TrackerClassClass *klass)
G_MAXINT,
0,
G_PARAM_READABLE | G_PARAM_WRITABLE));
+ g_object_class_install_property (object_class,
+ PROP_IS_NEW,
+ g_param_spec_boolean ("is-new",
+ "is-new",
+ "Is new",
+ FALSE,
+ G_PARAM_READWRITE));
g_type_class_add_private (object_class, sizeof (TrackerClassPriv));
}
@@ -156,6 +165,9 @@ class_get_property (GObject *object,
case PROP_ID:
g_value_set_int (value, priv->id);
break;
+ case PROP_IS_NEW:
+ g_value_set_boolean (value, priv->is_new);
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
break;
@@ -181,6 +193,10 @@ class_set_property (GObject *object,
tracker_class_set_id (TRACKER_CLASS (object),
g_value_get_int (value));
break;
+ case PROP_IS_NEW:
+ tracker_class_set_is_new (TRACKER_CLASS (object),
+ g_value_get_boolean (value));
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
break;
@@ -257,6 +273,18 @@ tracker_class_get_super_classes (TrackerClass *service)
return (TrackerClass **) priv->super_classes->data;
}
+gboolean
+tracker_class_get_is_new (TrackerClass *service)
+{
+ TrackerClassPriv *priv;
+
+ g_return_val_if_fail (TRACKER_IS_CLASS (service), FALSE);
+
+ priv = GET_PRIV (service);
+
+ return priv->is_new;
+}
+
void
tracker_class_set_uri (TrackerClass *service,
const gchar *value)
@@ -361,3 +389,16 @@ tracker_class_add_super_class (TrackerClass *service,
g_array_append_val (priv->super_classes, value);
}
+void
+tracker_class_set_is_new (TrackerClass *service,
+ gboolean value)
+{
+ TrackerClassPriv *priv;
+
+ g_return_if_fail (TRACKER_IS_CLASS (service));
+
+ priv = GET_PRIV (service);
+
+ priv->is_new = value;
+ g_object_notify (G_OBJECT (service), "is-new");
+}
diff --git a/src/libtracker-common/tracker-class.h b/src/libtracker-common/tracker-class.h
index ceca625..672d3ce 100644
--- a/src/libtracker-common/tracker-class.h
+++ b/src/libtracker-common/tracker-class.h
@@ -53,6 +53,7 @@ const gchar * tracker_class_get_uri (TrackerClass *service);
const gchar * tracker_class_get_name (TrackerClass *service);
gint tracker_class_get_count (TrackerClass *service);
gint tracker_class_get_id (TrackerClass *service);
+gboolean tracker_class_get_is_new (TrackerClass *service);
TrackerClass **tracker_class_get_super_classes (TrackerClass *service);
void tracker_class_set_uri (TrackerClass *service,
@@ -65,6 +66,8 @@ void tracker_class_add_super_class (TrackerClass *self,
TrackerClass *value);
void tracker_class_set_id (TrackerClass *service,
gint id);
+void tracker_class_set_is_new (TrackerClass *service,
+ gboolean value);
G_END_DECLS
diff --git a/src/libtracker-common/tracker-namespace.c b/src/libtracker-common/tracker-namespace.c
index 532870a..e189702 100644
--- a/src/libtracker-common/tracker-namespace.c
+++ b/src/libtracker-common/tracker-namespace.c
@@ -33,6 +33,7 @@ typedef struct _TrackerNamespacePriv TrackerNamespacePriv;
struct _TrackerNamespacePriv {
gchar *uri;
gchar *prefix;
+ gboolean is_new;
};
static void namespace_finalize (GObject *object);
@@ -48,7 +49,8 @@ static void namespace_set_property (GObject *object,
enum {
PROP_0,
PROP_URI,
- PROP_PREFIX
+ PROP_PREFIX,
+ PROP_IS_NEW
};
G_DEFINE_TYPE (TrackerNamespace, tracker_namespace, G_TYPE_OBJECT);
@@ -76,6 +78,13 @@ tracker_namespace_class_init (TrackerNamespaceClass *klass)
"Prefix",
NULL,
G_PARAM_READWRITE));
+ g_object_class_install_property (object_class,
+ PROP_IS_NEW,
+ g_param_spec_boolean ("is-new",
+ "is-new",
+ "Set to TRUE when a new class or property is to be added to the database ontology",
+ FALSE,
+ G_PARAM_READWRITE));
g_type_class_add_private (object_class, sizeof (TrackerNamespacePriv));
}
@@ -115,6 +124,9 @@ namespace_get_property (GObject *object,
case PROP_PREFIX:
g_value_set_string (value, priv->prefix);
break;
+ case PROP_IS_NEW:
+ g_value_set_boolean (value, priv->is_new);
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
break;
@@ -140,6 +152,10 @@ namespace_set_property (GObject *object,
tracker_namespace_set_prefix (TRACKER_NAMESPACE (object),
g_value_get_string (value));
break;
+ case PROP_IS_NEW:
+ tracker_namespace_set_is_new (TRACKER_NAMESPACE (object),
+ g_value_get_boolean (value));
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
break;
@@ -180,6 +196,18 @@ tracker_namespace_get_prefix (TrackerNamespace *namespace)
return priv->prefix;
}
+gboolean
+tracker_namespace_get_is_new (TrackerNamespace *namespace)
+{
+ TrackerNamespacePriv *priv;
+
+ g_return_val_if_fail (TRACKER_IS_NAMESPACE (namespace), FALSE);
+
+ priv = GET_PRIV (namespace);
+
+ return priv->is_new;
+}
+
void
tracker_namespace_set_uri (TrackerNamespace *namespace,
const gchar *value)
@@ -222,3 +250,16 @@ tracker_namespace_set_prefix (TrackerNamespace *namespace,
g_object_notify (G_OBJECT (namespace), "prefix");
}
+void
+tracker_namespace_set_is_new (TrackerNamespace *namespace,
+ gboolean value)
+{
+ TrackerNamespacePriv *priv;
+
+ g_return_if_fail (TRACKER_IS_NAMESPACE (namespace));
+
+ priv = GET_PRIV (namespace);
+
+ priv->is_new = value;
+ g_object_notify (G_OBJECT (namespace), "is-new");
+}
diff --git a/src/libtracker-common/tracker-namespace.h b/src/libtracker-common/tracker-namespace.h
index 708db59..9265cae 100644
--- a/src/libtracker-common/tracker-namespace.h
+++ b/src/libtracker-common/tracker-namespace.h
@@ -46,14 +46,18 @@ struct _TrackerNamespaceClass {
GObjectClass parent_class;
};
-GType tracker_namespace_get_type (void) G_GNUC_CONST;
-TrackerNamespace *tracker_namespace_new (void);
-const gchar * tracker_namespace_get_uri (TrackerNamespace *namespace_);
-const gchar * tracker_namespace_get_prefix (TrackerNamespace *namespace_);
-void tracker_namespace_set_uri (TrackerNamespace *namespace_,
- const gchar *value);
-void tracker_namespace_set_prefix (TrackerNamespace *namespace_,
- const gchar *value);
+GType tracker_namespace_get_type (void) G_GNUC_CONST;
+TrackerNamespace *tracker_namespace_new (void);
+const gchar * tracker_namespace_get_uri (TrackerNamespace *namespace_);
+const gchar * tracker_namespace_get_prefix (TrackerNamespace *namespace_);
+gboolean tracker_namespace_get_is_new (TrackerNamespace *namespace_);
+
+void tracker_namespace_set_uri (TrackerNamespace *namespace_,
+ const gchar *value);
+void tracker_namespace_set_prefix (TrackerNamespace *namespace_,
+ const gchar *value);
+void tracker_namespace_set_is_new (TrackerNamespace *namespace_,
+ gboolean value);
G_END_DECLS
diff --git a/src/libtracker-common/tracker-ontologies.c b/src/libtracker-common/tracker-ontologies.c
index 021ba52..3fa2630 100644
--- a/src/libtracker-common/tracker-ontologies.c
+++ b/src/libtracker-common/tracker-ontologies.c
@@ -312,4 +312,3 @@ tracker_ontologies_get_ontology_by_uri (const gchar *uri)
return g_hash_table_lookup (ontology_uris, uri);
}
-
diff --git a/src/libtracker-common/tracker-ontologies.h b/src/libtracker-common/tracker-ontologies.h
index 4ebeff5..ec9e58f 100644
--- a/src/libtracker-common/tracker-ontologies.h
+++ b/src/libtracker-common/tracker-ontologies.h
@@ -85,4 +85,3 @@ void tracker_ontologies_add_id_uri_pair (gint id
G_END_DECLS
#endif /* __LIBTRACKER_COMMON_ONTOLOGY_H__ */
-
diff --git a/src/libtracker-common/tracker-ontology.c b/src/libtracker-common/tracker-ontology.c
index 1fef7dc..6615c70 100644
--- a/src/libtracker-common/tracker-ontology.c
+++ b/src/libtracker-common/tracker-ontology.c
@@ -35,6 +35,7 @@ typedef struct _TrackerOntologyPriv TrackerOntologyPriv;
struct _TrackerOntologyPriv {
gchar *uri;
time_t last_modified;
+ gboolean is_new;
};
static void ontology_finalize (GObject *object);
@@ -51,6 +52,7 @@ enum {
PROP_0,
PROP_URI,
PROP_LAST_MODIFIED,
+ PROP_IS_NEW
};
G_DEFINE_TYPE (TrackerOntology, tracker_ontology, G_TYPE_OBJECT);
@@ -71,7 +73,6 @@ tracker_ontology_class_init (TrackerOntologyClass *klass)
"URI",
NULL,
G_PARAM_READWRITE));
-
g_object_class_install_property (object_class,
PROP_LAST_MODIFIED,
g_param_spec_int64 ("last-modified",
@@ -81,6 +82,13 @@ tracker_ontology_class_init (TrackerOntologyClass *klass)
G_MAXINT64,
0,
G_PARAM_READWRITE));
+ g_object_class_install_property (object_class,
+ PROP_IS_NEW,
+ g_param_spec_boolean ("is-new",
+ "is-new",
+ "Set to TRUE when a new class or property is to be added to the database ontology",
+ FALSE,
+ G_PARAM_READWRITE));
g_type_class_add_private (object_class, sizeof (TrackerOntologyPriv));
}
@@ -119,6 +127,9 @@ ontology_get_property (GObject *object,
case PROP_LAST_MODIFIED:
g_value_set_int64 (value, priv->last_modified);
break;
+ case PROP_IS_NEW:
+ g_value_set_boolean (value, priv->is_new);
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
break;
@@ -144,6 +155,10 @@ ontology_set_property (GObject *object,
tracker_ontology_set_last_modified (TRACKER_ONTOLOGY (object),
g_value_get_int64 (value));
break;
+ case PROP_IS_NEW:
+ tracker_ontology_set_is_new (TRACKER_ONTOLOGY (object),
+ g_value_get_boolean (value));
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
break;
@@ -172,6 +187,18 @@ tracker_ontology_get_last_modified (TrackerOntology *ontology)
return (gint64) priv->last_modified;
}
+gboolean
+tracker_ontology_get_is_new (TrackerOntology *ontology)
+{
+ TrackerOntologyPriv *priv;
+
+ g_return_val_if_fail (TRACKER_IS_ONTOLOGY (ontology), FALSE);
+
+ priv = GET_PRIV (ontology);
+
+ return priv->is_new;
+}
+
void
tracker_ontology_set_last_modified (TrackerOntology *ontology,
@@ -222,3 +249,17 @@ tracker_ontology_set_uri (TrackerOntology *ontology,
g_object_notify (G_OBJECT (ontology), "uri");
}
+
+void
+tracker_ontology_set_is_new (TrackerOntology *ontology,
+ gboolean value)
+{
+ TrackerOntologyPriv *priv;
+
+ g_return_if_fail (TRACKER_IS_ONTOLOGY (ontology));
+
+ priv = GET_PRIV (ontology);
+
+ priv->is_new = value;
+ g_object_notify (G_OBJECT (ontology), "is-new");
+}
diff --git a/src/libtracker-common/tracker-ontology.h b/src/libtracker-common/tracker-ontology.h
index 0cc0d50..4a2a851 100644
--- a/src/libtracker-common/tracker-ontology.h
+++ b/src/libtracker-common/tracker-ontology.h
@@ -54,8 +54,12 @@ time_t tracker_ontology_get_last_modified (TrackerOntology *ontology)
void tracker_ontology_set_last_modified (TrackerOntology *ontology,
time_t value);
const gchar * tracker_ontology_get_uri (TrackerOntology *ontology);
+gboolean tracker_ontology_get_is_new (TrackerOntology *ontology);
+
void tracker_ontology_set_uri (TrackerOntology *ontology,
const gchar *value);
+void tracker_ontology_set_is_new (TrackerOntology *ontology,
+ gboolean value);
G_END_DECLS
diff --git a/src/libtracker-common/tracker-property.c b/src/libtracker-common/tracker-property.c
index c091b3f..0e742e2 100644
--- a/src/libtracker-common/tracker-property.c
+++ b/src/libtracker-common/tracker-property.c
@@ -55,6 +55,7 @@ struct _TrackerPropertyPriv {
gboolean filtered;
gboolean transient;
gboolean is_inverse_functional_property;
+ gboolean is_new;
GArray *super_properties;
};
@@ -84,7 +85,8 @@ enum {
PROP_FILTERED,
PROP_TRANSIENT,
PROP_IS_INVERSE_FUNCTIONAL_PROPERTY,
- PROP_ID
+ PROP_ID,
+ PROP_IS_NEW
};
GType
@@ -259,6 +261,13 @@ tracker_property_class_init (TrackerPropertyClass *klass)
"Is inverse functional property",
FALSE,
G_PARAM_READWRITE));
+ g_object_class_install_property (object_class,
+ PROP_IS_NEW,
+ g_param_spec_boolean ("is-new",
+ "is-new",
+ "Set to TRUE when a new class or property is to be added to the database ontology",
+ FALSE,
+ G_PARAM_READWRITE));
g_type_class_add_private (object_class, sizeof (TrackerPropertyPriv));
@@ -341,6 +350,9 @@ property_get_property (GObject *object,
case PROP_FULLTEXT_INDEXED:
g_value_set_boolean (value, priv->fulltext_indexed);
break;
+ case PROP_IS_NEW:
+ g_value_set_boolean (value, priv->is_new);
+ break;
case PROP_EMBEDDED:
g_value_set_boolean (value, priv->embedded);
break;
@@ -397,6 +409,10 @@ property_set_property (GObject *object,
tracker_property_set_indexed (TRACKER_PROPERTY (object),
g_value_get_boolean (value));
break;
+ case PROP_IS_NEW:
+ tracker_property_set_is_new (TRACKER_PROPERTY (object),
+ g_value_get_boolean (value));
+ break;
case PROP_FULLTEXT_INDEXED:
tracker_property_set_fulltext_indexed (TRACKER_PROPERTY (object),
g_value_get_boolean (value));
@@ -590,6 +606,17 @@ tracker_property_get_fulltext_indexed (TrackerProperty *field)
return priv->fulltext_indexed;
}
+gboolean
+tracker_property_get_is_new (TrackerProperty *field)
+{
+ TrackerPropertyPriv *priv;
+
+ g_return_val_if_fail (TRACKER_IS_PROPERTY (field), FALSE);
+
+ priv = GET_PRIV (field);
+
+ return priv->is_new;
+}
gboolean
tracker_property_get_embedded (TrackerProperty *field)
@@ -830,6 +857,20 @@ tracker_property_set_indexed (TrackerProperty *field,
}
void
+tracker_property_set_is_new (TrackerProperty *field,
+ gboolean value)
+{
+ TrackerPropertyPriv *priv;
+
+ g_return_if_fail (TRACKER_IS_PROPERTY (field));
+
+ priv = GET_PRIV (field);
+
+ priv->is_new = value;
+ g_object_notify (G_OBJECT (field), "is-new");
+}
+
+void
tracker_property_set_fulltext_indexed (TrackerProperty *field,
gboolean value)
{
diff --git a/src/libtracker-common/tracker-property.h b/src/libtracker-common/tracker-property.h
index 1ec000d..7cb4e02 100644
--- a/src/libtracker-common/tracker-property.h
+++ b/src/libtracker-common/tracker-property.h
@@ -86,6 +86,7 @@ gboolean tracker_property_get_embedded (TrackerProperty
gboolean tracker_property_get_multiple_values (TrackerProperty *property);
gboolean tracker_property_get_filtered (TrackerProperty *property);
gboolean tracker_property_get_transient (TrackerProperty *property);
+gboolean tracker_property_get_is_new (TrackerProperty *property);
gboolean tracker_property_get_is_inverse_functional_property
(TrackerProperty *property);
TrackerProperty ** tracker_property_get_super_properties (TrackerProperty *property);
@@ -113,6 +114,8 @@ void tracker_property_set_filtered (TrackerProperty
gboolean value);
void tracker_property_set_transient (TrackerProperty *property,
gboolean value);
+void tracker_property_set_is_new (TrackerProperty *property,
+ gboolean value);
void tracker_property_set_is_inverse_functional_property
(TrackerProperty *property,
gboolean value);
diff --git a/src/libtracker-data/tracker-data-manager.c b/src/libtracker-data/tracker-data-manager.c
index f37bc40..0bc973d 100644
--- a/src/libtracker-data/tracker-data-manager.c
+++ b/src/libtracker-data/tracker-data-manager.c
@@ -74,14 +74,16 @@ load_ontology_statement (const gchar *ontology_file,
const gchar *subject,
const gchar *predicate,
const gchar *object,
- gint *max_id)
+ gint *max_id,
+ gboolean is_new)
{
if (g_strcmp0 (predicate, RDF_TYPE) == 0) {
if (g_strcmp0 (object, RDFS_CLASS) == 0) {
TrackerClass *class;
if (tracker_ontologies_get_class_by_uri (subject) != NULL) {
- g_critical ("%s: Duplicate definition of class %s", ontology_file, subject);
+ if (!is_new)
+ g_critical ("%s: Duplicate definition of class %s", ontology_file, subject);
return;
}
@@ -90,16 +92,19 @@ load_ontology_statement (const gchar *ontology_file,
}
class = tracker_class_new ();
+ tracker_class_set_is_new (class, is_new);
tracker_class_set_uri (class, subject);
tracker_class_set_id (class, subject_id);
tracker_ontologies_add_class (class);
tracker_ontologies_add_id_uri_pair (subject_id, subject);
g_object_unref (class);
+
} else if (g_strcmp0 (object, RDF_PROPERTY) == 0) {
TrackerProperty *property;
if (tracker_ontologies_get_property_by_uri (subject) != NULL) {
- g_critical ("%s: Duplicate definition of property %s", ontology_file, subject);
+ if (!is_new)
+ g_critical ("%s: Duplicate definition of property %s", ontology_file, subject);
return;
}
@@ -108,11 +113,13 @@ load_ontology_statement (const gchar *ontology_file,
}
property = tracker_property_new ();
+ tracker_property_set_is_new (property, is_new);
tracker_property_set_uri (property, subject);
tracker_property_set_id (property, subject_id);
tracker_ontologies_add_property (property);
tracker_ontologies_add_id_uri_pair (subject_id, subject);
g_object_unref (property);
+
} else if (g_strcmp0 (object, NRL_INVERSE_FUNCTIONAL_PROPERTY) == 0) {
TrackerProperty *property;
@@ -127,26 +134,32 @@ load_ontology_statement (const gchar *ontology_file,
TrackerNamespace *namespace;
if (tracker_ontologies_get_namespace_by_uri (subject) != NULL) {
- g_critical ("%s: Duplicate definition of namespace %s", ontology_file, subject);
+ if (!is_new)
+ g_critical ("%s: Duplicate definition of namespace %s", ontology_file, subject);
return;
}
namespace = tracker_namespace_new ();
+ tracker_namespace_set_is_new (namespace, is_new);
tracker_namespace_set_uri (namespace, subject);
tracker_ontologies_add_namespace (namespace);
g_object_unref (namespace);
+
} else if (g_strcmp0 (object, TRACKER_PREFIX "Ontology") == 0) {
TrackerOntology *ontology;
if (tracker_ontologies_get_ontology_by_uri (subject) != NULL) {
- g_critical ("%s: Duplicate definition of ontology %s", ontology_file, subject);
+ if (!is_new)
+ g_critical ("%s: Duplicate definition of ontology %s", ontology_file, subject);
return;
}
ontology = tracker_ontology_new ();
+ tracker_ontology_set_is_new (ontology, is_new);
tracker_ontology_set_uri (ontology, subject);
tracker_ontologies_add_ontology (ontology);
g_object_unref (ontology);
+
}
} else if (g_strcmp0 (predicate, RDFS_SUB_CLASS_OF) == 0) {
TrackerClass *class, *super_class;
@@ -157,6 +170,10 @@ load_ontology_statement (const gchar *ontology_file,
return;
}
+ if (tracker_class_get_is_new (class) != is_new) {
+ return;
+ }
+
super_class = tracker_ontologies_get_class_by_uri (object);
if (super_class == NULL) {
g_critical ("%s: Unknown class %s", ontology_file, object);
@@ -173,6 +190,10 @@ load_ontology_statement (const gchar *ontology_file,
return;
}
+ if (tracker_property_get_is_new (property) != is_new) {
+ return;
+ }
+
super_property = tracker_ontologies_get_property_by_uri (object);
if (super_property == NULL) {
g_critical ("%s: Unknown property %s", ontology_file, object);
@@ -190,6 +211,10 @@ load_ontology_statement (const gchar *ontology_file,
return;
}
+ if (tracker_property_get_is_new (property) != is_new) {
+ return;
+ }
+
domain = tracker_ontologies_get_class_by_uri (object);
if (domain == NULL) {
g_critical ("%s: Unknown class %s", ontology_file, object);
@@ -207,6 +232,10 @@ load_ontology_statement (const gchar *ontology_file,
return;
}
+ if (tracker_property_get_is_new (property) != is_new) {
+ return;
+ }
+
range = tracker_ontologies_get_class_by_uri (object);
if (range == NULL) {
g_critical ("%s: Unknown class %s", ontology_file, object);
@@ -223,6 +252,10 @@ load_ontology_statement (const gchar *ontology_file,
return;
}
+ if (tracker_property_get_is_new (property) != is_new) {
+ return;
+ }
+
if (atoi (object) == 1) {
tracker_property_set_multiple_values (property, FALSE);
}
@@ -235,6 +268,10 @@ load_ontology_statement (const gchar *ontology_file,
return;
}
+ if (tracker_property_get_is_new (property) != is_new) {
+ return;
+ }
+
if (strcmp (object, "true") == 0) {
tracker_property_set_indexed (property, TRUE);
}
@@ -247,6 +284,10 @@ load_ontology_statement (const gchar *ontology_file,
return;
}
+ if (tracker_property_get_is_new (property) != is_new) {
+ return;
+ }
+
if (g_strcmp0 (object, "true") == 0) {
tracker_property_set_transient (property, TRUE);
}
@@ -259,6 +300,10 @@ load_ontology_statement (const gchar *ontology_file,
return;
}
+ if (tracker_property_get_is_new (property) != is_new) {
+ return;
+ }
+
if (g_strcmp0 (object, "true") == 0) {
tracker_property_set_embedded (property, FALSE);
}
@@ -271,6 +316,10 @@ load_ontology_statement (const gchar *ontology_file,
return;
}
+ if (tracker_property_get_is_new (property) != is_new) {
+ return;
+ }
+
if (strcmp (object, "true") == 0) {
tracker_property_set_fulltext_indexed (property, TRUE);
}
@@ -283,6 +332,10 @@ load_ontology_statement (const gchar *ontology_file,
return;
}
+ if (tracker_namespace_get_is_new (namespace) != is_new) {
+ return;
+ }
+
tracker_namespace_set_prefix (namespace, object);
} else if (g_strcmp0 (predicate, NAO_LAST_MODIFIED) == 0) {
TrackerOntology *ontology;
@@ -293,6 +346,10 @@ load_ontology_statement (const gchar *ontology_file,
return;
}
+ if (tracker_ontology_get_is_new (ontology) != is_new) {
+ return;
+ }
+
tracker_ontology_set_last_modified (ontology, tracker_string_to_date (object));
}
@@ -300,7 +357,8 @@ load_ontology_statement (const gchar *ontology_file,
static void
load_ontology_file_from_path (const gchar *ontology_file,
- gint *max_id)
+ gint *max_id,
+ gboolean is_new)
{
TrackerTurtleReader *reader;
GError *error = NULL;
@@ -319,7 +377,8 @@ 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, 0, subject, predicate, object, max_id);
+ load_ontology_statement (ontology_file, 0, subject, predicate, object,
+ max_id, is_new);
}
g_object_unref (reader);
@@ -338,11 +397,16 @@ get_ontology_from_file (const gchar *ontology_file)
GError *error = NULL;
GHashTable *ontology_uris;
TrackerOntology *ret = NULL;
+ gchar *ontology_path;
+
+ ontology_path = g_build_filename (ontologies_dir, ontology_file, NULL);
+
+ reader = tracker_turtle_reader_new (ontology_path, &error);
- reader = tracker_turtle_reader_new (ontology_file, &error);
if (error) {
g_critical ("Turtle parse error: %s", error->message);
g_error_free (error);
+ g_free (ontology_path);
return NULL;
}
@@ -362,11 +426,6 @@ get_ontology_from_file (const gchar *ontology_file)
if (g_strcmp0 (object, TRACKER_PREFIX "Ontology") == 0) {
TrackerOntology *ontology;
- if (tracker_ontologies_get_ontology_by_uri (subject) != NULL) {
- g_critical ("%s: Duplicate definition of ontology %s", ontology_file, subject);
- return NULL;
- }
-
ontology = tracker_ontology_new ();
tracker_ontology_set_uri (ontology, subject);
@@ -382,6 +441,7 @@ get_ontology_from_file (const gchar *ontology_file)
ontology = g_hash_table_lookup (ontology_uris, subject);
if (ontology == NULL) {
g_critical ("%s: Unknown ontology %s", ontology_file, subject);
+ g_free (ontology_path);
return NULL;
}
@@ -399,17 +459,20 @@ get_ontology_from_file (const gchar *ontology_file)
g_error_free (error);
}
+ g_free (ontology_path);
+
return ret;
}
static void
load_ontology_file (const gchar *filename,
- gint *max_id)
+ gint *max_id,
+ gboolean is_new)
{
gchar *ontology_file;
ontology_file = g_build_filename (ontologies_dir, filename, NULL);
- load_ontology_file_from_path (ontology_file, max_id);
+ load_ontology_file_from_path (ontology_file, max_id, is_new);
g_free (ontology_file);
}
@@ -449,7 +512,7 @@ load_ontology_from_journal (void)
subject = g_hash_table_lookup (id_uri_map, GINT_TO_POINTER (subject_id));
predicate = g_hash_table_lookup (id_uri_map, GINT_TO_POINTER (predicate_id));
- load_ontology_statement ("journal", subject_id, subject, predicate, object, NULL);
+ load_ontology_statement ("journal", subject_id, subject, predicate, object, NULL, FALSE);
}
}
@@ -458,14 +521,140 @@ load_ontology_from_journal (void)
return id_uri_map;
}
+
static void
-import_ontology_file (const gchar *filename)
+load_turtle_file (const gchar* path,
+ gboolean is_new)
+{
+ GError *error = NULL;
+ TrackerTurtleReader* reader;
+
+ reader = tracker_turtle_reader_new (path, &error);
+
+ if (error != NULL) {
+ g_critical ("%s", error->message);
+ g_error_free (error);
+ return;
+ }
+
+ while (tracker_turtle_reader_next (reader, &error)) {
+
+ const gchar *graph = tracker_turtle_reader_get_graph (reader);
+ const gchar *subject = tracker_turtle_reader_get_subject (reader);
+ const gchar *predicate = tracker_turtle_reader_get_predicate (reader);
+ const gchar *object = tracker_turtle_reader_get_object (reader);
+
+ if (g_strcmp0 (predicate, RDF_TYPE) == 0) {
+ if (g_strcmp0 (object, RDFS_CLASS) == 0) {
+ TrackerClass *class;
+
+ class = tracker_ontologies_get_class_by_uri (subject);
+
+ if (class && tracker_class_get_is_new (class) != is_new) {
+ continue;
+ }
+ } else if (g_strcmp0 (object, RDF_PROPERTY) == 0) {
+ TrackerProperty *prop;
+
+ prop = tracker_ontologies_get_property_by_uri (subject);
+
+ if (prop && tracker_property_get_is_new (prop) != is_new) {
+ continue;
+ }
+ } else if (g_strcmp0 (object, TRACKER_PREFIX "Namespace") == 0) {
+ TrackerNamespace *namespace;
+
+ namespace = tracker_ontologies_get_namespace_by_uri (subject);
+
+ if (namespace && tracker_namespace_get_is_new (namespace) != is_new) {
+ continue;
+ }
+ } else if (g_strcmp0 (object, TRACKER_PREFIX "Ontology") == 0) {
+ TrackerOntology *ontology;
+
+ ontology = tracker_ontologies_get_ontology_by_uri (subject);
+
+ if (ontology && tracker_ontology_get_is_new (ontology) != is_new) {
+ continue;
+ }
+ }
+ } else if (g_strcmp0 (predicate, RDFS_SUB_CLASS_OF) == 0) {
+ TrackerClass *class;
+
+ class = tracker_ontologies_get_class_by_uri (subject);
+
+ if (class && tracker_class_get_is_new (class) != is_new) {
+ continue;
+ }
+ } else if (g_strcmp0 (predicate, RDFS_SUB_PROPERTY_OF) == 0 ||
+ g_strcmp0 (predicate, RDFS_DOMAIN) == 0 ||
+ g_strcmp0 (predicate, RDFS_RANGE) == 0 ||
+ g_strcmp0 (predicate, NRL_MAX_CARDINALITY) == 0 ||
+ g_strcmp0 (predicate, TRACKER_PREFIX "indexed") == 0 ||
+ g_strcmp0 (predicate, TRACKER_PREFIX "transient") == 0 ||
+ g_strcmp0 (predicate, TRACKER_PREFIX "isAnnotation") == 0 ||
+ g_strcmp0 (predicate, TRACKER_PREFIX "fulltextIndexed") == 0) {
+ TrackerProperty *prop;
+
+ prop = tracker_ontologies_get_property_by_uri (subject);
+
+ if (prop && tracker_property_get_is_new (prop) != is_new) {
+ continue;
+ }
+ } else if (g_strcmp0 (predicate, TRACKER_PREFIX "prefix") == 0) {
+ TrackerNamespace *namespace;
+
+ namespace = tracker_ontologies_get_namespace_by_uri (subject);
+
+ if (namespace && tracker_namespace_get_is_new (namespace) != is_new) {
+ continue;
+ }
+ } else if (g_strcmp0 (predicate, NAO_LAST_MODIFIED) == 0) {
+ TrackerOntology *ontology;
+
+ ontology = tracker_ontologies_get_ontology_by_uri (subject);
+
+ if (ontology && tracker_ontology_get_is_new (ontology) != is_new) {
+ continue;
+ }
+ }
+
+ if (tracker_turtle_reader_get_object_is_uri (reader)) {
+ tracker_data_insert_statement_with_uri (graph, subject,
+ predicate, object,
+ &error);
+
+ if (error != NULL) {
+ g_critical ("%s", error->message);
+ g_error_free (error);
+ return;
+ }
+
+ } else {
+ tracker_data_insert_statement_with_string (graph, subject,
+ predicate, object,
+ &error);
+
+ if (error != NULL) {
+ g_critical ("%s", error->message);
+ g_error_free (error);
+ return;
+ }
+ }
+ }
+
+ g_object_unref (reader);
+}
+
+static void
+import_ontology_file (const gchar *filename,
+ gboolean is_new)
{
gchar *ontology_file;
GError *error = NULL;
ontology_file = g_build_filename (ontologies_dir, filename, NULL);
- tracker_turtle_reader_load (ontology_file, &error);
+ load_turtle_file (ontology_file, is_new);
g_free (ontology_file);
if (error) {
@@ -669,6 +858,35 @@ db_get_static_data (TrackerDBInterface *iface)
TrackerDBResultSet *result_set;
stmt = tracker_db_interface_create_statement (iface,
+ "SELECT (SELECT Uri FROM Resource WHERE ID = \"tracker:Ontology\".ID), "
+ "\"nao:lastModified\" "
+ "FROM \"tracker:Ontology\"");
+ cursor = tracker_db_statement_start_cursor (stmt, NULL);
+ g_object_unref (stmt);
+
+ if (cursor) {
+ while (tracker_db_cursor_iter_next (cursor)) {
+ TrackerOntology *ontology;
+ const gchar *uri;
+ time_t last_mod;
+
+ ontology = tracker_ontology_new ();
+
+ uri = tracker_db_cursor_get_string (cursor, 0);
+ last_mod = (time_t) tracker_db_cursor_get_int (cursor, 1);
+
+ tracker_ontology_set_is_new (ontology, FALSE);
+ tracker_ontology_set_uri (ontology, uri);
+ tracker_ontology_set_last_modified (ontology, last_mod);
+ tracker_ontologies_add_ontology (ontology);
+
+ g_object_unref (ontology);
+ }
+
+ g_object_unref (cursor);
+ }
+
+ stmt = tracker_db_interface_create_statement (iface,
"SELECT (SELECT Uri FROM Resource WHERE ID = \"tracker:Namespace\".ID), "
"\"tracker:prefix\" "
"FROM \"tracker:Namespace\"");
@@ -685,6 +903,7 @@ db_get_static_data (TrackerDBInterface *iface)
uri = tracker_db_cursor_get_string (cursor, 0);
prefix = tracker_db_cursor_get_string (cursor, 1);
+ tracker_namespace_set_is_new (namespace, FALSE);
tracker_namespace_set_uri (namespace, uri);
tracker_namespace_set_prefix (namespace, prefix);
tracker_ontologies_add_namespace (namespace);
@@ -714,6 +933,7 @@ db_get_static_data (TrackerDBInterface *iface)
id = tracker_db_cursor_get_int (cursor, 0);
uri = tracker_db_cursor_get_string (cursor, 1);
+ tracker_class_set_is_new (class, FALSE);
tracker_class_set_uri (class, uri);
class_add_super_classes_from_db (iface, class);
@@ -831,6 +1051,7 @@ db_get_static_data (TrackerDBInterface *iface)
is_inverse_functional_property = FALSE;
}
+ tracker_property_set_is_new (property, FALSE);
tracker_property_set_transient (property, transient);
tracker_property_set_uri (property, uri);
tracker_property_set_id (property, id);
@@ -980,6 +1201,9 @@ create_decomposed_metadata_tables (TrackerDBInterface *iface,
gboolean main_class;
gint i, n_props;
+ /* TODO: copy with tracker_property_get_is_new together with a
+ * tracker_property_get_multiple_values (ALTER TABLE situation) */
+
service_name = tracker_class_get_name (service);
main_class = (strcmp (service_name, "rdfs:Resource") == 0);
@@ -1097,7 +1321,7 @@ create_fts_table (TrackerDBInterface *iface)
}
static void
-import_ontology_into_db (void)
+import_ontology_into_db (gboolean is_new)
{
TrackerDBInterface *iface;
@@ -1112,26 +1336,37 @@ import_ontology_into_db (void)
/* create tables */
for (i = 0; i < n_classes; i++) {
- create_decomposed_metadata_tables (iface, classes[i]);
+ /* TODO: allow this always when create_dec.. is adapted */
+ if (tracker_class_get_is_new (classes[i]) == is_new) {
+ create_decomposed_metadata_tables (iface, classes[i]);
+ }
}
- create_fts_table (iface);
+ /* Allow when create_fts_table is adapted */
+ if (!is_new)
+ 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]));
+ if (tracker_class_get_is_new (classes[i]) == is_new) {
+ 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]));
+ /* TODO: allow this always when above is it's allowed */
+ if (tracker_property_get_is_new (properties[i]) == is_new) {
+ insert_uri_in_resource_table (iface, tracker_property_get_uri (properties[i]),
+ tracker_property_get_id (properties[i]));
+ }
}
}
static GList*
-get_ontologies (gboolean test_schema, const gchar *ontologies_dir)
+get_ontologies (gboolean test_schema,
+ const gchar *ontologies_dir)
{
GList *sorted = NULL;
@@ -1176,6 +1411,7 @@ tracker_data_manager_init (TrackerDBManagerFlags flags,
GHashTable *ontos_table;
GList *sorted = NULL, *l;
const gchar *env_path;
+ gint max_id = 0;
/* First set defaults for return values */
if (first_time) {
@@ -1226,7 +1462,7 @@ tracker_data_manager_init (TrackerDBManagerFlags flags,
load_ontology_from_journal ();
tracker_data_begin_replay_transaction (tracker_db_journal_reader_get_time ());
- import_ontology_into_db ();
+ import_ontology_into_db (FALSE);
tracker_data_commit_transaction ();
tracker_db_journal_reader_shutdown ();
@@ -1239,7 +1475,6 @@ tracker_data_manager_init (TrackerDBManagerFlags flags,
tracker_db_journal_init (NULL);
check_ontology = TRUE;
} else if (is_first_time_index) {
- gint max_id = 0;
GError *error = NULL;
gchar *test_schema_path = NULL;
@@ -1247,26 +1482,27 @@ tracker_data_manager_init (TrackerDBManagerFlags flags,
tracker_db_journal_init (NULL);
- /* load ontology from files into memory */
+ /* load ontology from files into memory (max_id starts at zero: first-time) */
+
for (l = sorted; l; l = l->next) {
g_debug ("Loading ontology %s", (char *) l->data);
- load_ontology_file (l->data, &max_id);
+ load_ontology_file (l->data, &max_id, FALSE);
}
if (test_schema) {
g_debug ("Loading ontology:'%s' (TEST ONTOLOGY)", test_schema_path);
- load_ontology_file_from_path (test_schema_path, &max_id);
+ load_ontology_file_from_path (test_schema_path, &max_id, FALSE);
}
tracker_data_begin_transaction ();
tracker_db_journal_start_transaction (time (NULL));
- import_ontology_into_db ();
+ import_ontology_into_db (FALSE);
/* store ontology in database */
for (l = sorted; l; l = l->next) {
- import_ontology_file (l->data);
+ import_ontology_file (l->data, FALSE);
}
if (test_schema) {
tracker_turtle_reader_load (test_schema_path, &error);
@@ -1294,7 +1530,12 @@ tracker_data_manager_init (TrackerDBManagerFlags flags,
check_ontology = TRUE;
}
+ /* ensure FTS is fully initialized */
+ tracker_db_interface_execute_query (iface, NULL, "SELECT 1 FROM fulltext.fts WHERE rowid = 0");
+
if (check_ontology) {
+ GList *to_reload = NULL;
+
sorted = get_ontologies (test_schema != NULL, ontologies_dir);
/* check ontology against database */
@@ -1308,7 +1549,6 @@ tracker_data_manager_init (TrackerDBManagerFlags flags,
cursor = tracker_db_statement_start_cursor (stmt, NULL);
g_object_unref (stmt);
-
ontos_table = g_hash_table_new_full (g_str_hash,
g_str_equal,
g_free,
@@ -1316,11 +1556,11 @@ tracker_data_manager_init (TrackerDBManagerFlags flags,
while (tracker_db_cursor_iter_next (cursor)) {
const gchar *onto_uri = tracker_db_cursor_get_string (cursor, 0);
- /* It's stored as an int in the db anyway. This is caused by
+ /* It's stored as an int in the db anyway. This is caused by
* string_to_gvalue in tracker-data-update.c */
gint value = tracker_db_cursor_get_int (cursor, 1);
- g_hash_table_insert (ontos_table, g_strdup (onto_uri),
+ g_hash_table_insert (ontos_table, g_strdup (onto_uri),
GINT_TO_POINTER (value));
}
@@ -1328,49 +1568,65 @@ tracker_data_manager_init (TrackerDBManagerFlags flags,
for (l = sorted; l; l = l->next) {
TrackerOntology *ontology;
- gchar *ontology_file;
+ const gchar *ontology_file = l->data;
gboolean found;
gpointer value;
- ontology_file = g_build_filename (ontologies_dir, l->data, NULL);
ontology = get_ontology_from_file (ontology_file);
if (!ontology) {
g_critical ("Can't get ontology from file: %s", ontology_file);
g_free (l->data);
- g_free (ontology_file);
continue;
}
- found = g_hash_table_lookup_extended (ontos_table,
+ found = g_hash_table_lookup_extended (ontos_table,
tracker_ontology_get_uri (ontology),
NULL, &value);
if (found) {
- gint val = GPOINTER_TO_INT (value);
+ gint val, last_mod;
+
/* We can't do better than this cast, it's stored as an int in the
* db. See above comment for more info. */
- if (val != (gint) tracker_ontology_get_last_modified (ontology)) {
- g_print ("%s NOT up to date\n", ontology_file);
- } else {
- g_print ("%s up to date\n", ontology_file);
+ last_mod = (gint) tracker_ontology_get_last_modified (ontology);
+ val = GPOINTER_TO_INT (value);
+
+ if (val != last_mod) {
+
+ g_debug ("Ontology file '%s' needs update", ontology_file);
+
+ if (max_id == 0) {
+ /* In case of first-time, this wont start at zero */
+ max_id = tracker_data_update_get_new_service_id ();
+ }
+
+ load_ontology_file (ontology_file, &max_id, TRUE);
+ to_reload = g_list_prepend (to_reload, l->data);
}
+
}
- g_free (ontology_file);
g_object_unref (ontology);
- g_free (l->data);
+ }
+
+ if (to_reload) {
+ import_ontology_into_db (TRUE);
+ for (l = to_reload; l; l = l->next) {
+ const gchar *ontology_file = l->data;
+ import_ontology_file (ontology_file, TRUE);
+ }
+ g_list_free (to_reload);
}
tracker_data_commit_transaction ();
g_hash_table_unref (ontos_table);
+
+ g_list_foreach (sorted, (GFunc) g_free, NULL);
g_list_free (sorted);
}
- /* ensure FTS is fully initialized */
- tracker_db_interface_execute_query (iface, NULL, "SELECT 1 FROM fulltext.fts WHERE rowid = 0");
-
initialized = TRUE;
g_free (ontologies_dir);
diff --git a/src/libtracker-data/tracker-data-update.c b/src/libtracker-data/tracker-data-update.c
index afa269f..769c96c 100644
--- a/src/libtracker-data/tracker-data-update.c
+++ b/src/libtracker-data/tracker-data-update.c
@@ -197,11 +197,11 @@ GQuark tracker_data_error_quark (void) {
return g_quark_from_static_string ("tracker_data_error-quark");
}
-static gint
-tracker_data_update_get_new_service_id (TrackerDBInterface *iface)
+gint
+tracker_data_update_get_new_service_id (void)
{
TrackerDBCursor *cursor;
- TrackerDBInterface *temp_iface;
+ TrackerDBInterface *iface;
TrackerDBStatement *stmt;
static gint max = 0;
@@ -210,9 +210,9 @@ tracker_data_update_get_new_service_id (TrackerDBInterface *iface)
return ++max;
}
- temp_iface = tracker_db_manager_get_db_interface ();
+ iface = tracker_db_manager_get_db_interface ();
- stmt = tracker_db_interface_create_statement (temp_iface,
+ stmt = tracker_db_interface_create_statement (iface,
"SELECT MAX(ID) AS A FROM Resource");
cursor = tracker_db_statement_start_cursor (stmt, NULL);
g_object_unref (stmt);
@@ -382,7 +382,7 @@ static gint
ensure_resource_id (const gchar *uri,
gboolean *create)
{
- TrackerDBInterface *iface, *common;
+ TrackerDBInterface *iface;
TrackerDBStatement *stmt;
gint id;
@@ -394,11 +394,9 @@ ensure_resource_id (const gchar *uri,
}
if (id == 0) {
- /* object resource not yet in the database */
- common = tracker_db_manager_get_db_interface ();
iface = tracker_db_manager_get_db_interface ();
- id = tracker_data_update_get_new_service_id (common);
+ id = tracker_data_update_get_new_service_id ();
stmt = tracker_db_interface_create_statement (iface, "INSERT INTO Resource (ID, Uri) VALUES (?, ?)");
tracker_db_statement_bind_int (stmt, 0, id);
tracker_db_statement_bind_text (stmt, 1, uri);
diff --git a/src/libtracker-data/tracker-data-update.h b/src/libtracker-data/tracker-data-update.h
index da3d429..8ab9216 100644
--- a/src/libtracker-data/tracker-data-update.h
+++ b/src/libtracker-data/tracker-data-update.h
@@ -51,6 +51,7 @@ typedef void (*TrackerStatementCallback) (const gchar *graph,
typedef void (*TrackerCommitCallback) (gpointer user_data);
GQuark tracker_data_error_quark (void);
+gint tracker_data_update_get_new_service_id (void);
/* Metadata */
void tracker_data_delete_resource_description (const gchar *graph,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]