Merging QofBook structures
[Query Object Framework]


Detailed Description

Collision handling principles.

  1. Always check for a GUID first and compare. qof_book_merge only accepts valid QofBook data and therefore ALL objects in the import book will include valid GUID's.
  2. If the original import data did not contain a GUID (e.g. an external non-GnuCash source) the GUID values will have been created during the import and will not match any existing GUID's in the target book so objects that do not have a GUID match cannot be assumed to be MERGE_NEW - parameter values must be checked.
  3. If import contains data from closed books, store the data from the closed books in the current book as active. i.e. re-open the books.

More information is at http://code.neil.williamsleesmill.me.uk/

Each foreach function uses g_return_if_fail checks to protect the target book. If any essential data is missing, the loop returns without changing the target book. Note that this will not set or return an error value. However, g_return is only used for critical errors that arise from programming errors, not for invalid import data which should be cleaned up before creating the import QofBook.

Only qof_book_mergeUpdateResult and qof_book_mergeCommit return any error values to the calling process. qof_book_mergeInit returns a pointer to the qof_book_mergeData struct - the calling process needs to make sure this is non-NULL to know that the Init has been successful.


Files

file  qof_book_merge.h
 API for merging two QofBook structures with collision handling.

Data Structures

struct  qof_book_mergeRule
 One rule per entity, built into a single GList for the entire merge. More...
struct  qof_book_mergeData
 mergeData contains the essential context data for any merge. More...

qof_book_merge API

typedef void(* qof_book_mergeRuleForeachCB )(qof_book_mergeData *, qof_book_mergeRule *, guint)
 Definition of the dialog control callback routine.
qof_book_mergeDataqof_book_mergeInit (QofBook *importBook, QofBook *targetBook)
 Initialise the qof_book_merge process.
void qof_book_mergeRuleForeach (qof_book_mergeData *mergeData, qof_book_mergeRuleForeachCB callback, qof_book_mergeResult mergeResult)
 Dialog Control Callback.
char * qof_book_merge_param_as_string (QofParam *qtparam, QofEntity *qtEnt)
 provides easy string access to parameter data for dialog use
qof_book_mergeDataqof_book_mergeUpdateResult (qof_book_mergeData *mergeData, qof_book_mergeResult tag)
 called by dialog callback to set the result of user intervention
int qof_book_mergeCommit (qof_book_mergeData *mergeData)
 Commits the import data to the target book.
void qof_book_merge_abort (qof_book_mergeData *mergeData)
 Abort the merge and free all memory allocated by the merge.

Enumerations

enum  qof_book_mergeResult {
  MERGE_UNDEF, MERGE_ABSOLUTE, MERGE_NEW, MERGE_REPORT,
  MERGE_DUPLICATE, MERGE_UPDATE, MERGE_INVALID
}
 Results of collisions and user resolution. More...


Typedef Documentation

typedef void(* qof_book_mergeRuleForeachCB)(qof_book_mergeData *, qof_book_mergeRule *, guint)
 

Definition of the dialog control callback routine.

All MERGE_REPORT rules must be offered for user intervention using this template.
Commit will fail if any rules are still tagged as MERGE_REPORT.

Calling processes are free to also offer MERGE_NEW, MERGE_UPDATE, MERGE_DUPLICATE and MERGE_ABSOLUTE for user intervention. Attempting to query MERGE_INVALID rules will cause an error.

For an example, consider test_rule_loop, declared as:

void test_rule_loop(qof_book_mergeData *mergeData, qof_book_mergeRule *rule, guint remainder);
void test_rule_loop(qof_book_mergeData *mergeData, qof_book_mergeRule *rule, guint remainder)
{
g_return_if_fail(rule != NULL);
g_return_if_fail(mergeData != NULL); printf("Rule Result %s", rule->mergeType);
qof_book_mergeUpdateResult(mergeData, rule, MERGE_UPDATE);
}

The dialog is free to call qof_book_mergeUpdateResult in the loop or at the end as long as the link between the rule and the result is maintained, e.g. by using a GHashTable.
The parameters are:

  • data : pointer to the qof_book_mergeData metadata context returned by Init.
  • rule : pointer to the qof_book_mergeRule that generated the collision report
  • remainder : guint value returned from g_slist_length for the number of other rules remaining with the same result. This might be useful for a progress dialog, it might not. When updating MERGE_REPORT, remainder must equal zero before calling qof_book_mergeCommit or the import will abort.

If the dialog sets any rule result to MERGE_INVALID, the import will abort when qof_book_mergeCommit is called. It is the responsibility of the calling function to handle the error code from qof_book_mergeCommit, close the dialog and return. The merge routines in these files will already have halted the merge operation and freed any memory allocated to merge structures before returning the error code. There is no need for the dialog process to report back to qof_book_merge in this situation.

Definition at line 287 of file qof_book_merge.h.


Enumeration Type Documentation

enum qof_book_mergeResult
 

Results of collisions and user resolution.

All rules are initialised as MERGE_UNDEF. Once the comparison is complete, each object within the import will be updated.

MERGE_ABSOLUTE, MERGE_NEW, MERGE_DUPLICATE and MERGE_UPDATE can be reported to the user along with all MERGE_REPORT objects for confirmation. It may be useful later to allow MERGE_ABSOLUTE, MERGE_NEW, MERGE_DUPLICATE and MERGE_UPDATE to not be reported, if the user sets a preferences option for each result. (Always accept new items: Y/N default NO, ignores all MERGE_NEW if set to Y etc.) This option would not require any changes to qof_book_merge.

MERGE_NEW, MERGE_DUPLICATE and MERGE_UPDATE are only actioned after conflicts are resolved by the user using a dialog and all MERGE_REPORT objects are re-assigned to one of MERGE_NEW, MERGE_DUPLICATE or MERGE_UPDATE. There is no automatic merge, even if no entities are tagged as MERGE_REPORT, the calling process must still check for REPORT items using qof_book_mergeRuleForeach and call qof_book_mergeCommit.

MERGE_INVALID data should be rare and allows for user-abort - the imported file/source may be corrupted and the prescence of invalid data should raise concerns that the rest of the data may be corrupted, damaged or otherwise altered. If any entity is tagged as MERGE_INVALID, the merge operation will abort and leave the target book completely unchanged.

MERGE_ABSOLUTE is only used for a complete match. The import object contains the same data in the same parameters with no omissions or amendments. If any data is missing, amended or added, the data is labelled MERGE_UPDATE.

Every piece of data has a corresponding result. Only when the count of items labelled MERGE_REPORT is equal to zero are MERGE_NEW and MERGE_UPDATE items added to the existing book.
MERGE_DUPLICATE items are silently ignored. Aborting the dialog/process (by the user or in a program crash) at any point before the final commit leaves the existing book completely untouched.

Enumerator:
MERGE_UNDEF  default value before comparison is made.
MERGE_ABSOLUTE  GUID exact match, no new data - ignore
MERGE_NEW  import object does not exist in the target book - add
MERGE_REPORT  import object needs user intervention - report
MERGE_DUPLICATE  import object with different GUID exactly matches existing GUID - ignore
MERGE_UPDATE  import object matches an existing entity but includes new or modified parameter data - update
MERGE_INVALID  import object didn't match registered object or parameter types or user decided to abort - abort

Definition at line 118 of file qof_book_merge.h.

00118              { 
00119         MERGE_UNDEF,     
00120         MERGE_ABSOLUTE,  
00121         MERGE_NEW,       
00122         MERGE_REPORT,    
00123         MERGE_DUPLICATE, 
00124         MERGE_UPDATE,    
00126         MERGE_INVALID    
00128 }qof_book_mergeResult;


Function Documentation

void qof_book_merge_abort qof_book_mergeData mergeData  ) 
 

Abort the merge and free all memory allocated by the merge.

Sometimes, setting MERGE_INVALID is insufficient: e.g. if the user aborts the merge from outside the functions dealing with the merge ruleset. This function causes an immediate abort - the calling process must start again at Init if a new merge is required.

Definition at line 762 of file qof_book_merge.c.

00763 {
00764         qof_book_mergeRule *currentRule;
00765 
00766         g_return_if_fail(mergeData != NULL);
00767         while(mergeData->mergeList != NULL) {
00768                 currentRule = mergeData->mergeList->data;
00769                 g_slist_free(currentRule->linkedEntList);
00770                 g_slist_free(currentRule->mergeParam);
00771                 g_free(mergeData->mergeList->data);
00772                 if(currentRule) {
00773                         g_slist_free(currentRule->linkedEntList);
00774                         g_slist_free(currentRule->mergeParam);
00775                         g_free(currentRule);
00776                 }
00777                 mergeData->mergeList = g_list_next(mergeData->mergeList);
00778         }
00779         g_list_free(mergeData->mergeList);
00780         g_slist_free(mergeData->mergeObjectParams);
00781         g_slist_free(mergeData->targetList);
00782         if(mergeData->orphan_list != NULL) { g_slist_free(mergeData->orphan_list); }
00783         g_hash_table_destroy(mergeData->target_table);
00784         g_free(mergeData);
00785 }

char* qof_book_merge_param_as_string QofParam qtparam,
QofEntity qtEnt
 

provides easy string access to parameter data for dialog use

Uses the param_getfcn to retrieve the parameter value as a string, suitable for display in dialogs and user intervention output. Within a qof_book_merge context, only the parameters used in the merge are available, i.e. parameters where both param_getfcn and param_setfcn are not NULL.

Note that the object type description (a full text version of the object name) is also available to the dialog as qof_book_mergeRule::mergeLabel.

This allows the dialog to display the description of the object and all parameter data.

Definition at line 798 of file qof_book_merge.c.

00799 {
00800         gchar       *param_string, param_date[QOF_DATE_STRING_LENGTH];
00801         char        param_sa[GUID_ENCODING_LENGTH + 1];
00802         QofType     paramType;
00803         const GUID *param_guid;
00804         time_t      param_t;
00805         gnc_numeric param_numeric,  (*numeric_getter) (QofEntity*, QofParam*);
00806         Timespec    param_ts,       (*date_getter)    (QofEntity*, QofParam*);
00807         double      param_double,   (*double_getter)  (QofEntity*, QofParam*);
00808         gboolean    param_boolean,  (*boolean_getter) (QofEntity*, QofParam*);
00809         gint32      param_i32,      (*int32_getter)   (QofEntity*, QofParam*);
00810         gint64      param_i64,      (*int64_getter)   (QofEntity*, QofParam*);
00811         char        param_char,     (*char_getter)    (QofEntity*, QofParam*);
00812 
00813         param_string = NULL;
00814         paramType = qtparam->param_type;
00815         if(safe_strcmp(paramType, QOF_TYPE_STRING) == 0)  { 
00816                         param_string = g_strdup(qtparam->param_getfcn(qtEnt,qtparam));
00817                         if(param_string == NULL) { param_string = ""; }
00818                         return param_string;
00819                 }
00820                 if(safe_strcmp(paramType, QOF_TYPE_DATE) == 0) { 
00821                         date_getter = (Timespec (*)(QofEntity*, QofParam*))qtparam->param_getfcn;
00822                         param_ts = date_getter(qtEnt, qtparam);
00823                         param_t = timespecToTime_t(param_ts);
00824                         strftime(param_date, QOF_DATE_STRING_LENGTH, QOF_UTC_DATE_FORMAT, gmtime(&param_t));
00825                         param_string = g_strdup(param_date);
00826                         return param_string;
00827                 }
00828                 if((safe_strcmp(paramType, QOF_TYPE_NUMERIC) == 0)  ||
00829                 (safe_strcmp(paramType, QOF_TYPE_DEBCRED) == 0)) { 
00830                         numeric_getter = (gnc_numeric (*)(QofEntity*, QofParam*)) qtparam->param_getfcn;
00831                         param_numeric = numeric_getter(qtEnt,qtparam);
00832                         param_string = g_strdup(gnc_numeric_to_string(param_numeric));
00833                         return param_string;
00834                 }
00835                 if(safe_strcmp(paramType, QOF_TYPE_GUID) == 0) { 
00836                         param_guid = qtparam->param_getfcn(qtEnt,qtparam);
00837                         guid_to_string_buff(param_guid, param_sa);
00838                         param_string = g_strdup(param_sa);
00839                         return param_string;
00840                 }
00841                 if(safe_strcmp(paramType, QOF_TYPE_INT32) == 0) { 
00842                         int32_getter = (gint32 (*)(QofEntity*, QofParam*)) qtparam->param_getfcn;
00843                         param_i32 = int32_getter(qtEnt, qtparam);
00844                         param_string = g_strdup_printf("%d", param_i32);
00845                         return param_string;
00846                 }
00847                 if(safe_strcmp(paramType, QOF_TYPE_INT64) == 0) { 
00848                         int64_getter = (gint64 (*)(QofEntity*, QofParam*)) qtparam->param_getfcn;
00849                         param_i64 = int64_getter(qtEnt, qtparam);
00850                         param_string = g_strdup_printf("%" G_GINT64_FORMAT, param_i64);
00851                         return param_string;
00852                 }
00853                 if(safe_strcmp(paramType, QOF_TYPE_DOUBLE) == 0) { 
00854                         double_getter = (double (*)(QofEntity*, QofParam*)) qtparam->param_getfcn;
00855                         param_double = double_getter(qtEnt, qtparam);
00856                         param_string = g_strdup_printf("%f", param_double);
00857                         return param_string;
00858                 }
00859                 if(safe_strcmp(paramType, QOF_TYPE_BOOLEAN) == 0){ 
00860                         boolean_getter = (gboolean (*)(QofEntity*, QofParam*)) qtparam->param_getfcn;
00861                         param_boolean = boolean_getter(qtEnt, qtparam);
00862                         /* Boolean values need to be lowercase for QSF validation. */
00863                         if(param_boolean == TRUE) { param_string = g_strdup("true"); }
00864                         else { param_string = g_strdup("false"); }
00865                         return param_string;
00866                 }
00867                 /* "kvp" contains repeating values, cannot be a single string for the frame. */
00868                 if(safe_strcmp(paramType, QOF_TYPE_KVP) == 0) { return param_string; }
00869                 if(safe_strcmp(paramType, QOF_TYPE_CHAR) == 0) { 
00870                         char_getter = (char (*)(QofEntity*, QofParam*)) qtparam->param_getfcn;
00871                         param_char = char_getter(qtEnt, qtparam);
00872                         param_string = g_strdup_printf("%c", param_char);
00873                         return param_string;
00874                 }
00875         return NULL;
00876 }

int qof_book_mergeCommit qof_book_mergeData mergeData  ) 
 

Commits the import data to the target book.

The last function in the API and the final part of any qof_book_merge operation.

qof_book_mergeCommit will abort the entire merge operation if any rule is set to MERGE_INVALID. It is the responsibility of the calling function to handle the error code from qof_book_mergeCommit, close the dialog and return. qof_book_mergeCommit will already have halted the merge operation and freed any memory allocated to all merge structures before returning the error code. There is no way for the dialog process to report back to qof_book_merge in this situation.

qof_book_mergeCommit checks for any entities still tagged as MERGE_REPORT and then proceeds to import all entities tagged as MERGE_UPDATE or MERGE_NEW into the target book.
This final process cannot be UNDONE!

Parameters:
mergeData the merge context, qof_book_mergeData*
Returns:
  • -2 if any rules are tagged as MERGE_INVALID
    • mergeData will have been g_free'd).
    • note that this will be before any operations are done on the target QofBook.
  • -1 if mergeData is invalid or no merge has been initialised with qof_book_mergeInit - the calling process must check the value of mergeData
  • +1 if some entities are still tagged as MERGE_REPORT - use qof_book_mergeUpdateRule and try again (mergeData is retained).
  • 0 on success - mergeData will have been freed.

Definition at line 917 of file qof_book_merge.c.

00918 {
00919         qof_book_mergeRule *currentRule;
00920         GList *check;
00921 
00922         g_return_val_if_fail(mergeData != NULL, -1);
00923         g_return_val_if_fail(mergeData->mergeList != NULL, -1);
00924         g_return_val_if_fail(mergeData->targetBook != NULL, -1);
00925         if(mergeData->abort == TRUE) return -1;
00926         check = g_list_copy(mergeData->mergeList);
00927         g_return_val_if_fail(check != NULL, -1);
00928         while(check != NULL) {
00929                 currentRule = check->data;
00930                 if(currentRule->mergeResult == MERGE_INVALID) {
00931                         qof_book_merge_abort(mergeData);
00932                         return(-2);
00933                 }
00934                 if(currentRule->mergeResult == MERGE_REPORT) {
00935                         g_list_free(check);
00936                         return 1;
00937                 }
00938                 check = g_list_next(check);
00939         }
00940         qof_book_mergeCommitForeach( qof_book_mergeCommitRuleLoop, MERGE_NEW, mergeData);
00941         qof_book_mergeCommitForeach( qof_book_mergeCommitRuleLoop, MERGE_UPDATE, mergeData);
00942         /* Placeholder for QofObject merge_helper_cb - all objects and all parameters set */
00943         while(mergeData->mergeList != NULL) {
00944                 currentRule = mergeData->mergeList->data;
00945                 g_slist_free(currentRule->mergeParam);
00946                 g_slist_free(currentRule->linkedEntList);
00947                 mergeData->mergeList = g_list_next(mergeData->mergeList);
00948         }
00949         g_list_free(mergeData->mergeList);
00950         g_slist_free(mergeData->mergeObjectParams);
00951         g_slist_free(mergeData->targetList);
00952         if(mergeData->orphan_list != NULL) { g_slist_free(mergeData->orphan_list); }
00953         g_hash_table_destroy(mergeData->target_table);
00954         g_free(mergeData);
00955         return 0;
00956 }

qof_book_mergeData* qof_book_mergeInit QofBook importBook,
QofBook targetBook
 

Initialise the qof_book_merge process.

First function of the qof_book_merge API. Every merge must begin with Init.

Requires the book to import (QofBook *) and the book to receive the import, the target book (QofBook *). Returns a pointer to qof_book_mergeData which must be checked for a NULL before continuing.
Process:

  1. Invoke the callback qof_book_mergeForeachType on every registered object class definition.
  2. Callback obtains the registered parameter list for each object type. This provides run time access to all registered objects and all object parameters without any changes to qof_book_merge - no registered object or parameter is omitted from any merge operation.
  3. Use qof_object_foreach to invoke the callback qof_book_mergeForeach, one object at a time on every instance stored in mergeBook. This is the first point where real data from the import book is accessed.
  4. qof_book_mergeForeach obtains the GUID for the object from the import book and runs the first check on the original book, checking for any exact GUID match. With the full parameter list, the rules for this object can be created. If there is a GUID match, the data in each parameter of the import object is compared with the same semantic object in the original book. If there is no GUID in the import object or no GUID match with the original book, the original book is searched to find a parameter match - checking for a MERGE_DUPLICATE result.
  5. qof_book_mergeCompare sets the qof_book_mergeResult of the comparison.
  6. Inserts the completed rule into qof_book_mergeData::mergeList GSList.

Returns:
NULL in case of error, otherwise a qof_book_mergeData* metadata context.

Definition at line 724 of file qof_book_merge.c.

00725 {
00726         qof_book_mergeData *mergeData;
00727         qof_book_mergeRule *currentRule;
00728         GList *check;
00729 
00730         g_return_val_if_fail((importBook != NULL)&&(targetBook != NULL), NULL);
00731         mergeData = g_new(qof_book_mergeData, 1);
00732         mergeData->abort = FALSE;
00733         mergeData->mergeList = NULL;
00734         mergeData->targetList = NULL;
00735         mergeData->mergeBook = importBook;
00736         mergeData->targetBook = targetBook;
00737         mergeData->mergeObjectParams = NULL;
00738         mergeData->orphan_list = NULL;
00739         mergeData->target_table = g_hash_table_new( g_direct_hash, qof_book_merge_rule_cmp);
00740         currentRule = g_new(qof_book_mergeRule, 1);
00741         mergeData->currentRule = currentRule;
00742         qof_object_foreach_type(qof_book_mergeForeachType, mergeData);
00743         g_return_val_if_fail(mergeData->mergeObjectParams, NULL);
00744         if(mergeData->orphan_list != NULL) {
00745                 qof_book_merge_match_orphans(mergeData);
00746         }
00747         
00748         check = g_list_copy(mergeData->mergeList);
00749         while(check != NULL) {
00750                 currentRule = check->data;
00751                 if(currentRule->mergeResult == MERGE_INVALID) {
00752                         mergeData->abort = TRUE;
00753                         return(NULL);
00754                 }
00755                 check = g_list_next(check);
00756         }
00757         g_list_free(check);
00758         return mergeData;
00759 }

void qof_book_mergeRuleForeach qof_book_mergeData mergeData,
qof_book_mergeRuleForeachCB  callback,
qof_book_mergeResult  mergeResult
 

Dialog Control Callback.

This function is designed to be used to iterate over all rules tagged with a specific qof_book_mergeResult value.

Parameters:
callback external loop of type qof_book_mergeRuleForeachCB
mergeResult qof_book_mergeResult value to look up.
mergeData qof_book_mergeData merge context.
Note : MERGE_NEW causes a new entity to be created in the target book at Commit which is then assigned as the targetEnt of that rule. If mergeResult == MERGE_NEW, the rules returned by qof_book_mergeRuleForeach will have a NULL set for the targetEnt. This is because Commit has not yet been called and no changes can be made to the target book. The calling process must handle the NULL targetEnt and NOT call any param_getfcn routines for the target entity. The import entity is available for display.

Uses qof_book_get_collection with the qof_book_mergeRule::mergeType object type to return a collection of QofEntity entities from either the qof_book_mergeData::mergeBook or qof_book_mergeData::targetBook. Then uses qof_collection_lookup_entity to lookup the qof_book_mergeRule::importEnt and again the qof_book_mergeRule::targetEnt to return the two specific entities.

Definition at line 959 of file qof_book_merge.c.

00962 {
00963         struct qof_book_mergeRuleIterate iter;
00964         qof_book_mergeRule *currentRule;
00965         GList *matching_rules;
00966 
00967         g_return_if_fail(cb != NULL);
00968         g_return_if_fail(mergeData != NULL);
00969         currentRule = mergeData->currentRule;
00970         g_return_if_fail(mergeResult > 0);
00971         g_return_if_fail(mergeResult != MERGE_INVALID);
00972         g_return_if_fail(mergeData->abort == FALSE);
00973         iter.fcn = cb;
00974         iter.data = mergeData;
00975         matching_rules = NULL;
00976         iter.ruleList = g_list_copy(mergeData->mergeList);
00977         while(iter.ruleList!=NULL) {
00978                 currentRule = iter.ruleList->data;
00979                 if(currentRule->mergeResult == mergeResult) {
00980                         matching_rules = g_list_prepend(matching_rules, currentRule);
00981                 }
00982                 iter.ruleList = g_list_next(iter.ruleList);
00983         }
00984         iter.remainder = g_list_length(matching_rules);
00985         g_list_foreach (matching_rules, qof_book_mergeRuleCB, &iter);
00986         g_list_free(matching_rules);
00987 }

qof_book_mergeData* qof_book_mergeUpdateResult qof_book_mergeData mergeData,
qof_book_mergeResult  tag
 

called by dialog callback to set the result of user intervention

Set any rule result to MERGE_INVALID to abort the import when qof_book_mergeCommit is called, without changing the target book.

The calling process should make it absolutely clear that a merge operation cannot be undone and that a backup copy should always be available before a merge is initialised.

Recommended method: Only offer three options to the user per rule:

  1. Allow import data to be merged into target data
    • change MERGE_REPORT to MERGE_UPDATE
  2. Allow import data without an exact match to be added as new
    • change MERGE_REPORT to MERGE_NEW IF mergeAbsolute = FALSE
  3. Ignore import data and leave target data unchanged
    • change MERGE_REPORT to MERGE_ABSOLUTE or MERGE_DUPLICATE

Handle the required result changes in code: Check the value of qof_book_mergeRule::mergeAbsolute and use these principles:

To ignore entities tagged as:

  • MERGE_REPORT, you must check the value of mergeAbsolute.
    • if mergeAbsolute is TRUE, change MERGE_REPORT to MERGE_ABSOLUTE
    • if mergeAbsolute is FALSE, change MERGE_REPORT to MERGE_DUPLICATE
  • MERGE_NEW, set MERGE_DUPLICATE.
  • MERGE_UPDATE, you must check the value of mergeAbsolute.
    • if mergeAbsolute is TRUE, change MERGE_UPDATE to MERGE_ABSOLUTE
    • if mergeAbsolute is FALSE, change MERGE_UPDATE to MERGE_DUPLICATE

To merge entities that are not pre-set to MERGE_NEW, set MERGE_UPDATE.
Attempting to merge an entity when the pre-set value was MERGE_NEW will force a change back to MERGE_NEW because no suitable target exists for the merge.

To add entities, check mergeAbsolute is FALSE and set MERGE_NEW.
An entity only be added if mergeAbsolute is FALSE. Attempting to add an entity when mergeAbsolute is TRUE will always force a MERGE_UPDATE.

It is not possible to update the same rule more than once.

  1. MERGE_NEW is reserved for new objects and is only pre-set if all parameters, including GUID, have already failed to match any relevant object. qof_book_mergeCommit will create new entities for all rules tagged as MERGE_NEW.
    • if mergeAbsolute is TRUE and the user wants to import the data, requests to set MERGE_NEW will be forced to MERGE_UPDATE because an entity with that GUID already exists in the target book.
    • if MERGE_NEW is pre-set, requests to change to MERGE_UPDATE will be ignored because a new entity is needed.
  2. MERGE_UPDATE is reserved for existing objects - qof_book_mergeCommit will require a matching entity to update and will force a change to back to MERGE_NEW if none is known to exist, using the principle above.
  3. MERGE_INVALID will cause an abort of the merge process.
  4. MERGE_UNDEF and MERGE_REPORT cannot be set - the entity result will be unchanged.
  5. MERGE_DUPLICATE and MERGE_ABSOLUTE are handled identically but are semantically different - qof_book_mergeRule::mergeAbsolute is used to dictate which to set:
    • if mergeAbsolute is TRUE but MERGE_DUPLICATE is requested, force a change to MERGE_ABSOLUTE.
    • if mergeAbsolute is FALSE but MERGE_ABSOLUTE is requested, force a change to MERGE_DUPLICATE.

qof_book_mergeCommit only commits entities tagged with MERGE_NEW and MERGE_UPDATE results.
Entities tagged with MERGE_ABSOLUTE and MERGE_DUPLICATE results are ignored.

The calling process must check the return value and call qof_book_merge_abort(mergeData) if non-zero.

Parameters:
mergeData the merge context, qof_book_mergeData*
tag the result to attempt to set, qof_book_mergeResult
Returns:
-1 if supplied parameters are invalid or NULL, 0 on success.

Definition at line 879 of file qof_book_merge.c.

00881 {
00882         qof_book_mergeRule *resolved;
00883 
00884         g_return_val_if_fail((mergeData != NULL), NULL);
00885         g_return_val_if_fail((tag > 0), NULL);
00886         g_return_val_if_fail((tag != MERGE_REPORT), NULL);
00887         resolved = mergeData->currentRule;
00888         g_return_val_if_fail((resolved != NULL), NULL);
00889         if((resolved->mergeAbsolute == TRUE)&&(tag == MERGE_DUPLICATE))
00890         { 
00891                 tag = MERGE_ABSOLUTE; 
00892         }
00893         if((resolved->mergeAbsolute == TRUE)&&(tag == MERGE_NEW))
00894         {
00895                 tag = MERGE_UPDATE; 
00896         }
00897         if((resolved->mergeAbsolute == FALSE)&& (tag == MERGE_ABSOLUTE))
00898         { 
00899                 tag = MERGE_DUPLICATE; 
00900         }
00901         if((resolved->mergeResult == MERGE_NEW)&&(tag == MERGE_UPDATE)) 
00902         { 
00903                 tag = MERGE_NEW; 
00904         }
00905         if(resolved->updated == FALSE) { resolved->mergeResult = tag; }
00906         resolved->updated = TRUE;
00907         if(tag >= MERGE_INVALID) { 
00908                 mergeData->abort = TRUE;
00909                 mergeData->currentRule = resolved;
00910                 return NULL; 
00911         }
00912         mergeData->currentRule = resolved;
00913         return mergeData;
00914 }


Generated on Sun Sep 4 18:09:15 2005 for GnuCash by  doxygen 1.4.3-20050530