r16692 - gnucash/branches/gda-dev - Initial work on business objects. Doesn't contain any address, terms or

Phil Longstaff plongstaff at cvs.gnucash.org
Fri Dec 21 19:40:23 EST 2007


Author: plongstaff
Date: 2007-12-21 19:40:22 -0500 (Fri, 21 Dec 2007)
New Revision: 16692
Trac: http://svn.gnucash.org/trac/changeset/16692

Added:
   gnucash/branches/gda-dev/src/business/business-core/gda/
   gnucash/branches/gda-dev/src/business/business-core/gda/Makefile.am
   gnucash/branches/gda-dev/src/business/business-core/gda/gnc-customer-gda.c
   gnucash/branches/gda-dev/src/business/business-core/gda/gnc-customer-gda.h
   gnucash/branches/gda-dev/src/business/business-core/gda/gnc-employee-gda.c
   gnucash/branches/gda-dev/src/business/business-core/gda/gnc-employee-gda.h
   gnucash/branches/gda-dev/src/business/business-core/gda/gnc-invoice-gda.c
   gnucash/branches/gda-dev/src/business/business-core/gda/gnc-invoice-gda.h
   gnucash/branches/gda-dev/src/business/business-core/gda/gnc-job-gda.c
   gnucash/branches/gda-dev/src/business/business-core/gda/gnc-job-gda.h
   gnucash/branches/gda-dev/src/business/business-core/gda/gnc-order-gda.c
   gnucash/branches/gda-dev/src/business/business-core/gda/gnc-order-gda.h
   gnucash/branches/gda-dev/src/business/business-core/gda/gnc-vendor-gda.c
   gnucash/branches/gda-dev/src/business/business-core/gda/gnc-vendor-gda.h
   gnucash/branches/gda-dev/src/business/business-core/gda/gncmod-business-backend-gda.c
Modified:
   gnucash/branches/gda-dev/configure.in
   gnucash/branches/gda-dev/src/business/business-core/Makefile.am
   gnucash/branches/gda-dev/src/business/business-gnome/business-gnome.scm
Log:
Initial work on business objects.  Doesn't contain any address, terms or
tax table info.  No owner or entry info.  Minimal testing (I verified
that a customer could be created and restored).


Modified: gnucash/branches/gda-dev/configure.in
===================================================================
--- gnucash/branches/gda-dev/configure.in	2007-12-22 00:36:29 UTC (rev 16691)
+++ gnucash/branches/gda-dev/configure.in	2007-12-22 00:40:22 UTC (rev 16692)
@@ -1564,6 +1564,7 @@
           src/test-core/Makefile
           src/business/Makefile
           src/business/business-core/Makefile
+          src/business/business-core/gda/Makefile
           src/business/business-core/test/Makefile
           src/business/business-core/xml/Makefile
           src/business/business-utils/Makefile

Modified: gnucash/branches/gda-dev/src/business/business-core/Makefile.am
===================================================================
--- gnucash/branches/gda-dev/src/business/business-core/Makefile.am	2007-12-22 00:36:29 UTC (rev 16691)
+++ gnucash/branches/gda-dev/src/business/business-core/Makefile.am	2007-12-22 00:40:22 UTC (rev 16692)
@@ -1,4 +1,4 @@
-SUBDIRS = . test xml
+SUBDIRS = . gda test xml
 
 pkglib_LTLIBRARIES = libgncmod-business-core.la
 

Added: gnucash/branches/gda-dev/src/business/business-core/gda/Makefile.am
===================================================================
--- gnucash/branches/gda-dev/src/business/business-core/gda/Makefile.am	                        (rev 0)
+++ gnucash/branches/gda-dev/src/business/business-core/gda/Makefile.am	2007-12-22 00:40:22 UTC (rev 16692)
@@ -0,0 +1,61 @@
+SUBDIRS = .
+
+pkglib_LTLIBRARIES = libgncmod-business-backend-gda.la
+
+AM_CFLAGS = \
+  -I${top_srcdir}/src \
+  -I${top_srcdir}/src/backend \
+  -I${top_srcdir}/src/backend/gda \
+  -I${top_srcdir}/src/engine \
+  -I${top_srcdir}/src/gnc-module \
+  -I${top_srcdir}/src/business/business-core \
+  ${QOF_CFLAGS} \
+  ${GLIB_CFLAGS} \
+  ${LIBGDA_CFLAGS}
+
+libgncmod_business_backend_gda_la_SOURCES = \
+  gncmod-business-backend-gda.c \
+  gnc-customer-gda.c \
+  gnc-employee-gda.c \
+  gnc-invoice-gda.c \
+  gnc-job-gda.c \
+  gnc-order-gda.c \
+  gnc-vendor-gda.c
+
+#libgncmod_business_backend_gda_la_SOURCES = \
+#  gncmod-business-backend-gda.c \
+#  gnc-address-gda.c \
+#  gnc-bill-term-gda.c \
+#  gnc-customer-gda.c \
+#  gnc-employee-gda.c \
+#  gnc-entry-gda.c \
+#  gnc-invoice-gda.c \
+#  gnc-job-gda.c \
+#  gnc-order-gda.c \
+#  gnc-owner-gda.c \
+#  gnc-tax-table-gda.c \
+#  gnc-vendor-gda.c
+
+noinst_HEADERS = \
+  gnc-address-gda.h \
+  gnc-bill-term-gda.h \
+  gnc-customer-gda.h \
+  gnc-employee-gda.h \
+  gnc-entry-gda.h \
+  gnc-invoice-gda.h \
+  gnc-job-gda.h \
+  gnc-order-gda.h \
+  gnc-owner-gda.h \
+  gnc-tax-table-gda.h \
+  gnc-vendor-gda.h
+
+libgncmod_business_backend_gda_la_LDFLAGS = -module -avoid-version
+
+libgncmod_business_backend_gda_la_LIBADD = \
+  ${top_builddir}/src/business/business-core/libgncmod-business-core.la \
+  ${top_builddir}/src/backend/gda/libgnc-backend-gda-utils.la \
+  ${top_builddir}/src/engine/libgncmod-engine.la \
+  ${top_builddir}/src/gnc-module/libgnc-module.la \
+  ${QOF_LIBS} \
+  ${GLIB_LIBS} \
+  ${LIBGDA_LIBS}

Added: gnucash/branches/gda-dev/src/business/business-core/gda/gnc-customer-gda.c
===================================================================
--- gnucash/branches/gda-dev/src/business/business-core/gda/gnc-customer-gda.c	                        (rev 0)
+++ gnucash/branches/gda-dev/src/business/business-core/gda/gnc-customer-gda.c	2007-12-22 00:40:22 UTC (rev 16692)
@@ -0,0 +1,185 @@
+/********************************************************************\
+ * gnc-customer-gda.c -- customer gda backend                       *
+ *                                                                  *
+ * 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, contact:                        *
+ *                                                                  *
+ * Free Software Foundation           Voice:  +1-617-542-5942       *
+ * 51 Franklin Street, Fifth Floor    Fax:    +1-617-542-2652       *
+ * Boston, MA  02110-1301,  USA       gnu at gnu.org                   *
+ *                                                                  *
+\********************************************************************/
+
+#include "config.h"
+
+#include <glib.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <libgda/libgda.h>
+
+#include "gnc-backend-util-gda.h"
+
+#include "gncBillTermP.h"
+#include "gncCustomerP.h"
+#include "gncTaxTableP.h"
+#include "gnc-customer-gda.h"
+#include "gnc-address-gda.h"
+#include "gnc-bill-term-gda.h"
+
+#define _GNC_MOD_NAME	GNC_ID_CUSTOMER
+
+static QofLogModule log_module = GNC_MOD_BACKEND;
+
+#define TABLE_NAME "customers"
+
+#define MAX_NAME_LEN 50
+#define MAX_ID_LEN 50
+#define MAX_NOTES_LEN 50
+
+static col_cvt_t col_table[] =
+{
+	{ "guid",         CT_GUID,    0,             COL_NNUL, "guid" },
+	{ "name",         CT_STRING,  MAX_NAME_LEN,  COL_NNUL, NULL, CUSTOMER_NAME },
+	{ "id",           CT_STRING,  MAX_ID_LEN,    COL_NNUL, NULL, CUSTOMER_ID },
+	{ "notes",        CT_STRING,  MAX_NOTES_LEN, COL_NNUL, NULL, CUSTOMER_NOTES },
+	{ "active",       CT_BOOLEAN, 0,             COL_NNUL, NULL, QOF_PARAM_ACTIVE },
+	{ "discount",     CT_NUMERIC, 0,             COL_NNUL, NULL, CUSTOMER_DISCOUNT },
+	{ "credit",       CT_NUMERIC, 0,             COL_NNUL, NULL, CUSTOMER_CREDIT },
+	{ "currency",     CT_GUID_C,  0,             COL_NNUL, NULL, NULL,
+			(QofAccessFunc)gncCustomerGetCurrency, (QofSetterFunc)gncCustomerSetCurrency },
+	{ "tax_override", CT_BOOLEAN, 0,             COL_NNUL, NULL, CUSTOMER_TT_OVER },
+	{ NULL }
+};
+
+#if 0
+/* ids */
+#define cust_addr_string "cust:addr"
+#define cust_shipaddr_string "cust:shipaddr"
+#define cust_terms_string "cust:terms"
+#define cust_taxincluded_string "cust:taxincluded"
+#define cust_taxtable_string "cust:taxtable"
+
+    xmlAddChild(ret, gnc_address_to_dom_tree(cust_addr_string,
+					     gncCustomerGetAddr (cust)));
+    
+    xmlAddChild(ret, gnc_address_to_dom_tree(cust_shipaddr_string,
+					     gncCustomerGetShipAddr (cust)));
+    
+    term = gncCustomerGetTerms (cust);
+    if (term)
+      xmlAddChild(ret, guid_to_dom_tree(cust_terms_string,
+					qof_instance_get_guid (QOF_INSTANCE(term))));
+
+    xmlAddChild(ret, text_to_dom_tree(cust_taxincluded_string,
+				      gncTaxIncludedTypeToString (
+				     gncCustomerGetTaxIncluded (cust))));
+
+    taxtable = gncCustomerGetTaxTable (cust);
+    if (taxtable)
+      xmlAddChild (ret, guid_to_dom_tree (cust_taxtable_string,
+					  qof_instance_get_guid(QOF_INSTANCE(taxtable))));
+#endif
+
+static GncCustomer*
+load_single_customer( GncGdaBackend* be, GdaDataModel* pModel, int row )
+{
+    const GUID* guid;
+    GUID customer_guid;
+	GncCustomer* pCustomer;
+
+    guid = gnc_gda_load_guid( be, pModel, row );
+    customer_guid = *guid;
+
+    pCustomer = gncCustomerLookup( be->primary_book, &customer_guid );
+    if( pCustomer == NULL ) {
+        pCustomer = gncCustomerCreate( be->primary_book );
+    }
+    gnc_gda_load_object( be, pModel, row, GNC_ID_CUSTOMER, pCustomer, col_table );
+    gnc_gda_slots_load( be, qof_instance_get_guid( QOF_INSTANCE( pCustomer )),
+                        qof_instance_get_slots( QOF_INSTANCE(pCustomer) ) );
+
+    qof_instance_mark_clean( QOF_INSTANCE(pCustomer) );
+
+    return pCustomer;
+}
+
+static void
+load_all_customers( GncGdaBackend* be )
+{
+    static GdaQuery* query = NULL;
+    GdaObject* ret;
+    QofBook* pBook = be->primary_book;
+
+    /* First time, create the query */
+    if( query == NULL ) {
+        query = gnc_gda_create_select_query( be, TABLE_NAME );
+    }
+
+    ret = gnc_gda_execute_query( be, query );
+    if( GDA_IS_DATA_MODEL( ret ) ) {
+        GdaDataModel* pModel = GDA_DATA_MODEL(ret);
+        int numRows = gda_data_model_get_n_rows( pModel );
+        int r;
+
+        for( r = 0; r < numRows; r++ ) {
+            (void)load_single_customer( be, pModel, r );
+		}
+    }
+}
+
+/* ================================================================= */
+static void
+create_customer_tables( GncGdaBackend* be )
+{
+    gnc_gda_create_table_if_needed( be, TABLE_NAME, col_table );
+}
+
+/* ================================================================= */
+void
+gnc_gda_save_customer( GncGdaBackend* be, QofInstance* inst )
+{
+    GncCustomer* customer = GNC_CUSTOMER(inst);
+    const GUID* guid;
+
+    (void)gnc_gda_do_db_operation( be,
+                        (qof_instance_get_destroying(inst) ? OP_DB_DELETE : OP_DB_ADD_OR_UPDATE ),
+                        TABLE_NAME,
+                        GNC_ID_CUSTOMER, customer,
+                        col_table );
+
+    // Now, commit or delete any slots
+    guid = qof_instance_get_guid( inst );
+    if( !qof_instance_get_destroying(inst) ) {
+        gnc_gda_slots_save( be, guid, qof_instance_get_slots( inst ) );
+    } else {
+        gnc_gda_slots_delete( be, guid );
+    }
+}
+
+/* ================================================================= */
+void
+gnc_customer_gda_initialize( void )
+{
+    static GncGdaDataType_t be_data =
+    {
+        GNC_GDA_BACKEND_VERSION,
+        GNC_ID_CUSTOMER,
+        gnc_gda_save_customer,				/* commit */
+        load_all_customers,					/* initial_load */
+        create_customer_tables				/* create_tables */
+    };
+
+    qof_object_register_backend( GNC_ID_CUSTOMER, GNC_GDA_BACKEND, &be_data );
+}
+/* ========================== END OF FILE ===================== */

Added: gnucash/branches/gda-dev/src/business/business-core/gda/gnc-customer-gda.h
===================================================================
--- gnucash/branches/gda-dev/src/business/business-core/gda/gnc-customer-gda.h	                        (rev 0)
+++ gnucash/branches/gda-dev/src/business/business-core/gda/gnc-customer-gda.h	2007-12-22 00:40:22 UTC (rev 16692)
@@ -0,0 +1,35 @@
+/*
+ * gnc-customer-gda.h -- customer gda backend
+ *
+ * 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, contact:
+ *
+ * Free Software Foundation           Voice:  +1-617-542-5942
+ * 51 Franklin Street, Fifth Floor    Fax:    +1-617-542-2652
+ * Boston, MA  02110-1301,  USA       gnu at gnu.org
+ */
+
+/** @file gnc-customer-gda.h
+ *  @brief load and save customer data to SQL via libgda
+ *  @author Copyright (c) 2007 Phil Longstaff <plongstaff at rogers.com>
+ *
+ * This file implements the top-level QofBackend API for saving/
+ * restoring data to/from an SQL database via libgda
+ */
+
+#ifndef GNC_CUSTOMER_GDA_H
+#define GNC_CUSTOMER_GDA_H
+
+void gnc_customer_gda_initialize( void );
+
+#endif /* GNC_CUSTOMER_GDA_H */

Added: gnucash/branches/gda-dev/src/business/business-core/gda/gnc-employee-gda.c
===================================================================
--- gnucash/branches/gda-dev/src/business/business-core/gda/gnc-employee-gda.c	                        (rev 0)
+++ gnucash/branches/gda-dev/src/business/business-core/gda/gnc-employee-gda.c	2007-12-22 00:40:22 UTC (rev 16692)
@@ -0,0 +1,165 @@
+/********************************************************************\
+ * gnc-employee-xml-v2.c -- employee xml i/o implementation         *
+ *                                                                  *
+ * Copyright (C) 2002 Derek Atkins <warlord at MIT.EDU>                *
+ *                                                                  *
+ * 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, contact:                        *
+ *                                                                  *
+ * Free Software Foundation           Voice:  +1-617-542-5942       *
+ * 51 Franklin Street, Fifth Floor    Fax:    +1-617-542-2652       *
+ * Boston, MA  02110-1301,  USA       gnu at gnu.org                   *
+ *                                                                  *
+\********************************************************************/
+
+#include "config.h"
+
+#include <glib.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <libgda/libgda.h>
+
+#include "gncEmployeeP.h"
+#include "gnc-employee-gda.h"
+#include "gnc-address-gda.h"
+#include "gnc-commodity.h"
+
+#include "gnc-backend-util-gda.h"
+
+#define _GNC_MOD_NAME	GNC_ID_EMPLOYEE
+
+static QofLogModule log_module = GNC_MOD_BACKEND;
+
+#define MAX_USERNAME_LEN 50
+#define MAX_ID_LEN 50
+#define MAX_LANGUAGE_LEN 50
+#define MAX_ACL_LEN 50
+
+#define employee_addr_string "employee:addr"
+
+#define TABLE_NAME "employees"
+
+static col_cvt_t col_table[] =
+{
+	{ "guid",       CT_GUID,    0,                COL_NNUL, "guid" },
+	{ "username",   CT_STRING,  MAX_USERNAME_LEN, COL_NNUL, NULL, EMPLOYEE_USERNAME },
+	{ "id",         CT_STRING,  MAX_ID_LEN,       COL_NNUL, NULL, EMPLOYEE_ID },
+	{ "language",   CT_STRING,  MAX_LANGUAGE_LEN, COL_NNUL, NULL, EMPLOYEE_LANGUAGE },
+	{ "acl",        CT_STRING,  MAX_ACL_LEN,      COL_NNUL, NULL, EMPLOYEE_ACL },
+	{ "active",     CT_BOOLEAN, 0,                COL_NNUL, NULL, NULL,
+			(QofAccessFunc)gncEmployeeGetActive, (QofSetterFunc)gncEmployeeSetActive },
+	{ "currency",   CT_GUID_C,  0,                COL_NNUL, NULL, NULL,
+			(QofAccessFunc)gncEmployeeGetCurrency, (QofSetterFunc)gncEmployeeSetCurrency },
+	{ "ccard_guid", CT_GUID_A,  0,                COL_NNUL, NULL, EMPLOYEE_CC },
+	{ "workday",    CT_NUMERIC, 0,                COL_NNUL, NULL, EMPLOYEE_WORKDAY },
+	{ "rate",       CT_NUMERIC, 0,                COL_NNUL, NULL, EMPLOYEE_RATE },
+    { NULL }
+};
+
+static GncEmployee*
+load_single_employee( GncGdaBackend* be, GdaDataModel* pModel, int row )
+{
+    const GUID* guid;
+    GUID emp_guid;
+	GncEmployee* pEmployee;
+
+    guid = gnc_gda_load_guid( be, pModel, row );
+    emp_guid = *guid;
+
+    pEmployee = gncEmployeeLookup( be->primary_book, &emp_guid );
+    if( pEmployee == NULL ) {
+        pEmployee = gncEmployeeCreate( be->primary_book );
+    }
+    gnc_gda_load_object( be, pModel, row, GNC_ID_EMPLOYEE, pEmployee, col_table );
+    gnc_gda_slots_load( be, qof_instance_get_guid( QOF_INSTANCE( pEmployee )),
+                        qof_instance_get_slots( QOF_INSTANCE(pEmployee) ) );
+
+    qof_instance_mark_clean( QOF_INSTANCE(pEmployee) );
+
+    return pEmployee;
+}
+
+static void
+load_all_employees( GncGdaBackend* be )
+{
+    static GdaQuery* query = NULL;
+    GdaObject* ret;
+    QofBook* pBook = be->primary_book;
+    gnc_commodity_table* pTable = gnc_commodity_table_get_table( pBook );
+
+    /* First time, create the query */
+    if( query == NULL ) {
+        query = gnc_gda_create_select_query( be, TABLE_NAME );
+    }
+
+    ret = gnc_gda_execute_query( be, query );
+    if( GDA_IS_DATA_MODEL( ret ) ) {
+        GdaDataModel* pModel = GDA_DATA_MODEL(ret);
+        int numRows = gda_data_model_get_n_rows( pModel );
+        int r;
+
+        for( r = 0; r < numRows; r++ ) {
+            (void)load_single_employee( be, pModel, r );
+		}
+    }
+}
+
+/* ================================================================= */
+static void
+create_employee_tables( GncGdaBackend* be )
+{
+    gnc_gda_create_table_if_needed( be, TABLE_NAME, col_table );
+}
+
+/* ================================================================= */
+void
+gnc_gda_save_employee( GncGdaBackend* be, QofInstance* inst )
+{
+    GncEmployee* emp = GNC_EMPLOYEE(inst);
+    const GUID* guid;
+
+    // Ensure the commodity is in the db
+    gnc_gda_save_commodity( be, gncEmployeeGetCurrency( emp ) );
+
+    (void)gnc_gda_do_db_operation( be,
+                        (qof_instance_get_destroying(inst) ? OP_DB_DELETE : OP_DB_ADD_OR_UPDATE ),
+                        TABLE_NAME,
+                        GNC_ID_EMPLOYEE, emp,
+                        col_table );
+
+    // Now, commit or delete any slots
+    guid = qof_instance_get_guid( inst );
+    if( !qof_instance_get_destroying(inst) ) {
+        gnc_gda_slots_save( be, guid, qof_instance_get_slots( inst ) );
+    } else {
+        gnc_gda_slots_delete( be, guid );
+    }
+}
+
+/* ================================================================= */
+void
+gnc_employee_gda_initialize( void )
+{
+    static GncGdaDataType_t be_data =
+    {
+        GNC_GDA_BACKEND_VERSION,
+        GNC_ID_EMPLOYEE,
+        gnc_gda_save_employee,				/* commit */
+        load_all_employees,					/* initial_load */
+        create_employee_tables				/* create_tables */
+    };
+
+    qof_object_register_backend( GNC_ID_EMPLOYEE, GNC_GDA_BACKEND, &be_data );
+}
+/* ========================== END OF FILE ===================== */

Added: gnucash/branches/gda-dev/src/business/business-core/gda/gnc-employee-gda.h
===================================================================
--- gnucash/branches/gda-dev/src/business/business-core/gda/gnc-employee-gda.h	                        (rev 0)
+++ gnucash/branches/gda-dev/src/business/business-core/gda/gnc-employee-gda.h	2007-12-22 00:40:22 UTC (rev 16692)
@@ -0,0 +1,35 @@
+/*
+ * gnc-employee-gda.h -- employee gda backend
+ *
+ * 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, contact:
+ *
+ * Free Software Foundation           Voice:  +1-617-542-5942
+ * 51 Franklin Street, Fifth Floor    Fax:    +1-617-542-2652
+ * Boston, MA  02110-1301,  USA       gnu at gnu.org
+ */
+
+/** @file gnc-employee-gda.h
+ *  @brief load and save employee data to SQL via libgda
+ *  @author Copyright (c) 2007 Phil Longstaff <plongstaff at rogers.com>
+ *
+ * This file implements the top-level QofBackend API for saving/
+ * restoring data to/from an SQL database via libgda
+ */
+
+#ifndef GNC_EMPLOYEE_GDA_H
+#define GNC_EMPLOYEE_GDA_H
+
+void gnc_employee_gda_initialize( void );
+
+#endif /* GNC_EMPLOYEE_GDA_H */

Added: gnucash/branches/gda-dev/src/business/business-core/gda/gnc-invoice-gda.c
===================================================================
--- gnucash/branches/gda-dev/src/business/business-core/gda/gnc-invoice-gda.c	                        (rev 0)
+++ gnucash/branches/gda-dev/src/business/business-core/gda/gnc-invoice-gda.c	2007-12-22 00:40:22 UTC (rev 16692)
@@ -0,0 +1,202 @@
+/********************************************************************\
+ * gnc-invoice-gda.c - invoice gda backend                          *
+ *                                                                  *
+ * 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, contact:                        *
+ *                                                                  *
+ * Free Software Foundation           Voice:  +1-617-542-5942       *
+ * 51 Franklin Street, Fifth Floor    Fax:    +1-617-542-2652       *
+ * Boston, MA  02110-1301,  USA       gnu at gnu.org                   *
+ *                                                                  *
+\********************************************************************/
+
+#include "config.h"
+
+#include <glib.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <libgda/libgda.h>
+
+#include "gnc-backend-util-gda.h"
+
+#include "gncBillTermP.h"
+#include "gncInvoiceP.h"
+#include "gnc-invoice-gda.h"
+#include "gnc-owner-gda.h"
+#include "gnc-bill-term-gda.h"
+
+#define _GNC_MOD_NAME	GNC_ID_INVOICE
+
+static QofLogModule log_module = GNC_MOD_BACKEND;
+
+#define TABLE_NAME "invoices"
+
+#define MAX_ID_LEN 50
+#define MAX_NOTES_LEN 100
+
+static col_cvt_t col_table[] =
+{
+	{ "guid",         CT_GUID,     0,             COL_NNUL, "guid" },
+	{ "id",           CT_STRING,   MAX_ID_LEN,    COL_NNUL, NULL, INVOICE_ID },
+	{ "date_opened",  CT_TIMESPEC, 0,             COL_NNUL, NULL, INVOICE_OPENED },
+	{ "date_posted",  CT_TIMESPEC, 0,             0,        NULL, INVOICE_POSTED },
+	{ "notes",        CT_STRING,   MAX_NOTES_LEN, COL_NNUL, NULL, INVOICE_NOTES },
+	{ "active",       CT_BOOLEAN,  0,             COL_NNUL, NULL, QOF_PARAM_ACTIVE },
+	{ "currency",     CT_GUID_C,   0,             COL_NNUL, NULL, NULL,
+			(QofAccessFunc)gncInvoiceGetCurrency, (QofSetterFunc)gncInvoiceSetCurrency },
+	{ NULL }
+};
+
+#if 0
+/* ids */
+
+#define invoice_owner_string "invoice:owner"
+#define invoice_terms_string "invoice:terms"
+#define invoice_billing_id_string "invoice:billing_id"
+#define invoice_posttxn_string "invoice:posttxn"
+#define invoice_postlot_string "invoice:postlot"
+#define invoice_postacc_string "invoice:postacc"
+#define invoice_billto_string "invoice:billto"
+#define invoice_tochargeamt_string "invoice:charge-amt"
+
+    xmlAddChild(ret, gnc_owner_to_dom_tree (invoice_owner_string,
+					    gncInvoiceGetOwner (invoice)));
+
+    term = gncInvoiceGetTerms (invoice);
+    if (term)
+      xmlAddChild(ret, guid_to_dom_tree(invoice_terms_string,
+					qof_instance_get_guid (QOF_INSTANCE(term))));
+      
+    maybe_add_string (ret, invoice_billing_id_string,
+		      gncInvoiceGetBillingID (invoice));
+
+    txn = gncInvoiceGetPostedTxn (invoice);
+    if (txn)
+      xmlAddChild (ret, guid_to_dom_tree (invoice_posttxn_string,
+					  xaccTransGetGUID (txn)));
+
+    lot = gncInvoiceGetPostedLot (invoice);
+    if (lot)
+      xmlAddChild (ret, guid_to_dom_tree (invoice_postlot_string,
+					  gnc_lot_get_guid (lot)));
+
+    acc = gncInvoiceGetPostedAcc (invoice);
+    if (acc)
+      xmlAddChild (ret, guid_to_dom_tree (invoice_postacc_string,
+					  qof_instance_get_guid(QOF_INSTANCE(acc))));
+
+    billto = gncInvoiceGetBillTo (invoice);
+    if (billto && billto->owner.undefined != NULL)
+      xmlAddChild (ret, gnc_owner_to_dom_tree (invoice_billto_string, billto));
+
+    amt = gncInvoiceGetToChargeAmount (invoice);
+    if (! gnc_numeric_zero_p (amt))
+      xmlAddChild (ret, gnc_numeric_to_dom_tree (invoice_tochargeamt_string, &amt));
+#endif
+
+static GncInvoice*
+load_single_invoice( GncGdaBackend* be, GdaDataModel* pModel, int row )
+{
+    const GUID* guid;
+    GUID v_guid;
+	GncInvoice* pInvoice;
+
+    guid = gnc_gda_load_guid( be, pModel, row );
+    v_guid = *guid;
+
+    pInvoice = gncInvoiceLookup( be->primary_book, &v_guid );
+    if( pInvoice == NULL ) {
+        pInvoice = gncInvoiceCreate( be->primary_book );
+    }
+    gnc_gda_load_object( be, pModel, row, GNC_ID_INVOICE, pInvoice, col_table );
+    gnc_gda_slots_load( be, qof_instance_get_guid( QOF_INSTANCE( pInvoice )),
+                        qof_instance_get_slots( QOF_INSTANCE(pInvoice) ) );
+
+    qof_instance_mark_clean( QOF_INSTANCE(pInvoice) );
+
+    return pInvoice;
+}
+
+static void
+load_all_invoices( GncGdaBackend* be )
+{
+    static GdaQuery* query = NULL;
+    GdaObject* ret;
+    QofBook* pBook = be->primary_book;
+
+    /* First time, create the query */
+    if( query == NULL ) {
+        query = gnc_gda_create_select_query( be, TABLE_NAME );
+    }
+
+    ret = gnc_gda_execute_query( be, query );
+    if( GDA_IS_DATA_MODEL( ret ) ) {
+        GdaDataModel* pModel = GDA_DATA_MODEL(ret);
+        int numRows = gda_data_model_get_n_rows( pModel );
+        int r;
+
+        for( r = 0; r < numRows; r++ ) {
+            (void)load_single_invoice( be, pModel, r );
+		}
+    }
+}
+
+/* ================================================================= */
+static void
+create_invoice_tables( GncGdaBackend* be )
+{
+    gnc_gda_create_table_if_needed( be, TABLE_NAME, col_table );
+}
+
+/* ================================================================= */
+void
+gnc_gda_save_invoice( GncGdaBackend* be, QofInstance* inst )
+{
+    GncInvoice* v = GNC_INVOICE(inst);
+    const GUID* guid;
+
+    // Ensure the commodity is in the db
+    gnc_gda_save_commodity( be, gncInvoiceGetCurrency( v ) );
+
+    (void)gnc_gda_do_db_operation( be,
+                        (qof_instance_get_destroying(inst) ? OP_DB_DELETE : OP_DB_ADD_OR_UPDATE ),
+                        TABLE_NAME,
+                        GNC_ID_INVOICE, v,
+                        col_table );
+
+    // Now, commit or delete any slots
+    guid = qof_instance_get_guid( inst );
+    if( !qof_instance_get_destroying(inst) ) {
+        gnc_gda_slots_save( be, guid, qof_instance_get_slots( inst ) );
+    } else {
+        gnc_gda_slots_delete( be, guid );
+    }
+}
+
+/* ================================================================= */
+void
+gnc_invoice_gda_initialize( void )
+{
+    static GncGdaDataType_t be_data =
+    {
+        GNC_GDA_BACKEND_VERSION,
+        GNC_ID_INVOICE,
+        gnc_gda_save_invoice,				/* commit */
+        load_all_invoices,					/* initial_load */
+        create_invoice_tables				/* create_tables */
+    };
+
+    qof_object_register_backend( GNC_ID_INVOICE, GNC_GDA_BACKEND, &be_data );
+}
+/* ========================== END OF FILE ===================== */

Added: gnucash/branches/gda-dev/src/business/business-core/gda/gnc-invoice-gda.h
===================================================================
--- gnucash/branches/gda-dev/src/business/business-core/gda/gnc-invoice-gda.h	                        (rev 0)
+++ gnucash/branches/gda-dev/src/business/business-core/gda/gnc-invoice-gda.h	2007-12-22 00:40:22 UTC (rev 16692)
@@ -0,0 +1,35 @@
+/*
+ * gnc-invoice-gda.h -- invoice gda backend
+ *
+ * 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, contact:
+ *
+ * Free Software Foundation           Voice:  +1-617-542-5942
+ * 51 Franklin Street, Fifth Floor    Fax:    +1-617-542-2652
+ * Boston, MA  02110-1301,  USA       gnu at gnu.org
+ */
+
+/** @file gnc-invoice-gda.h
+ *  @brief load and save invoice data to SQL via libgda
+ *  @author Copyright (c) 2007 Phil Longstaff <plongstaff at rogers.com>
+ *
+ * This file implements the top-level QofBackend API for saving/
+ * restoring data to/from an SQL database via libgda
+ */
+
+#ifndef GNC_INVOICE_GDA_H
+#define GNC_INVOICE_GDA_H
+
+void gnc_invoice_gda_initialize( void );
+
+#endif /* GNC_INVOICE_GDA_H */

Added: gnucash/branches/gda-dev/src/business/business-core/gda/gnc-job-gda.c
===================================================================
--- gnucash/branches/gda-dev/src/business/business-core/gda/gnc-job-gda.c	                        (rev 0)
+++ gnucash/branches/gda-dev/src/business/business-core/gda/gnc-job-gda.c	2007-12-22 00:40:22 UTC (rev 16692)
@@ -0,0 +1,157 @@
+/********************************************************************\
+ * gnc-job-gda.c -- job gda backend                                 *
+ *                                                                  *
+ * 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, contact:                        *
+ *                                                                  *
+ * Free Software Foundation           Voice:  +1-617-542-5942       *
+ * 51 Franklin Street, Fifth Floor    Fax:    +1-617-542-2652       *
+ * Boston, MA  02110-1301,  USA       gnu at gnu.org                   *
+ *                                                                  *
+\********************************************************************/
+
+#include "config.h"
+
+#include <glib.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <libgda/libgda.h>
+
+#include "gnc-backend-util-gda.h"
+
+#include "gncJobP.h"
+#include "gnc-job-gda.h"
+#include "gnc-owner-gda.h"
+
+#define _GNC_MOD_NAME	GNC_ID_JOB
+
+static QofLogModule log_module = GNC_MOD_BACKEND;
+
+#define TABLE_NAME "jobs"
+
+#define MAX_ID_LEN 50
+#define MAX_NAME_LEN 50
+#define MAX_REFERENCE_LEN 50
+
+#if 0
+/* ids */
+#define job_owner_string "job:owner"
+#define job_slots_string "job:slots"
+
+    xmlAddChild(ret, gnc_owner_to_dom_tree (job_owner_string,
+					    gncJobGetOwner (job)));
+#endif
+
+static col_cvt_t col_table[] =
+{
+	{ "guid",         CT_GUID,    0,                 COL_NNUL, "guid" },
+	{ "id",           CT_STRING,  MAX_ID_LEN,        COL_NNUL, NULL, JOB_ID },
+	{ "name",         CT_STRING,  MAX_NAME_LEN,      COL_NNUL, NULL, JOB_NAME },
+	{ "reference",    CT_STRING,  MAX_REFERENCE_LEN, COL_NNUL, NULL, JOB_REFERENCE },
+	{ "active",       CT_BOOLEAN, 0,                 COL_NNUL, NULL, JOB_ACTIVE },
+	{ NULL }
+};
+
+static GncJob*
+load_single_job( GncGdaBackend* be, GdaDataModel* pModel, int row )
+{
+    const GUID* guid;
+    GUID job_guid;
+	GncJob* pJob;
+
+    guid = gnc_gda_load_guid( be, pModel, row );
+    job_guid = *guid;
+
+    pJob = gncJobLookup( be->primary_book, &job_guid );
+    if( pJob == NULL ) {
+        pJob = gncJobCreate( be->primary_book );
+    }
+    gnc_gda_load_object( be, pModel, row, GNC_ID_JOB, pJob, col_table );
+    gnc_gda_slots_load( be, qof_instance_get_guid( QOF_INSTANCE( pJob )),
+                        qof_instance_get_slots( QOF_INSTANCE(pJob) ) );
+
+    qof_instance_mark_clean( QOF_INSTANCE(pJob) );
+
+    return pJob;
+}
+
+static void
+load_all_jobs( GncGdaBackend* be )
+{
+    static GdaQuery* query = NULL;
+    GdaObject* ret;
+    QofBook* pBook = be->primary_book;
+
+    /* First time, create the query */
+    if( query == NULL ) {
+        query = gnc_gda_create_select_query( be, TABLE_NAME );
+    }
+
+    ret = gnc_gda_execute_query( be, query );
+    if( GDA_IS_DATA_MODEL( ret ) ) {
+        GdaDataModel* pModel = GDA_DATA_MODEL(ret);
+        int numRows = gda_data_model_get_n_rows( pModel );
+        int r;
+
+        for( r = 0; r < numRows; r++ ) {
+            (void)load_single_job( be, pModel, r );
+		}
+    }
+}
+
+/* ================================================================= */
+static void
+create_job_tables( GncGdaBackend* be )
+{
+    gnc_gda_create_table_if_needed( be, TABLE_NAME, col_table );
+}
+
+/* ================================================================= */
+void
+gnc_gda_save_job( GncGdaBackend* be, QofInstance* inst )
+{
+    GncJob* job = GNC_JOB(inst);
+    const GUID* guid;
+
+    (void)gnc_gda_do_db_operation( be,
+                        (qof_instance_get_destroying(inst) ? OP_DB_DELETE : OP_DB_ADD_OR_UPDATE ),
+                        TABLE_NAME,
+                        GNC_ID_JOB, job,
+                        col_table );
+
+    // Now, commit or delete any slots
+    guid = qof_instance_get_guid( inst );
+    if( !qof_instance_get_destroying(inst) ) {
+        gnc_gda_slots_save( be, guid, qof_instance_get_slots( inst ) );
+    } else {
+        gnc_gda_slots_delete( be, guid );
+    }
+}
+
+/* ================================================================= */
+void
+gnc_job_gda_initialize( void )
+{
+    static GncGdaDataType_t be_data =
+    {
+        GNC_GDA_BACKEND_VERSION,
+        GNC_ID_JOB,
+        gnc_gda_save_job,				/* commit */
+        load_all_jobs,					/* initial_load */
+        create_job_tables				/* create_tables */
+    };
+
+    qof_object_register_backend( GNC_ID_JOB, GNC_GDA_BACKEND, &be_data );
+}
+/* ========================== END OF FILE ===================== */

Added: gnucash/branches/gda-dev/src/business/business-core/gda/gnc-job-gda.h
===================================================================
--- gnucash/branches/gda-dev/src/business/business-core/gda/gnc-job-gda.h	                        (rev 0)
+++ gnucash/branches/gda-dev/src/business/business-core/gda/gnc-job-gda.h	2007-12-22 00:40:22 UTC (rev 16692)
@@ -0,0 +1,35 @@
+/*
+ * gnc-job-gda.h -- job gda backend
+ *
+ * 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, contact:
+ *
+ * Free Software Foundation           Voice:  +1-617-542-5942
+ * 51 Franklin Street, Fifth Floor    Fax:    +1-617-542-2652
+ * Boston, MA  02110-1301,  USA       gnu at gnu.org
+ */
+
+/** @file gnc-job-gda.h
+ *  @brief load and save job data to SQL via libgda
+ *  @author Copyright (c) 2007 Phil Longstaff <plongstaff at rogers.com>
+ *
+ * This file implements the top-level QofBackend API for saving/
+ * restoring data to/from an SQL database via libgda
+ */
+
+#ifndef GNC_JOB_GDA_H
+#define GNC_JOB_GDA_H
+
+void gnc_job_gda_initialize( void );
+
+#endif /* GNC_JOB_GDA_H */

Added: gnucash/branches/gda-dev/src/business/business-core/gda/gnc-order-gda.c
===================================================================
--- gnucash/branches/gda-dev/src/business/business-core/gda/gnc-order-gda.c	                        (rev 0)
+++ gnucash/branches/gda-dev/src/business/business-core/gda/gnc-order-gda.c	2007-12-22 00:40:22 UTC (rev 16692)
@@ -0,0 +1,159 @@
+/********************************************************************\
+ * gnc-order-gda.c -- order gda backend                             *
+ *                                                                  *
+ * 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, contact:                        *
+ *                                                                  *
+ * Free Software Foundation           Voice:  +1-617-542-5942       *
+ * 51 Franklin Street, Fifth Floor    Fax:    +1-617-542-2652       *
+ * Boston, MA  02110-1301,  USA       gnu at gnu.org                   *
+ *                                                                  *
+\********************************************************************/
+
+#include "config.h"
+
+#include <glib.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <libgda/libgda.h>
+
+#include "gnc-backend-util-gda.h"
+
+#include "gncOrderP.h"
+
+#include "gnc-order-gda.h"
+#include "gnc-owner-gda.h"
+
+#define _GNC_MOD_NAME	GNC_ID_ORDER
+
+static QofLogModule log_module = GNC_MOD_BACKEND;
+
+#define TABLE_NAME "orders"
+
+#define MAX_ID_LEN 50
+#define MAX_NOTES_LEN 50
+#define MAX_REFERENCE_LEN 50
+
+static col_cvt_t col_table[] =
+{
+	{ "guid",        CT_GUID,     0,                 COL_NNUL, "guid" },
+	{ "id",          CT_STRING,   MAX_ID_LEN,        COL_NNUL, NULL, ORDER_ID },
+	{ "notes",       CT_STRING,   MAX_NOTES_LEN,     COL_NNUL, NULL, ORDER_NOTES },
+	{ "reference",   CT_STRING,   MAX_REFERENCE_LEN, COL_NNUL, NULL, ORDER_REFERENCE },
+	{ "active",      CT_BOOLEAN,  0,                 COL_NNUL, NULL, QOF_PARAM_ACTIVE },
+	{ "date_opened", CT_TIMESPEC, 0,                 COL_NNUL, NULL, ORDER_OPENED },
+	{ "date_closed", CT_TIMESPEC, 0,                 COL_NNUL, NULL, ORDER_CLOSED },
+	{ NULL },
+};
+
+#if 0
+/* ids */
+#define order_owner_string "order:owner"
+
+    xmlAddChild(ret, gnc_owner_to_dom_tree (order_owner_string,
+					    gncOrderGetOwner (order)));
+#endif
+
+static GncOrder*
+load_single_order( GncGdaBackend* be, GdaDataModel* pModel, int row )
+{
+    const GUID* guid;
+    GUID v_guid;
+	GncOrder* pOrder;
+
+    guid = gnc_gda_load_guid( be, pModel, row );
+    v_guid = *guid;
+
+    pOrder = gncOrderLookup( be->primary_book, &v_guid );
+    if( pOrder == NULL ) {
+        pOrder = gncOrderCreate( be->primary_book );
+    }
+    gnc_gda_load_object( be, pModel, row, GNC_ID_ORDER, pOrder, col_table );
+    gnc_gda_slots_load( be, qof_instance_get_guid( QOF_INSTANCE( pOrder )),
+                        qof_instance_get_slots( QOF_INSTANCE(pOrder) ) );
+
+    qof_instance_mark_clean( QOF_INSTANCE(pOrder) );
+
+    return pOrder;
+}
+
+static void
+load_all_orders( GncGdaBackend* be )
+{
+    static GdaQuery* query = NULL;
+    GdaObject* ret;
+    QofBook* pBook = be->primary_book;
+
+    /* First time, create the query */
+    if( query == NULL ) {
+        query = gnc_gda_create_select_query( be, TABLE_NAME );
+    }
+
+    ret = gnc_gda_execute_query( be, query );
+    if( GDA_IS_DATA_MODEL( ret ) ) {
+        GdaDataModel* pModel = GDA_DATA_MODEL(ret);
+        int numRows = gda_data_model_get_n_rows( pModel );
+        int r;
+
+        for( r = 0; r < numRows; r++ ) {
+            (void)load_single_order( be, pModel, r );
+		}
+    }
+}
+
+/* ================================================================= */
+static void
+create_order_tables( GncGdaBackend* be )
+{
+    gnc_gda_create_table_if_needed( be, TABLE_NAME, col_table );
+}
+
+/* ================================================================= */
+void
+gnc_gda_save_order( GncGdaBackend* be, QofInstance* inst )
+{
+    GncOrder* v = GNC_ORDER(inst);
+    const GUID* guid;
+
+    (void)gnc_gda_do_db_operation( be,
+                        (qof_instance_get_destroying(inst) ? OP_DB_DELETE : OP_DB_ADD_OR_UPDATE ),
+                        TABLE_NAME,
+                        GNC_ID_ORDER, v,
+                        col_table );
+
+    // Now, commit or delete any slots
+    guid = qof_instance_get_guid( inst );
+    if( !qof_instance_get_destroying(inst) ) {
+        gnc_gda_slots_save( be, guid, qof_instance_get_slots( inst ) );
+    } else {
+        gnc_gda_slots_delete( be, guid );
+    }
+}
+
+/* ================================================================= */
+void
+gnc_order_gda_initialize( void )
+{
+    static GncGdaDataType_t be_data =
+    {
+        GNC_GDA_BACKEND_VERSION,
+        GNC_ID_ORDER,
+        gnc_gda_save_order,				/* commit */
+        load_all_orders,				/* initial_load */
+        create_order_tables				/* create_tables */
+    };
+
+    qof_object_register_backend( GNC_ID_ORDER, GNC_GDA_BACKEND, &be_data );
+}
+/* ========================== END OF FILE ===================== */

Added: gnucash/branches/gda-dev/src/business/business-core/gda/gnc-order-gda.h
===================================================================
--- gnucash/branches/gda-dev/src/business/business-core/gda/gnc-order-gda.h	                        (rev 0)
+++ gnucash/branches/gda-dev/src/business/business-core/gda/gnc-order-gda.h	2007-12-22 00:40:22 UTC (rev 16692)
@@ -0,0 +1,35 @@
+/*
+ * gnc-order-gda.h -- order gda backend
+ *
+ * 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, contact:
+ *
+ * Free Software Foundation           Voice:  +1-617-542-5942
+ * 51 Franklin Street, Fifth Floor    Fax:    +1-617-542-2652
+ * Boston, MA  02110-1301,  USA       gnu at gnu.org
+ */
+
+/** @file gnc-order-gda.h
+ *  @brief load and save order data to SQL via libgda
+ *  @author Copyright (c) 2007 Phil Longstaff <plongstaff at rogers.com>
+ *
+ * This file implements the top-level QofBackend API for saving/
+ * restoring data to/from an SQL database via libgda
+ */
+
+#ifndef GNC_ORDER_GDA_H
+#define GNC_ORDER_GDA_H
+
+void gnc_order_gda_initialize( void );
+
+#endif /* GNC_ORDER_GDA_H */

Added: gnucash/branches/gda-dev/src/business/business-core/gda/gnc-vendor-gda.c
===================================================================
--- gnucash/branches/gda-dev/src/business/business-core/gda/gnc-vendor-gda.c	                        (rev 0)
+++ gnucash/branches/gda-dev/src/business/business-core/gda/gnc-vendor-gda.c	2007-12-22 00:40:22 UTC (rev 16692)
@@ -0,0 +1,189 @@
+/********************************************************************\
+ * gnc-vendor-gda.c -- vendor gda backend                           *
+ *                                                                  *
+ * Copyright (C) 2002 Derek Atkins <warlord at MIT.EDU>                *
+ *                                                                  *
+ * 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, contact:                        *
+ *                                                                  *
+ * Free Software Foundation           Voice:  +1-617-542-5942       *
+ * 51 Franklin Street, Fifth Floor    Fax:    +1-617-542-2652       *
+ * Boston, MA  02110-1301,  USA       gnu at gnu.org                   *
+ *                                                                  *
+\********************************************************************/
+
+#include "config.h"
+
+#include <glib.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <libgda/libgda.h>
+
+#include "gnc-backend-util-gda.h"
+
+#include "gnc-commodity.h"
+#include "gncBillTermP.h"
+#include "gncVendorP.h"
+#include "gncTaxTableP.h"
+#include "gnc-vendor-gda.h"
+#include "gnc-address-gda.h"
+#include "gnc-bill-term-gda.h"
+
+#define _GNC_MOD_NAME	GNC_ID_VENDOR
+
+static QofLogModule log_module = GNC_MOD_BACKEND;
+
+#define MAX_NAME_LEN 50
+#define MAX_ID_LEN 50
+#define MAX_NOTES_LEN 100
+
+#define TABLE_NAME "vendors"
+
+static col_cvt_t col_table[] =
+{
+	{ "guid",         CT_GUID,    0,             COL_NNUL, "guid" },
+	{ "name",         CT_STRING,  MAX_NAME_LEN,  COL_NNUL, NULL, VENDOR_NAME },
+	{ "id",           CT_STRING,  MAX_ID_LEN,    COL_NNUL, NULL, VENDOR_ID },
+	{ "notes",        CT_STRING,  MAX_NOTES_LEN, COL_NNUL, NULL, VENDOR_NOTES },
+	{ "currency",     CT_GUID_C,  0,             COL_NNUL, NULL, NULL,
+			(QofAccessFunc)gncVendorGetCurrency, (QofSetterFunc)gncVendorSetCurrency },
+	{ "active",       CT_BOOLEAN, 0,             COL_NNUL, NULL, NULL,
+			(QofAccessFunc)gncVendorGetActive, (QofSetterFunc)gncVendorSetActive },
+	{ "tax_override", CT_BOOLEAN, 0,             COL_NNUL, NULL, VENDOR_TAX_OVERRIDE },
+	{ NULL }
+};
+
+#if 0
+#define vendor_addr_string "vendor:addr"
+#define vendor_terms_string "vendor:terms"
+#define vendor_taxtable_string "vendor:taxtable"
+#define vendor_taxtableoverride_string "vendor:use-tt"
+#define vendor_slots_string "vendor:slots"
+
+    xmlAddChild(ret, gnc_address_to_dom_tree(vendor_addr_string,
+					     gncVendorGetAddr (vendor)));
+    
+    term = gncVendorGetTerms (vendor);
+    if (term)
+      xmlAddChild(ret, guid_to_dom_tree(vendor_terms_string,
+					qof_instance_get_guid(QOF_INSTANCE(term))));
+
+    xmlAddChild(ret, text_to_dom_tree(vendor_taxincluded_string,
+				      gncTaxIncludedTypeToString (
+				     gncVendorGetTaxIncluded (vendor))));
+
+    taxtable = gncVendorGetTaxTable (vendor);
+    if (taxtable)
+      xmlAddChild (ret, guid_to_dom_tree (vendor_taxtable_string,
+					  qof_instance_get_guid(QOF_INSTANCE(taxtable))));
+
+    return ret;
+}
+#endif
+
+static GncVendor*
+load_single_vendor( GncGdaBackend* be, GdaDataModel* pModel, int row )
+{
+    const GUID* guid;
+    GUID v_guid;
+	GncVendor* pVendor;
+
+    guid = gnc_gda_load_guid( be, pModel, row );
+    v_guid = *guid;
+
+    pVendor = gncVendorLookup( be->primary_book, &v_guid );
+    if( pVendor == NULL ) {
+        pVendor = gncVendorCreate( be->primary_book );
+    }
+    gnc_gda_load_object( be, pModel, row, GNC_ID_VENDOR, pVendor, col_table );
+    gnc_gda_slots_load( be, qof_instance_get_guid( QOF_INSTANCE( pVendor )),
+                        qof_instance_get_slots( QOF_INSTANCE(pVendor) ) );
+
+    qof_instance_mark_clean( QOF_INSTANCE(pVendor) );
+
+    return pVendor;
+}
+
+static void
+load_all_vendors( GncGdaBackend* be )
+{
+    static GdaQuery* query = NULL;
+    GdaObject* ret;
+    QofBook* pBook = be->primary_book;
+
+    /* First time, create the query */
+    if( query == NULL ) {
+        query = gnc_gda_create_select_query( be, TABLE_NAME );
+    }
+
+    ret = gnc_gda_execute_query( be, query );
+    if( GDA_IS_DATA_MODEL( ret ) ) {
+        GdaDataModel* pModel = GDA_DATA_MODEL(ret);
+        int numRows = gda_data_model_get_n_rows( pModel );
+        int r;
+
+        for( r = 0; r < numRows; r++ ) {
+            (void)load_single_vendor( be, pModel, r );
+		}
+    }
+}
+
+/* ================================================================= */
+static void
+create_vendor_tables( GncGdaBackend* be )
+{
+    gnc_gda_create_table_if_needed( be, TABLE_NAME, col_table );
+}
+
+/* ================================================================= */
+void
+gnc_gda_save_vendor( GncGdaBackend* be, QofInstance* inst )
+{
+    GncVendor* v = GNC_VENDOR(inst);
+    const GUID* guid;
+
+    // Ensure the commodity is in the db
+    gnc_gda_save_commodity( be, gncVendorGetCurrency( v ) );
+
+    (void)gnc_gda_do_db_operation( be,
+                        (qof_instance_get_destroying(inst) ? OP_DB_DELETE : OP_DB_ADD_OR_UPDATE ),
+                        TABLE_NAME,
+                        GNC_ID_VENDOR, v,
+                        col_table );
+
+    // Now, commit or delete any slots
+    guid = qof_instance_get_guid( inst );
+    if( !qof_instance_get_destroying(inst) ) {
+        gnc_gda_slots_save( be, guid, qof_instance_get_slots( inst ) );
+    } else {
+        gnc_gda_slots_delete( be, guid );
+    }
+}
+
+/* ================================================================= */
+void
+gnc_vendor_gda_initialize( void )
+{
+    static GncGdaDataType_t be_data =
+    {
+        GNC_GDA_BACKEND_VERSION,
+        GNC_ID_VENDOR,
+        gnc_gda_save_vendor,				/* commit */
+        load_all_vendors,					/* initial_load */
+        create_vendor_tables				/* create_tables */
+    };
+
+    qof_object_register_backend( GNC_ID_VENDOR, GNC_GDA_BACKEND, &be_data );
+}
+/* ========================== END OF FILE ===================== */

Added: gnucash/branches/gda-dev/src/business/business-core/gda/gnc-vendor-gda.h
===================================================================
--- gnucash/branches/gda-dev/src/business/business-core/gda/gnc-vendor-gda.h	                        (rev 0)
+++ gnucash/branches/gda-dev/src/business/business-core/gda/gnc-vendor-gda.h	2007-12-22 00:40:22 UTC (rev 16692)
@@ -0,0 +1,35 @@
+/*
+ * gnc-vendor-gda.h -- vendor gda backend
+ *
+ * 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, contact:
+ *
+ * Free Software Foundation           Voice:  +1-617-542-5942
+ * 51 Franklin Street, Fifth Floor    Fax:    +1-617-542-2652
+ * Boston, MA  02110-1301,  USA       gnu at gnu.org
+ */
+
+/** @file gnc-vendor-gda.h
+ *  @brief load and save vendor data to SQL via libgda
+ *  @author Copyright (c) 2007 Phil Longstaff <plongstaff at rogers.com>
+ *
+ * This file implements the top-level QofBackend API for saving/
+ * restoring data to/from an SQL database via libgda
+ */
+
+#ifndef GNC_VENDOR_GDA_H
+#define GNC_VENDOR_GDA_H
+
+void gnc_vendor_gda_initialize( void );
+
+#endif /* GNC_VENDOR_GDA_H */

Added: gnucash/branches/gda-dev/src/business/business-core/gda/gncmod-business-backend-gda.c
===================================================================
--- gnucash/branches/gda-dev/src/business/business-core/gda/gncmod-business-backend-gda.c	                        (rev 0)
+++ gnucash/branches/gda-dev/src/business/business-core/gda/gncmod-business-backend-gda.c	2007-12-22 00:40:22 UTC (rev 16692)
@@ -0,0 +1,109 @@
+/*********************************************************************
+ * gncmod-business-backend-gda.c
+ * module definition/initialization for the gda backend module
+ *
+ * Copyright (c) 2002 Derek Atkins <warlord at MIT.EDU>
+ *
+ * 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, contact:
+ *
+ * Free Software Foundation           Voice:  +1-617-542-5942
+ * 51 Franklin Street, Fifth Floor    Fax:    +1-617-542-2652
+ * Boston, MA  02110-1301,  USA       gnu at gnu.org
+ *
+ *********************************************************************/
+
+#include "config.h"
+#include <gmodule.h>
+
+#include "gnc-module.h"
+#include "gnc-module-api.h"
+#include "gnc-engine.h"
+
+#include "gnc-address-gda.h"
+#include "gnc-bill-term-gda.h"
+#include "gnc-customer-gda.h"
+#include "gnc-employee-gda.h"
+#include "gnc-entry-gda.h"
+#include "gnc-invoice-gda.h"
+#include "gnc-job-gda.h"
+#include "gnc-order-gda.h"
+#include "gnc-owner-gda.h"
+#include "gnc-tax-table-gda.h"
+#include "gnc-vendor-gda.h"
+
+GNC_MODULE_API_DECL(libgncmod_business_backend_gda)
+
+/* version of the gnc module system interface we require */
+int libgncmod_business_backend_gda_gnc_module_system_interface = 0;
+
+/* module versioning uses libtool semantics. */
+int libgncmod_business_backend_gda_gnc_module_current  = 0;
+int libgncmod_business_backend_gda_gnc_module_revision = 0;
+int libgncmod_business_backend_gda_gnc_module_age      = 0;
+
+static GNCModule bus_core;
+
+
+gchar *
+libgncmod_business_backend_gda_gnc_module_path(void)
+{
+  return g_strdup("gnucash/business-core-gda");
+}
+
+gchar *
+libgncmod_business_backend_gda_gnc_module_description(void)
+{
+  return g_strdup("The GDA backend for GnuCash business objects");
+}
+
+int
+libgncmod_business_backend_gda_gnc_module_init(int refcount)
+{
+  if(!gnc_engine_is_initialized()) { return FALSE; }
+
+  bus_core = gnc_module_load("gnucash/business-core", 0);
+  if(!bus_core) return FALSE;
+
+  if (refcount == 0) {
+    /* Initialize our pointers into the backend subsystem */
+//    gnc_address_gda_initialize ();
+//    gnc_billterm_gda_initialize ();
+    gnc_customer_gda_initialize ();
+    gnc_employee_gda_initialize ();
+//    gnc_entry_gda_initialize ();
+    gnc_invoice_gda_initialize ();
+    gnc_job_gda_initialize ();
+    gnc_order_gda_initialize ();
+//    gnc_owner_gda_initialize ();
+//    gnc_taxtable_gda_initialize ();
+    gnc_vendor_gda_initialize ();
+  }
+
+  return TRUE;
+}
+
+int
+libgncmod_business_backend_gda_gnc_module_end(int refcount)
+{
+  int unload = TRUE;
+
+  if (bus_core)
+    unload = gnc_module_unload(bus_core);
+
+  if (refcount == 0) {
+    bus_core = NULL;
+  }
+
+  return unload;
+}

Modified: gnucash/branches/gda-dev/src/business/business-gnome/business-gnome.scm
===================================================================
--- gnucash/branches/gda-dev/src/business/business-gnome/business-gnome.scm	2007-12-22 00:36:29 UTC (rev 16691)
+++ gnucash/branches/gda-dev/src/business/business-gnome/business-gnome.scm	2007-12-22 00:40:22 UTC (rev 16692)
@@ -5,7 +5,8 @@
 (gnc:module-load "gnucash/business-core" 0)
 (gnc:module-load "gnucash/business-utils" 0)
 (gnc:module-load "gnucash/gnome-search" 0)
-(gnc:module-load "gnucash/business-core-file" 0)
+(gnc:module-load "gnucash/business-core-xml" 0)
+(gnc:module-load "gnucash/business-core-gda" 0)
 (gnc:module-load "gnucash/dialog-tax-table" 0)
 
 (gnc:module-load "gnucash/report/report-gnome" 0)



More information about the gnucash-changes mailing list