start using the backend like its intended to be used ...

git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@2337 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
Linas Vepstas 2000-05-16 07:17:09 +00:00
parent 466f31bc60
commit 07e9c68777
2 changed files with 38 additions and 8 deletions

View File

@ -20,6 +20,15 @@
typedef struct _backend Backend;
/*
* trans_commit_edit() takes two transaction arguments:
* the first is the proposed new transaction; the second is the
* 'original' transaction. The second argument is here for
* convencience; it had better be substantially equivalent to
* the argument for the trans_begin_edit() callback. (It doesn't
* have to be identical, it can be a clone).
*/
struct _backend
{
AccountGroup * (*session_begin) (Session *, const char * sessionid);
@ -27,7 +36,7 @@ struct _backend
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_commit_edit) (Backend *, Transaction *new, Transaction *orig);
int (*trans_rollback_edit) (Backend *, Transaction *);
};

View File

@ -955,6 +955,7 @@ void
xaccTransBeginEdit (Transaction *trans, int defer)
{
char open;
Backend *be;
assert (trans);
open = trans->open;
@ -962,6 +963,12 @@ xaccTransBeginEdit (Transaction *trans, int defer)
if (defer) trans->open |= DEFER_REBALANCE;
if (open & BEGIN_EDIT) return;
/* See if there's a backend. If there is, invoke it. */
be = xaccTransactionGetBackend (trans);
if (be && be->trans_begin_edit) {
(be->trans_begin_edit) (be, trans, defer);
}
xaccOpenLog ();
xaccTransWriteLog (trans, 'B');
@ -974,7 +981,7 @@ xaccTransBeginEdit (Transaction *trans, int defer)
void
xaccTransCommitEdit (Transaction *trans)
{
int i;
int i, rc;
Split *split;
Account *acc;
Backend *be;
@ -1033,6 +1040,26 @@ xaccTransCommitEdit (Transaction *trans)
trans->open &= ~DEFER_REBALANCE;
xaccTransRebalance (trans);
/* ------------------------------------------------- */
/* OK, at this point, we are done making sure that
* we've got a validly constructed transaction.
* Next, we send it off to the back-end, to see if the
* back-end will accept it.
*/
/* See if there's a backend. If there is, invoke it. */
be = xaccTransactionGetBackend (trans);
if (be && be->trans_commit_edit) {
rc = (be->trans_commit_edit) (be, trans, trans->orig);
}
if (rc) {
/* if the backend puked, then we must roll-back
* at this point, and let the user know that we failed.
*/
}
/* ------------------------------------------------- */
/* Make sure all associated splits are in proper order
* in their accounts. */
i=0;
@ -1062,12 +1089,6 @@ xaccTransCommitEdit (Transaction *trans)
xaccFreeTransaction (trans->orig);
trans->orig = NULL;
/* see if there's a backend. If there is, invoke it */
be = xaccTransactionGetBackend (trans);
if (be) {
(be->trans_commit_edit) (be, trans);
}
LEAVE ("trans addr=%p\n", trans);
}