QOF  0.7.5
qofsession.c File Reference

Encapsulate a connection to a storage backend. More...

#include "config.h"
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <glib.h>
#include <libintl.h>
#include "qof.h"
#include "qoferror-p.h"
#include "qofbackend-p.h"
#include "qofbook-p.h"
#include "qofsession-p.h"
#include "qofobject-p.h"

Go to the source code of this file.

Defines

#define _(String)   dgettext (GETTEXT_PACKAGE, String)

Typedefs

typedef struct qof_entity_copy_data QofEntityCopyData

Functions

void qof_backend_register_provider (QofBackendProvider *prov)
void qof_session_add_close_hook (GFunc fn, gpointer data)
void qof_session_call_close_hooks (QofSession *session)
static void qof_session_init (QofSession *session)
QofSessionqof_session_new (void)
QofBookqof_session_get_book (QofSession *session)
void qof_session_add_book (QofSession *session, QofBook *addbook)
QofBackendqof_session_get_backend (QofSession *session)
const gchar * qof_session_get_file_path (QofSession *session)
const gchar * qof_session_get_url (QofSession *session)
static void qof_book_set_partial (QofBook *book)
void qof_session_update_reference_list (QofSession *session, QofEntityReference *reference)
 Adds a new reference to the partial book data hash.
static void qof_entity_param_cb (QofParam *param, gpointer data)
static void col_ref_cb (QofEntity *ref_ent, gpointer user_data)
static void qof_entity_foreach_copy (gpointer data, gpointer user_data)
static gboolean qof_entity_guid_match (QofSession *new_session, QofEntity *original)
static void qof_entity_list_foreach (gpointer data, gpointer user_data)
static void qof_entity_coll_foreach (QofEntity *original, gpointer user_data)
static void qof_entity_coll_copy (QofEntity *original, gpointer user_data)
gboolean qof_entity_copy_to_session (QofSession *new_session, QofEntity *original)
 Copy a single QofEntity to another session.
gboolean qof_entity_copy_list (QofSession *new_session, GList *entity_list)
 Copy a GList of entities to another session.
gboolean qof_entity_copy_coll (QofSession *new_session, QofCollection *entity_coll)
 Copy a QofCollection of entities.
static void recurse_collection_cb (QofEntity *ent, gpointer user_data)
static void recurse_ent_cb (QofEntity *ent, gpointer user_data)
gboolean qof_entity_copy_coll_r (QofSession *new_session, QofCollection *coll)
 Recursively copy a collection of entities to a session.
gboolean qof_entity_copy_one_r (QofSession *new_session, QofEntity *ent)
 Recursively copy a single entity to a new session.
static void qof_session_load_backend (QofSession *session, gchar *access_method)
static void qof_session_destroy_backend (QofSession *session)
void qof_session_begin (QofSession *session, const gchar *book_id, gboolean ignore_lock, gboolean create_if_nonexistent)
void qof_session_load (QofSession *session, QofPercentageFunc percentage_func)
gboolean qof_session_save_may_clobber_data (QofSession *session)
void qof_session_save (QofSession *session, QofPercentageFunc percentage_func)
void qof_session_end (QofSession *session)
void qof_session_destroy (QofSession *session)
void qof_session_swap_data (QofSession *session_1, QofSession *session_2)
gboolean qof_session_events_pending (QofSession *session)
gboolean qof_session_process_events (QofSession *session)

Variables

static GHookList * session_closed_hooks = NULL
static QofLogModule log_module = "qof-session"
static GSList * provider_list = NULL
struct backend_providers backend_list []

Detailed Description

Encapsulate a connection to a storage backend.

HISTORY: Created by Linas Vepstas December 1998

Author:
Copyright (c) 1998-2004 Linas Vepstas <linas@linas.org>
Copyright (c) 2000 Dave Peticolas
Copyright (c) 2005-2006 Neil Williams <linux@codehelp.co.uk>

Definition in file qofsession.c.


Function Documentation

static void qof_entity_foreach_copy ( gpointer  data,
gpointer  user_data 
) [static]

< secondary collections are used for one-to-many references between entities and are implemented using QofCollection. These are NOT the same as the main collections in the QofBook. -# Each QofCollection contains one or many entities - *all* of a single type. -# The entity type within the collection can be determined at run time. -# Easy conversions to GList or whatever in the param_setfcn handler. -# Each parameter can have its own collection. -# Each entity can have a different *type* of collection to its siblings, provided that it is acceptable to the set function. -# Each object decides which types are acceptable for which parameter in the set functions. This is then part of the API for that object. QOF_TYPE_COLLECT has two functions, both related to one-to-many links: - Represent a reference between 2 entities with a list of acceptable types. (one object linked to many types of single entities) - Represent a reference between one entity and many entities of another type. (one object linked to many entities of a single type.) If the set function can handle it, it could also be used for true one-to-many links: one object linked to many entities of many types. n.b. Always subject to each collection holding only one type at runtime. (otherwise use books).

Definition at line 299 of file qofsession.c.

{
    QofEntity *importEnt, *targetEnt /*, *referenceEnt */ ;
    QofEntityCopyData *context;
    QofEntityReference *reference;
    gboolean registered_type;
    /* cm_ prefix used for variables that hold the data to commit */
    QofParam *cm_param;
    gchar *cm_string, *cm_char;
    const GUID *cm_guid;
    KvpFrame *cm_kvp;
    QofCollection *cm_col;
    /* function pointers and variables for parameter getters that don't use pointers normally */
    QofNumeric cm_numeric, (*numeric_getter) (QofEntity *, QofParam *);
    gdouble cm_double, (*double_getter) (QofEntity *, QofParam *);
    gboolean cm_boolean, (*boolean_getter) (QofEntity *, QofParam *);
    gint32 cm_i32, (*int32_getter) (QofEntity *, QofParam *);
    gint64 cm_i64, (*int64_getter) (QofEntity *, QofParam *);
    /* function pointers to the parameter setters */
    void (*string_setter) (QofEntity *, const gchar *);
    void (*numeric_setter) (QofEntity *, QofNumeric);
    void (*guid_setter) (QofEntity *, const GUID *);
    void (*double_setter) (QofEntity *, gdouble);
    void (*boolean_setter) (QofEntity *, gboolean);
    void (*i32_setter) (QofEntity *, gint32);
    void (*i64_setter) (QofEntity *, gint64);
    void (*char_setter) (QofEntity *, gchar *);
    void (*kvp_frame_setter) (QofEntity *, KvpFrame *);

    g_return_if_fail (user_data != NULL);
    context = (QofEntityCopyData *) user_data;
    importEnt = context->from;
    targetEnt = context->to;
    registered_type = FALSE;
    cm_param = (QofParam *) data;
    g_return_if_fail (cm_param != NULL);
    context->param = cm_param;
    if (safe_strcmp (cm_param->param_type, QOF_TYPE_STRING) == 0)
    {
        cm_string = (gchar *) cm_param->param_getfcn (importEnt, cm_param);
        if (cm_string)
        {
            string_setter =
                (void (*)(QofEntity *,
                    const char *)) cm_param->param_setfcn;
            if (string_setter != NULL)
            {
                qof_util_param_edit ((QofInstance *) targetEnt, cm_param);
                string_setter (targetEnt, cm_string);
                qof_util_param_commit ((QofInstance *) targetEnt, cm_param);
            }
        }
        registered_type = TRUE;
    }
    if (safe_strcmp (cm_param->param_type, QOF_TYPE_TIME) == 0)
    {
        QofTime *qt;
        void (*time_setter) (QofEntity *, QofTime *);

        qt = cm_param->param_getfcn (importEnt, cm_param);
        time_setter = 
            (void (*)(QofEntity *, QofTime*))cm_param->param_setfcn;
        if (time_setter != NULL)
        {
            qof_util_param_edit ((QofInstance *) targetEnt, cm_param);
            time_setter (targetEnt, qt);
            qof_util_param_commit ((QofInstance *) targetEnt, cm_param);
        }
        registered_type = TRUE;
    }
#ifndef QOF_DISABLE_DEPRECATED
    if (safe_strcmp (cm_param->param_type, QOF_TYPE_DATE) == 0)
    {
        Timespec cm_date, (*date_getter) (QofEntity *, QofParam *);
        void (*date_setter) (QofEntity *, Timespec);

        cm_date.tv_nsec = 0;
        cm_date.tv_sec = 0;
        date_getter =
            (Timespec (*)(QofEntity *, QofParam *)) cm_param->param_getfcn;
        cm_date = date_getter (importEnt, cm_param);
        date_setter =
            (void (*)(QofEntity *, Timespec)) cm_param->param_setfcn;
        if (date_setter != NULL)
        {
            qof_util_param_edit ((QofInstance *) targetEnt, cm_param);
            date_setter (targetEnt, cm_date);
            qof_util_param_commit ((QofInstance *) targetEnt, cm_param);
        }
        registered_type = TRUE;
    }
#endif
    if ((safe_strcmp (cm_param->param_type, QOF_TYPE_NUMERIC) == 0) ||
        (safe_strcmp (cm_param->param_type, QOF_TYPE_DEBCRED) == 0))
    {
        numeric_getter =
            (QofNumeric (*)(QofEntity *,
                QofParam *)) cm_param->param_getfcn;
        cm_numeric = numeric_getter (importEnt, cm_param);
        numeric_setter =
            (void (*)(QofEntity *, QofNumeric)) cm_param->param_setfcn;
        if (numeric_setter != NULL)
        {
            qof_util_param_edit ((QofInstance *) targetEnt, cm_param);
            numeric_setter (targetEnt, cm_numeric);
            qof_util_param_commit ((QofInstance *) targetEnt, cm_param);
        }
        registered_type = TRUE;
    }
    if (safe_strcmp (cm_param->param_type, QOF_TYPE_GUID) == 0)
    {
        cm_guid =
            (const GUID *) cm_param->param_getfcn (importEnt, cm_param);
        guid_setter =
            (void (*)(QofEntity *, const GUID *)) cm_param->param_setfcn;
        if (guid_setter != NULL)
        {
            qof_util_param_edit ((QofInstance *) targetEnt, cm_param);
            guid_setter (targetEnt, cm_guid);
            qof_util_param_commit ((QofInstance *) targetEnt, cm_param);
        }
        registered_type = TRUE;
    }
    if (safe_strcmp (cm_param->param_type, QOF_TYPE_INT32) == 0)
    {
        int32_getter =
            (gint32 (*)(QofEntity *, QofParam *)) cm_param->param_getfcn;
        cm_i32 = int32_getter (importEnt, cm_param);
        i32_setter =
            (void (*)(QofEntity *, gint32)) cm_param->param_setfcn;
        if (i32_setter != NULL)
        {
            qof_util_param_edit ((QofInstance *) targetEnt, cm_param);
            i32_setter (targetEnt, cm_i32);
            qof_util_param_commit ((QofInstance *) targetEnt, cm_param);
        }
        registered_type = TRUE;
    }
    if (safe_strcmp (cm_param->param_type, QOF_TYPE_INT64) == 0)
    {
        int64_getter =
            (gint64 (*)(QofEntity *, QofParam *)) cm_param->param_getfcn;
        cm_i64 = int64_getter (importEnt, cm_param);
        i64_setter =
            (void (*)(QofEntity *, gint64)) cm_param->param_setfcn;
        if (i64_setter != NULL)
        {
            qof_util_param_edit ((QofInstance *) targetEnt, cm_param);
            i64_setter (targetEnt, cm_i64);
            qof_util_param_commit ((QofInstance *) targetEnt, cm_param);
        }
        registered_type = TRUE;
    }
    if (safe_strcmp (cm_param->param_type, QOF_TYPE_DOUBLE) == 0)
    {
        double_getter =
            (gdouble (*)(QofEntity *, QofParam *)) cm_param->param_getfcn;
        cm_double = double_getter (importEnt, cm_param);
        double_setter =
            (void (*)(QofEntity *, gdouble)) cm_param->param_setfcn;
        if (double_setter != NULL)
        {
            qof_util_param_edit ((QofInstance *) targetEnt, cm_param);
            double_setter (targetEnt, cm_double);
            qof_util_param_commit ((QofInstance *) targetEnt, cm_param);
        }
        registered_type = TRUE;
    }
    if (safe_strcmp (cm_param->param_type, QOF_TYPE_BOOLEAN) == 0)
    {
        boolean_getter =
            (gboolean (*)(QofEntity *, QofParam *)) cm_param->param_getfcn;
        cm_boolean = boolean_getter (importEnt, cm_param);
        boolean_setter =
            (void (*)(QofEntity *, gboolean)) cm_param->param_setfcn;
        if (boolean_setter != NULL)
        {
            qof_util_param_edit ((QofInstance *) targetEnt, cm_param);
            boolean_setter (targetEnt, cm_boolean);
            qof_util_param_commit ((QofInstance *) targetEnt, cm_param);
        }
        registered_type = TRUE;
    }
    if (safe_strcmp (cm_param->param_type, QOF_TYPE_KVP) == 0)
    {
        cm_kvp = (KvpFrame *) cm_param->param_getfcn (importEnt, cm_param);
        kvp_frame_setter =
            (void (*)(QofEntity *, KvpFrame *)) cm_param->param_setfcn;
        if (kvp_frame_setter != NULL)
        {
            qof_util_param_edit ((QofInstance *) targetEnt, cm_param);
            kvp_frame_setter (targetEnt, cm_kvp);
            qof_util_param_commit ((QofInstance *) targetEnt, cm_param);
        }
        else
        {
            QofInstance *target_inst;

            target_inst = (QofInstance *) targetEnt;
            kvp_frame_delete (target_inst->kvp_data);
            target_inst->kvp_data = kvp_frame_copy (cm_kvp);
        }
        registered_type = TRUE;
    }
    if (safe_strcmp (cm_param->param_type, QOF_TYPE_CHAR) == 0)
    {
        cm_char = (gchar *) cm_param->param_getfcn (importEnt, cm_param);
        char_setter =
            (void (*)(QofEntity *, char *)) cm_param->param_setfcn;
        if (char_setter != NULL)
        {
            qof_util_param_edit ((QofInstance *) targetEnt, cm_param);
            char_setter (targetEnt, cm_char);
            qof_util_param_commit ((QofInstance *) targetEnt, cm_param);
        }
        registered_type = TRUE;
    }
    if (safe_strcmp (cm_param->param_type, QOF_TYPE_COLLECT) == 0)
    {
        cm_col =
            (QofCollection *) cm_param->param_getfcn (importEnt, cm_param);
        if (cm_col)
        {
            /* create one reference for each member of the collection. */
            qof_collection_foreach (cm_col, col_ref_cb, context);
        }
        registered_type = TRUE;
    }
    if (registered_type == FALSE)
    {
/*      referenceEnt = (QofEntity*)cm_param->param_getfcn(importEnt, cm_param);
        if(!referenceEnt) { return; }
        if(!referenceEnt->e_type) { return; }*/
        reference = qof_entity_get_reference_from (importEnt, cm_param);
        if (reference)
        {
            qof_session_update_reference_list (context->new_session,
                reference);
        }
    }
}
static void recurse_ent_cb ( QofEntity ent,
gpointer  user_data 
) [static]

< secondary collections are used for one-to-many references between entities and are implemented using QofCollection. These are NOT the same as the main collections in the QofBook. -# Each QofCollection contains one or many entities - *all* of a single type. -# The entity type within the collection can be determined at run time. -# Easy conversions to GList or whatever in the param_setfcn handler. -# Each parameter can have its own collection. -# Each entity can have a different *type* of collection to its siblings, provided that it is acceptable to the set function. -# Each object decides which types are acceptable for which parameter in the set functions. This is then part of the API for that object. QOF_TYPE_COLLECT has two functions, both related to one-to-many links: - Represent a reference between 2 entities with a list of acceptable types. (one object linked to many types of single entities) - Represent a reference between one entity and many entities of another type. (one object linked to many entities of a single type.) If the set function can handle it, it could also be used for true one-to-many links: one object linked to many entities of many types. n.b. Always subject to each collection holding only one type at runtime. (otherwise use books).

Definition at line 766 of file qofsession.c.

{
    GList *ref_list, *i, *j, *ent_list, *child_list;
    QofParam *ref_param;
    QofEntity *ref_ent, *child_ent;
    QofSession *session;
    struct recurse_s *store;
    gboolean success;

    if (user_data == NULL)
    {
        return;
    }
    store = (struct recurse_s *) user_data;
    session = store->session;
    success = store->success;
    ref_list = NULL;
    child_ent = NULL;
    ref_list = g_list_copy (store->ref_list);
    if ((!session) || (!ent))
    {
        return;
    }
    ent_list = NULL;
    child_list = NULL;
    i = NULL;
    j = NULL;
    for (i = ref_list; i != NULL; i = i->next)
    {
        if (i->data == NULL)
        {
            continue;
        }
        ref_param = (QofParam *) i->data;
        if (ref_param->param_name == NULL)
        {
            continue;
        }
        if (0 == safe_strcmp (ref_param->param_type, QOF_TYPE_COLLECT))
        {
            QofCollection *col;

            col = ref_param->param_getfcn (ent, ref_param);
            if (col)
            {
                qof_collection_foreach (col, recurse_collection_cb, store);
            }
            continue;
        }
        ref_ent = (QofEntity *) ref_param->param_getfcn (ent, ref_param);
        if ((ref_ent) && (ref_ent->e_type))
        {
            store->success = qof_entity_copy_to_session (session, ref_ent);
            if (store->success)
            {
                ent_list = g_list_append (ent_list, ref_ent);
            }
        }
    }
    for (i = ent_list; i != NULL; i = i->next)
    {
        if (i->data == NULL)
        {
            continue;
        }
        child_ent = (QofEntity *) i->data;
        if (child_ent == NULL)
        {
            continue;
        }
        ref_list = qof_class_get_referenceList (child_ent->e_type);
        for (j = ref_list; j != NULL; j = j->next)
        {
            if (j->data == NULL)
            {
                continue;
            }
            ref_param = (QofParam *) j->data;
            ref_ent = ref_param->param_getfcn (child_ent, ref_param);
            if (ref_ent != NULL)
            {
                success = qof_entity_copy_to_session (session, ref_ent);
                if (success)
                {
                    child_list = g_list_append (child_list, ref_ent);
                }
            }
        }
    }
    for (i = child_list; i != NULL; i = i->next)
    {
        if (i->data == NULL)
        {
            continue;
        }
        ref_ent = (QofEntity *) i->data;
        if (ref_ent == NULL)
        {
            continue;
        }
        ref_list = qof_class_get_referenceList (ref_ent->e_type);
        for (j = ref_list; j != NULL; j = j->next)
        {
            if (j->data == NULL)
            {
                continue;
            }
            ref_param = (QofParam *) j->data;
            child_ent = ref_param->param_getfcn (ref_ent, ref_param);
            if (child_ent != NULL)
            {
                qof_entity_copy_to_session (session, child_ent);
            }
        }
    }
}

Variable Documentation

struct backend_providers backend_list[]
Initial value:
 {
    { "/usr/lib64" ,  "libqof-backend-qsf" ,  "qsf_provider_init" },
    { "/usr/lib64" , "libqof-backend-sqlite", "qof_sqlite_provider_init"},






    {NULL, NULL, NULL}
}

Definition at line 953 of file qofsession.c.