Replace C API with C++ API for functions used by GncSqlDbiBackend.

Since these are now parent-class member functions they can be called
directly from dbi_be without any casting gymnastics.

Also: Move the GncSqlObjectBackend registry to its own class, a private
member of GncSqlBackend. This eliminates a static variable in gnc-backend-sql.cpp
and allows the GncSqlBackend::ObjectRegistry constructor to insert all of
the backends into the list, eliminating gnc_sql_init() and all of the
gnc_sql_init_foo_handler() functions. The cost of this is that the objects
are now created on the free store instead of the text segment.

Because the object backends are created at GncSqlBackend construction
there is now a GncSqlBookBackend in the registry and the second error
message in test_gnc_sql_commit_edit is no longer emitted; instead, the
object is properly committed.
This commit is contained in:
John Ralls
2016-11-03 14:21:11 -07:00
parent b2a644c29d
commit ee0e61a07e
47 changed files with 891 additions and 1099 deletions

View File

@@ -88,16 +88,9 @@ static const EntryVec col_table
"quote_tz", COMMODITY_MAX_QUOTE_TZ_LEN, 0, "quote-tz"),
};
class GncSqlCommodityBackend : public GncSqlObjectBackend
{
public:
GncSqlCommodityBackend(int version, const std::string& type,
const std::string& table, const EntryVec& vec) :
GncSqlObjectBackend(version, type, table, vec) {}
void load_all(GncSqlBackend*) override;
bool commit(GncSqlBackend*, QofInstance*) override;
};
GncSqlCommodityBackend::GncSqlCommodityBackend() :
GncSqlObjectBackend(GNC_SQL_BACKEND_VERSION, GNC_ID_COMMODITY,
COMMODITIES_TABLE, col_table) {}
/* ================================================================= */
static gpointer
@@ -166,7 +159,7 @@ GncSqlCommodityBackend::load_all (GncSqlBackend* sql_be)
guid = *qof_instance_get_guid (QOF_INSTANCE (pCommodity));
pCommodity = gnc_commodity_table_insert (pTable, pCommodity);
if (qof_instance_is_dirty (QOF_INSTANCE (pCommodity)))
gnc_sql_push_commodity_for_postload_processing (sql_be, (gpointer)pCommodity);
sql_be->commodity_for_postload_processing(pCommodity);
qof_instance_set_guid (QOF_INSTANCE (pCommodity), &guid);
}
@@ -292,13 +285,5 @@ GncSqlColumnTableEntryImpl<CT_COMMODITYREF>::add_to_query(const GncSqlBackend* s
{
add_objectref_guid_to_query(sql_be, obj_name, pObject, vec);
}
/* ================================================================= */
void
gnc_sql_init_commodity_handler (void)
{
static GncSqlCommodityBackend be_data =
{
GNC_SQL_BACKEND_VERSION, GNC_ID_COMMODITY, COMMODITIES_TABLE, col_table};
gnc_sql_register_backend(&be_data);
}
/* ========================== END OF FILE ===================== */