[tracker/ttl: 5/8] libtracker-data: Journal imported turtle files



commit e8c0c8fdbc49be6207231d4141b705ce01288a5c
Author: Jürg Billeter <j bitron ch>
Date:   Thu Mar 18 08:55:46 2010 +0100

    libtracker-data: Journal imported turtle files

 src/libtracker-data/libtracker-data.vapi       |    3 ++
 src/libtracker-data/tracker-turtle-reader.vala |   26 +++++++++++++++++------
 src/tracker-store/tracker-store.c              |   21 +++++++++++++++++++
 3 files changed, 43 insertions(+), 7 deletions(-)
---
diff --git a/src/libtracker-data/libtracker-data.vapi b/src/libtracker-data/libtracker-data.vapi
index b9aa4d0..7087ed0 100644
--- a/src/libtracker-data/libtracker-data.vapi
+++ b/src/libtracker-data/libtracker-data.vapi
@@ -77,6 +77,9 @@ namespace Tracker {
 		public int query_resource_id (string uri);
 		public void begin_db_transaction ();
 		public void commit_db_transaction ();
+		public void begin_transaction () throws DBInterfaceError;
+		public void commit_transaction () throws DBInterfaceError;
+		public void rollback_transaction ();
 		public void delete_statement (string graph, string subject, string predicate, string object) throws DataError;
 		public void insert_statement (string graph, string subject, string predicate, string object) throws DataError;
 		public void insert_statement_with_uri (string graph, string subject, string predicate, string object) throws DataError;
diff --git a/src/libtracker-data/tracker-turtle-reader.vala b/src/libtracker-data/tracker-turtle-reader.vala
index c9e7edf..85f8d3b 100644
--- a/src/libtracker-data/tracker-turtle-reader.vala
+++ b/src/libtracker-data/tracker-turtle-reader.vala
@@ -365,14 +365,26 @@ public class Tracker.TurtleReader : Object {
 		}
 	}
 
-	public static void load (string path) throws FileError, SparqlError, DataError {
-		var reader = new TurtleReader (path);
-		while (reader.next ()) {
-			if (reader.object_is_uri) {
-				Data.insert_statement_with_uri (reader.graph, reader.subject, reader.predicate, reader.object);
-			} else {
-				Data.insert_statement_with_string (reader.graph, reader.subject, reader.predicate, reader.object);
+	public static void load (string path) throws FileError, SparqlError, DataError, DBInterfaceError {
+		try {
+			Data.begin_transaction ();
+
+			var reader = new TurtleReader (path);
+			while (reader.next ()) {
+				if (reader.object_is_uri) {
+					Data.insert_statement_with_uri (reader.graph, reader.subject, reader.predicate, reader.object);
+				} else {
+					Data.insert_statement_with_string (reader.graph, reader.subject, reader.predicate, reader.object);
+				}
 			}
+
+			Data.commit_transaction ();
+		} catch (DataError e) {
+			Data.rollback_transaction ();
+			throw e;
+		} catch (DBInterfaceError e) {
+			Data.rollback_transaction ();
+			throw e;
 		}
 	}
 
diff --git a/src/tracker-store/tracker-store.c b/src/tracker-store/tracker-store.c
index 488b4e2..2871432 100644
--- a/src/tracker-store/tracker-store.c
+++ b/src/tracker-store/tracker-store.c
@@ -104,6 +104,18 @@ process_turtle_file_part (TrackerTurtleReader *reader, GError **error)
 
 	i = 0;
 
+	/* There is no logical structure in turtle files, so we have no choice
+	 * but fallback to fixed number of statements per transaction to avoid
+	 * blocking tracker-store.
+	 * Real applications should all use SPARQL update instead of turtle
+	 * import to avoid this issue.
+	 */
+	tracker_data_begin_transaction (&new_error);
+	if (new_error) {
+		g_propagate_error (error, new_error);
+		return FALSE;
+	}
+
 	while (new_error == NULL && tracker_turtle_reader_next (reader, &new_error)) {
 		/* insert statement */
 		if (tracker_turtle_reader_get_object_is_uri (reader)) {
@@ -130,7 +142,16 @@ process_turtle_file_part (TrackerTurtleReader *reader, GError **error)
 	}
 
 	if (new_error) {
+		tracker_data_rollback_transaction ();
+		g_propagate_error (error, new_error);
+		return FALSE;
+	}
+
+	tracker_data_commit_transaction (&new_error);
+	if (new_error) {
+		tracker_data_rollback_transaction ();
 		g_propagate_error (error, new_error);
+		return FALSE;
 	}
 
 	return FALSE;



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]