Commit 81b20c3f authored by Carlos Garnacho's avatar Carlos Garnacho

libtracker-data: Make TrackerDataManager a non singleton

There can now be multiple instances looking into separate database
and journal locations. TrackerDataManager has been made an initable
too, and busy handling has been lifted to a signal, in order to
reduce the arguments at new() a bit.
parent 308a710c
......@@ -69,6 +69,7 @@ namespace Tracker {
[CCode (cheader_filename = "libtracker-data/tracker-db-interface-sqlite.h")]
public void sqlite_wal_hook (DBWalCallback callback);
public void sqlite_wal_checkpoint (bool blocking) throws DBInterfaceError;
public unowned GLib.Object get_user_data ();
}
[CCode (cheader_filename = "libtracker-data/tracker-data-update.h")]
......@@ -219,22 +220,21 @@ namespace Tracker {
public void remove_rollback_statement_callback (CommitCallback callback);
}
[CCode (cheader_filename = "libtracker-data/tracker-data-backup.h")]
[CCode (cheader_filename = "libtracker-data/tracker-data-backup.h,libtracker-data/tracker-data-query.h")]
namespace Data {
public int query_resource_id (string uri);
public DBCursor query_sparql_cursor (string query) throws Sparql.Error;
public int query_resource_id (Data.Manager manager, string uri);
public DBCursor query_sparql_cursor (Data.Manager manager, string query) throws Sparql.Error;
public void backup_save (GLib.File destination, GLib.File data_location, owned BackupFinished callback);
public void backup_restore (GLib.File journal, string? cache_location, string? data_location, GLib.File? ontology_location, BusyCallback busy_callback) throws GLib.Error;
public void backup_restore (Data.Manager manager, GLib.File journal, string? cache_location, string? data_location, GLib.File? ontology_location, BusyCallback busy_callback) throws GLib.Error;
[CCode (cheader_filename = "libtracker-data/tracker-data-backup.h")]
public delegate void BackupFinished (GLib.Error error);
}
[CCode (cheader_filename = "libtracker-data/tracker-data-manager.h")]
namespace Data.Manager {
public bool init (DBManagerFlags flags, GLib.File cache_location, GLib.File data_location, GLib.File ontology_location, out bool first_time, bool journal_check, bool restoring_backup, uint select_cache_size, uint update_cache_size, BusyCallback? busy_callback, string? busy_status) throws DBInterfaceError, DBJournalError;
public void shutdown ();
[CCode (cheader_filename = "libtracker-data/tracker-data-manager.h", type_id = "TRACKER_TYPE_DATA_MANAGER")]
public class Data.Manager : GLib.Object, GLib.Initable {
public Manager (DBManagerFlags flags, GLib.File cache_location, GLib.File data_location, GLib.File ontology_location, bool journal_check, bool restoring_backup, uint select_cache_size, uint update_cache_size);
public unowned Ontologies get_ontologies ();
public unowned DBInterface get_db_interface ();
public unowned Data.Update get_data ();
......
......@@ -543,7 +543,8 @@ tracker_data_backup_save (GFile *destination,
}
void
tracker_data_backup_restore (GFile *journal,
tracker_data_backup_restore (TrackerDataManager *manager,
GFile *journal,
GFile *cache_location,
GFile *data_location,
GFile *ontology_location,
......@@ -563,7 +564,7 @@ tracker_data_backup_restore (GFile *journal,
return;
}
db_manager = tracker_data_manager_get_db_manager ();
db_manager = tracker_data_manager_get_db_manager (manager);
info = g_new0 (BackupSaveInfo, 1);
#ifndef DISABLE_JOURNAL
info->destination = g_file_get_child (data_location, TRACKER_DB_JOURNAL_FILENAME);
......@@ -577,7 +578,6 @@ tracker_data_backup_restore (GFile *journal,
TrackerDBManagerFlags flags;
TrackerDBJournal *journal_writer;
guint select_cache_size, update_cache_size;
gboolean is_first;
#ifndef DISABLE_JOURNAL
GError *n_error = NULL;
GFile *parent = g_file_get_parent (info->destination);
......@@ -590,7 +590,7 @@ tracker_data_backup_restore (GFile *journal,
flags = tracker_db_manager_get_flags (db_manager, &select_cache_size, &update_cache_size);
tracker_data_manager_shutdown ();
//tracker_data_manager_shutdown ();
move_to_temp (cache_location, data_location);
......@@ -691,24 +691,18 @@ tracker_data_backup_restore (GFile *journal,
}
#endif /* DISABLE_JOURNAL */
tracker_data_manager_init (flags, cache_location, data_location, ontology_location,
&is_first, TRUE, TRUE,
select_cache_size, update_cache_size,
busy_callback, busy_user_data,
"Restoring backup", &internal_error);
manager = tracker_data_manager_new (flags, cache_location, data_location, ontology_location,
TRUE, TRUE, select_cache_size, update_cache_size);
g_initable_init (G_INITABLE (manager), NULL, &internal_error);
#ifdef DISABLE_JOURNAL
if (internal_error) {
restore_from_temp ();
g_object_unref (manager);
tracker_data_manager_init (flags,
cache_location,
data_location,
ontology_location,
&is_first, TRUE, TRUE,
select_cache_size, update_cache_size,
busy_callback, busy_user_data,
"Restoring backup", &internal_error);
manager = tracker_data_manager_new (flags, cache_location, data_location, ontology_location,
TRUE, TRUE, select_cache_size, update_cache_size);
g_initable_init (G_INITABLE (manager), NULL, &internal_error);
} else {
remove_temp ();
}
......
......@@ -48,7 +48,8 @@ void tracker_data_backup_save (GFile *destination,
TrackerDataBackupFinished callback,
gpointer user_data,
GDestroyNotify destroy);
void tracker_data_backup_restore (GFile *journal,
void tracker_data_backup_restore (TrackerDataManager *manager,
GFile *journal,
GFile *cache_location,
GFile *data_location,
GFile *ontology_location,
......
This diff is collapsed.
......@@ -23,8 +23,17 @@
#ifndef __LIBTRACKER_DATA_MANAGER_H__
#define __LIBTRACKER_DATA_MANAGER_H__
#if !defined (__LIBTRACKER_DATA_INSIDE__) && !defined (TRACKER_COMPILATION)
#error "only <libtracker-data/tracker-data.h> must be included directly."
#endif
#include <glib.h>
G_BEGIN_DECLS
typedef struct _TrackerDataManager TrackerDataManager;
typedef struct _TrackerDataManagerClass TrackerDataManagerClass;
#include <libtracker-common/tracker-common.h>
#include <libtracker-sparql/tracker-sparql.h>
......@@ -33,46 +42,42 @@
#include <libtracker-data/tracker-db-manager.h>
#include <libtracker-data/tracker-db-journal.h>
G_BEGIN_DECLS
#if !defined (__LIBTRACKER_DATA_INSIDE__) && !defined (TRACKER_COMPILATION)
#error "only <libtracker-data/tracker-data.h> must be included directly."
#endif
#define TRACKER_DATA_ONTOLOGY_ERROR (tracker_data_ontology_error_quark ())
#define TRACKER_TYPE_DATA_MANAGER (tracker_data_manager_get_type ())
#define TRACKER_DATA_MANAGER(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), TRACKER_TYPE_DATA_MANAGER, TrackerDataManager))
#define TRACKER_DATA_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_CAST ((k), TRACKER_TYPE_DATA_MANAGER, TrackerDataManagerClass))
#define TRACKER_IS_DATA_MANAGER(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), TRACKER_TYPE_DATA_MANAGER))
#define TRACKER_IS_DATA_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), TRACKER_TYPE_DATA_MANAGER))
#define TRACKER_DATA_MANAGER_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), TRACKER_TYPE_DATA_MANAGER, TrackerDataManagerClass))
typedef enum {
TRACKER_DATA_UNSUPPORTED_ONTOLOGY_CHANGE,
TRACKER_DATA_ONTOLOGY_NOT_FOUND,
TRACKER_DATA_UNSUPPORTED_LOCATION
} TrackerDataOntologyError;
GType tracker_data_manager_get_type (void) G_GNUC_CONST;
GQuark tracker_data_ontology_error_quark (void);
gboolean tracker_data_manager_init (TrackerDBManagerFlags flags,
TrackerDataManager * tracker_data_manager_new (TrackerDBManagerFlags flags,
GFile *cache_location,
GFile *data_location,
GFile *ontology_location,
gboolean *first_time,
gboolean journal_check,
gboolean restoring_backup,
guint select_cache_size,
guint update_cache_size,
TrackerBusyCallback busy_callback,
gpointer busy_user_data,
const gchar *busy_operation,
GError **error);
void tracker_data_manager_shutdown (void);
GFile * tracker_data_manager_get_cache_location();
GFile * tracker_data_manager_get_data_location ();
TrackerDBJournal * tracker_data_manager_get_journal_writer (void);
TrackerDBJournal * tracker_data_manager_get_ontology_writer (void);
TrackerOntologies * tracker_data_manager_get_ontologies (void);
TrackerDBManager * tracker_data_manager_get_db_manager (void);
TrackerDBInterface * tracker_data_manager_get_db_interface (void);
TrackerData * tracker_data_manager_get_data (void);
guint update_cache_size);
GFile * tracker_data_manager_get_cache_location (TrackerDataManager *manager);
GFile * tracker_data_manager_get_data_location (TrackerDataManager *manager);
TrackerDBJournal * tracker_data_manager_get_journal_writer (TrackerDataManager *manager);
TrackerDBJournal * tracker_data_manager_get_ontology_writer (TrackerDataManager *manager);
TrackerOntologies * tracker_data_manager_get_ontologies (TrackerDataManager *manager);
TrackerDBManager * tracker_data_manager_get_db_manager (TrackerDataManager *manager);
TrackerDBInterface * tracker_data_manager_get_db_interface (TrackerDataManager *manager);
TrackerData * tracker_data_manager_get_data (TrackerDataManager *manager);
gboolean tracker_data_manager_init_fts (TrackerDBInterface *interface,
gboolean create);
......
......@@ -34,7 +34,8 @@
#include "tracker-sparql-query.h"
GPtrArray*
tracker_data_query_rdf_type (gint id)
tracker_data_query_rdf_type (TrackerDataManager *manager,
gint id)
{
TrackerDBCursor *cursor = NULL;
TrackerDBInterface *iface;
......@@ -43,8 +44,8 @@ tracker_data_query_rdf_type (gint id)
GError *error = NULL;
TrackerOntologies *ontologies;
iface = tracker_data_manager_get_db_interface ();
ontologies = tracker_data_manager_get_ontologies ();
iface = tracker_data_manager_get_db_interface (manager);
ontologies = tracker_data_manager_get_ontologies (manager);
stmt = tracker_db_interface_create_statement (iface, TRACKER_DB_STATEMENT_CACHE_TYPE_SELECT, &error,
"SELECT (SELECT Uri FROM Resource WHERE ID = \"rdf:type\") "
......@@ -93,7 +94,8 @@ tracker_data_query_rdf_type (gint id)
}
gint
tracker_data_query_resource_id (const gchar *uri)
tracker_data_query_resource_id (TrackerDataManager *manager,
const gchar *uri)
{
TrackerDBCursor *cursor = NULL;
TrackerDBInterface *iface;
......@@ -103,7 +105,7 @@ tracker_data_query_resource_id (const gchar *uri)
g_return_val_if_fail (uri != NULL, 0);
iface = tracker_data_manager_get_db_interface ();
iface = tracker_data_manager_get_db_interface (manager);
stmt = tracker_db_interface_create_statement (iface, TRACKER_DB_STATEMENT_CACHE_TYPE_SELECT, &error,
"SELECT ID FROM Resource WHERE Uri = ?");
......@@ -132,15 +134,16 @@ tracker_data_query_resource_id (const gchar *uri)
TrackerDBCursor *
tracker_data_query_sparql_cursor (const gchar *query,
GError **error)
tracker_data_query_sparql_cursor (TrackerDataManager *manager,
const gchar *query,
GError **error)
{
TrackerSparqlQuery *sparql_query;
TrackerDBCursor *cursor;
g_return_val_if_fail (query != NULL, NULL);
sparql_query = tracker_sparql_query_new (query);
sparql_query = tracker_sparql_query_new (manager, query);
cursor = tracker_sparql_query_execute_cursor (sparql_query, error);
......
......@@ -26,6 +26,7 @@
#include <glib.h>
#include "tracker-db-interface.h"
#include "tracker-data-manager.h"
G_BEGIN_DECLS
......@@ -33,11 +34,14 @@ G_BEGIN_DECLS
#error "only <libtracker-data/tracker-data.h> must be included directly."
#endif
gint tracker_data_query_resource_id (const gchar *uri);
TrackerDBCursor *tracker_data_query_sparql_cursor (const gchar *query,
GError **error);
gint tracker_data_query_resource_id (TrackerDataManager *manager,
const gchar *uri);
TrackerDBCursor *tracker_data_query_sparql_cursor (TrackerDataManager *manager,
const gchar *query,
GError **error);
GPtrArray* tracker_data_query_rdf_type (gint id);
GPtrArray* tracker_data_query_rdf_type (TrackerDataManager *manager,
gint id);
G_END_DECLS
......
This diff is collapsed.
......@@ -21,18 +21,21 @@
#ifndef __LIBTRACKER_DATA_UPDATE_H__
#define __LIBTRACKER_DATA_UPDATE_H__
#if !defined (__LIBTRACKER_DATA_INSIDE__) && !defined (TRACKER_COMPILATION)
#error "only <libtracker-data/tracker-data.h> must be included directly."
#endif
#include <glib.h>
#include <gio/gio.h>
#include <libtracker-sparql/tracker-sparql.h>
#include "tracker-db-interface.h"
G_BEGIN_DECLS
#if !defined (__LIBTRACKER_DATA_INSIDE__) && !defined (TRACKER_COMPILATION)
#error "only <libtracker-data/tracker-data.h> must be included directly."
#endif
typedef struct _TrackerData TrackerData;
typedef struct _TrackerDataClass TrackerDataClass;
#include <libtracker-sparql/tracker-sparql.h>
#include "tracker-db-interface.h"
#include "tracker-data-manager.h"
#define TRACKER_TYPE_DATA (tracker_data_get_type ())
#define TRACKER_DATA(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), TRACKER_TYPE_DATA, TrackerData))
......@@ -159,7 +162,7 @@ void tracker_data_remove_rollback_statement_callback (TrackerData
gpointer user_data);
GType tracker_data_get_type (void) G_GNUC_CONST;
TrackerData * tracker_data_new (void);
TrackerData * tracker_data_new (TrackerDataManager *manager);
G_END_DECLS
......
......@@ -129,6 +129,8 @@ struct _TrackerDBManager {
TrackerDBManagerFlags flags;
guint s_cache_size;
guint u_cache_size;
GWeakRef iface_data;
};
static gboolean db_exec_no_reply (TrackerDBInterface *iface,
......@@ -568,6 +570,7 @@ tracker_db_manager_new (TrackerDBManagerFlags flags,
TrackerBusyCallback busy_callback,
gpointer busy_user_data,
const gchar *busy_operation,
GObject *iface_data,
GError **error)
{
TrackerDBManager *db_manager;
......@@ -603,6 +606,7 @@ tracker_db_manager_new (TrackerDBManagerFlags flags,
g_set_object (&db_manager->cache_location, cache_location);
g_set_object (&db_manager->data_location, data_location);
g_weak_ref_init (&db_manager->iface_data, iface_data);
tracker_db_manager_ensure_locations (db_manager, cache_location, data_location);
db_manager->in_use_filename = g_build_filename (db_manager->user_data_dir,
......@@ -915,6 +919,7 @@ tracker_db_manager_free (TrackerDBManager *db_manager)
{
g_free (db_manager->db.abs_filename);
g_clear_object (&db_manager->db.iface);
g_weak_ref_clear (&db_manager->iface_data);
g_free (db_manager->data_dir);
g_free (db_manager->user_data_dir);
......@@ -980,6 +985,9 @@ tracker_db_manager_create_db_interface (TrackerDBManager *db_manager,
connection = tracker_db_interface_sqlite_new (db_manager->db.abs_filename,
flags,
&internal_error);
tracker_db_interface_set_user_data (connection,
g_weak_ref_get (&db_manager->iface_data),
g_object_unref);
if (internal_error) {
g_propagate_error (error, internal_error);
......
......@@ -56,6 +56,7 @@ TrackerDBManager *tracker_db_manager_new (TrackerDBManagerF
TrackerBusyCallback busy_callback,
gpointer busy_user_data,
const gchar *busy_operation,
GObject *iface_data,
GError **error);
void tracker_db_manager_free (TrackerDBManager *db_manager);
void tracker_db_manager_remove_all (TrackerDBManager *db_manager);
......
......@@ -34,8 +34,11 @@ class Tracker.Sparql.Expression : Object {
string? fts_sql;
Data.Manager manager;
public Expression (Query query) {
this.query = query;
this.manager = query.manager;
}
Context context {
......@@ -853,7 +856,7 @@ class Tracker.Sparql.Expression : Object {
return PropertyType.STRING;
} else {
// support properties as functions
var ontologies = Data.Manager.get_ontologies ();
var ontologies = manager.get_ontologies ();
var prop = ontologies.get_property_by_uri (uri);
if (prop == null) {
throw get_error ("Unknown function");
......
......@@ -26,18 +26,24 @@ namespace Tracker.Sparql {
public Class? domain;
Data.Manager manager;
public PredicateVariable (Data.Manager manager) {
this.manager = manager;
}
public string get_sql_query (Query query) throws Sparql.Error {
try {
var sql = new StringBuilder ();
var ontologies = Data.Manager.get_ontologies ();
var ontologies = manager.get_ontologies ();
if (subject != null) {
// single subject
var subject_id = Data.query_resource_id (subject);
var subject_id = Tracker.Data.query_resource_id (manager, subject);
DBCursor cursor = null;
if (subject_id > 0) {
var iface = Data.Manager.get_db_interface ();
var iface = manager.get_db_interface ();
var stmt = iface.create_statement (DBStatementCacheType.SELECT,
"SELECT (SELECT Uri FROM Resource WHERE ID = \"rdf:type\") " +
"FROM \"rdfs:Resource_rdf:type\" WHERE ID = ?");
......@@ -84,9 +90,9 @@ namespace Tracker.Sparql {
}
} else if (object != null) {
// single object
var object_id = Data.query_resource_id (object);
var object_id = Data.query_resource_id (manager, object);
var iface = Data.Manager.get_db_interface ();
var iface = manager.get_db_interface ();
var stmt = iface.create_statement (DBStatementCacheType.SELECT,
"SELECT (SELECT Uri FROM Resource WHERE ID = \"rdf:type\") " +
"FROM \"rdfs:Resource_rdf:type\" WHERE ID = ?");
......@@ -175,8 +181,11 @@ class Tracker.Sparql.Pattern : Object {
internal StringBuilder? match_str;
public bool queries_fts_data = false;
Data.Manager manager;
public Pattern (Query query) {
this.query = query;
this.manager = query.manager;
this.expression = query.expression;
}
......@@ -879,7 +888,7 @@ class Tracker.Sparql.Pattern : Object {
} else {
return false;
}
var ontologies = Data.Manager.get_ontologies ();
var ontologies = manager.get_ontologies ();
var prop = ontologies.get_property_by_uri (predicate);
if (prop == null) {
return false;
......@@ -1353,7 +1362,7 @@ class Tracker.Sparql.Pattern : Object {
Class subject_type = null;
var ontologies = Data.Manager.get_ontologies ();
var ontologies = manager.get_ontologies ();
if (!current_predicate_is_var) {
prop = ontologies.get_property_by_uri (current_predicate);
......@@ -1390,7 +1399,7 @@ class Tracker.Sparql.Pattern : Object {
}
var pv = context.predicate_variable_map.lookup (context.get_variable (current_subject));
if (pv == null) {
pv = new PredicateVariable ();
pv = new PredicateVariable (manager);
context.predicate_variable_map.insert (context.get_variable (current_subject), pv);
}
pv.domain = domain;
......@@ -1465,7 +1474,7 @@ class Tracker.Sparql.Pattern : Object {
table = new DataTable ();
table.predicate_variable = context.predicate_variable_map.lookup (context.get_variable (current_predicate));
if (table.predicate_variable == null) {
table.predicate_variable = new PredicateVariable ();
table.predicate_variable = new PredicateVariable (manager);
context.predicate_variable_map.insert (context.get_variable (current_predicate), table.predicate_variable);
}
if (!current_subject_is_var) {
......
......@@ -242,12 +242,14 @@ public class Tracker.Sparql.Query : Object {
uchar[] base_uuid;
HashTable<string,string> blank_nodes;
public Data.Manager manager;
// Keep track of used SQL identifiers for SPARQL variables
public int last_var_index;
public bool no_cache { get; set; }
public Query (string query) {
public Query (Data.Manager manager, string query) {
no_cache = false; /* Start with false, expression sets it */
tokens = new TokenInfo[BUFFER_SIZE];
prefix_map = new HashTable<string,string>.full (str_hash, str_equal, g_free, g_free);
......@@ -256,13 +258,14 @@ public class Tracker.Sparql.Query : Object {
uuid_generate (base_uuid);
this.query_string = query;
this.manager = manager;
expression = new Expression (this);
pattern = new Pattern (this);
}
public Query.update (string query) {
this (query);
public Query.update (Data.Manager manager, string query) {
this (manager, query);
this.update_extensions = true;
}
......@@ -298,7 +301,7 @@ public class Tracker.Sparql.Query : Object {
uri = get_uuid_for_name (base_uuid, user_bnodeid);
if (blank_nodes != null) {
while (Data.query_resource_id (uri) > 0) {
while (Data.query_resource_id (manager, uri) > 0) {
// uri collision, generate new UUID
uchar[] new_base_uuid = new uchar[16];
uuid_generate (new_base_uuid);
......@@ -404,7 +407,7 @@ public class Tracker.Sparql.Query : Object {
// declare fn prefix for XPath functions
prefix_map.insert ("fn", FN_NS);
var ontologies = Data.Manager.get_ontologies ();
var ontologies = manager.get_ontologies ();
foreach (Namespace ns in ontologies.get_namespaces ()) {
if (ns.prefix == null) {
......@@ -449,7 +452,7 @@ public class Tracker.Sparql.Query : Object {
// declare fn prefix for XPath functions
prefix_map.insert ("fn", FN_NS);
var ontologies = Data.Manager.get_ontologies ();
var ontologies = manager.get_ontologies ();
foreach (Namespace ns in ontologies.get_namespaces ()) {
if (ns.prefix == null) {
......@@ -505,7 +508,7 @@ public class Tracker.Sparql.Query : Object {
}
DBStatement prepare_for_exec (string sql) throws DBInterfaceError, Sparql.Error, DateError {
var iface = Data.Manager.get_db_interface ();
var iface = manager.get_db_interface ();
if (iface == null) {
throw new DBInterfaceError.OPEN_ERROR ("Error opening database");
}
......@@ -628,7 +631,7 @@ public class Tracker.Sparql.Query : Object {
bool delete_where = false;
bool data = false;
var data_update = Data.Manager.get_data ();
var data_update = manager.get_data ();
// Sparql 1.1 defines deletes/inserts as a single
// operation with the syntax:
......@@ -1055,7 +1058,7 @@ public class Tracker.Sparql.Query : Object {
void parse_construct_object (Solution var_value_map, UpdateType type) throws Sparql.Error, DateError {
bool is_null = false;
string object = parse_construct_var_or_term (var_value_map, type, out is_null);
var data = Data.Manager.get_data ();
var data = manager.get_data ();
if (current_subject == null || current_predicate == null || object == null) {
// the SPARQL specification says that triples containing unbound variables
// should be excluded from the output RDF graph of CONSTRUCT
......
......@@ -380,8 +380,7 @@ public class Tracker.TurtleReader : Object {
}
}
public static void load (File file) throws Error, FileError, Sparql.Error, DateError, DBInterfaceError {
var data = Data.Manager.get_data ();
public static void load (File file, Data.Update data) throws Error, FileError, Sparql.Error, DateError, DBInterfaceError {
try {
data.begin_transaction ();
......
......@@ -24,6 +24,8 @@ public class Tracker.Direct.Connection : Tracker.Sparql.Connection, AsyncInitabl
File? ontology_loc;
Sparql.ConnectionFlags flags;
Data.Manager data_manager;
// Mutex to hold datamanager
private Mutex mutex = Mutex ();
Thread<void*> thread;
......@@ -96,9 +98,8 @@ public class Tracker.Direct.Connection : Tracker.Sparql.Connection, AsyncInitabl
}
}
static void wal_checkpoint_on_thread () {
static void wal_checkpoint_on_thread (DBInterface iface) {
new Thread<void*> ("wal-checkpoint", () => {
var iface = Data.Manager.get_db_interface ();
wal_checkpoint (iface, false);
return null;
});
......@@ -110,7 +111,7 @@ public class Tracker.Direct.Connection : Tracker.Sparql.Connection, AsyncInitabl
// to prevent excessive wal file growth
wal_checkpoint (iface, true);
} else if (n_pages >= 1000) {
wal_checkpoint_on_thread ();
wal_checkpoint_on_thread (iface);
}
}
......@@ -122,11 +123,13 @@ public class Tracker.Direct.Connection : Tracker.Sparql.Connection, AsyncInitabl
DBManagerFlags db_flags = DBManagerFlags.ENABLE_MUTEXES;
if ((flags & Sparql.ConnectionFlags.READONLY) != 0)
db_flags |= DBManagerFlags.READONLY;
Data.Manager.init (db_flags,
database_loc, journal_loc, ontology_loc,
null, false, false, 100, 100, null, null);
var iface = Data.Manager.get_db_interface ();
data_manager = new Data.Manager (db_flags,
database_loc, journal_loc, ontology_loc,
false, false, 100, 100);
data_manager.init ();
var iface = data_manager.get_db_interface ();
iface.sqlite_wal_hook (wal_hook);
} catch (Error e) {
init_error = e;
......@@ -207,18 +210,9 @@ public class Tracker.Direct.Connection : Tracker.Sparql.Connection, AsyncInitabl
update_queue = new AsyncQueue<Task> ();
}
~Connection () {
if (!initialized) {
return;
}
// Clean up connection
Data.Manager.shutdown ();
}
Sparql.Cursor query_unlocked (string sparql) throws Sparql.Error, DBusError {
try {
var query_object = new Sparql.Query (sparql);
var query_object = new Sparql.Query (data_manager, sparql);
var cursor = query_object.execute_cursor ();
cursor.connection = this;
return cursor;
......@@ -289,7 +283,7 @@ public class Tracker.Direct.Connection : Tracker.Sparql.Connection, AsyncInitabl
public override void update (string sparql, int priority = GLib.Priority.DEFAULT, Cancellable? cancellable = null) throws Sparql.Error, IOError, DBusError, GLib.Error {
mutex.lock ();
try {
var data = Data.Manager.get_data ();
var data = data_manager.get_data ();
data.update_sparql (sparql);
} finally {
mutex.unlock ();
......@@ -310,7 +304,7 @@ public class Tracker.Direct.Connection : Tracker.Sparql.Connection, AsyncInitabl
GLib.Variant? blank_nodes = null;
mutex.lock ();
try {
var data = Data.Manager.get_data ();
var data = data_manager.get_data ();
blank_nodes = data.update_sparql_blank (sparql);
} finally {
mutex.unlock ();
......@@ -334,7 +328,7 @@ public class Tracker.Direct.Connection : Tracker.Sparql.Connection, AsyncInitabl
public override void load (File file, Cancellable? cancellable = null) throws Sparql.Error, IOError, DBusError {
mutex.lock ();
try {
var data = Data.Manager.get_data ();
var data = data_manager.get_data ();
data.load_turtle_file (file);
} finally {
mutex.unlock ();
......
......@@ -272,16 +272,18 @@ tracker_offsets_function (const Fts5ExtensionApi *api,
}
static GHashTable *
get_fts_weights (sqlite3_context *context)
get_fts_weights (TrackerDBInterface *iface,
sqlite3_context *context)
{
static GHashTable *weights = NULL;
static GMutex mutex;
int rc = SQLITE_DONE;
TrackerOntologies *ontologies;
g_mutex_lock (&mutex);
if (G_UNLIKELY (weights == NULL)) {
TrackerDataManager *manager;
TrackerOntologies *ontologies;
sqlite3_stmt *stmt;
sqlite3 *db;
const gchar *uri;
......@@ -295,7 +297,8 @@ get_fts_weights (sqlite3_context *context)
"WHERE \"rdf:Property\".\"tracker:fulltextIndexed\" = 1 ",
-1, &stmt, NULL);
ontologies = tracker_data_manager_get_ontologies ();
manager = tracker_db_interface_get_user_data (iface);
ontologies = tracker_data_manager_get_ontologies (manager);
while ((rc = sqlite3_step (stmt)) != SQLITE_DONE) {
if (rc == SQLITE_ROW) {
......@@ -346,7 +349,7 @@ tracker_rank_function (const Fts5ExtensionApi *api,
n_columns = api->xColumnCount (fts_ctx);
data = api->xUserData (fts_ctx);
weights = get_fts_weights (ctx);
weights = get_fts_weights (data->interface, ctx);
if (!weights) {