[evolution-data-server/sqlite-refactor: 5/13] EDataBookCursorSqlite: Ported to EBookBackendSqlite
- From: Tristan Van Berkom <tvb src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution-data-server/sqlite-refactor: 5/13] EDataBookCursorSqlite: Ported to EBookBackendSqlite
- Date: Mon, 25 Nov 2013 14:55:41 +0000 (UTC)
commit c5d5d864cafaae763caf43b8a0e38ecb1d3b09ec
Author: Tristan Van Berkom <tristanvb openismus com>
Date: Tue Nov 19 23:55:29 2013 +0900
EDataBookCursorSqlite: Ported to EBookBackendSqlite
.../libedata-book/e-data-book-cursor-sqlite.c | 172 ++++++++++----------
.../libedata-book/e-data-book-cursor-sqlite.h | 16 +-
2 files changed, 92 insertions(+), 96 deletions(-)
---
diff --git a/addressbook/libedata-book/e-data-book-cursor-sqlite.c
b/addressbook/libedata-book/e-data-book-cursor-sqlite.c
index 408a031..cd040e4 100644
--- a/addressbook/libedata-book/e-data-book-cursor-sqlite.c
+++ b/addressbook/libedata-book/e-data-book-cursor-sqlite.c
@@ -24,7 +24,7 @@
* @short_description: The SQLite cursor implementation
*
* This cursor implementation can be used with any backend which
- * stores contacts using #EBookBackendSqliteDB.
+ * stores contacts using #EBookBackendSqlite.
*/
#ifdef HAVE_CONFIG_H
@@ -70,15 +70,15 @@ static gboolean e_data_book_cursor_sqlite_load_locale (EDataBookCursor
GError **error);
struct _EDataBookCursorSqlitePrivate {
- EBookBackendSqliteDB *ebsdb;
- EbSdbCursor *cursor;
- gchar *folder_id;
+ EBookBackendSqlite *ebsql;
+ EbSqlCursor *cursor;
+ gchar *revision_key;
};
enum {
PROP_0,
- PROP_EBSDB,
- PROP_FOLDER_ID,
+ PROP_EBSQL,
+ PROP_REVISION_KEY,
PROP_CURSOR,
};
@@ -108,29 +108,28 @@ e_data_book_cursor_sqlite_class_init (EDataBookCursorSqliteClass *class)
g_object_class_install_property (
object_class,
- PROP_EBSDB,
+ PROP_EBSQL,
g_param_spec_object (
- "ebsdb", "EBookBackendSqliteDB",
- "The EBookBackendSqliteDB to use for queries",
- E_TYPE_BOOK_BACKEND_SQLITEDB,
+ "ebsql", "EBookBackendSqlite",
+ "The EBookBackendSqlite to use for queries",
+ E_TYPE_BOOK_BACKEND_SQLITE,
G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
g_object_class_install_property (
object_class,
- PROP_FOLDER_ID,
+ PROP_REVISION_KEY,
g_param_spec_string (
- "folder-id", "Folder ID",
- "The folder identifier to use with the EBookBackendSqliteDB object",
+ "revision-key", "Revision Key",
+ "The key name to fetch the revision from the sqlite backend",
NULL,
- G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY |
- G_PARAM_STATIC_STRINGS));
+ G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
g_object_class_install_property (
object_class,
PROP_CURSOR,
g_param_spec_pointer (
"cursor", "Cursor",
- "The EbSdbCursor pointer",
+ "The EbSqlCursor pointer",
G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
g_type_class_add_private (class, sizeof (EDataBookCursorSqlitePrivate));
@@ -151,14 +150,14 @@ e_data_book_cursor_sqlite_dispose (GObject *object)
EDataBookCursorSqlite *cursor = E_DATA_BOOK_CURSOR_SQLITE (object);
EDataBookCursorSqlitePrivate *priv = cursor->priv;
- if (priv->ebsdb) {
+ if (priv->ebsql) {
if (priv->cursor)
- e_book_backend_sqlitedb_cursor_free (priv->ebsdb,
+ e_book_backend_sqlite_cursor_free (priv->ebsql,
priv->cursor);
- g_object_unref (priv->ebsdb);
- priv->ebsdb = NULL;
+ g_object_unref (priv->ebsql);
+ priv->ebsql = NULL;
priv->cursor = NULL;
}
@@ -171,7 +170,7 @@ e_data_book_cursor_sqlite_finalize (GObject *object)
EDataBookCursorSqlite *cursor = E_DATA_BOOK_CURSOR_SQLITE (object);
EDataBookCursorSqlitePrivate *priv = cursor->priv;
- g_free (priv->folder_id);
+ g_free (priv->revision_key);
G_OBJECT_CLASS (e_data_book_cursor_sqlite_parent_class)->finalize (object);
}
@@ -186,13 +185,13 @@ e_data_book_cursor_sqlite_set_property (GObject *object,
EDataBookCursorSqlitePrivate *priv = cursor->priv;
switch (property_id) {
- case PROP_EBSDB:
+ case PROP_EBSQL:
/* Construct-only, can only be set once */
- priv->ebsdb = g_value_dup_object (value);
+ priv->ebsql = g_value_dup_object (value);
break;
- case PROP_FOLDER_ID:
+ case PROP_REVISION_KEY:
/* Construct-only, can only be set once */
- priv->folder_id = g_value_dup_string (value);
+ priv->revision_key = g_value_dup_string (value);
break;
case PROP_CURSOR:
/* Construct-only, can only be set once */
@@ -220,15 +219,15 @@ e_data_book_cursor_sqlite_set_sexp (EDataBookCursor *cursor,
cursor_sqlite = E_DATA_BOOK_CURSOR_SQLITE (cursor);
priv = cursor_sqlite->priv;
- success = e_book_backend_sqlitedb_cursor_set_sexp (priv->ebsdb,
+ success = e_book_backend_sqlite_cursor_set_sexp (priv->ebsql,
priv->cursor,
sexp,
&local_error);
if (!success) {
if (g_error_matches (local_error,
- E_BOOK_SDB_ERROR,
- E_BOOK_SDB_ERROR_INVALID_QUERY)) {
+ E_BOOK_SQL_ERROR,
+ E_BOOK_SQL_ERROR_INVALID_QUERY)) {
g_set_error_literal (error,
E_CLIENT_ERROR,
E_CLIENT_ERROR_INVALID_QUERY,
@@ -244,20 +243,20 @@ e_data_book_cursor_sqlite_set_sexp (EDataBookCursor *cursor,
static gboolean
convert_origin (EBookCursorOrigin src_origin,
- EbSdbCursorOrigin *dest_origin,
+ EbSqlCursorOrigin *dest_origin,
GError **error)
{
gboolean success = TRUE;
switch (src_origin) {
case E_BOOK_CURSOR_ORIGIN_CURRENT:
- *dest_origin = EBSDB_CURSOR_ORIGIN_CURRENT;
+ *dest_origin = EBSQL_CURSOR_ORIGIN_CURRENT;
break;
case E_BOOK_CURSOR_ORIGIN_BEGIN:
- *dest_origin = EBSDB_CURSOR_ORIGIN_BEGIN;
+ *dest_origin = EBSQL_CURSOR_ORIGIN_BEGIN;
break;
case E_BOOK_CURSOR_ORIGIN_END:
- *dest_origin = EBSDB_CURSOR_ORIGIN_END;
+ *dest_origin = EBSQL_CURSOR_ORIGIN_END;
break;
default:
success = FALSE;
@@ -273,13 +272,13 @@ convert_origin (EBookCursorOrigin src_origin,
static void
convert_flags (EBookCursorStepFlags src_flags,
- EbSdbCursorStepFlags *dest_flags)
+ EbSqlCursorStepFlags *dest_flags)
{
if (src_flags & E_BOOK_CURSOR_STEP_MOVE)
- *dest_flags |= EBSDB_CURSOR_STEP_MOVE;
+ *dest_flags |= EBSQL_CURSOR_STEP_MOVE;
if (src_flags & E_BOOK_CURSOR_STEP_FETCH)
- *dest_flags |= EBSDB_CURSOR_STEP_FETCH;
+ *dest_flags |= EBSQL_CURSOR_STEP_FETCH;
}
static gint
@@ -294,8 +293,8 @@ e_data_book_cursor_sqlite_step (EDataBookCursor *cursor,
EDataBookCursorSqlite *cursor_sqlite;
EDataBookCursorSqlitePrivate *priv;
GSList *local_results = NULL, *local_converted_results = NULL, *l;
- EbSdbCursorOrigin sqlitedb_origin = EBSDB_CURSOR_ORIGIN_CURRENT;
- EbSdbCursorStepFlags sqlitedb_flags = 0;
+ EbSqlCursorOrigin sqlite_origin = EBSQL_CURSOR_ORIGIN_CURRENT;
+ EbSqlCursorStepFlags sqlite_flags = 0;
gchar *revision = NULL;
gboolean success = FALSE;
gint n_results = -1;
@@ -303,25 +302,25 @@ e_data_book_cursor_sqlite_step (EDataBookCursor *cursor,
cursor_sqlite = E_DATA_BOOK_CURSOR_SQLITE (cursor);
priv = cursor_sqlite->priv;
- if (!convert_origin (origin, &sqlitedb_origin, error))
+ if (!convert_origin (origin, &sqlite_origin, error))
return FALSE;
- convert_flags (flags, &sqlitedb_flags);
+ convert_flags (flags, &sqlite_flags);
- /* Here we check the EBookBackendSqliteDB revision
+ /* Here we check the EBookBackendSqlite revision
* against the revision_guard with an atomic transaction
* with the sqlite.
*
* The addressbook modifications and revision changes
* are also atomically committed to the SQLite.
*/
- success = e_book_backend_sqlitedb_lock_updates (priv->ebsdb, error);
+ success = e_book_backend_sqlite_lock_updates (priv->ebsql, FALSE, error);
if (success && revision_guard)
- success = e_book_backend_sqlitedb_get_revision (priv->ebsdb,
- priv->folder_id,
- &revision,
- error);
+ success = e_book_backend_sqlite_get_key_value (priv->ebsql,
+ priv->revision_key,
+ &revision,
+ error);
if (success && revision_guard &&
g_strcmp0 (revision, revision_guard) != 0) {
@@ -336,10 +335,10 @@ e_data_book_cursor_sqlite_step (EDataBookCursor *cursor,
if (success) {
GError *local_error = NULL;
- n_results = e_book_backend_sqlitedb_cursor_step (priv->ebsdb,
+ n_results = e_book_backend_sqlite_cursor_step (priv->ebsql,
priv->cursor,
- sqlitedb_flags,
- sqlitedb_origin,
+ sqlite_flags,
+ sqlite_origin,
count,
&local_results,
&local_error);
@@ -348,8 +347,8 @@ e_data_book_cursor_sqlite_step (EDataBookCursor *cursor,
/* Convert the SQLite backend error to an EClient error */
if (g_error_matches (local_error,
- E_BOOK_SDB_ERROR,
- E_BOOK_SDB_ERROR_END_OF_LIST)) {
+ E_BOOK_SQL_ERROR,
+ E_BOOK_SQL_ERROR_END_OF_LIST)) {
g_set_error_literal (error, E_CLIENT_ERROR,
E_CLIENT_ERROR_QUERY_REFUSED,
local_error->message);
@@ -362,13 +361,13 @@ e_data_book_cursor_sqlite_step (EDataBookCursor *cursor,
}
if (success) {
- success = e_book_backend_sqlitedb_unlock_updates (priv->ebsdb, TRUE, error);
+ success = e_book_backend_sqlite_unlock_updates (priv->ebsql, TRUE, error);
} else {
GError *local_error = NULL;
/* Rollback transaction */
- if (!e_book_backend_sqlitedb_unlock_updates (priv->ebsdb, FALSE, &local_error)) {
+ if (!e_book_backend_sqlite_unlock_updates (priv->ebsql, FALSE, &local_error)) {
g_warning ("Failed to rollback transaction after failing move cursor: %s",
local_error->message);
g_clear_error (&local_error);
@@ -376,14 +375,14 @@ e_data_book_cursor_sqlite_step (EDataBookCursor *cursor,
}
for (l = local_results; l; l = l->next) {
- EbSdbSearchData *data = l->data;
+ EbSqlSearchData *data = l->data;
local_converted_results =
g_slist_prepend (local_converted_results, data->vcard);
data->vcard = NULL;
}
- g_slist_free_full (local_results, (GDestroyNotify)e_book_backend_sqlitedb_search_data_free);
+ g_slist_free_full (local_results, (GDestroyNotify)e_book_backend_sqlite_search_data_free);
if (results)
*results = g_slist_reverse (local_converted_results);
@@ -411,8 +410,7 @@ e_data_book_cursor_sqlite_set_alphabetic_index (EDataBookCursor *cursor,
cursor_sqlite = E_DATA_BOOK_CURSOR_SQLITE (cursor);
priv = cursor_sqlite->priv;
- if (!e_book_backend_sqlitedb_get_locale (priv->ebsdb, priv->folder_id,
- ¤t_locale, error))
+ if (!e_book_backend_sqlite_get_locale (priv->ebsql, ¤t_locale, error))
return FALSE;
/* Locale mismatch, need to report error */
@@ -425,7 +423,7 @@ e_data_book_cursor_sqlite_set_alphabetic_index (EDataBookCursor *cursor,
return FALSE;
}
- e_book_backend_sqlitedb_cursor_set_target_alphabetic_index (priv->ebsdb,
+ e_book_backend_sqlite_cursor_set_target_alphabetic_index (priv->ebsql,
priv->cursor,
index);
g_free (current_locale);
@@ -444,7 +442,7 @@ e_data_book_cursor_sqlite_get_position (EDataBookCursor *cursor,
cursor_sqlite = E_DATA_BOOK_CURSOR_SQLITE (cursor);
priv = cursor_sqlite->priv;
- return e_book_backend_sqlitedb_cursor_calculate (priv->ebsdb,
+ return e_book_backend_sqlite_cursor_calculate (priv->ebsql,
priv->cursor,
total, position,
error);
@@ -461,7 +459,7 @@ e_data_book_cursor_sqlite_compare_contact (EDataBookCursor *cursor,
cursor_sqlite = E_DATA_BOOK_CURSOR_SQLITE (cursor);
priv = cursor_sqlite->priv;
- return e_book_backend_sqlitedb_cursor_compare_contact (priv->ebsdb,
+ return e_book_backend_sqlite_cursor_compare_contact (priv->ebsql,
priv->cursor,
contact,
matches_sexp);
@@ -478,10 +476,9 @@ e_data_book_cursor_sqlite_load_locale (EDataBookCursor *cursor,
cursor_sqlite = E_DATA_BOOK_CURSOR_SQLITE (cursor);
priv = cursor_sqlite->priv;
- return e_book_backend_sqlitedb_get_locale (priv->ebsdb,
- priv->folder_id,
- locale,
- error);
+ return e_book_backend_sqlite_get_locale (priv->ebsql,
+ locale,
+ error);
}
/************************************************
@@ -490,52 +487,51 @@ e_data_book_cursor_sqlite_load_locale (EDataBookCursor *cursor,
/**
* e_data_book_cursor_sqlite_new:
* @backend: the #EBookBackend creating this cursor
- * @ebsdb: the #EBookBackendSqliteDB object to base this cursor on
- * @folder_id: the folder identifier to be used in EBookBackendSqliteDB API calls
+ * @ebsql: the #EBookBackendSqlite object to base this cursor on
+ * @revision_key: The key name to consult for the current overall contacts database revision
* @sort_fields: (array length=n_fields): an array of #EContactFields as sort keys in order of priority
* @sort_types: (array length=n_fields): an array of #EBookCursorSortTypes, one for each field in
@sort_fields
* @n_fields: the number of fields to sort results by.
* @error: a return location to story any error that might be reported.
*
* Creates an #EDataBookCursor and implements all of the cursor methods
- * using the delegate @ebsdb object.
+ * using the delegate @ebsql object.
*
* This is a suitable cursor type for any backend which stores its contacts
- * using the #EBookBackendSqliteDB object.
+ * using the #EBookBackendSqlite object.
*
* Returns: (transfer full): A newly created #EDataBookCursor, or %NULL if cursor creation failed.
*
* Since: 3.12
*/
EDataBookCursor *
-e_data_book_cursor_sqlite_new (EBookBackend *backend,
- EBookBackendSqliteDB *ebsdb,
- const gchar *folder_id,
- EContactField *sort_fields,
- EBookCursorSortType *sort_types,
- guint n_fields,
- GError **error)
+e_data_book_cursor_sqlite_new (EBookBackend *backend,
+ EBookBackendSqlite *ebsql,
+ const gchar *revision_key,
+ const EContactField *sort_fields,
+ const EBookCursorSortType *sort_types,
+ guint n_fields,
+ GError **error)
{
EDataBookCursor *cursor = NULL;
- EbSdbCursor *ebsdb_cursor;
+ EbSqlCursor *ebsql_cursor;
GError *local_error = NULL;
g_return_val_if_fail (E_IS_BOOK_BACKEND (backend), NULL);
- g_return_val_if_fail (E_IS_BOOK_BACKEND_SQLITEDB (ebsdb), NULL);
- g_return_val_if_fail (folder_id && folder_id[0], NULL);
+ g_return_val_if_fail (E_IS_BOOK_BACKEND_SQLITE (ebsql), NULL);
- ebsdb_cursor = e_book_backend_sqlitedb_cursor_new (ebsdb, folder_id, NULL,
- sort_fields,
- sort_types,
- n_fields,
- &local_error);
+ ebsql_cursor = e_book_backend_sqlite_cursor_new (ebsql, NULL,
+ sort_fields,
+ sort_types,
+ n_fields,
+ &local_error);
- if (ebsdb_cursor) {
+ if (ebsql_cursor) {
cursor = g_object_new (E_TYPE_DATA_BOOK_CURSOR_SQLITE,
"backend", backend,
- "ebsdb", ebsdb,
- "folder-id", folder_id,
- "cursor", ebsdb_cursor,
+ "ebsql", ebsql,
+ "revision-key", revision_key,
+ "cursor", ebsql_cursor,
NULL);
/* Initially created cursors should have a position & total */
@@ -544,8 +540,8 @@ e_data_book_cursor_sqlite_new (EBookBackend *backend,
g_clear_object (&cursor);
} else if (g_error_matches (local_error,
- E_BOOK_SDB_ERROR,
- E_BOOK_SDB_ERROR_INVALID_QUERY)) {
+ E_BOOK_SQL_ERROR,
+ E_BOOK_SQL_ERROR_INVALID_QUERY)) {
g_set_error_literal (error,
E_CLIENT_ERROR,
E_CLIENT_ERROR_INVALID_QUERY,
diff --git a/addressbook/libedata-book/e-data-book-cursor-sqlite.h
b/addressbook/libedata-book/e-data-book-cursor-sqlite.h
index 88ea577..5128baf 100644
--- a/addressbook/libedata-book/e-data-book-cursor-sqlite.h
+++ b/addressbook/libedata-book/e-data-book-cursor-sqlite.h
@@ -26,7 +26,7 @@
#define E_DATA_BOOK_CURSOR_SQLITE_H
#include <libedata-book/e-data-book-cursor.h>
-#include <libedata-book/e-book-backend-sqlitedb.h>
+#include <libedata-book/e-book-backend-sqlite.h>
#include <libedata-book/e-book-backend.h>
#define E_TYPE_DATA_BOOK_CURSOR_SQLITE (e_data_book_cursor_sqlite_get_type ())
@@ -68,13 +68,13 @@ struct _EDataBookCursorSqliteClass {
};
GType e_data_book_cursor_sqlite_get_type (void);
-EDataBookCursor *e_data_book_cursor_sqlite_new (EBookBackend *backend,
- EBookBackendSqliteDB *ebsdb,
- const gchar *folder_id,
- EContactField *sort_fields,
- EBookCursorSortType *sort_types,
- guint n_fields,
- GError **error);
+EDataBookCursor *e_data_book_cursor_sqlite_new (EBookBackend *backend,
+ EBookBackendSqlite *ebsql,
+ const gchar *revision_key,
+ const EContactField *sort_fields,
+ const EBookCursorSortType *sort_types,
+ guint n_fields,
+ GError **error);
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]