mirror of https://github.com/Gnucash/gnucash
some SQL backend prototyping work. git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@2309 57a11ea4-9604-0410-9ed3-97b8803252fdzzzoldreleases/1.4
parent
e92c343927
commit
565ae5fd90
@ -0,0 +1,95 @@
|
||||
/********************************************************************\
|
||||
* Backend.c -- utility routines for dealing with the data backend *
|
||||
* Copyright (C) 2000 Linas Vepstas <linas@linas.org> *
|
||||
* *
|
||||
* 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 *
|
||||
* 59 Temple Place - Suite 330 Fax: +1-617-542-2652 *
|
||||
* Boston, MA 02111-1307, USA gnu@gnu.org *
|
||||
* *
|
||||
\********************************************************************/
|
||||
|
||||
#include "Account.h"
|
||||
#include "AccountP.h"
|
||||
#include "BackendP.h"
|
||||
#include "Group.h"
|
||||
#include "GroupP.h"
|
||||
#include "TransactionP.h"
|
||||
#include "util.h"
|
||||
|
||||
/* static short module = MOD_ENGINE; */
|
||||
|
||||
|
||||
/********************************************************************\
|
||||
* Fetch the backend *
|
||||
\********************************************************************/
|
||||
|
||||
Backend *
|
||||
xaccAccountGetBackend (Account * acc)
|
||||
{
|
||||
Account *parent_acc;
|
||||
AccountGroup * grp;
|
||||
|
||||
if (!acc) return NULL;
|
||||
|
||||
/* find the first account group that has a backend */
|
||||
grp = (AccountGroup *) acc->parent;
|
||||
while (grp) {
|
||||
if (grp->backend) return (grp->backend);
|
||||
parent_acc = grp -> parent;
|
||||
grp = NULL;
|
||||
if (parent_acc) {
|
||||
grp = (AccountGroup *) parent_acc->parent;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/********************************************************************\
|
||||
* Fetch the backend *
|
||||
\********************************************************************/
|
||||
|
||||
Backend *
|
||||
xaccTransactionGetBackend (Transaction *trans)
|
||||
{
|
||||
Backend *be;
|
||||
Split *s;
|
||||
if (!trans) return NULL;
|
||||
|
||||
/* find an account */
|
||||
s = trans->splits[0];
|
||||
if (!s) return NULL;
|
||||
|
||||
/* I suppose it would be more 'technically correct' to make sure that
|
||||
* all splits share teh same backend, and flag an error if they
|
||||
* don't. However, at this point, it seems quite unlikely, so we'll
|
||||
* just use teh first backend we find.
|
||||
*/
|
||||
be = xaccAccountGetBackend (s->acc);
|
||||
return be;
|
||||
}
|
||||
|
||||
/********************************************************************\
|
||||
* Set the backend *
|
||||
\********************************************************************/
|
||||
|
||||
void
|
||||
xaccGroupSetBackend (AccountGroup *grp, Backend *be)
|
||||
{
|
||||
if (!grp) return;
|
||||
grp->backend = be;
|
||||
}
|
||||
|
||||
/************************* END OF FILE ********************************/
|
||||
@ -0,0 +1,55 @@
|
||||
/*
|
||||
* BackendP.h
|
||||
*
|
||||
* Pseudo-object defining how the engine can interact with different
|
||||
* back-ends (which will probably be sql databases).
|
||||
*
|
||||
* The callbacks will be called at the appropriate times during
|
||||
* a session to allow the backend to store the data as needed.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef __XACC_BACKEND_P_H__
|
||||
#define __XACC_BACKEND_P_H__
|
||||
|
||||
#include "config.h"
|
||||
#include "Account.h"
|
||||
#include "Group.h"
|
||||
#include "Session.h"
|
||||
#include "Transaction.h"
|
||||
|
||||
typedef struct _backend Backend;
|
||||
|
||||
struct _backend
|
||||
{
|
||||
AccountGroup * (*session_begin) (Session *, const char * sessionid);
|
||||
int (*session_end) (Session *);
|
||||
int (*account_begin_edit) (Backend *, Account *, int defer);
|
||||
int (*account_commit_edit) (Backend *, Account *);
|
||||
int (*trans_begin_edit) (Backend *, Transaction *, int defer);
|
||||
int (*trans_commit_edit) (Backend *, Transaction *);
|
||||
int (*trans_rollback_edit) (Backend *, Transaction *);
|
||||
};
|
||||
|
||||
/*
|
||||
* The xaccGetAccountBackend() subroutine will find the
|
||||
* persistent-data storage backend associated with this account.
|
||||
* This routine traverses up the account heirarchy until it
|
||||
* finds and account-group node that has a backend associated with
|
||||
* it. The assumption is that all accounts in that account-group
|
||||
* share a common back-end.
|
||||
*
|
||||
* The xaccGetTransactionBackend() subroutine does the same, for a given
|
||||
* transaction.
|
||||
*/
|
||||
|
||||
Backend * xaccAccountGetBackend (Account *);
|
||||
Backend * xaccTransactionGetBackend (Transaction *);
|
||||
|
||||
/*
|
||||
* The xaccGroupSetBackend() associates a backend to a group
|
||||
*/
|
||||
void xaccGroupSetBackend (AccountGroup *, Backend *);
|
||||
|
||||
|
||||
#endif /* __XACC_BACKEND_P_H__ */
|
||||
Loading…
Reference in new issue