r21190 - gnucash/trunk/src - Delete unused QofInstance copy functions from qofsession.c
John Ralls
jralls at code.gnucash.org
Fri Aug 19 23:44:41 EDT 2011
Author: jralls
Date: 2011-08-19 23:44:40 -0400 (Fri, 19 Aug 2011)
New Revision: 21190
Trac: http://svn.gnucash.org/trac/changeset/21190
Removed:
gnucash/trunk/src/engine/test/test-recursive.c
Modified:
gnucash/trunk/src/engine/test/Makefile.am
gnucash/trunk/src/libqof/qof/qofsession.c
gnucash/trunk/src/libqof/qof/qofsession.h
Log:
Delete unused QofInstance copy functions from qofsession.c
Modified: gnucash/trunk/src/engine/test/Makefile.am
===================================================================
--- gnucash/trunk/src/engine/test/Makefile.am 2011-08-18 18:35:17 UTC (rev 21189)
+++ gnucash/trunk/src/engine/test/Makefile.am 2011-08-20 03:44:40 UTC (rev 21190)
@@ -38,7 +38,6 @@
test-period \
test-querynew \
test-query \
- test-recursive \
test-split-vs-account \
test-transaction-reversal \
test-transaction-voiding \
@@ -73,7 +72,6 @@
test-object \
test-query \
test-querynew \
- test-recursive \
test-scm-query \
test-split-vs-account \
test-transaction-reversal \
Deleted: gnucash/trunk/src/engine/test/test-recursive.c
===================================================================
--- gnucash/trunk/src/engine/test/test-recursive.c 2011-08-18 18:35:17 UTC (rev 21189)
+++ gnucash/trunk/src/engine/test/test-recursive.c 2011-08-20 03:44:40 UTC (rev 21190)
@@ -1,1226 +0,0 @@
-/***************************************************************************
- * test-recursive.c
- *
- * Wed Feb 1 21:54:49 2006
- * Copyright 2006 Neil Williams
- * linux at codehelp.co.uk
- ****************************************************************************/
-/*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor
- * Boston, MA 02110-1301, USA
- */
-
-#include "config.h"
-#include <glib.h>
-#include <glib/gprintf.h>
-
-#include "qof.h"
-#include "test-engine-stuff.h"
-#include "test-stuff.h"
-
-#define GRAND_MODULE_NAME "recursive-grandparent"
-#define PARENT_MODULE_NAME "recursive-parent"
-#define CHILD_MODULE_NAME "recursive-child"
-#define GRAND_MODULE_DESC "Recursive Grand Parent Test"
-#define PARENT_MODULE_DESC "Recursive Parent Test"
-#define CHILD_MODULE_DESC "Recursive Child Test"
-#define OBJ_NAME "somename"
-#define OBJ_AMOUNT "anamount"
-#define OBJ_DATE "nottoday"
-#define OBJ_DISCOUNT "hefty"
-#define OBJ_VERSION "early"
-#define OBJ_MINOR "tiny"
-#define OBJ_ACTIVE "ofcourse"
-#define OBJ_FLAG "tiny_flag"
-#define OBJ_RELATIVE "family"
-#define OBJ_LIST "descendents"
-
-/* set to TRUE to get XML output on stdout
- * requires a stdout capable backend available (i.e. make install) */
-static gboolean debug = FALSE;
-
-/* simple object structure */
-typedef struct child_s
-{
- QofInstance inst;
- gchar *Name;
- gchar flag;
- gnc_numeric Amount;
- Timespec date;
- double discount; /* cheap pun, I know. */
- gboolean active;
- gint32 version;
- gint64 minor;
-} mychild;
-
-typedef struct childClass_s
-{
- QofInstanceClass parent_class;
-} mychildClass;
-
-/* simple object structure */
-typedef struct parent_s
-{
- QofInstance inst;
- mychild *child;
- gchar *Name;
- gchar flag;
- gnc_numeric Amount;
- Timespec date;
- double discount; /* cheap pun, I know. */
- gboolean active;
- gint32 version;
- gint64 minor;
-} myparent;
-
-typedef struct parentClass_s
-{
- QofInstanceClass parent_class;
-} myparentClass;
-
-/* simple object structure */
-typedef struct grand_s
-{
- QofInstance inst;
- myparent *child;
- GList *descend;
- gchar *Name;
- gchar flag;
- gnc_numeric Amount;
- Timespec date;
- double discount; /* cheap pun, I know. */
- gboolean active;
- gint32 version;
- gint64 minor;
-} mygrand;
-
-typedef struct grandClass_s
-{
- QofInstanceClass parent_class;
-} mygrandClass;
-
-mygrand* grand_create(QofBook*);
-myparent* parent_create(QofBook*);
-mychild* child_create(QofBook*);
-
-gboolean mygrandRegister (void);
-gboolean myparentRegister (void);
-gboolean mychildRegister (void);
-
-/* obvious setter functions */
-void grand_setName(mygrand*, gchar*);
-void grand_setAmount(mygrand*, gnc_numeric);
-void grand_setDate(mygrand*, Timespec h);
-void grand_setDiscount(mygrand*, double);
-void grand_setActive(mygrand*, gboolean);
-void grand_setVersion(mygrand*, gint32);
-void grand_setMinor(mygrand*, gint64);
-void grand_setFlag(mygrand*, gchar);
-
-/* obvious getter functions */
-gchar* grand_getName(mygrand*);
-gnc_numeric grand_getAmount(mygrand*);
-Timespec grand_getDate(mygrand*);
-double grand_getDiscount(mygrand*);
-gboolean grand_getActive(mygrand*);
-gint32 grand_getVersion(mygrand*);
-gint64 grand_getMinor(mygrand*);
-gchar grand_getFlag(mygrand*);
-
-/* obvious setter functions */
-void parent_setName(myparent*, gchar*);
-void parent_setAmount(myparent*, gnc_numeric);
-void parent_setDate(myparent*, Timespec h);
-void parent_setDiscount(myparent*, double);
-void parent_setActive(myparent*, gboolean);
-void parent_setVersion(myparent*, gint32);
-void parent_setMinor(myparent*, gint64);
-void parent_setFlag(myparent*, gchar);
-
-/* obvious getter functions */
-gchar* parent_getName(myparent*);
-gnc_numeric parent_getAmount(myparent*);
-Timespec parent_getDate(myparent*);
-double parent_getDiscount(myparent*);
-gboolean parent_getActive(myparent*);
-gint32 parent_getVersion(myparent*);
-gint64 parent_getMinor(myparent*);
-gchar parent_getFlag(myparent*);
-
-/* obvious setter functions */
-void child_setName(mychild*, gchar*);
-void child_setAmount(mychild*, gnc_numeric);
-void child_setDate(mychild*, Timespec h);
-void child_setDiscount(mychild*, double);
-void child_setActive(mychild*, gboolean);
-void child_setVersion(mychild*, gint32);
-void child_setMinor(mychild*, gint64);
-void child_setFlag(mychild*, gchar);
-
-/* obvious getter functions */
-gchar* child_getName(mychild*);
-gnc_numeric child_getAmount(mychild*);
-Timespec child_getDate(mychild*);
-double child_getDiscount(mychild*);
-gboolean child_getActive(mychild*);
-gint32 child_getVersion(mychild*);
-gint64 child_getMinor(mychild*);
-gchar child_getFlag(mychild*);
-
-/* --- type macros --- */
-#define GNC_TYPE_MYCHILD (gnc_mychild_get_type ())
-#define GNC_MYCHILD(o) \
- (G_TYPE_CHECK_INSTANCE_CAST ((o), GNC_TYPE_MYCHILD, mychild))
-#define GNC_MYCHILD_CLASS(k) \
- (G_TYPE_CHECK_CLASS_CAST((k), GNC_TYPE_MYCHILD, mychildClass))
-#define GNC_IS_MYCHILD(o) \
- (G_TYPE_CHECK_INSTANCE_TYPE ((o), GNC_TYPE_MYCHILD))
-#define GNC_IS_MYCHILD_CLASS(k) \
- (G_TYPE_CHECK_CLASS_TYPE ((k), GNC_TYPE_MYCHILD))
-#define GNC_MYCHILD_GET_CLASS(o) \
- (G_TYPE_INSTANCE_GET_CLASS ((o), GNC_TYPE_MYCHILD, mychildClass))
-GType gnc_mychild_get_type(void);
-
-/* --- type macros --- */
-#define GNC_TYPE_MYPARENT (gnc_myparent_get_type ())
-#define GNC_MYPARENT(o) \
- (G_TYPE_CHECK_INSTANCE_CAST ((o), GNC_TYPE_MYPARENT, myparent))
-#define GNC_MYPARENT_CLASS(k) \
- (G_TYPE_CHECK_CLASS_CAST((k), GNC_TYPE_MYPARENT, myparentClass))
-#define GNC_IS_MYPARENT(o) \
- (G_TYPE_CHECK_INSTANCE_TYPE ((o), GNC_TYPE_MYPARENT))
-#define GNC_IS_MYPARENT_CLASS(k) \
- (G_TYPE_CHECK_CLASS_TYPE ((k), GNC_TYPE_MYPARENT))
-#define GNC_MYPARENT_GET_CLASS(o) \
- (G_TYPE_INSTANCE_GET_CLASS ((o), GNC_TYPE_MYPARENT, myparentClass))
-GType gnc_myparent_get_type(void);
-
-/* --- type macros --- */
-#define GNC_TYPE_MYGRAND (gnc_mygrand_get_type ())
-#define GNC_MYGRAND(o) \
- (G_TYPE_CHECK_INSTANCE_CAST ((o), GNC_TYPE_MYGRAND, mygrand))
-#define GNC_MYGRAND_CLASS(k) \
- (G_TYPE_CHECK_CLASS_CAST((k), GNC_TYPE_MYGRAND, mygrandClass))
-#define GNC_IS_MYGRAND(o) \
- (G_TYPE_CHECK_INSTANCE_TYPE ((o), GNC_TYPE_MYGRAND))
-#define GNC_IS_MYGRAND_CLASS(k) \
- (G_TYPE_CHECK_CLASS_TYPE ((k), GNC_TYPE_MYGRAND))
-#define GNC_MYGRAND_GET_CLASS(o) \
- (G_TYPE_INSTANCE_GET_CLASS ((o), GNC_TYPE_MYGRAND, mygrandClass))
-GType gnc_mygrand_get_type(void);
-
-/* GObject Initialization */
-QOF_GOBJECT_IMPL(gnc_mychild, mychild, QOF_TYPE_INSTANCE);
-
-static void
-gnc_mychild_init(mychild* obj)
-{
-}
-
-static void
-gnc_mychild_dispose_real (GObject *objp)
-{
-}
-
-static void
-gnc_mychild_finalize_real(GObject* objp)
-{
-}
-
-/* GObject Initialization */
-QOF_GOBJECT_IMPL(gnc_myparent, myparent, QOF_TYPE_INSTANCE);
-
-static void
-gnc_myparent_init(myparent* obj)
-{
-}
-
-static void
-gnc_myparent_dispose_real (GObject *objp)
-{
-}
-
-static void
-gnc_myparent_finalize_real(GObject* objp)
-{
-}
-
-/* GObject Initialization */
-QOF_GOBJECT_IMPL(gnc_mygrand, mygrand, QOF_TYPE_INSTANCE);
-
-static void
-gnc_mygrand_init(mygrand* obj)
-{
-}
-
-static void
-gnc_mygrand_dispose_real (GObject *objp)
-{
-}
-
-static void
-gnc_mygrand_finalize_real(GObject* objp)
-{
-}
-
-mygrand*
-grand_create(QofBook *book)
-{
- mygrand *g;
-
- g_return_val_if_fail(book, NULL);
- g = g_object_new(GNC_TYPE_MYGRAND, NULL);
- qof_instance_init_data (&g->inst, GRAND_MODULE_NAME, book);
- g->date = *get_random_timespec();
- g->discount = get_random_double();;
- g->active = get_random_boolean();
- g->version = get_random_int_in_range(1, 10000);
- g->minor = get_random_int_in_range(100001, 99999999);
- g->flag = get_random_character();
- g->Name = get_random_string();
- g->Amount = get_random_gnc_numeric();
- g->child = NULL;
- g->descend = NULL;
- qof_event_gen(&g->inst, QOF_EVENT_CREATE, NULL);
- return g;
-}
-
-myparent*
-parent_create(QofBook *book)
-{
- myparent *g;
-
- g_return_val_if_fail(book, NULL);
- g = g_object_new(GNC_TYPE_MYPARENT, NULL);
- qof_instance_init_data (&g->inst, PARENT_MODULE_NAME, book);
- g->date = *get_random_timespec();
- g->discount = get_random_double();
- g->active = get_random_boolean();
- g->version = get_random_int_in_range(1, 10000);
- g->minor = get_random_int_in_range(100001, 99999999);
- g->flag = get_random_character();
- g->Name = get_random_string();
- g->Amount = get_random_gnc_numeric();
- g->child = NULL;
- qof_event_gen(&g->inst, QOF_EVENT_CREATE, NULL);
- return g;
-}
-
-mychild*
-child_create(QofBook *book)
-{
- mychild *g;
-
- g_return_val_if_fail(book, NULL);
- g = g_object_new(GNC_TYPE_MYCHILD, NULL);
- qof_instance_init_data (&g->inst, CHILD_MODULE_NAME, book);
- g->date = *get_random_timespec();
- g->discount = get_random_double();
- g->active = get_random_boolean();
- g->version = get_random_int_in_range(1, 10000);
- g->minor = get_random_int_in_range(100001, 99999999);
- g->flag = get_random_character();
- g->Name = get_random_string();
- g->Amount = get_random_gnc_numeric();
- qof_event_gen(&g->inst, QOF_EVENT_CREATE, NULL);
- return g;
-}
-
-static void
-descend_cb (QofInstance *ent, gpointer user_data)
-{
- mygrand *g = (mygrand*)user_data;
-
- g_return_if_fail(g || ent);
- g->descend = g_list_prepend(g->descend, (mychild*)ent);
-}
-
-static void
-grand_setDescend(mygrand *g, QofCollection *coll)
-{
- g_return_if_fail(g || coll);
- if (0 != safe_strcmp(qof_collection_get_type(coll), CHILD_MODULE_NAME))
- {
- return;
- }
- qof_collection_foreach(coll, descend_cb, g);
-}
-
-static QofCollection*
-grand_getDescend(mygrand *g)
-{
- QofCollection *col;
- QofInstance *ent;
- GList *list;
-
- g_return_val_if_fail(g, NULL);
- col = qof_collection_new(CHILD_MODULE_NAME);
- for (list = g_list_copy(g->descend); list; list = list->next)
- {
- ent = QOF_INSTANCE(list->data);
- if (!ent)
- {
- break;
- }
- do_test(0 == safe_strcmp(ent->e_type, CHILD_MODULE_NAME), "wrong entity");
- qof_collection_add_entity(col, ent);
- }
- return col;
-}
-
-static void
-grand_setChild(mygrand *g, myparent *p)
-{
- g_return_if_fail(g || p);
- g->child = p;
-}
-
-static myparent*
-grand_getChild(mygrand *g)
-{
- g_return_val_if_fail(g, NULL);
- return g->child;
-}
-
-void
-grand_setFlag(mygrand *g, gchar f)
-{
- g_return_if_fail(g);
- g->flag = f;
-}
-
-gchar
-grand_getFlag(mygrand *g)
-{
- g_return_val_if_fail(g, 'n');
- return g->flag;
-}
-
-void
-grand_setMinor(mygrand *g, gint64 h)
-{
- g_return_if_fail(g != NULL);
- g->minor = h;
-}
-
-gint64
-grand_getMinor(mygrand *g)
-{
- g_return_val_if_fail((g != NULL), 0);
- return g->minor;
-}
-
-void
-grand_setVersion(mygrand *g, gint32 h)
-{
- g_return_if_fail(g != NULL);
- g->version = h;
-}
-
-gint32
-grand_getVersion(mygrand *g)
-{
- if (!g) return 0;
- return g->version;
-}
-
-void
-grand_setActive(mygrand *g, gboolean h)
-{
- if (!g) return;
- g->active = h;
-}
-
-gboolean
-grand_getActive(mygrand *g)
-{
- if (!g) return FALSE;
- return g->active;
-}
-
-void
-grand_setDiscount(mygrand *g, double h)
-{
- if (!g) return;
- g->discount = h;
-}
-
-double
-grand_getDiscount(mygrand *g)
-{
- if (!g) return 0;
- return g->discount;
-}
-
-void
-grand_setDate(mygrand *g, Timespec h)
-{
- if (!g) return;
- g->date = h;
-}
-
-Timespec
-grand_getDate(mygrand *g)
-{
- Timespec ts;
- ts.tv_sec = 0;
- ts.tv_nsec = 0;
- if (!g) return ts;
- ts = g->date;
- return ts;
-}
-
-void
-grand_setName(mygrand* g, gchar* h)
-{
- if (!g || !h) return;
- g->Name = strdup(h);
-}
-
-gchar*
-grand_getName(mygrand *g)
-{
- if (!g) return NULL;
- return g->Name;
-}
-
-void
-grand_setAmount(mygrand *g, gnc_numeric h)
-{
- if (!g) return;
- g->Amount = h;
-}
-
-gnc_numeric
-grand_getAmount(mygrand *g)
-{
- if (!g) return gnc_numeric_zero();
- return g->Amount;
-}
-
-static void
-parent_setChild(myparent *p, mychild *c)
-{
- g_return_if_fail(p || c);
- p->child = c;
-}
-
-static mychild*
-parent_getChild(myparent* p)
-{
- g_return_val_if_fail(p, NULL);
- return p->child;
-}
-
-void
-parent_setFlag(myparent *p, gchar f)
-{
- g_return_if_fail(p);
- p->flag = f;
-}
-
-gchar
-parent_getFlag(myparent *p)
-{
- g_return_val_if_fail(p, 'n');
- return p->flag;
-}
-
-void
-parent_setMinor(myparent *p, gint64 h)
-{
- g_return_if_fail(p != NULL);
- p->minor = h;
-}
-
-gint64
-parent_getMinor(myparent *p)
-{
- g_return_val_if_fail((p != NULL), 0);
- return p->minor;
-}
-
-void
-parent_setVersion(myparent *p, gint32 h)
-{
- g_return_if_fail(p != NULL);
- p->version = h;
-}
-
-gint32
-parent_getVersion(myparent *p)
-{
- if (!p) return 0;
- return p->version;
-}
-
-void
-parent_setActive(myparent *p, gboolean h)
-{
- if (!p) return;
- p->active = h;
-}
-
-gboolean
-parent_getActive(myparent *p)
-{
- if (!p) return FALSE;
- return p->active;
-}
-
-void
-parent_setDiscount(myparent *p, double h)
-{
- if (!p) return;
- p->discount = h;
-}
-
-double
-parent_getDiscount(myparent *p)
-{
- if (!p) return 0;
- return p->discount;
-}
-
-void
-parent_setDate(myparent *p, Timespec h)
-{
- if (!p) return;
- p->date = h;
-}
-
-Timespec
-parent_getDate(myparent *p)
-{
- Timespec ts;
- ts.tv_sec = 0;
- ts.tv_nsec = 0;
- if (!p) return ts;
- ts = p->date;
- return ts;
-}
-
-void
-parent_setName(myparent* p, gchar* h)
-{
- if (!p || !h) return;
- p->Name = strdup(h);
-}
-
-gchar*
-parent_getName(myparent *p)
-{
- if (!p) return NULL;
- return p->Name;
-}
-
-void
-parent_setAmount(myparent *p, gnc_numeric h)
-{
- if (!p) return;
- p->Amount = h;
-}
-
-gnc_numeric
-parent_getAmount(myparent *p)
-{
- if (!p) return gnc_numeric_zero();
- return p->Amount;
-}
-
-void
-child_setFlag(mychild *c, gchar f)
-{
- g_return_if_fail(c);
- c->flag = f;
-}
-
-gchar
-child_getFlag(mychild *c)
-{
- g_return_val_if_fail(c, 'n');
- return c->flag;
-}
-
-void
-child_setMinor(mychild *c, gint64 h)
-{
- g_return_if_fail(c != NULL);
- c->minor = h;
-}
-
-gint64
-child_getMinor(mychild *c)
-{
- g_return_val_if_fail((c != NULL), 0);
- return c->minor;
-}
-
-void
-child_setVersion(mychild *c, gint32 h)
-{
- g_return_if_fail(c != NULL);
- c->version = h;
-}
-
-gint32
-child_getVersion(mychild *c)
-{
- if (!c) return 0;
- return c->version;
-}
-
-void
-child_setActive(mychild *c, gboolean h)
-{
- if (!c) return;
- c->active = h;
-}
-
-gboolean
-child_getActive(mychild *c)
-{
- if (!c) return FALSE;
- return c->active;
-}
-
-void
-child_setDiscount(mychild *c, double h)
-{
- if (!c) return;
- c->discount = h;
-}
-
-double
-child_getDiscount(mychild *c)
-{
- if (!c) return 0;
- return c->discount;
-}
-
-void
-child_setDate(mychild *c, Timespec h)
-{
- if (!c) return;
- c->date = h;
-}
-
-Timespec
-child_getDate(mychild *c)
-{
- Timespec ts;
- ts.tv_sec = 0;
- ts.tv_nsec = 0;
- if (!c) return ts;
- ts = c->date;
- return ts;
-}
-
-void
-child_setName(mychild* c, gchar* h)
-{
- if (!c || !h) return;
- c->Name = strdup(h);
-}
-
-gchar*
-child_getName(mychild *c)
-{
- if (!c) return NULL;
- return c->Name;
-}
-
-void
-child_setAmount(mychild *c, gnc_numeric h)
-{
- if (!c) return;
- c->Amount = h;
-}
-
-gnc_numeric
-child_getAmount(mychild *c)
-{
- if (!c) return gnc_numeric_zero();
- return c->Amount;
-}
-
-static QofObject grand_object_def =
-{
-interface_version:
- QOF_OBJECT_VERSION,
-e_type:
- GRAND_MODULE_NAME,
-type_label:
- GRAND_MODULE_DESC,
-create:
- (gpointer)grand_create,
-book_begin:
- NULL,
-book_end:
- NULL,
-is_dirty:
- qof_collection_is_dirty,
-mark_clean:
- qof_collection_mark_clean,
-foreach:
- qof_collection_foreach,
-printable:
- NULL,
-version_cmp:
- (int (*)(gpointer, gpointer)) qof_instance_version_cmp,
-};
-
-gboolean mygrandRegister (void)
-{
- static QofParam params[] =
- {
- {
- OBJ_NAME, QOF_TYPE_STRING, (QofAccessFunc)grand_getName,
- (QofSetterFunc)grand_setName
- },
- {
- OBJ_AMOUNT, QOF_TYPE_NUMERIC, (QofAccessFunc)grand_getAmount,
- (QofSetterFunc)grand_setAmount
- },
- {
- OBJ_DATE, QOF_TYPE_DATE, (QofAccessFunc)grand_getDate,
- (QofSetterFunc)grand_setDate
- },
- {
- OBJ_DISCOUNT, QOF_TYPE_DOUBLE, (QofAccessFunc)grand_getDiscount,
- (QofSetterFunc)grand_setDiscount
- },
- {
- OBJ_ACTIVE, QOF_TYPE_BOOLEAN, (QofAccessFunc)grand_getActive,
- (QofSetterFunc)grand_setActive
- },
- {
- OBJ_VERSION, QOF_TYPE_INT32, (QofAccessFunc)grand_getVersion,
- (QofSetterFunc)grand_setVersion
- },
- {
- OBJ_MINOR, QOF_TYPE_INT64, (QofAccessFunc)grand_getMinor,
- (QofSetterFunc)grand_setMinor
- },
- {
- OBJ_FLAG, QOF_TYPE_CHAR, (QofAccessFunc)grand_getFlag,
- (QofSetterFunc)grand_setFlag
- },
- {
- OBJ_RELATIVE, PARENT_MODULE_NAME, (QofAccessFunc)grand_getChild,
- (QofSetterFunc)grand_setChild
- },
- {
- OBJ_LIST, QOF_TYPE_COLLECT, (QofAccessFunc)grand_getDescend,
- (QofSetterFunc)grand_setDescend
- },
- { QOF_PARAM_BOOK, QOF_ID_BOOK, (QofAccessFunc)qof_instance_get_book, NULL },
- { QOF_PARAM_GUID, QOF_TYPE_GUID, (QofAccessFunc)qof_instance_get_guid, NULL },
- { NULL },
- };
-
- qof_class_register (GRAND_MODULE_NAME, NULL, params);
- /* if(!qof_choice_create(GRAND_MODULE_NAME)) { return FALSE; }*/
-
- return qof_object_register (&grand_object_def);
-}
-
-static QofObject parent_object_def =
-{
-interface_version:
- QOF_OBJECT_VERSION,
-e_type:
- PARENT_MODULE_NAME,
-type_label:
- PARENT_MODULE_DESC,
-create:
- (gpointer)parent_create,
-book_begin:
- NULL,
-book_end:
- NULL,
-is_dirty:
- qof_collection_is_dirty,
-mark_clean:
- qof_collection_mark_clean,
-foreach:
- qof_collection_foreach,
-printable:
- NULL,
-version_cmp:
- (int (*)(gpointer, gpointer)) qof_instance_version_cmp,
-};
-
-gboolean myparentRegister (void)
-{
- static QofParam params[] =
- {
- {
- OBJ_NAME, QOF_TYPE_STRING, (QofAccessFunc)parent_getName,
- (QofSetterFunc)parent_setName
- },
- {
- OBJ_AMOUNT, QOF_TYPE_NUMERIC, (QofAccessFunc)parent_getAmount,
- (QofSetterFunc)parent_setAmount
- },
- {
- OBJ_DATE, QOF_TYPE_DATE, (QofAccessFunc)parent_getDate,
- (QofSetterFunc)parent_setDate
- },
- {
- OBJ_DISCOUNT, QOF_TYPE_DOUBLE, (QofAccessFunc)parent_getDiscount,
- (QofSetterFunc)parent_setDiscount
- },
- {
- OBJ_ACTIVE, QOF_TYPE_BOOLEAN, (QofAccessFunc)parent_getActive,
- (QofSetterFunc)parent_setActive
- },
- {
- OBJ_VERSION, QOF_TYPE_INT32, (QofAccessFunc)parent_getVersion,
- (QofSetterFunc)parent_setVersion
- },
- {
- OBJ_MINOR, QOF_TYPE_INT64, (QofAccessFunc)parent_getMinor,
- (QofSetterFunc)parent_setMinor
- },
- {
- OBJ_FLAG, QOF_TYPE_CHAR, (QofAccessFunc)parent_getFlag,
- (QofSetterFunc)parent_setFlag
- },
- {
- OBJ_RELATIVE, CHILD_MODULE_NAME, (QofAccessFunc)parent_getChild,
- (QofSetterFunc)parent_setChild
- },
- { QOF_PARAM_BOOK, QOF_ID_BOOK, (QofAccessFunc)qof_instance_get_book, NULL },
- { QOF_PARAM_GUID, QOF_TYPE_GUID, (QofAccessFunc)qof_instance_get_guid, NULL },
- { NULL },
- };
-
- qof_class_register (PARENT_MODULE_NAME, NULL, params);
-
- return qof_object_register (&parent_object_def);
-}
-
-static QofObject child_object_def =
-{
-interface_version:
- QOF_OBJECT_VERSION,
-e_type:
- CHILD_MODULE_NAME,
-type_label:
- CHILD_MODULE_DESC,
-create:
- (gpointer)child_create,
-book_begin:
- NULL,
-book_end:
- NULL,
-is_dirty:
- qof_collection_is_dirty,
-mark_clean:
- qof_collection_mark_clean,
-foreach:
- qof_collection_foreach,
-printable:
- NULL,
-version_cmp:
- (int (*)(gpointer, gpointer)) qof_instance_version_cmp,
-};
-
-gboolean mychildRegister (void)
-{
- static QofParam params[] =
- {
- {
- OBJ_NAME, QOF_TYPE_STRING, (QofAccessFunc)child_getName,
- (QofSetterFunc)child_setName
- },
- {
- OBJ_AMOUNT, QOF_TYPE_NUMERIC, (QofAccessFunc)child_getAmount,
- (QofSetterFunc)child_setAmount
- },
- {
- OBJ_DATE, QOF_TYPE_DATE, (QofAccessFunc)child_getDate,
- (QofSetterFunc)child_setDate
- },
- {
- OBJ_DISCOUNT, QOF_TYPE_DOUBLE, (QofAccessFunc)child_getDiscount,
- (QofSetterFunc)child_setDiscount
- },
- {
- OBJ_ACTIVE, QOF_TYPE_BOOLEAN, (QofAccessFunc)child_getActive,
- (QofSetterFunc)child_setActive
- },
- {
- OBJ_VERSION, QOF_TYPE_INT32, (QofAccessFunc)child_getVersion,
- (QofSetterFunc)child_setVersion
- },
- {
- OBJ_MINOR, QOF_TYPE_INT64, (QofAccessFunc)child_getMinor,
- (QofSetterFunc)child_setMinor
- },
- {
- OBJ_FLAG, QOF_TYPE_CHAR, (QofAccessFunc)child_getFlag,
- (QofSetterFunc)child_setFlag
- },
- { QOF_PARAM_BOOK, QOF_ID_BOOK, (QofAccessFunc)qof_instance_get_book, NULL },
- { QOF_PARAM_GUID, QOF_TYPE_GUID, (QofAccessFunc)qof_instance_get_guid, NULL },
- { NULL },
- };
-
- qof_class_register (CHILD_MODULE_NAME, NULL, params);
-
- return qof_object_register (&child_object_def);
-}
-
-static void
-create_data (QofSession *original, guint counter)
-{
- QofCollection *coll;
- QofBook *start;
- mygrand *grand1;
- myparent *parent1;
- mychild *child1;
-
- start = qof_session_get_book(original);
- grand1 = (mygrand*)qof_object_new_instance(GRAND_MODULE_NAME, start);
- do_test ((NULL != &grand1->inst), "instance init");
- switch (counter)
- {
- case 0 : /* NULL tree */
- {
- do_test((grand1 != NULL), "empty tree check");
- coll = qof_book_get_collection(start, GRAND_MODULE_NAME);
- do_test((qof_collection_count(coll) == 1),
- "Too many grandparents found - should be 1");
- coll = qof_book_get_collection(start, CHILD_MODULE_NAME);
- do_test((qof_collection_count(coll) == 0),
- "child found, should be empty");
- coll = qof_book_get_collection(start, PARENT_MODULE_NAME);
- do_test((qof_collection_count(coll) == 0),
- "tree not empty: parent found");
- break;
- }
- case 1 : /* one parent, no child */
- {
- parent1 = (myparent*)qof_object_new_instance(PARENT_MODULE_NAME, start);
- grand_setChild(grand1, parent1);
- do_test((parent1 != NULL), "single parent check");
- do_test((grand_getChild(grand1) == parent1), "set child in grandparent");
- coll = qof_book_get_collection(start, GRAND_MODULE_NAME);
- do_test((qof_collection_count(coll) == 1),
- "Wrong number of grandparents, should be 1");
- coll = qof_book_get_collection(start, CHILD_MODULE_NAME);
- do_test((qof_collection_count(coll) == 0),
- "Should be no child entities this iteration.");
- coll = qof_book_get_collection(start, PARENT_MODULE_NAME);
- do_test((qof_collection_count(coll) == 1),
- "Wrong number of parents found, should be 1");
- break;
- }
- case 2 : /* one parent, one child */
- {
- parent1 = (myparent*)qof_object_new_instance(PARENT_MODULE_NAME, start);
- grand_setChild(grand1, parent1);
- child1 = (mychild*)qof_object_new_instance(CHILD_MODULE_NAME, start);
- parent1 = grand_getChild(grand1);
- parent_setChild(parent1, child1);
- do_test((child1 != NULL), "one parent with one related child");
- do_test((child1 == parent_getChild(parent1)), "child of single parent");
- coll = qof_book_get_collection(start, GRAND_MODULE_NAME);
- do_test((qof_collection_count(coll) == 1),
- "Wrong number of grandparents. Should be 1");
- coll = qof_book_get_collection(start, CHILD_MODULE_NAME);
- do_test((qof_collection_count(coll) == 1),
- "Wrong number of child entities, should be 1");
- coll = qof_book_get_collection(start, PARENT_MODULE_NAME);
- do_test((qof_collection_count(coll) == 1),
- "Wrong number of parents. Should be 1");
- break;
- }
- case 3 : /* same grand, new parent, same child */
- {
- child1 = (mychild*)qof_object_new_instance(CHILD_MODULE_NAME, start);
- parent1 = (myparent*)qof_object_new_instance(PARENT_MODULE_NAME, start);
- grand_setChild(grand1, parent1);
- parent_setChild(parent1, child1);
- do_test((parent1 == grand_getChild(grand1)), "same grandparent, new parent");
- do_test((child1 == parent_getChild(parent1)), "new parent, same child");
- coll = qof_book_get_collection(start, GRAND_MODULE_NAME);
- do_test((qof_collection_count(coll) == 1),
- "Wrong number of grandparents. Should be 1, Iteration 3.");
- coll = qof_book_get_collection(start, CHILD_MODULE_NAME);
- do_test((qof_collection_count(coll) == 1),
- "Wrong number of child entities, should be 1. Iteration 3.");
- coll = qof_book_get_collection(start, PARENT_MODULE_NAME);
- do_test((qof_collection_count(coll) == 1),
- "Wrong number of parents. Should be 1. Iteration 3.");
- break;
- }
- case 4 : /* new grand, unrelated parent, child unrelated to grand */
- {
- grand1 = (mygrand*)qof_object_new_instance(GRAND_MODULE_NAME, start);
- parent1 = (myparent*)qof_object_new_instance(PARENT_MODULE_NAME, start);
- child1 = (mychild*)qof_object_new_instance(CHILD_MODULE_NAME, start);
- parent_setChild(parent1, child1);
- do_test((NULL == grand_getChild(grand1)), "new grand, unrelated parent");
- do_test((child1 == parent_getChild(parent1)), "child unrelated to grand");
- coll = grand_getDescend(grand1);
- do_test((coll != NULL), "grandparent not valid");
- if (coll)
- {
- QofInstance *ent;
-
- ent = QOF_INSTANCE(child1);
- qof_collection_add_entity(coll, ent);
- grand_setDescend(grand1, coll);
- qof_collection_destroy(coll);
- do_test((g_list_length(grand1->descend) > 0), "entity not added");
- do_test((qof_collection_count(grand_getDescend(grand1)) > 0),
- "empty collection returned");
- }
- break;
- }
- }
-}
-
-struct tally
-{
- guint nulls, total, collect;
- QofBook *book;
-};
-
-static void
-check_cb (QofInstance *ent, gpointer data)
-{
- QofInstance *parent, *child;
- QofCollection *coll;
- struct tally *c;
- const QofParam *param;
- mygrand *testg;
- myparent *testp;
- mychild *testc;
-
- c = (struct tally*)data;
- /* check the same number and type of entities
- exist in the copied book */
- testg = (mygrand*)ent;
- /* we always have a grandparent */
- do_test((testg != NULL), "grandparent not found");
- c->total++;
- param = qof_class_get_parameter(GRAND_MODULE_NAME, OBJ_LIST);
- coll = (QofCollection*)param->param_getfcn(ent, param);
- c->collect = qof_collection_count(coll);
- if (c->book)
- {
- qof_book_set_references(c->book);
- }
- param = qof_class_get_parameter(GRAND_MODULE_NAME, OBJ_RELATIVE);
- parent = QOF_INSTANCE(param->param_getfcn(ent, param));
- testp = grand_getChild((mygrand*)ent);
- /* not all grandparents have family so just keep count. */
- if (!parent)
- {
- c->nulls++;
- return;
- }
- do_test((0 == safe_strcmp(parent_getName(testp),
- parent_getName((myparent*)parent))), "parent copy test");
- param = qof_class_get_parameter(PARENT_MODULE_NAME, OBJ_RELATIVE);
- child = param->param_getfcn(parent, param);
- testc = parent_getChild((myparent*)parent);
- if (!child)
- {
- c->nulls++;
- return;
- }
- do_test((0 == safe_strcmp(child_getName(testc),
- child_getName((mychild*)child))), "child copy test");
-}
-
-static void
-test_recursion (QofSession *original, guint counter)
-{
- QofSession *copy;
- QofCollection *grand_coll;
- struct tally c;
- QofBook *book;
- guint d, e, f;
-
- c.nulls = 0;
- c.total = 0;
- c.collect = 0;
- c.book = NULL;
- book = qof_session_get_book(original);
- grand_coll = qof_book_get_collection(book, GRAND_MODULE_NAME);
- copy = qof_session_new();
- if (debug)
- {
- /* FIXME XML backend can't handle STDOUT
- * qof_session_begin(copy, QOF_STDOUT, TRUE, FALSE, FALSE); */
- }
- /* TODO: implement QOF_TYPE_CHOICE testing. */
- qof_instance_copy_coll_r(copy, grand_coll);
- /* test the original */
- qof_object_foreach(GRAND_MODULE_NAME, book, check_cb, &c);
- book = qof_session_get_book(copy);
- /* test the copy */
- d = c.nulls;
- e = c.total;
- f = c.collect;
- c.nulls = 0;
- c.total = 0;
- c.collect = 0;
- c.book = book;
- qof_object_foreach(GRAND_MODULE_NAME, book, check_cb, &c);
- do_test((d == c.nulls), "Null parents do not match");
- do_test((e == c.total), "Total parents do not match");
- do_test((f == c.collect), "Number of children in descendents does not match");
- if (counter == 4 && debug == TRUE)
- {
- /* FIXME XML backend can't handle STDOUT
- * qof_session_save(copy, NULL);
- qof_session_save(original, NULL); */
- }
- qof_session_end(copy);
- copy = NULL;
-}
-
-int
-main (int argc, const char *argv[])
-{
- QofSession *original;
- guint counter;
-
- qof_init ();
- mygrandRegister();
- myparentRegister();
- mychildRegister();
- for (counter = 0; counter < 35; counter++)
- {
- original = qof_session_new();
- if (debug)
- {
- /* FIXME XML backend can't handle STDOUT
- * qof_session_begin(original, QOF_STDOUT, TRUE, FALSE, FALSE); */
- }
- create_data(original, (counter % 5));
- test_recursion(original, (counter % 5));
- qof_session_end(original);
- }
- print_test_results();
- qof_close();
- return EXIT_SUCCESS;
-}
Modified: gnucash/trunk/src/libqof/qof/qofsession.c
===================================================================
--- gnucash/trunk/src/libqof/qof/qofsession.c 2011-08-18 18:35:17 UTC (rev 21189)
+++ gnucash/trunk/src/libqof/qof/qofsession.c 2011-08-20 03:44:40 UTC (rev 21190)
@@ -314,692 +314,6 @@
qof_session_push_error (session, qof_backend_get_error(backend), NULL);
}
-/* =============================================================== */
-
-typedef struct qof_instance_copy_data
-{
- QofInstance *from;
- QofInstance *to;
- QofParam *param;
- GList *referenceList;
- GSList *param_list;
- QofSession *new_session;
- gboolean error;
-} QofInstanceCopyData;
-
-static void
-qof_book_set_partial(QofBook *book)
-{
- gboolean partial;
-
- partial =
- (gboolean)GPOINTER_TO_INT(qof_book_get_data(book, PARTIAL_QOFBOOK));
- if (!partial)
- {
- qof_book_set_data(book, PARTIAL_QOFBOOK, GINT_TO_POINTER(TRUE));
- }
-}
-
-/** \brief Adds a new reference to the partial book data hash.
-
-Retrieves any existing reference list and appends the new reference.
-
-If the book is not already marked as partial, it will be marked as
-partial.
-*/
-static void
-qof_session_update_reference_list(QofSession *session, QofInstanceReference *reference)
-{
- QofBook *book;
- GList *book_ref_list;
-
- book = qof_session_get_book(session);
- book_ref_list = (GList*)qof_book_get_data(book, ENTITYREFERENCE);
- book_ref_list = g_list_append(book_ref_list, reference);
- qof_book_set_data(book, ENTITYREFERENCE, book_ref_list);
- qof_book_set_partial(book);
-}
-
-static void
-qof_instance_param_cb(QofParam *param, gpointer data)
-{
- QofInstanceCopyData *qecd;
-
- g_return_if_fail(data != NULL);
- qecd = (QofInstanceCopyData*)data;
- g_return_if_fail(param != NULL);
- /* KVP doesn't need a set routine to be copied. */
- if (0 == safe_strcmp(param->param_type, QOF_TYPE_KVP))
- {
- qecd->param_list = g_slist_prepend(qecd->param_list, param);
- return;
- }
- if ((param->param_getfcn != NULL) && (param->param_setfcn != NULL))
- {
- qecd->param_list = g_slist_prepend(qecd->param_list, param);
- }
-}
-
-static void
-col_ref_cb (QofInstance* ref_ent, gpointer user_data)
-{
- QofInstanceReference *ref;
- QofInstanceCopyData *qecd;
- QofInstance *ent;
- const GncGUID *cm_guid;
- char cm_sa[GUID_ENCODING_LENGTH + 1];
- gchar *cm_string;
-
- g_return_if_fail(user_data);
- qecd = (QofInstanceCopyData*)user_data;
- ent = qecd->from;
- g_return_if_fail(ent);
- ref = g_new0(QofInstanceReference, 1);
- ref->type = ent->e_type;
- ref->ref_guid = g_new(GncGUID, 1);
- ref->ent_guid = qof_instance_get_guid(ent);
- ref->param = qof_class_get_parameter(ent->e_type,
- qecd->param->param_name);
- cm_guid = qof_entity_get_guid(ref_ent);
- guid_to_string_buff(cm_guid, cm_sa);
- cm_string = g_strdup(cm_sa);
- if (TRUE == string_to_guid(cm_string, ref->ref_guid))
- {
- g_free(cm_string);
- qof_session_update_reference_list(qecd->new_session, ref);
- }
-}
-
-static void
-qof_instance_foreach_copy(gpointer data, gpointer user_data)
-{
- QofInstance *importEnt, *targetEnt/*, *referenceEnt*/;
- QofInstanceCopyData *context;
- QofInstanceReference *reference;
- gboolean registered_type;
- /* cm_ prefix used for variables that hold the data to commit */
- QofParam *cm_param;
- gchar *cm_string, *cm_char;
- const GncGUID *cm_guid;
- KvpFrame *cm_kvp;
- QofCollection *cm_col;
- /* function pointers and variables for parameter getters that don't use pointers normally */
- gnc_numeric cm_numeric, (*numeric_getter) (QofInstance*, QofParam*);
- double cm_double, (*double_getter) (QofInstance*, QofParam*);
- gboolean cm_boolean, (*boolean_getter) (QofInstance*, QofParam*);
- gint32 cm_i32, (*int32_getter) (QofInstance*, QofParam*);
- gint64 cm_i64, (*int64_getter) (QofInstance*, QofParam*);
- Timespec cm_date, (*date_getter) (QofInstance*, QofParam*);
- /* function pointers to the parameter setters */
- void (*string_setter) (QofInstance*, const char*);
- void (*date_setter) (QofInstance*, Timespec);
- void (*numeric_setter) (QofInstance*, gnc_numeric);
- void (*guid_setter) (QofInstance*, const GncGUID*);
- void (*double_setter) (QofInstance*, double);
- void (*boolean_setter) (QofInstance*, gboolean);
- void (*i32_setter) (QofInstance*, gint32);
- void (*i64_setter) (QofInstance*, gint64);
- void (*char_setter) (QofInstance*, char*);
- void (*kvp_frame_setter) (QofInstance*, KvpFrame*);
-
- g_return_if_fail(user_data != NULL);
- context = (QofInstanceCopyData*) user_data;
- cm_date.tv_nsec = 0;
- cm_date.tv_sec = 0;
- 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(*)(QofInstance*, const char*))cm_param->param_setfcn;
- if (string_setter != NULL)
- {
- string_setter(targetEnt, cm_string);
- }
- }
- registered_type = TRUE;
- }
- if (safe_strcmp(cm_param->param_type, QOF_TYPE_DATE) == 0)
- {
- date_getter = (Timespec (*)(QofInstance*, QofParam*))cm_param->param_getfcn;
- cm_date = date_getter(importEnt, cm_param);
- date_setter = (void(*)(QofInstance*, Timespec))cm_param->param_setfcn;
- if (date_setter != NULL)
- {
- date_setter(targetEnt, cm_date);
- }
- registered_type = TRUE;
- }
- if ((safe_strcmp(cm_param->param_type, QOF_TYPE_NUMERIC) == 0) ||
- (safe_strcmp(cm_param->param_type, QOF_TYPE_DEBCRED) == 0))
- {
- numeric_getter = (gnc_numeric (*)(QofInstance*, QofParam*))cm_param->param_getfcn;
- cm_numeric = numeric_getter(importEnt, cm_param);
- numeric_setter = (void(*)(QofInstance*, gnc_numeric))cm_param->param_setfcn;
- if (numeric_setter != NULL)
- {
- numeric_setter(targetEnt, cm_numeric);
- }
- registered_type = TRUE;
- }
- if (safe_strcmp(cm_param->param_type, QOF_TYPE_GUID) == 0)
- {
- cm_guid = (const GncGUID*)cm_param->param_getfcn(importEnt, cm_param);
- guid_setter = (void(*)(QofInstance*, const GncGUID*))cm_param->param_setfcn;
- if (guid_setter != NULL)
- {
- guid_setter(targetEnt, cm_guid);
- }
- registered_type = TRUE;
- }
- if (safe_strcmp(cm_param->param_type, QOF_TYPE_INT32) == 0)
- {
- int32_getter = (gint32 (*)(QofInstance*, QofParam*)) cm_param->param_getfcn;
- cm_i32 = int32_getter(importEnt, cm_param);
- i32_setter = (void(*)(QofInstance*, gint32))cm_param->param_setfcn;
- if (i32_setter != NULL)
- {
- i32_setter(targetEnt, cm_i32);
- }
- registered_type = TRUE;
- }
- if (safe_strcmp(cm_param->param_type, QOF_TYPE_INT64) == 0)
- {
- int64_getter = (gint64 (*)(QofInstance*, QofParam*)) cm_param->param_getfcn;
- cm_i64 = int64_getter(importEnt, cm_param);
- i64_setter = (void(*)(QofInstance*, gint64))cm_param->param_setfcn;
- if (i64_setter != NULL)
- {
- i64_setter(targetEnt, cm_i64);
- }
- registered_type = TRUE;
- }
- if (safe_strcmp(cm_param->param_type, QOF_TYPE_DOUBLE) == 0)
- {
- double_getter = (double (*)(QofInstance*, QofParam*)) cm_param->param_getfcn;
- cm_double = double_getter(importEnt, cm_param);
- double_setter = (void(*)(QofInstance*, double))cm_param->param_setfcn;
- if (double_setter != NULL)
- {
- double_setter(targetEnt, cm_double);
- }
- registered_type = TRUE;
- }
- if (safe_strcmp(cm_param->param_type, QOF_TYPE_BOOLEAN) == 0)
- {
- boolean_getter = (gboolean (*)(QofInstance*, QofParam*)) cm_param->param_getfcn;
- cm_boolean = boolean_getter(importEnt, cm_param);
- boolean_setter = (void(*)(QofInstance*, gboolean))cm_param->param_setfcn;
- if (boolean_setter != NULL)
- {
- boolean_setter(targetEnt, cm_boolean);
- }
- 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(*)(QofInstance*, KvpFrame*))cm_param->param_setfcn;
- if (kvp_frame_setter != NULL)
- {
- kvp_frame_setter(targetEnt, cm_kvp);
- }
- 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(*)(QofInstance*, char*))cm_param->param_setfcn;
- if (char_setter != NULL)
- {
- char_setter(targetEnt, cm_char);
- }
- 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 = QOF_INSTANCE(cm_param->param_getfcn(importEnt, cm_param));
- if(!referenceEnt) { return; }
- if(!referenceEnt->e_type) { return; }*/
- reference = qof_instance_get_reference_from(importEnt, cm_param);
- if (reference)
- {
- qof_session_update_reference_list(context->new_session, reference);
- }
- }
-}
-
-static gboolean
-qof_instance_guid_match(QofSession *new_session, QofInstance *original)
-{
- QofInstance *copy;
- const GncGUID *g;
- QofIdTypeConst type;
- QofBook *targetBook;
- QofCollection *coll;
-
- copy = NULL;
- g_return_val_if_fail(original != NULL, FALSE);
- targetBook = qof_session_get_book(new_session);
- g_return_val_if_fail(targetBook != NULL, FALSE);
- g = qof_instance_get_guid(original);
- type = g_strdup(original->e_type);
- coll = qof_book_get_collection(targetBook, type);
- copy = qof_collection_lookup_entity(coll, g);
- if (copy)
- {
- return TRUE;
- }
- return FALSE;
-}
-
-static void
-qof_instance_list_foreach(gpointer data, gpointer user_data)
-{
- QofInstanceCopyData *qecd;
- QofInstance *original;
- QofInstance *inst;
- QofBook *book;
- const GncGUID *g;
-
- g_return_if_fail(data != NULL);
- original = QOF_INSTANCE(data);
- g_return_if_fail(user_data != NULL);
- qecd = (QofInstanceCopyData*)user_data;
- if (qof_instance_guid_match(qecd->new_session, original))
- {
- return;
- }
- qecd->from = original;
- if (!qof_object_compliance(original->e_type, FALSE))
- {
- qecd->error = TRUE;
- return;
- }
- book = qof_session_get_book(qecd->new_session);
- inst = (QofInstance*)qof_object_new_instance(original->e_type, book);
- if (!inst)
- {
- PERR (" failed to create new entity type=%s.", original->e_type);
- qecd->error = TRUE;
- return;
- }
- qecd->to = inst;
- g = qof_instance_get_guid(original);
- qof_instance_set_guid(qecd->to, g);
- if (qecd->param_list != NULL)
- {
- g_slist_free(qecd->param_list);
- qecd->param_list = NULL;
- }
- qof_class_param_foreach(original->e_type, qof_instance_param_cb, qecd);
- qof_begin_edit(inst);
- g_slist_foreach(qecd->param_list, qof_instance_foreach_copy, qecd);
- qof_commit_edit(inst);
-}
-
-static void
-qof_instance_coll_foreach(QofInstance *original, gpointer user_data)
-{
- QofInstanceCopyData *qecd;
- const GncGUID *g;
- QofBook *targetBook;
- QofCollection *coll;
- QofInstance *copy;
-
- g_return_if_fail(original != NULL);
- g_return_if_fail(user_data != NULL);
- copy = NULL;
- qecd = (QofInstanceCopyData*)user_data;
- targetBook = qof_session_get_book(qecd->new_session);
- g = qof_instance_get_guid(original);
- coll = qof_book_get_collection(targetBook, original->e_type);
- copy = qof_collection_lookup_entity(coll, g);
- if (copy)
- {
- qecd->error = TRUE;
- }
-}
-
-static void
-qof_instance_coll_copy(QofInstance *original, gpointer user_data)
-{
- QofInstanceCopyData *qecd;
- QofBook *book;
- QofInstance *inst;
- const GncGUID *g;
-
- g_return_if_fail(original != NULL);
- g_return_if_fail(user_data != NULL);
- qecd = (QofInstanceCopyData*)user_data;
- book = qof_session_get_book(qecd->new_session);
- if (!qof_object_compliance(original->e_type, TRUE))
- {
- return;
- }
- inst = (QofInstance*)qof_object_new_instance(original->e_type, book);
- qecd->to = inst;
- qecd->from = original;
- g = qof_instance_get_guid(original);
- qof_instance_set_guid(qecd->to, g);
- qof_begin_edit(inst);
- g_slist_foreach(qecd->param_list, qof_instance_foreach_copy, qecd);
- qof_commit_edit(inst);
-}
-
-gboolean
-qof_instance_copy_to_session(QofSession* new_session, QofInstance* original)
-{
- QofInstanceCopyData qecd;
- QofInstance *inst;
- QofBook *book;
-
- if (!new_session || !original)
- {
- return FALSE;
- }
- if (qof_instance_guid_match(new_session, original))
- {
- return FALSE;
- }
- if (!qof_object_compliance(original->e_type, TRUE))
- {
- return FALSE;
- }
- qof_event_suspend();
- qecd.param_list = NULL;
- book = qof_session_get_book(new_session);
- qecd.new_session = new_session;
- qof_book_set_partial(book);
- inst = (QofInstance*)qof_object_new_instance(original->e_type, book);
- qecd.to = inst;
- qecd.from = original;
- qof_instance_set_guid(qecd.to, qof_instance_get_guid(original));
- qof_begin_edit(inst);
- qof_class_param_foreach(original->e_type, qof_instance_param_cb, &qecd);
- qof_commit_edit(inst);
- if (g_slist_length(qecd.param_list) == 0)
- {
- return FALSE;
- }
- g_slist_foreach(qecd.param_list, qof_instance_foreach_copy, &qecd);
- g_slist_free(qecd.param_list);
- qof_event_resume();
- return TRUE;
-}
-
-gboolean qof_instance_copy_list(QofSession *new_session, GList *entity_list)
-{
- QofInstanceCopyData *qecd;
-
- if (!new_session || !entity_list)
- {
- return FALSE;
- }
- ENTER (" list=%d", g_list_length(entity_list));
- qecd = g_new0(QofInstanceCopyData, 1);
- qof_event_suspend();
- qecd->param_list = NULL;
- qecd->new_session = new_session;
- qof_book_set_partial(qof_session_get_book(new_session));
- g_list_foreach(entity_list, qof_instance_list_foreach, qecd);
- qof_event_resume();
- if (qecd->error)
- {
- PWARN (" some/all entities in the list could not be copied.");
- }
- g_free(qecd);
- LEAVE (" ");
- return TRUE;
-}
-
-gboolean
-qof_instance_copy_coll(QofSession *new_session, QofCollection *entity_coll)
-{
- QofInstanceCopyData qecd;
-
- g_return_val_if_fail(new_session, FALSE);
- if (!entity_coll)
- {
- return FALSE;
- }
- qof_event_suspend();
- qecd.param_list = NULL;
- qecd.new_session = new_session;
- qof_book_set_partial(qof_session_get_book(qecd.new_session));
- qof_collection_foreach(entity_coll, qof_instance_coll_foreach, &qecd);
- qof_class_param_foreach(qof_collection_get_type(entity_coll),
- qof_instance_param_cb, &qecd);
- qof_collection_foreach(entity_coll, qof_instance_coll_copy, &qecd);
- if (qecd.param_list != NULL)
- {
- g_slist_free(qecd.param_list);
- }
- qof_event_resume();
- return TRUE;
-}
-
-struct recurse_s
-{
- QofSession *session;
- gboolean success;
- GList *ref_list;
- GList *ent_list;
-};
-
-static void
-recurse_collection_cb (QofInstance *ent, gpointer user_data)
-{
- struct recurse_s *store;
-
- if (user_data == NULL)
- {
- return;
- }
- store = (struct recurse_s*)user_data;
- if (!ent || !store)
- {
- return;
- }
- store->success = qof_instance_copy_to_session(store->session, ent);
- if (store->success)
- {
- store->ent_list = g_list_append(store->ent_list, ent);
- }
-}
-
-static void
-recurse_ent_cb(QofInstance *ent, gpointer user_data)
-{
- GList *ref_list, *i, *j, *ent_list, *child_list;
- QofParam *ref_param;
- QofInstance *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 = QOF_INSTANCE(ref_param->param_getfcn(ent, ref_param));
- if ((ref_ent) && (ref_ent->e_type))
- {
- store->success = qof_instance_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 = QOF_INSTANCE(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_instance_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 = QOF_INSTANCE(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_instance_copy_to_session(session, child_ent);
- }
- }
- }
-}
-
-gboolean
-qof_instance_copy_coll_r(QofSession *new_session, QofCollection *coll)
-{
- struct recurse_s store;
- gboolean success;
-
- if ((!new_session) || (!coll))
- {
- return FALSE;
- }
- store.session = new_session;
- success = TRUE;
- store.success = success;
- store.ent_list = NULL;
- store.ref_list = qof_class_get_referenceList(qof_collection_get_type(coll));
- success = qof_instance_copy_coll(new_session, coll);
- if (success)
- {
- qof_collection_foreach(coll, recurse_ent_cb, &store);
- }
- return success;
-}
-
-gboolean qof_instance_copy_one_r(QofSession *new_session, QofInstance *ent)
-{
- struct recurse_s store;
- QofCollection *coll;
- gboolean success;
-
- if ((!new_session) || (!ent))
- {
- return FALSE;
- }
- store.session = new_session;
- success = TRUE;
- store.success = success;
- store.ref_list = qof_class_get_referenceList(ent->e_type);
- success = qof_instance_copy_to_session(new_session, ent);
- if (success == TRUE)
- {
- coll = qof_book_get_collection(qof_session_get_book(new_session), ent->e_type);
- if (coll)
- {
- qof_collection_foreach(coll, recurse_ent_cb, &store);
- }
- }
- return success;
-}
-
-
/* ====================================================================== */
/** Programs that use their own backends also need to call
Modified: gnucash/trunk/src/libqof/qof/qofsession.h
===================================================================
--- gnucash/trunk/src/libqof/qof/qofsession.h 2011-08-18 18:35:17 UTC (rev 21189)
+++ gnucash/trunk/src/libqof/qof/qofsession.h 2011-08-20 03:44:40 UTC (rev 21190)
@@ -255,143 +255,6 @@
*/
void qof_session_end (QofSession *session);
-/** @name Copying entities between sessions.
-
-Only certain backends can cope with selective copying of
-entities and only fully defined QOF entities can be copied
-between sessions - see the \ref QSF (QSF) documentation
-(::qsf_write_file) for more information.
-
-The recommended backend for the new session is QSF or a future
-SQL backend. Using any of these entity copy functions sets a
-flag in the backend that this is now a partial QofBook. See \ref Reference.
-When you save a session containing a partial QofBook,
-the session will check that the backend is able to handle the
-partial book. If not, the backend will be replaced by one that
-can handle partial books, preferably one using the same
-::access_method. Currently, this means that a book
-using the GnuCash XML v2 file backend will be switched to QSF.
-
-Copied entities are identical to the source entity, all parameters
-defined with ::QofAccessFunc and ::QofSetterFunc in QOF are copied
-and the ::GncGUID of the original ::QofInstance is set in the new entity.
-Sessions containing copied entities are intended for use
-as mechanisms for data export.
-
-It is acceptable to add entities to new_session in batches. Note that
-any of these calls will fail if an entity already exists in new_session
-with the same GncGUID as any entity to be copied.
-
-To merge a whole QofBook or where there is any possibility
-of collisions or requirement for user intervention,
-see \ref BookMerge
-
-@{
-
-*/
-
-/** \brief Copy a single QofInstance to another session
-
-Checks first that no entity in the session book contains
-the GncGUID of the source entity.
-
- @param new_session - the target session
- @param original - the QofInstance* to copy
-
- at return FALSE without copying if the session contains an entity
-with the same GncGUID already, otherwise TRUE.
-*/
-
-gboolean qof_instance_copy_to_session(QofSession* new_session, QofInstance* original);
-
-/** @brief Copy a GList of entities to another session
-
-The QofBook in the new_session must \b not contain any entities
-with the same GncGUID as any of the source entities - there is
-no support for handling collisions, instead use \ref BookMerge
-
-Note that the GList (e.g. from ::qof_sql_query_run) can contain
-QofInstance pointers of any ::QofIdType, in any sequence. As long
-as all members of the list are ::QofInstance*, and all GncGUID's are
-unique, the list can be copied.
-
- @param new_session - the target session
- @param entity_list - a GList of QofInstance pointers of any type(s).
-
- at return FALSE, without copying, if new_session contains any entities
-with the same GncGUID. Otherwise TRUE.
-
-*/
-gboolean qof_instance_copy_list(QofSession *new_session, GList *entity_list);
-
-/** @brief Copy a QofCollection of entities.
-
-The QofBook in the new_session must \b not contain any entities
-with the same GncGUID as any entities in the collection - there is
-no support for handling collisions - instead, use \ref BookMerge
-
- at param new_session - the target session
- at param entity_coll - a QofCollection of any QofIdType.
-
- at return FALSE, without copying, if new_session contains any entities
-with the same GncGUID. Otherwise TRUE.
-*/
-
-gboolean qof_instance_copy_coll(QofSession *new_session, QofCollection *entity_coll);
-
-/** \brief Recursively copy a collection of entities to a session.
-
-\note This function creates a <b>partial QofBook</b>. See
-::qof_instance_copy_to_session for more information.
-
-The QofBook in the new_session must \b not contain any entities
-with the same GncGUID as any entities to be copied - there is
-no support for handling collisions - instead, use \ref BookMerge
-
-Objects can be defined solely in terms of QOF data types or
-as a mix of data types and other objects, which may in turn
-include other objects. These references can be copied recursively
-down to the third level. See ::QofInstanceReference.
-
-\note This is a deep recursive copy - every referenced entity is copied
-to the new session, including all parameters. The starting point is all
-entities in the top level collection. It can take some time.
-
- at param coll A QofCollection of entities that may or may not have
-references.
-
- at param new_session The QofSession to receive the copied entities.
-
- at return TRUE on success; if any individual copy fails, returns FALSE.
-<b>Note</b> : Some entities may have been copied successfully even if
-one of the references fails to copy.
-
-*/
-gboolean
-qof_instance_copy_coll_r(QofSession *new_session, QofCollection *coll);
-
-/** \brief Recursively copy a single entity to a new session.
-
-Copy the single entity and all referenced entities to the second level.
-
-Only entities that are directly referenced by the top level entity are
-copied.
-
-This is a deep copy - all parameters of all referenced entities are copied. If
-the top level entity has no references, this is identical to
-::qof_instance_copy_to_session.
-
- at param ent A single entity that may or may not have references.
-
- at param new_session The QofSession to receive the copied entities.
-
- at return TRUE on success; if any individual copy fails, returns FALSE.
-<b>Note</b> : Some entities may have been copied successfully even if
-one of the references fails to copy.
-*/
-gboolean
-qof_instance_copy_one_r(QofSession *new_session, QofInstance *ent);
-
/** @}
*/
More information about the gnucash-changes
mailing list