Work on moving entity tables into sessions.

git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@5476 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
Dave Peticolas 2001-10-09 08:26:03 +00:00
parent 48ac2e2dcb
commit 7317297b6a
15 changed files with 170 additions and 114 deletions

View File

@ -42,7 +42,7 @@
#include "io-gncxml-gen.h"
#include "sixtp-dom-parsers.h"
#include "SchedXaction.h"
#include "SchedXactionP.h"
static short module = MOD_SX;

View File

@ -236,7 +236,7 @@ get_price_cb (PGBackend *be, PGresult *result, int j, gpointer data)
/* first, lets see if we've already got this one */
string_to_guid (DB_GET_VAL ("priceGuid", j), &guid);
pr = gnc_price_lookup (&guid);
pr = gnc_price_lookup (&guid, be->session);
if (!pr)
{

View File

@ -109,7 +109,7 @@ xaccInitAccount (Account * acc, GNCSession *session)
acc->entity_table = gnc_session_get_entity_table (session);
xaccGUIDNew(&acc->guid);
xaccStoreEntity(acc, &acc->guid, GNC_ID_ACCOUNT);
xaccStoreEntity(acc->entity_table, acc, &acc->guid, GNC_ID_ACCOUNT);
LEAVE ("account=%p\n", acc);
}
@ -167,7 +167,7 @@ xaccFreeAccount (Account *acc)
gnc_engine_generate_event (&acc->guid, GNC_EVENT_DESTROY);
xaccRemoveEntity(&acc->guid);
xaccRemoveEntity (acc->entity_table, &acc->guid);
if (acc->children)
{
@ -527,11 +527,12 @@ xaccAccountSetGUID (Account *account, const GUID *guid)
PINFO("acct=%p", account);
xaccAccountBeginEdit (account);
xaccRemoveEntity(&account->guid);
xaccRemoveEntity (account->entity_table, &account->guid);
account->guid = *guid;
xaccStoreEntity(account, &account->guid, GNC_ID_ACCOUNT);
xaccStoreEntity (account->entity_table, account,
&account->guid, GNC_ID_ACCOUNT);
account->core_dirty = TRUE;
xaccAccountCommitEdit (account);
}
@ -544,14 +545,16 @@ xaccAccountLookup (const GUID *guid, GNCSession *session)
{
if (!guid) return NULL;
g_return_val_if_fail (session, NULL);
return xaccLookupEntity (guid, GNC_ID_ACCOUNT);
return xaccLookupEntity (gnc_session_get_entity_table (session),
guid, GNC_ID_ACCOUNT);
}
Account *
xaccAccountLookupDirect (GUID guid, GNCSession *session)
{
g_return_val_if_fail (session, NULL);
return xaccLookupEntity (&guid, GNC_ID_ACCOUNT);
return xaccLookupEntity (gnc_session_get_entity_table (session),
&guid, GNC_ID_ACCOUNT);
}
Account *
@ -561,7 +564,7 @@ xaccAccountLookupEntityTable (const GUID *guid,
if (!guid) return NULL;
/* FIXME: uncomment when entity tables are in sessions */
/* g_return_val_if_fail (entity_table, NULL); */
return xaccLookupEntity (guid, GNC_ID_ACCOUNT);
return xaccLookupEntity (entity_table, guid, GNC_ID_ACCOUNT);
}
/********************************************************************\

View File

@ -86,11 +86,10 @@
#include "FreqSpecP.h"
#include "GNCIdP.h"
/*#include "Transaction.h"*/
/*#include "TransactionP.h"*/
#include "date.h"
#include "gnc-engine-util.h"
#include "gnc-event-p.h"
#include "gnc-session-p.h"
#include "messages.h"
/* I have done this to prevent compiler warnings...
@ -178,8 +177,10 @@ xaccFreqSpecInit( FreqSpec *fs, GNCSession *session )
g_return_if_fail( fs );
g_return_if_fail (session);
fs->entity_table = gnc_session_get_entity_table (session);
xaccGUIDNew( &fs->guid );
xaccStoreEntity( fs, &fs->guid, GNC_ID_FREQSPEC );
xaccStoreEntity( fs->entity_table, fs, &fs->guid, GNC_ID_FREQSPEC );
fs->type = INVALID;
fs->uift = UIFREQ_ONCE;
@ -229,7 +230,7 @@ xaccFreqSpecFree( FreqSpec *fs )
{
if ( fs == NULL ) return;
gnc_engine_generate_event( &fs->guid, GNC_EVENT_DESTROY );
xaccRemoveEntity( &fs->guid );
xaccRemoveEntity( fs->entity_table, &fs->guid );
xaccFreqSpecCleanUp( fs );

View File

@ -34,6 +34,7 @@ Currently the only files which include this file are:
#define XACC_FREQSPECP_H
#include "FreqSpec.h"
#include "GNCIdP.h"
/**
* Scheduled transactions have a frequency defined by a frequency
@ -107,6 +108,7 @@ struct gncp_freq_spec {
} composites;
} s;
GUID guid;
GNCEntityTable *entity_table;
};
#endif /* XACC_FREQSPECP_H */

View File

@ -172,7 +172,7 @@ entity_table_init(void)
entity_table = g_hash_table_new(id_hash, id_compare);
xaccStoreEntity(NULL, xaccGUIDNULL(), GNC_ID_NULL);
xaccStoreEntity(entity_table, NULL, xaccGUIDNULL(), GNC_ID_NULL);
#if GNCID_DEBUG
atexit(summarize_table);
@ -248,8 +248,9 @@ xaccGUIDNULL(void)
return &null_guid;
}
void *
xaccLookupEntity(const GUID * guid, GNCIdType entity_type)
gpointer
xaccLookupEntity (GNCEntityTable *entity_table_tmp,
const GUID * guid, GNCIdType entity_type)
{
EntityNode *e_node;
@ -270,7 +271,8 @@ xaccLookupEntity(const GUID * guid, GNCIdType entity_type)
}
void
xaccStoreEntity(void * entity, const GUID * guid, GNCIdType entity_type)
xaccStoreEntity (GNCEntityTable *entity_table_tmp, gpointer entity,
const GUID * guid, GNCIdType entity_type)
{
EntityNode *e_node;
GUID *new_guid;
@ -283,7 +285,7 @@ xaccStoreEntity(void * entity, const GUID * guid, GNCIdType entity_type)
if (guid_equal(guid, xaccGUIDNULL())) return;
xaccRemoveEntity(guid);
xaccRemoveEntity(entity_table, guid);
e_node = g_new(EntityNode, 1);
e_node->entity_type = entity_type;
@ -299,7 +301,7 @@ xaccStoreEntity(void * entity, const GUID * guid, GNCIdType entity_type)
}
void
xaccRemoveEntity(const GUID * guid)
xaccRemoveEntity (GNCEntityTable *entity_table_tmp, const GUID * guid)
{
EntityNode *e_node;
gpointer old_guid;

View File

@ -43,14 +43,17 @@ GUID xaccGUIDNewReturn (void);
/* Lookup an entity given an id and a type. If there is no entity
* associated with the id, or if it has a different type, NULL
* is returned. */
void * xaccLookupEntity (const GUID * guid, GNCIdType entity_type);
gpointer xaccLookupEntity (GNCEntityTable *entity_table,
const GUID * guid, GNCIdType entity_type);
/* Store the given entity under the given id with the given type. */
void xaccStoreEntity (void * entity, const GUID * guid, GNCIdType entity_type);
void xaccStoreEntity (GNCEntityTable *entity_table,
gpointer entity, const GUID * guid,
GNCIdType entity_type);
/* Remove any existing association between an entity and the given
* id. The entity is not changed in any way. */
void xaccRemoveEntity (const GUID * guid);
void xaccRemoveEntity (GNCEntityTable *entity_table, const GUID * guid);
GHashTable *xaccGetAndResetEntityTable (void);
void xaccSetEntityTable (GHashTable *et);

View File

@ -72,6 +72,7 @@ noinst_HEADERS = \
FreqSpecP.h \
GNCIdP.h \
GroupP.h \
SchedXactionP.h \
SX-ttinfo.h \
TransactionP.h \
gnc-book-p.h \

View File

@ -29,12 +29,12 @@
#include "FreqSpec.h"
#include "GNCIdP.h"
#include "SX-ttinfo.h"
#include "SchedXaction.h"
#include "SchedXactionP.h"
#include "TransactionP.h"
#include "date.h"
#include "gnc-engine-util.h"
#include "gnc-event-p.h"
#include "gnc-session.h"
#include "gnc-session-p.h"
#include "guid.h"
#include "messages.h"
@ -53,12 +53,15 @@ xaccSchedXactionInit( SchedXaction *sx, GNCSession *session)
AccountGroup *ag;
char *name;
sx->entity_table = gnc_session_get_entity_table (session);
sx->freq = xaccFreqSpecMalloc(session);
book = gnc_session_get_book (session);
xaccGUIDNew( &sx->guid );
xaccStoreEntity( sx, &sx->guid, GNC_ID_SCHEDXACTION );
xaccStoreEntity( sx->entity_table, sx,
&sx->guid, GNC_ID_SCHEDXACTION );
g_date_clear( &sx->last_date, 1 );
g_date_clear( &sx->start_date, 1 );
g_date_clear( &sx->end_date, 1 );
@ -150,13 +153,11 @@ xaccSchedXactionFree( SchedXaction *sx )
xaccFreqSpecFree( sx->freq );
gnc_engine_generate_event( &sx->guid, GNC_EVENT_DESTROY );
xaccRemoveEntity( &sx->guid );
xaccRemoveEntity( sx->entity_table, &sx->guid );
if ( sx->name )
g_free( sx->name );
/*
* we have to delete the transactions in the
* template account ourselves

View File

@ -24,10 +24,9 @@
#ifndef XACC_SCHEDXACTION_H
#define XACC_SCHEDXACTION_H
#include "config.h"
#include <time.h>
#include <glib.h>
#include "GNCId.h"
#include "FreqSpec.h"
#include "date.h"
@ -37,6 +36,8 @@
/*
* #defines for kvp_frame strings
* FIXME: Is this the right spot for them <rgmerk>?
* FIXME: No, they should be private data and there should
* be an api for getting/setting the values <dave_p>
*/
#define GNC_SX_ID "sched-xaction"
@ -47,58 +48,7 @@
#define GNC_SX_AMOUNT "amnt"
#define GNC_SX_FROM_SCHED_XACTION "from-sched-xaction"
/**
* A single scheduled transaction.
*
* Scheduled transactions have a list of transactions, and a frequency
* [and associated date anchors] with which they are scheduled.
*
* Things that make sense to have in a template transaction:
* [not] Date [though eventually some/multiple template transactions
* might have relative dates].
* Memo
* Account
* Funds In/Out... or an expr involving 'amt' [A, x, y, a?] for
* variable expenses.
*
* Template transactions are instantiated by:
* . copying the fields of the template
* . setting the date to the calculated "due" date.
*
* We should be able to use the GeneralLedger [or, yet-another-subtype
* of the internal ledger] for this editing.
**/
typedef struct gncp_SchedXaction {
gchar *name;
FreqSpec *freq;
GDate last_date;
GDate start_date;
/* if end_date is invalid, then no end. */
GDate end_date;
/* if num_occurances_total == 0, then no limit */
gint num_occurances_total;
/* reminaing occurances are as-of the 'last_date'. */
gint num_occurances_remain;
gboolean autoCreateOption;
gboolean autoCreateNotify;
gint advanceCreateDays;
gint advanceRemindDays;
Account *template_acct;
GUID guid;
/* Changed since last save? */
gboolean dirty;
kvp_frame *kvp_data;
} SchedXaction;
typedef struct gncp_SchedXaction SchedXaction;
/**
* Creates and initializes a scheduled transaction.

View File

@ -0,0 +1,83 @@
/********************************************************************\
* SchedXactionP.h -- Scheduled Transaction private header *
* Copyright (C) 2001 Linux Developers Group *
* *
* 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 *
* *
\********************************************************************/
#ifndef XACC_SCHEDXACTION_P_H
#define XACC_SCHEDXACTION_P_H
#include "GNCIdP.h"
#include "SchedXaction.h"
/**
* A single scheduled transaction.
*
* Scheduled transactions have a list of transactions, and a frequency
* [and associated date anchors] with which they are scheduled.
*
* Things that make sense to have in a template transaction:
* [not] Date [though eventually some/multiple template transactions
* might have relative dates].
* Memo
* Account
* Funds In/Out... or an expr involving 'amt' [A, x, y, a?] for
* variable expenses.
*
* Template transactions are instantiated by:
* . copying the fields of the template
* . setting the date to the calculated "due" date.
*
* We should be able to use the GeneralLedger [or, yet-another-subtype
* of the internal ledger] for this editing.
**/
struct gncp_SchedXaction
{
gchar *name;
FreqSpec *freq;
GDate last_date;
GDate start_date;
/* if end_date is invalid, then no end. */
GDate end_date;
/* if num_occurances_total == 0, then no limit */
gint num_occurances_total;
/* reminaing occurances are as-of the 'last_date'. */
gint num_occurances_remain;
gboolean autoCreateOption;
gboolean autoCreateNotify;
gint advanceCreateDays;
gint advanceRemindDays;
Account *template_acct;
GUID guid;
GNCEntityTable *entity_table;
/* Changed since last save? */
gboolean dirty;
kvp_frame *kvp_data;
};
#endif

View File

@ -121,7 +121,7 @@ xaccInitSplit(Split * split, GNCEntityTable *entity_table)
split->entity_table = entity_table;
xaccGUIDNew(&split->guid);
xaccStoreEntity(split, &split->guid, GNC_ID_SPLIT);
xaccStoreEntity(split->entity_table, split, &split->guid, GNC_ID_SPLIT);
}
/********************************************************************\
@ -365,9 +365,9 @@ xaccSplitSetGUID (Split *split, const GUID *guid)
{
if (!split || !guid) return;
check_open (split->parent);
xaccRemoveEntity(&split->guid);
xaccRemoveEntity(split->entity_table, &split->guid);
split->guid = *guid;
xaccStoreEntity(split, &split->guid, GNC_ID_SPLIT);
xaccStoreEntity(split->entity_table, split, &split->guid, GNC_ID_SPLIT);
}
/********************************************************************\
@ -379,7 +379,7 @@ xaccSplitLookupEntityTable (const GUID *guid, GNCEntityTable *entity_table)
if (!guid) return NULL;
/* FIXME: uncomment soon */
/* g_return_val_if_fail (entity_table, NULL); */
return xaccLookupEntity(guid, GNC_ID_SPLIT);
return xaccLookupEntity(entity_table, guid, GNC_ID_SPLIT);
}
Split *
@ -387,7 +387,8 @@ xaccSplitLookup (const GUID *guid, GNCSession *session)
{
if (!guid) return NULL;
g_return_val_if_fail (session, NULL);
return xaccLookupEntity(guid, GNC_ID_SPLIT);
return xaccLookupEntity(gnc_session_get_entity_table (session),
guid, GNC_ID_SPLIT);
}
/********************************************************************\
@ -671,7 +672,7 @@ xaccInitTransaction (Transaction * trans, GNCSession *session)
trans->entity_table = gnc_session_get_entity_table (session);
xaccGUIDNew(&trans->guid);
xaccStoreEntity(trans, &trans->guid, GNC_ID_TRANS);
xaccStoreEntity(trans->entity_table, trans, &trans->guid, GNC_ID_TRANS);
}
/********************************************************************\
@ -890,9 +891,9 @@ void
xaccTransSetGUID (Transaction *trans, const GUID *guid)
{
if (!trans || !guid) return;
xaccRemoveEntity(&trans->guid);
xaccRemoveEntity(trans->entity_table, &trans->guid);
trans->guid = *guid;
xaccStoreEntity(trans, &trans->guid, GNC_ID_TRANS);
xaccStoreEntity(trans->entity_table, trans, &trans->guid, GNC_ID_TRANS);
}
@ -905,7 +906,7 @@ xaccTransLookupEntityTable (const GUID *guid,
{
/* FIXME: uncomment when entity tables are in sessions */
/* g_return_val_if_fail (entity_table, NULL); */
return xaccLookupEntity (guid, GNC_ID_TRANS);
return xaccLookupEntity (entity_table, guid, GNC_ID_TRANS);
}
Transaction *
@ -913,7 +914,8 @@ xaccTransLookup (const GUID *guid, GNCSession *session)
{
if (!guid) return NULL;
g_return_val_if_fail (session, NULL);
return xaccLookupEntity (guid, GNC_ID_TRANS);
return xaccLookupEntity (gnc_session_get_entity_table (session),
guid, GNC_ID_TRANS);
}
/********************************************************************\
@ -1433,7 +1435,7 @@ xaccTransCommitEdit (Transaction *trans)
PINFO ("delete trans at addr=%p", trans);
/* Make a log in the journal before destruction. */
xaccTransWriteLog (trans, 'D');
xaccRemoveEntity(&trans->guid);
xaccRemoveEntity(trans->entity_table, &trans->guid);
xaccFreeTransaction (trans);
return;
}
@ -1478,7 +1480,7 @@ xaccTransRollbackEdit (Transaction *trans)
/* If the transaction had been deleted before the rollback,
* the guid would have been unlisted. Restore that */
xaccStoreEntity(trans, &trans->guid, GNC_ID_TRANS);
xaccStoreEntity(trans->entity_table, trans, &trans->guid, GNC_ID_TRANS);
g_cache_remove (gnc_engine_get_string_cache(), trans->num);
trans->num = orig->num;
@ -1598,7 +1600,7 @@ xaccTransRollbackEdit (Transaction *trans)
mark_split (s);
xaccAccountRemoveSplit (xaccSplitGetAccount(s), s);
xaccAccountRecomputeBalance (xaccSplitGetAccount(s));
xaccRemoveEntity(&s->guid);
xaccRemoveEntity(s->entity_table, &s->guid);
xaccFreeSplit (s);
}
@ -1614,7 +1616,7 @@ xaccTransRollbackEdit (Transaction *trans)
Account *account = xaccSplitGetAccount(s);
xaccSplitSetAccount(s, NULL);
xaccStoreEntity(s, &s->guid, GNC_ID_SPLIT);
xaccStoreEntity(s->entity_table, s, &s->guid, GNC_ID_SPLIT);
xaccAccountInsertSplit (account, s);
xaccAccountRecomputeBalance (account);
mark_split (s);
@ -1712,7 +1714,7 @@ xaccTransDestroy (Transaction *trans)
xaccAccountRemoveSplit (xaccSplitGetAccount(split), split);
xaccAccountRecomputeBalance (xaccSplitGetAccount(split));
xaccRemoveEntity(&split->guid);
xaccRemoveEntity(split->entity_table, &split->guid);
xaccFreeSplit (split);
node->data = NULL;
@ -1721,7 +1723,7 @@ xaccTransDestroy (Transaction *trans)
g_list_free (trans->splits);
trans->splits = NULL;
xaccRemoveEntity(&trans->guid);
xaccRemoveEntity(trans->entity_table, &trans->guid);
/* the actual free is done with the commit call, else its rolled back */
/* xaccFreeTransaction (trans); don't do this here ... */
@ -1755,7 +1757,7 @@ xaccSplitDestroy (Split *split)
check_open (trans);
mark_split (split);
xaccRemoveEntity (&split->guid);
xaccRemoveEntity (split->entity_table, &split->guid);
if (trans)
{
@ -2710,7 +2712,8 @@ xaccTransGetVoidReason(Transaction *trans)
return NULL;
}
gnc_numeric xaccSplitVoidFormerAmount(Split *split)
gnc_numeric
xaccSplitVoidFormerAmount(Split *split)
{
kvp_frame *frame;
kvp_value *val;
@ -2730,7 +2733,8 @@ gnc_numeric xaccSplitVoidFormerAmount(Split *split)
}
gnc_numeric xaccSplitVoidFormerValue(Split *split)
gnc_numeric
xaccSplitVoidFormerValue(Split *split)
{
kvp_frame *frame;
kvp_value *val;
@ -2749,7 +2753,8 @@ gnc_numeric xaccSplitVoidFormerValue(Split *split)
return amt;
}
Timespec xaccTransGetVoidTime(Transaction *tr)
Timespec
xaccTransGetVoidTime(Transaction *tr)
{
kvp_frame *frame;
kvp_value *val;

View File

@ -26,14 +26,17 @@
#include <glib.h>
#include "gnc-book.h"
#include "BackendP.h"
#include "GNCIdP.h"
#include "gnc-book.h"
#include "gnc-pricedb.h"
struct gnc_price_s
{
/* 'public' data fields */
GUID guid; /* globally unique price id */
GNCEntityTable *entity_table; /* table in which price is stored */
GNCPriceDB *db;
gnc_commodity *commodity;
gnc_commodity *currency;

View File

@ -27,14 +27,12 @@
#include <string.h>
#include "Backend.h"
#include "GNCId.h"
#include "GNCIdP.h"
#include "gnc-engine.h"
#include "gnc-engine-util.h"
#include "gnc-event.h"
#include "gnc-event-p.h"
#include "gnc-pricedb.h"
#include "gnc-pricedb-p.h"
#include "gnc-session-p.h"
#include "guid.h"
/* This static indicates the debugging module that this .o belongs to. */
@ -64,8 +62,10 @@ gnc_price_create (GNCSession *session)
p->version = 0;
p->version_check = 0;
p->entity_table = gnc_session_get_entity_table (session);
xaccGUIDNew (&p->guid);
xaccStoreEntity(p, &p->guid, GNC_ID_PRICE);
xaccStoreEntity(p->entity_table, p, &p->guid, GNC_ID_PRICE);
gnc_engine_generate_event (&p->guid, GNC_EVENT_CREATE);
return p;
@ -76,7 +76,7 @@ gnc_price_destroy (GNCPrice *p)
{
ENTER(" ");
gnc_engine_generate_event (&p->guid, GNC_EVENT_DESTROY);
xaccRemoveEntity(&p->guid);
xaccRemoveEntity(p->entity_table, &p->guid);
if(p->type) g_cache_remove(gnc_engine_get_string_cache(), p->type);
if(p->source) g_cache_remove(gnc_engine_get_string_cache(), p->source);
@ -237,10 +237,10 @@ void
gnc_price_set_guid (GNCPrice *p, const GUID *guid)
{
if (!p || !guid) return;
xaccRemoveEntity (&p->guid);
xaccRemoveEntity (p->entity_table, &p->guid);
p->guid = *guid;
if(p->db) p->db->dirty = TRUE;
xaccStoreEntity(p, &p->guid, GNC_ID_PRICE);
xaccStoreEntity(p->entity_table, p, &p->guid, GNC_ID_PRICE);
}
void
@ -368,10 +368,12 @@ gnc_price_set_version(GNCPrice *p, gint32 vers)
/* getters */
GNCPrice *
gnc_price_lookup (const GUID *guid)
gnc_price_lookup (const GUID *guid, GNCSession *session)
{
if (!guid) return NULL;
return xaccLookupEntity (guid, GNC_ID_PRICE);
g_return_val_if_fail (session, NULL);
return xaccLookupEntity (gnc_session_get_entity_table (session),
guid, GNC_ID_PRICE);
}
const GUID *

View File

@ -163,7 +163,7 @@ void gnc_price_set_version(GNCPrice *p, gint32 versn);
/* As mentioned above all of the getters return data that's internal
to the GNCPrice, not copies, so don't free these values. */
GNCPrice * gnc_price_lookup (const GUID *guid);
GNCPrice * gnc_price_lookup (const GUID *guid, GNCSession *session);
const GUID * gnc_price_get_guid (GNCPrice *p);
gnc_commodity * gnc_price_get_commodity(GNCPrice *p);
gnc_commodity * gnc_price_get_currency(GNCPrice *p);