[tracker/async-queries] libtracker-data: Adapt to new libtracker-db async API
- From: Jürg Billeter <juergbi src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker/async-queries] libtracker-data: Adapt to new libtracker-db async API
- Date: Wed, 14 Apr 2010 08:25:54 +0000 (UTC)
commit be426e459616439282936dc34e20683ed94ac6d7
Author: Jürg Billeter <j bitron ch>
Date: Wed Apr 14 09:57:15 2010 +0200
libtracker-data: Adapt to new libtracker-db async API
src/libtracker-data/tracker-sparql-query.vala | 112 +++++++++++++++++--------
src/libtracker-db/libtracker-db.vapi | 9 ++-
src/tracker-store/tracker-store.c | 2 +-
3 files changed, 83 insertions(+), 40 deletions(-)
---
diff --git a/src/libtracker-data/tracker-sparql-query.vala b/src/libtracker-data/tracker-sparql-query.vala
index 7db2bb6..976c7e6 100644
--- a/src/libtracker-data/tracker-sparql-query.vala
+++ b/src/libtracker-data/tracker-sparql-query.vala
@@ -165,6 +165,65 @@ namespace Tracker.Sparql {
return result;
}
}
+
+ class SqlStatement {
+ public string sql;
+ public List<LiteralBinding> bindings;
+
+ public DBResultSet? execute () throws DBInterfaceError, SparqlError, DateError
+ {
+ var iface = DBManager.get_db_interface ();
+ var stmt = iface.create_statement ("%s", sql);
+
+ // set literals specified in query
+ int i = 0;
+ foreach (LiteralBinding binding in bindings) {
+ if (binding.data_type == PropertyType.BOOLEAN) {
+ if (binding.literal == "true" || binding.literal == "1") {
+ stmt.bind_int (i, 1);
+ } else if (binding.literal == "false" || binding.literal == "0") {
+ stmt.bind_int (i, 0);
+ } else {
+ throw new SparqlError.TYPE ("`%s' is not a valid boolean".printf (binding.literal));
+ }
+ } else if (binding.data_type == PropertyType.DATETIME) {
+ stmt.bind_int (i, string_to_date (binding.literal, null));
+ } else if (binding.data_type == PropertyType.INTEGER) {
+ stmt.bind_int (i, binding.literal.to_int ());
+ } else {
+ stmt.bind_text (i, binding.literal);
+ }
+ i++;
+ }
+
+ return stmt.execute ();
+ }
+
+ public async DBResultSet? execute_async (Cancellable? cancellable = null) throws IOError, DBInterfaceError, SparqlError, DateError {
+ var pool = DBManager.get_interface_pool ();
+ var bind_values = new ValueArray (bindings.length ());
+
+ // set literals specified in query
+ foreach (LiteralBinding binding in bindings) {
+ if (binding.data_type == PropertyType.BOOLEAN) {
+ if (binding.literal == "true" || binding.literal == "1") {
+ bind_values.append (1);
+ } else if (binding.literal == "false" || binding.literal == "0") {
+ bind_values.append (0);
+ } else {
+ throw new SparqlError.TYPE ("`%s' is not a valid boolean".printf (binding.literal));
+ }
+ } else if (binding.data_type == PropertyType.DATETIME) {
+ bind_values.append (string_to_date (binding.literal, null));
+ } else if (binding.data_type == PropertyType.INTEGER) {
+ bind_values.append (binding.literal.to_int ());
+ } else {
+ bind_values.append (binding.literal);
+ }
+ }
+ return yield pool.execute_query_async (0, sql, bind_values, cancellable);
+ }
+ }
}
public class Tracker.Sparql.Query : Object {
@@ -361,7 +420,7 @@ public class Tracker.Sparql.Query : Object {
}
}
- public DBStatement prepare () throws DBInterfaceError, SparqlError, DateError {
+ SqlStatement prepare () throws IOError, DBInterfaceError, SparqlError, DateError {
assert (!update_extensions);
scanner = new SparqlScanner ((char*) query_string, (long) query_string.size ());
@@ -394,17 +453,17 @@ public class Tracker.Sparql.Query : Object {
}
}
- public DBResultSet? execute () throws DBInterfaceError, SparqlError, DateError {
+ public DBResultSet? execute () throws IOError, DBInterfaceError, SparqlError, DateError {
var stmt = prepare ();
return stmt.execute ();
}
- public async DBResultSet? execute_async () throws DBInterfaceError, SparqlError, DateError {
+ public async DBResultSet? execute_async (Cancellable? cancellable = null) throws IOError, DBInterfaceError, SparqlError, DateError {
var stmt = prepare ();
- return yield stmt.execute_async ();
+ return yield stmt.execute_async (cancellable);
}
- public PtrArray? execute_update (bool blank) throws DataError, DBInterfaceError, SparqlError, DateError {
+ public PtrArray? execute_update (bool blank) throws IOError, DataError, DBInterfaceError, SparqlError, DateError {
assert (update_extensions);
scanner = new SparqlScanner ((char*) query_string, (long) query_string.size ());
@@ -452,40 +511,19 @@ public class Tracker.Sparql.Query : Object {
return blank_nodes;
}
- DBStatement create_db_statement (string sql) throws DBInterfaceError, SparqlError, DateError {
- var iface = DBManager.get_db_interface ();
- var stmt = iface.create_statement ("%s", sql);
-
- // set literals specified in query
- int i = 0;
- foreach (LiteralBinding binding in bindings) {
- if (binding.data_type == PropertyType.BOOLEAN) {
- if (binding.literal == "true" || binding.literal == "1") {
- stmt.bind_int (i, 1);
- } else if (binding.literal == "false" || binding.literal == "0") {
- stmt.bind_int (i, 0);
- } else {
- throw new SparqlError.TYPE ("`%s' is not a valid boolean".printf (binding.literal));
- }
- } else if (binding.data_type == PropertyType.DATETIME) {
- stmt.bind_int (i, string_to_date (binding.literal, null));
- } else if (binding.data_type == PropertyType.INTEGER) {
- stmt.bind_int (i, binding.literal.to_int ());
- } else {
- stmt.bind_text (i, binding.literal);
- }
- i++;
- }
-
+ SqlStatement create_sql_statement (string sql) {
+ var stmt = new SqlStatement ();
+ stmt.sql = sql;
+ stmt.bindings = (owned) bindings;
return stmt;
}
- DBResultSet? exec_sql (string sql) throws DBInterfaceError, SparqlError, DateError {
- var stmt = create_db_statement (sql);
+ DBResultSet? exec_sql (string sql) throws IOError, DBInterfaceError, SparqlError, DateError {
+ var stmt = create_sql_statement (sql);
return stmt.execute ();
}
- DBStatement prepare_select () throws DBInterfaceError, SparqlError, DateError {
+ SqlStatement prepare_select () throws DBInterfaceError, SparqlError, DateError {
// SELECT query
context = new Context ();
@@ -498,10 +536,10 @@ public class Tracker.Sparql.Query : Object {
context = context.parent_context;
- return create_db_statement (sql.str);
+ return create_sql_statement (sql.str);
}
- DBStatement prepare_ask () throws DBInterfaceError, SparqlError, DateError {
+ SqlStatement prepare_ask () throws DBInterfaceError, SparqlError, DateError {
// ASK query
var pattern_sql = new StringBuilder ();
@@ -526,7 +564,7 @@ public class Tracker.Sparql.Query : Object {
context = context.parent_context;
- return create_db_statement (sql.str);
+ return create_sql_statement (sql.str);
}
private void parse_from_or_into_param () throws SparqlError {
@@ -542,7 +580,7 @@ public class Tracker.Sparql.Query : Object {
}
}
- PtrArray? execute_insert_or_delete (bool blank) throws DBInterfaceError, DataError, SparqlError, DateError {
+ PtrArray? execute_insert_or_delete (bool blank) throws IOError, DBInterfaceError, DataError, SparqlError, DateError {
// INSERT or DELETE
if (accept (SparqlTokenType.WITH)) {
diff --git a/src/libtracker-db/libtracker-db.vapi b/src/libtracker-db/libtracker-db.vapi
index 2a80317..0e088a0 100644
--- a/src/libtracker-db/libtracker-db.vapi
+++ b/src/libtracker-db/libtracker-db.vapi
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2008-2009, Nokia
+ * Copyright (C) 2008-2010, Nokia
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -40,8 +40,14 @@ namespace Tracker {
}
[CCode (cheader_filename = "libtracker-db/tracker-db-manager.h")]
+ public class DBInterfacePool : GLib.Object {
+ public async DBResultSet execute_query_async (uint priority, string query, GLib.ValueArray? bind_values, GLib.Cancellable? cancellable = null) throws GLib.IOError, DBInterfaceError;
+ }
+
+ [CCode (cheader_filename = "libtracker-db/tracker-db-manager.h")]
namespace DBManager {
public unowned DBInterface get_db_interface ();
+ public unowned DBInterfacePool get_interface_pool ();
}
[CCode (cheader_filename = "libtracker-db/tracker-db-interface.h")]
@@ -56,7 +62,6 @@ namespace Tracker {
public abstract void bind_int (int index, int value);
public abstract void bind_text (int index, string value);
public abstract DBResultSet execute () throws DBInterfaceError;
- public abstract async DBResultSet execute_async () throws DBInterfaceError;
}
}
diff --git a/src/tracker-store/tracker-store.c b/src/tracker-store/tracker-store.c
index 2cddde4..fcc9af3 100644
--- a/src/tracker-store/tracker-store.c
+++ b/src/tracker-store/tracker-store.c
@@ -318,7 +318,7 @@ queue_idle_handler (gpointer user_data)
private->n_queries_running++;
sparql_query = tracker_sparql_query_new (task->data.query.query);
- tracker_sparql_query_execute_async (sparql_query, query_ready, task);
+ tracker_sparql_query_execute_async (sparql_query, NULL, query_ready, task);
g_object_unref (sparql_query);
// suspend idle handler until above quey finished
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]