[tracker/rss-enclosures] libtracker-data: Add default value support
- From: Roberto Guido <rguido src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker/rss-enclosures] libtracker-data: Add default value support
- Date: Sat, 26 Jun 2010 23:14:30 +0000 (UTC)
commit 6de054b4990bb0ebf75bbfef4bb44ef26082763c
Author: Jürg Billeter <j bitron ch>
Date: Mon Jun 7 10:54:26 2010 +0200
libtracker-data: Add default value support
data/ontologies/11-rdf.ontology | 5 +++
src/libtracker-data/tracker-data-manager.c | 46 ++++++++++++++++++++++++++-
src/libtracker-data/tracker-property.c | 28 +++++++++++++++++
src/libtracker-data/tracker-property.h | 3 ++
4 files changed, 80 insertions(+), 2 deletions(-)
---
diff --git a/data/ontologies/11-rdf.ontology b/data/ontologies/11-rdf.ontology
index b9e03a2..5d02162 100644
--- a/data/ontologies/11-rdf.ontology
+++ b/data/ontologies/11-rdf.ontology
@@ -112,6 +112,11 @@ tracker:weight a rdf:Property ;
rdfs:domain rdf:Property ;
rdfs:range xsd:integer .
+tracker:defaultValue a rdf:Property ;
+ nrl:maxCardinality 1 ;
+ rdfs:domain rdf:Property ;
+ rdfs:range xsd:string .
+
tracker:added a rdf:Property ;
nrl:maxCardinality 1 ;
rdfs:domain rdfs:Resource ;
diff --git a/src/libtracker-data/tracker-data-manager.c b/src/libtracker-data/tracker-data-manager.c
index f2e8d6e..5acedee 100644
--- a/src/libtracker-data/tracker-data-manager.c
+++ b/src/libtracker-data/tracker-data-manager.c
@@ -417,6 +417,7 @@ tracker_data_ontology_load_statement (const gchar *ontology_path,
tracker_property_set_indexed (property, FALSE);
tracker_property_set_secondary_index (property, NULL);
tracker_property_set_writeback (property, FALSE);
+ tracker_property_set_default_value (property, NULL);
}
return;
}
@@ -692,6 +693,16 @@ tracker_data_ontology_load_statement (const gchar *ontology_path,
if (strcmp (object, "true") == 0) {
tracker_property_set_fulltext_no_limit (property, TRUE);
}
+ } else if (g_strcmp0 (predicate, TRACKER_PREFIX "defaultValue") == 0) {
+ TrackerProperty *property;
+
+ property = tracker_ontologies_get_property_by_uri (subject);
+ if (property == NULL) {
+ g_critical ("%s: Unknown property %s", ontology_path, subject);
+ return;
+ }
+
+ tracker_property_set_default_value (property, object);
} else if (g_strcmp0 (predicate, TRACKER_PREFIX "prefix") == 0) {
TrackerNamespace *namespace;
@@ -831,6 +842,16 @@ tracker_data_ontology_process_changes (GPtrArray *seen_classes,
tracker_class_set_db_schema_changed (class, TRUE);
tracker_property_set_db_schema_changed (property, TRUE);
}
+
+ if (update_property_value ("tracker:defaultValue", subject, TRACKER_PREFIX "defaultValue",
+ tracker_property_get_default_value (property),
+ NULL, NULL, property)) {
+ TrackerClass *class;
+
+ class = tracker_property_get_domain (property);
+ tracker_class_set_db_schema_changed (class, TRUE);
+ tracker_property_set_db_schema_changed (property, TRUE);
+ }
}
}
}
@@ -1412,7 +1433,8 @@ db_get_static_data (TrackerDBInterface *iface)
"\"tracker:isAnnotation\", "
"\"tracker:writeback\", "
"(SELECT 1 FROM \"rdfs:Resource_rdf:type\" WHERE ID = \"rdf:Property\".ID AND "
- "\"rdf:type\" = (SELECT ID FROM Resource WHERE Uri = '" NRL_INVERSE_FUNCTIONAL_PROPERTY "')) "
+ "\"rdf:type\" = (SELECT ID FROM Resource WHERE Uri = '" NRL_INVERSE_FUNCTIONAL_PROPERTY "')), "
+ "\"tracker:defaultValue\" "
"FROM \"rdf:Property\" ORDER BY ID");
if (stmt) {
@@ -1424,7 +1446,7 @@ db_get_static_data (TrackerDBInterface *iface)
while (tracker_db_cursor_iter_next (cursor, &error)) {
GValue value = { 0 };
TrackerProperty *property;
- const gchar *uri, *domain_uri, *range_uri, *secondary_index_uri;
+ const gchar *uri, *domain_uri, *range_uri, *secondary_index_uri, *default_value;
gboolean multi_valued, indexed, fulltext_indexed, fulltext_no_limit;
gboolean transient, annotation, is_inverse_functional_property;
gboolean writeback;
@@ -1523,6 +1545,8 @@ db_get_static_data (TrackerDBInterface *iface)
is_inverse_functional_property = FALSE;
}
+ default_value = tracker_db_cursor_get_string (cursor, 13);
+
tracker_property_set_is_new (property, FALSE);
tracker_property_set_transient (property, transient);
tracker_property_set_uri (property, uri);
@@ -1531,6 +1555,7 @@ db_get_static_data (TrackerDBInterface *iface)
tracker_property_set_range (property, tracker_ontologies_get_class_by_uri (range_uri));
tracker_property_set_multiple_values (property, multi_valued);
tracker_property_set_indexed (property, indexed);
+ tracker_property_set_default_value (property, default_value);
tracker_property_set_db_schema_changed (property, FALSE);
tracker_property_set_writeback (property, writeback);
@@ -1880,8 +1905,12 @@ create_decomposed_metadata_tables (TrackerDBInterface *iface,
field_name = tracker_property_get_name (property);
if (sql_type_for_single_value) {
+ const gchar *default_value;
+
/* single value */
+ default_value = tracker_property_get_default_value (property);
+
if (in_update) {
g_debug ("%sAltering database for class '%s' property '%s': single value (%s)",
in_alter ? "" : " ",
@@ -1897,6 +1926,13 @@ create_decomposed_metadata_tables (TrackerDBInterface *iface,
g_string_append_printf (create_sql, ", \"%s\" %s",
field_name,
sql_type_for_single_value);
+
+ /* add DEFAULT in case that the ontology specifies a default value,
+ assumes that default values never contain quotes */
+ if (default_value != NULL) {
+ g_string_append_printf (create_sql, " DEFAULT '%s'", default_value);
+ }
+
if (tracker_property_get_is_inverse_functional_property (property)) {
g_string_append (create_sql, " UNIQUE");
}
@@ -1923,6 +1959,12 @@ create_decomposed_metadata_tables (TrackerDBInterface *iface,
service_name,
field_name,
sql_type_for_single_value);
+
+ /* add DEFAULT in case that the ontology specifies a default value,
+ assumes that default values never contain quotes */
+ if (default_value != NULL) {
+ g_string_append_printf (alter_sql, " DEFAULT '%s'", default_value);
+ }
if (tracker_property_get_is_inverse_functional_property (property)) {
g_string_append (alter_sql, " UNIQUE");
}
diff --git a/src/libtracker-data/tracker-property.c b/src/libtracker-data/tracker-property.c
index bcb715f..9e8ad3a 100644
--- a/src/libtracker-data/tracker-property.c
+++ b/src/libtracker-data/tracker-property.c
@@ -61,6 +61,7 @@ struct _TrackerPropertyPrivate {
gboolean is_new;
gboolean db_schema_changed;
gboolean writeback;
+ gchar *default_value;
GArray *super_properties;
};
@@ -162,6 +163,8 @@ property_finalize (GObject *object)
g_array_free (priv->super_properties, TRUE);
+ g_free (priv->default_value);
+
(G_OBJECT_CLASS (tracker_property_parent_class)->finalize) (object);
}
@@ -439,6 +442,18 @@ tracker_property_get_super_properties (TrackerProperty *property)
return (TrackerProperty **) priv->super_properties->data;
}
+const gchar *
+tracker_property_get_default_value (TrackerProperty *property)
+{
+ TrackerPropertyPrivate *priv;
+
+ g_return_val_if_fail (TRACKER_IS_PROPERTY (property), NULL);
+
+ priv = GET_PRIV (property);
+
+ return priv->default_value;
+}
+
void
tracker_property_set_uri (TrackerProperty *property,
const gchar *value)
@@ -730,3 +745,16 @@ tracker_property_add_super_property (TrackerProperty *property,
g_array_append_val (priv->super_properties, value);
}
+void
+tracker_property_set_default_value (TrackerProperty *property,
+ const gchar *value)
+{
+ TrackerPropertyPrivate *priv;
+
+ g_return_if_fail (TRACKER_IS_PROPERTY (property));
+
+ priv = GET_PRIV (property);
+
+ g_free (priv->default_value);
+ priv->default_value = g_strdup (value);
+}
diff --git a/src/libtracker-data/tracker-property.h b/src/libtracker-data/tracker-property.h
index c3a2c16..5ee3561 100644
--- a/src/libtracker-data/tracker-property.h
+++ b/src/libtracker-data/tracker-property.h
@@ -91,6 +91,7 @@ gboolean tracker_property_get_multiple_values (TrackerProperty
gboolean tracker_property_get_transient (TrackerProperty *property);
gboolean tracker_property_get_is_new (TrackerProperty *property);
gboolean tracker_property_get_writeback (TrackerProperty *property);
+const gchar * tracker_property_get_default_value (TrackerProperty *property);
gboolean tracker_property_get_db_schema_changed (TrackerProperty *property);
gboolean tracker_property_get_is_inverse_functional_property
(TrackerProperty *property);
@@ -123,6 +124,8 @@ void tracker_property_set_is_new (TrackerProperty
gboolean value);
void tracker_property_set_writeback (TrackerProperty *property,
gboolean value);
+void tracker_property_set_default_value (TrackerProperty *property,
+ const gchar *value);
void tracker_property_set_db_schema_changed (TrackerProperty *property,
gboolean value);
void tracker_property_set_is_inverse_functional_property
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]