[tracker] libtracker-data: Add error handling infrastructure for inserts
- From: Jürg Billeter <juergbi src gnome org>
- To: svn-commits-list gnome org
- Subject: [tracker] libtracker-data: Add error handling infrastructure for inserts
- Date: Wed, 15 Jul 2009 14:35:25 +0000 (UTC)
commit 98f422e4816f6c60adf1ecd722e8770186d96f0b
Author: Jürg Billeter <j bitron ch>
Date: Wed Jul 15 16:32:11 2009 +0200
libtracker-data: Add error handling infrastructure for inserts
src/libtracker-data/libtracker-data.vapi | 13 +++++--
src/libtracker-data/tracker-data-manager.c | 6 ++-
src/libtracker-data/tracker-data-update.c | 48 +++++++++++++++++++------
src/libtracker-data/tracker-data-update.h | 19 ++++++++--
src/tracker-store/tracker-store.c | 8 +++--
tests/libtracker-data/tracker-ontology-test.c | 2 +-
tests/libtracker-data/tracker-sparql-test.c | 2 +-
7 files changed, 74 insertions(+), 24 deletions(-)
---
diff --git a/src/libtracker-data/libtracker-data.vapi b/src/libtracker-data/libtracker-data.vapi
index 0bf06e2..704c633 100644
--- a/src/libtracker-data/libtracker-data.vapi
+++ b/src/libtracker-data/libtracker-data.vapi
@@ -18,15 +18,22 @@
*/
namespace Tracker {
+ [CCode (cheader_filename = "libtracker-data/tracker-data-update.h")]
+ public errordomain DataError {
+ UNKNOWN_CLASS,
+ UNKNOWN_PROPERTY,
+ INVALID_TYPE
+ }
+
[CCode (cheader_filename = "libtracker-data/tracker-data-query.h,libtracker-data/tracker-data-update.h")]
namespace Data {
public int query_resource_id (string uri);
public void begin_transaction ();
public void commit_transaction ();
public void delete_statement (string subject, string predicate, string object);
- public void insert_statement (string subject, string predicate, string object);
- public void insert_statement_with_uri (string subject, string predicate, string object);
- public void insert_statement_with_string (string subject, string predicate, string object);
+ public void insert_statement (string subject, string predicate, string object) throws DataError;
+ public void insert_statement_with_uri (string subject, string predicate, string object) throws DataError;
+ public void insert_statement_with_string (string subject, string predicate, string object) throws DataError;
public void delete_resource_description (string uri);
}
}
diff --git a/src/libtracker-data/tracker-data-manager.c b/src/libtracker-data/tracker-data-manager.c
index b11feec..5603871 100644
--- a/src/libtracker-data/tracker-data-manager.c
+++ b/src/libtracker-data/tracker-data-manager.c
@@ -286,12 +286,14 @@ import_ontology_file_from_path (const gchar *ontology_file)
tracker_data_insert_statement_with_uri (
tracker_turtle_reader_get_subject (),
tracker_turtle_reader_get_predicate (),
- tracker_turtle_reader_get_object ());
+ tracker_turtle_reader_get_object (),
+ NULL);
} else {
tracker_data_insert_statement_with_string (
tracker_turtle_reader_get_subject (),
tracker_turtle_reader_get_predicate (),
- tracker_turtle_reader_get_object ());
+ tracker_turtle_reader_get_object (),
+ NULL);
}
}
}
diff --git a/src/libtracker-data/tracker-data-update.c b/src/libtracker-data/tracker-data-update.c
index fcb78b7..cf272d6 100644
--- a/src/libtracker-data/tracker-data-update.c
+++ b/src/libtracker-data/tracker-data-update.c
@@ -113,6 +113,10 @@ tracker_data_set_delete_statement_callback (TrackerStatementCallback callback,
delete_data = user_data;
}
+GQuark tracker_data_error_quark (void) {
+ return g_quark_from_static_string ("tracker_data_error-quark");
+}
+
static guint32
tracker_data_update_get_new_service_id (TrackerDBInterface *iface)
{
@@ -463,7 +467,8 @@ tracker_data_blank_buffer_flush (void)
for (i = 0; i < blank_buffer.predicates->len; i++) {
tracker_data_insert_statement (blank_uri,
g_array_index (blank_buffer.predicates, gchar *, i),
- g_array_index (blank_buffer.objects, gchar *, i));
+ g_array_index (blank_buffer.objects, gchar *, i),
+ NULL);
}
tracker_data_update_buffer_flush ();
}
@@ -902,7 +907,8 @@ tracker_data_insert_statement_common (const gchar *subject,
void
tracker_data_insert_statement (const gchar *subject,
const gchar *predicate,
- const gchar *object)
+ const gchar *object,
+ GError **error)
{
TrackerProperty *property;
@@ -913,19 +919,21 @@ tracker_data_insert_statement (const gchar *subject,
property = tracker_ontology_get_property_by_uri (predicate);
if (property != NULL) {
if (tracker_property_get_data_type (property) == TRACKER_PROPERTY_TYPE_RESOURCE) {
- tracker_data_insert_statement_with_uri (subject, predicate, object);
+ tracker_data_insert_statement_with_uri (subject, predicate, object, error);
} else {
- tracker_data_insert_statement_with_string (subject, predicate, object);
+ tracker_data_insert_statement_with_string (subject, predicate, object, error);
}
} else {
- g_warning ("Property '%s' not found in the ontology", predicate);
+ g_set_error (error, TRACKER_DATA_ERROR, TRACKER_DATA_ERROR_UNKNOWN_PROPERTY,
+ "Property '%s' not found in the ontology", predicate);
}
}
void
tracker_data_insert_statement_with_uri (const gchar *subject,
const gchar *predicate,
- const gchar *object)
+ const gchar *object,
+ GError **error)
{
TrackerClass *class;
TrackerProperty *property;
@@ -935,7 +943,15 @@ tracker_data_insert_statement_with_uri (const gchar *subject,
g_return_if_fail (object != NULL);
property = tracker_ontology_get_property_by_uri (predicate);
- g_return_if_fail (property != NULL && tracker_property_get_data_type (property) == TRACKER_PROPERTY_TYPE_RESOURCE);
+ if (property == NULL) {
+ g_set_error (error, TRACKER_DATA_ERROR, TRACKER_DATA_ERROR_UNKNOWN_PROPERTY,
+ "Property '%s' not found in the ontology", predicate);
+ return;
+ } else if (tracker_property_get_data_type (property) != TRACKER_PROPERTY_TYPE_RESOURCE) {
+ g_set_error (error, TRACKER_DATA_ERROR, TRACKER_DATA_ERROR_INVALID_TYPE,
+ "Property '%s' does not accept URIs", predicate);
+ return;
+ }
tracker_data_begin_transaction ();
@@ -955,7 +971,7 @@ tracker_data_insert_statement_with_uri (const gchar *subject,
if (blank_uri != NULL) {
/* now insert statement referring to blank node */
- tracker_data_insert_statement (subject, predicate, blank_uri);
+ tracker_data_insert_statement (subject, predicate, blank_uri, error);
g_hash_table_remove (blank_buffer.table, object);
@@ -984,7 +1000,8 @@ tracker_data_insert_statement_with_uri (const gchar *subject,
g_ptr_array_add (update_buffer.types, g_strdup (object));
} else {
- g_warning ("Class '%s' not found in the ontology", object);
+ g_set_error (error, TRACKER_DATA_ERROR, TRACKER_DATA_ERROR_UNKNOWN_CLASS,
+ "Class '%s' not found in the ontology", object);
}
} else if (strcmp (predicate, TRACKER_PREFIX "uri") == 0) {
/* internal property tracker:uri, used to change uri of existing element */
@@ -1004,7 +1021,8 @@ tracker_data_insert_statement_with_uri (const gchar *subject,
void
tracker_data_insert_statement_with_string (const gchar *subject,
const gchar *predicate,
- const gchar *object)
+ const gchar *object,
+ GError **error)
{
TrackerProperty *property;
@@ -1013,7 +1031,15 @@ tracker_data_insert_statement_with_string (const gchar *subject,
g_return_if_fail (object != NULL);
property = tracker_ontology_get_property_by_uri (predicate);
- g_return_if_fail (property != NULL && tracker_property_get_data_type (property) != TRACKER_PROPERTY_TYPE_RESOURCE);
+ if (property == NULL) {
+ g_set_error (error, TRACKER_DATA_ERROR, TRACKER_DATA_ERROR_UNKNOWN_PROPERTY,
+ "Property '%s' not found in the ontology", predicate);
+ return;
+ } else if (tracker_property_get_data_type (property) == TRACKER_PROPERTY_TYPE_RESOURCE) {
+ g_set_error (error, TRACKER_DATA_ERROR, TRACKER_DATA_ERROR_INVALID_TYPE,
+ "Property '%s' only accepts URIs", predicate);
+ return;
+ }
tracker_data_begin_transaction ();
diff --git a/src/libtracker-data/tracker-data-update.h b/src/libtracker-data/tracker-data-update.h
index 5a28354..d9215b1 100644
--- a/src/libtracker-data/tracker-data-update.h
+++ b/src/libtracker-data/tracker-data-update.h
@@ -30,6 +30,16 @@
G_BEGIN_DECLS
+typedef enum {
+ TRACKER_DATA_ERROR_UNKNOWN_CLASS,
+ TRACKER_DATA_ERROR_UNKNOWN_PROPERTY,
+ TRACKER_DATA_ERROR_INVALID_TYPE
+} TrackerDataError;
+
+#define TRACKER_DATA_ERROR tracker_data_error_quark ()
+
+GQuark tracker_data_error_quark (void);
+
/* Services */
guint32 tracker_data_insert_resource (const gchar *uri);
void tracker_data_delete_resource (const gchar *uri);
@@ -43,13 +53,16 @@ void tracker_data_delete_statement (const gchar *subject,
void tracker_data_insert_statement (const gchar *subject,
const gchar *predicate,
- const gchar *object);
+ const gchar *object,
+ GError **error);
void tracker_data_insert_statement_with_uri (const gchar *subject,
const gchar *predicate,
- const gchar *object);
+ const gchar *object,
+ GError **error);
void tracker_data_insert_statement_with_string (const gchar *subject,
const gchar *predicate,
- const gchar *object);
+ const gchar *object,
+ GError **error);
void tracker_data_begin_transaction (void);
void tracker_data_commit_transaction (void);
diff --git a/src/tracker-store/tracker-store.c b/src/tracker-store/tracker-store.c
index c6dc33e..2693aff 100644
--- a/src/tracker-store/tracker-store.c
+++ b/src/tracker-store/tracker-store.c
@@ -101,12 +101,14 @@ process_turtle_file_part (void)
tracker_data_insert_statement_with_uri (
tracker_turtle_reader_get_subject (),
tracker_turtle_reader_get_predicate (),
- tracker_turtle_reader_get_object ());
+ tracker_turtle_reader_get_object (),
+ NULL);
} else {
tracker_data_insert_statement_with_string (
tracker_turtle_reader_get_subject (),
tracker_turtle_reader_get_predicate (),
- tracker_turtle_reader_get_object ());
+ tracker_turtle_reader_get_object (),
+ NULL);
}
i++;
@@ -399,7 +401,7 @@ tracker_store_insert_statement (const gchar *subject,
private->batch_count = 0;
}
- tracker_data_insert_statement (subject, predicate, object);
+ tracker_data_insert_statement (subject, predicate, object, NULL);
}
void
diff --git a/tests/libtracker-data/tracker-ontology-test.c b/tests/libtracker-data/tracker-ontology-test.c
index 39749c4..87f3f78 100644
--- a/tests/libtracker-data/tracker-ontology-test.c
+++ b/tests/libtracker-data/tracker-ontology-test.c
@@ -79,7 +79,7 @@ consume_triple_storer (const gchar *subject,
const gchar *object,
void *user_data)
{
- tracker_data_insert_statement (subject, predicate, object);
+ tracker_data_insert_statement (subject, predicate, object, NULL);
}
static void
diff --git a/tests/libtracker-data/tracker-sparql-test.c b/tests/libtracker-data/tracker-sparql-test.c
index 44c59da..b31b996 100644
--- a/tests/libtracker-data/tracker-sparql-test.c
+++ b/tests/libtracker-data/tracker-sparql-test.c
@@ -66,7 +66,7 @@ consume_triple_storer (const gchar *subject,
const gchar *object,
void *user_data)
{
- tracker_data_insert_statement (subject, predicate, object);
+ tracker_data_insert_statement (subject, predicate, object, NULL);
}
static void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]