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.

Macros

#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. More...
 
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. More...
 
gboolean qof_entity_copy_list (QofSession *new_session, GList *entity_list)
 Copy a GList of entities to another session. More...
 
gboolean qof_entity_copy_coll (QofSession *new_session, QofCollection *entity_coll)
 Copy a QofCollection of entities. More...
 
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. More...
 
gboolean qof_entity_copy_one_r (QofSession *new_session, QofEntity *ent)
 Recursively copy a single entity to a new session. More...
 
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.nosp@m.@lin.nosp@m.as.or.nosp@m.g
Copyright (c) 2000 Dave Peticolas
Copyright (c) 2005-2006 Neil Williams linux.nosp@m.@cod.nosp@m.ehelp.nosp@m..co..nosp@m.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.

300 {
301  QofEntity *importEnt, *targetEnt /*, *referenceEnt */ ;
302  QofEntityCopyData *context;
303  QofEntityReference *reference;
304  gboolean registered_type;
305  /* cm_ prefix used for variables that hold the data to commit */
306  QofParam *cm_param;
307  gchar *cm_string, *cm_char;
308  const GUID *cm_guid;
309  KvpFrame *cm_kvp;
310  QofCollection *cm_col;
311  /* function pointers and variables for parameter getters that don't use pointers normally */
312  QofNumeric cm_numeric, (*numeric_getter) (QofEntity *, QofParam *);
313  gdouble cm_double, (*double_getter) (QofEntity *, QofParam *);
314  gboolean cm_boolean, (*boolean_getter) (QofEntity *, QofParam *);
315  gint32 cm_i32, (*int32_getter) (QofEntity *, QofParam *);
316  gint64 cm_i64, (*int64_getter) (QofEntity *, QofParam *);
317  /* function pointers to the parameter setters */
318  void (*string_setter) (QofEntity *, const gchar *);
319  void (*numeric_setter) (QofEntity *, QofNumeric);
320  void (*guid_setter) (QofEntity *, const GUID *);
321  void (*double_setter) (QofEntity *, gdouble);
322  void (*boolean_setter) (QofEntity *, gboolean);
323  void (*i32_setter) (QofEntity *, gint32);
324  void (*i64_setter) (QofEntity *, gint64);
325  void (*char_setter) (QofEntity *, gchar *);
326  void (*kvp_frame_setter) (QofEntity *, KvpFrame *);
327 
328  g_return_if_fail (user_data != NULL);
329  context = (QofEntityCopyData *) user_data;
330  importEnt = context->from;
331  targetEnt = context->to;
332  registered_type = FALSE;
333  cm_param = (QofParam *) data;
334  g_return_if_fail (cm_param != NULL);
335  context->param = cm_param;
336  if (safe_strcmp (cm_param->param_type, QOF_TYPE_STRING) == 0)
337  {
338  cm_string = (gchar *) cm_param->param_getfcn (importEnt, cm_param);
339  if (cm_string)
340  {
341  string_setter =
342  (void (*)(QofEntity *,
343  const char *)) cm_param->param_setfcn;
344  if (string_setter != NULL)
345  {
346  qof_util_param_edit ((QofInstance *) targetEnt, cm_param);
347  string_setter (targetEnt, cm_string);
348  qof_util_param_commit ((QofInstance *) targetEnt, cm_param);
349  }
350  }
351  registered_type = TRUE;
352  }
353  if (safe_strcmp (cm_param->param_type, QOF_TYPE_TIME) == 0)
354  {
355  QofTime *qt;
356  void (*time_setter) (QofEntity *, QofTime *);
357 
358  qt = cm_param->param_getfcn (importEnt, cm_param);
359  time_setter =
360  (void (*)(QofEntity *, QofTime*))cm_param->param_setfcn;
361  if (time_setter != NULL)
362  {
363  qof_util_param_edit ((QofInstance *) targetEnt, cm_param);
364  time_setter (targetEnt, qt);
365  qof_util_param_commit ((QofInstance *) targetEnt, cm_param);
366  }
367  registered_type = TRUE;
368  }
369 #ifndef QOF_DISABLE_DEPRECATED
370  if (safe_strcmp (cm_param->param_type, QOF_TYPE_DATE) == 0)
371  {
372  Timespec cm_date, (*date_getter) (QofEntity *, QofParam *);
373  void (*date_setter) (QofEntity *, Timespec);
374 
375  cm_date.tv_nsec = 0;
376  cm_date.tv_sec = 0;
377  date_getter =
378  (Timespec (*)(QofEntity *, QofParam *)) cm_param->param_getfcn;
379  cm_date = date_getter (importEnt, cm_param);
380  date_setter =
381  (void (*)(QofEntity *, Timespec)) cm_param->param_setfcn;
382  if (date_setter != NULL)
383  {
384  qof_util_param_edit ((QofInstance *) targetEnt, cm_param);
385  date_setter (targetEnt, cm_date);
386  qof_util_param_commit ((QofInstance *) targetEnt, cm_param);
387  }
388  registered_type = TRUE;
389  }
390 #endif
391  if ((safe_strcmp (cm_param->param_type, QOF_TYPE_NUMERIC) == 0) ||
392  (safe_strcmp (cm_param->param_type, QOF_TYPE_DEBCRED) == 0))
393  {
394  numeric_getter =
395  (QofNumeric (*)(QofEntity *,
396  QofParam *)) cm_param->param_getfcn;
397  cm_numeric = numeric_getter (importEnt, cm_param);
398  numeric_setter =
399  (void (*)(QofEntity *, QofNumeric)) cm_param->param_setfcn;
400  if (numeric_setter != NULL)
401  {
402  qof_util_param_edit ((QofInstance *) targetEnt, cm_param);
403  numeric_setter (targetEnt, cm_numeric);
404  qof_util_param_commit ((QofInstance *) targetEnt, cm_param);
405  }
406  registered_type = TRUE;
407  }
408  if (safe_strcmp (cm_param->param_type, QOF_TYPE_GUID) == 0)
409  {
410  cm_guid =
411  (const GUID *) cm_param->param_getfcn (importEnt, cm_param);
412  guid_setter =
413  (void (*)(QofEntity *, const GUID *)) cm_param->param_setfcn;
414  if (guid_setter != NULL)
415  {
416  qof_util_param_edit ((QofInstance *) targetEnt, cm_param);
417  guid_setter (targetEnt, cm_guid);
418  qof_util_param_commit ((QofInstance *) targetEnt, cm_param);
419  }
420  registered_type = TRUE;
421  }
422  if (safe_strcmp (cm_param->param_type, QOF_TYPE_INT32) == 0)
423  {
424  int32_getter =
425  (gint32 (*)(QofEntity *, QofParam *)) cm_param->param_getfcn;
426  cm_i32 = int32_getter (importEnt, cm_param);
427  i32_setter =
428  (void (*)(QofEntity *, gint32)) cm_param->param_setfcn;
429  if (i32_setter != NULL)
430  {
431  qof_util_param_edit ((QofInstance *) targetEnt, cm_param);
432  i32_setter (targetEnt, cm_i32);
433  qof_util_param_commit ((QofInstance *) targetEnt, cm_param);
434  }
435  registered_type = TRUE;
436  }
437  if (safe_strcmp (cm_param->param_type, QOF_TYPE_INT64) == 0)
438  {
439  int64_getter =
440  (gint64 (*)(QofEntity *, QofParam *)) cm_param->param_getfcn;
441  cm_i64 = int64_getter (importEnt, cm_param);
442  i64_setter =
443  (void (*)(QofEntity *, gint64)) cm_param->param_setfcn;
444  if (i64_setter != NULL)
445  {
446  qof_util_param_edit ((QofInstance *) targetEnt, cm_param);
447  i64_setter (targetEnt, cm_i64);
448  qof_util_param_commit ((QofInstance *) targetEnt, cm_param);
449  }
450  registered_type = TRUE;
451  }
452  if (safe_strcmp (cm_param->param_type, QOF_TYPE_DOUBLE) == 0)
453  {
454  double_getter =
455  (gdouble (*)(QofEntity *, QofParam *)) cm_param->param_getfcn;
456  cm_double = double_getter (importEnt, cm_param);
457  double_setter =
458  (void (*)(QofEntity *, gdouble)) cm_param->param_setfcn;
459  if (double_setter != NULL)
460  {
461  qof_util_param_edit ((QofInstance *) targetEnt, cm_param);
462  double_setter (targetEnt, cm_double);
463  qof_util_param_commit ((QofInstance *) targetEnt, cm_param);
464  }
465  registered_type = TRUE;
466  }
467  if (safe_strcmp (cm_param->param_type, QOF_TYPE_BOOLEAN) == 0)
468  {
469  boolean_getter =
470  (gboolean (*)(QofEntity *, QofParam *)) cm_param->param_getfcn;
471  cm_boolean = boolean_getter (importEnt, cm_param);
472  boolean_setter =
473  (void (*)(QofEntity *, gboolean)) cm_param->param_setfcn;
474  if (boolean_setter != NULL)
475  {
476  qof_util_param_edit ((QofInstance *) targetEnt, cm_param);
477  boolean_setter (targetEnt, cm_boolean);
478  qof_util_param_commit ((QofInstance *) targetEnt, cm_param);
479  }
480  registered_type = TRUE;
481  }
482  if (safe_strcmp (cm_param->param_type, QOF_TYPE_KVP) == 0)
483  {
484  cm_kvp = (KvpFrame *) cm_param->param_getfcn (importEnt, cm_param);
485  kvp_frame_setter =
486  (void (*)(QofEntity *, KvpFrame *)) cm_param->param_setfcn;
487  if (kvp_frame_setter != NULL)
488  {
489  qof_util_param_edit ((QofInstance *) targetEnt, cm_param);
490  kvp_frame_setter (targetEnt, cm_kvp);
491  qof_util_param_commit ((QofInstance *) targetEnt, cm_param);
492  }
493  else
494  {
495  QofInstance *target_inst;
496 
497  target_inst = (QofInstance *) targetEnt;
498  kvp_frame_delete (target_inst->kvp_data);
499  target_inst->kvp_data = kvp_frame_copy (cm_kvp);
500  }
501  registered_type = TRUE;
502  }
503  if (safe_strcmp (cm_param->param_type, QOF_TYPE_CHAR) == 0)
504  {
505  cm_char = (gchar *) cm_param->param_getfcn (importEnt, cm_param);
506  char_setter =
507  (void (*)(QofEntity *, char *)) cm_param->param_setfcn;
508  if (char_setter != NULL)
509  {
510  qof_util_param_edit ((QofInstance *) targetEnt, cm_param);
511  char_setter (targetEnt, cm_char);
512  qof_util_param_commit ((QofInstance *) targetEnt, cm_param);
513  }
514  registered_type = TRUE;
515  }
516  if (safe_strcmp (cm_param->param_type, QOF_TYPE_COLLECT) == 0)
517  {
518  cm_col =
519  (QofCollection *) cm_param->param_getfcn (importEnt, cm_param);
520  if (cm_col)
521  {
522  /* create one reference for each member of the collection. */
523  qof_collection_foreach (cm_col, col_ref_cb, context);
524  }
525  registered_type = TRUE;
526  }
527  if (registered_type == FALSE)
528  {
529 /* referenceEnt = (QofEntity*)cm_param->param_getfcn(importEnt, cm_param);
530  if(!referenceEnt) { return; }
531  if(!referenceEnt->e_type) { return; }*/
532  reference = qof_entity_get_reference_from (importEnt, cm_param);
533  if (reference)
534  {
535  qof_session_update_reference_list (context->new_session,
536  reference);
537  }
538  }
539 }
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.

767 {
768  GList *ref_list, *i, *j, *ent_list, *child_list;
769  QofParam *ref_param;
770  QofEntity *ref_ent, *child_ent;
771  QofSession *session;
772  struct recurse_s *store;
773  gboolean success;
774 
775  if (user_data == NULL)
776  {
777  return;
778  }
779  store = (struct recurse_s *) user_data;
780  session = store->session;
781  success = store->success;
782  ref_list = NULL;
783  child_ent = NULL;
784  ref_list = g_list_copy (store->ref_list);
785  if ((!session) || (!ent))
786  {
787  return;
788  }
789  ent_list = NULL;
790  child_list = NULL;
791  i = NULL;
792  j = NULL;
793  for (i = ref_list; i != NULL; i = i->next)
794  {
795  if (i->data == NULL)
796  {
797  continue;
798  }
799  ref_param = (QofParam *) i->data;
800  if (ref_param->param_name == NULL)
801  {
802  continue;
803  }
804  if (0 == safe_strcmp (ref_param->param_type, QOF_TYPE_COLLECT))
805  {
806  QofCollection *col;
807 
808  col = ref_param->param_getfcn (ent, ref_param);
809  if (col)
810  {
811  qof_collection_foreach (col, recurse_collection_cb, store);
812  }
813  continue;
814  }
815  ref_ent = (QofEntity *) ref_param->param_getfcn (ent, ref_param);
816  if ((ref_ent) && (ref_ent->e_type))
817  {
818  store->success = qof_entity_copy_to_session (session, ref_ent);
819  if (store->success)
820  {
821  ent_list = g_list_append (ent_list, ref_ent);
822  }
823  }
824  }
825  for (i = ent_list; i != NULL; i = i->next)
826  {
827  if (i->data == NULL)
828  {
829  continue;
830  }
831  child_ent = (QofEntity *) i->data;
832  if (child_ent == NULL)
833  {
834  continue;
835  }
836  ref_list = qof_class_get_referenceList (child_ent->e_type);
837  for (j = ref_list; j != NULL; j = j->next)
838  {
839  if (j->data == NULL)
840  {
841  continue;
842  }
843  ref_param = (QofParam *) j->data;
844  ref_ent = ref_param->param_getfcn (child_ent, ref_param);
845  if (ref_ent != NULL)
846  {
847  success = qof_entity_copy_to_session (session, ref_ent);
848  if (success)
849  {
850  child_list = g_list_append (child_list, ref_ent);
851  }
852  }
853  }
854  }
855  for (i = child_list; i != NULL; i = i->next)
856  {
857  if (i->data == NULL)
858  {
859  continue;
860  }
861  ref_ent = (QofEntity *) i->data;
862  if (ref_ent == NULL)
863  {
864  continue;
865  }
866  ref_list = qof_class_get_referenceList (ref_ent->e_type);
867  for (j = ref_list; j != NULL; j = j->next)
868  {
869  if (j->data == NULL)
870  {
871  continue;
872  }
873  ref_param = (QofParam *) j->data;
874  child_ent = ref_param->param_getfcn (ref_ent, ref_param);
875  if (child_ent != NULL)
876  {
877  qof_entity_copy_to_session (session, child_ent);
878  }
879  }
880  }
881 }

Variable Documentation

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

Definition at line 953 of file qofsession.c.