![]() |
XML Mill
1.0.0
A GUI based XML editor with a memory.
|
Helper class assisting with batch updates to the database. More...
#include <gcbatchprocessorhelper.h>
Classes | |
struct | ElementRecord |
Represents a single element's associated first level children, attributes and known attribute values. More... | |
Public Member Functions | |
GCBatchProcessorHelper (const QDomDocument *domDoc, const QString &stringSeparator, const QStringList &knownElements, const QStringList &knownAttributes) | |
Constructor. | |
const QVariantList & | newElementsToAdd () const |
Returns a list of all the new element names that should be added to the database. | |
const QVariantList & | newElementChildrenToAdd () const |
Returns a list of lists of all new first level child element namess that should be added to the database. | |
const QVariantList & | newElementAttributesToAdd () const |
Returns a list of lists of all new associated attribute names that should be added to the database. | |
const QVariantList & | elementsToUpdate () const |
Returns a list of all the element names that should be updated. | |
const QVariantList & | elementChildrenToUpdate () const |
Returns a list of lists of all first level child element names corresponding to existing elements that should be updated. | |
const QVariantList & | elementAttributesToUpdate () const |
Returns a list of lists of all associated attribute names corresponding to existing elements that should be updated. | |
const QVariantList & | newAttributeKeysToAdd () const |
Returns a list of all the new attribute names that should be added to the database. | |
const QVariantList & | newAssociatedElementsToAdd () const |
Returns a list of all the new associated element names that should be added to the database. | |
const QVariantList & | newAttributeValuesToAdd () const |
Returns a list of lists of all new attribute values that should be added to the database. | |
const QVariantList & | attributeKeysToUpdate () const |
Returns a list of all the attribute keys that should be updated. | |
const QVariantList & | associatedElementsToUpdate () const |
Returns a list of all the associated element names corresponding to existing attribute keys that should be updated. | |
const QVariantList & | attributeValuesToUpdate () const |
Returns a list of lists of all attribute values associated with existing attributes that should be updated. | |
Private Member Functions | |
void | processElement (const QDomElement &parentElement) |
Processes an element by extracting information related to its first level children, associated attributes and the values of these attributes. | |
void | createRecord (const QDomElement &element) |
Creates an "ElementRecord" from "element". | |
void | sortRecords () |
Sorts all the element records in the unsorted record map and consolidates values where duplicates are encountered. | |
void | createVariantLists () |
Creates the lists of QVariants representing elements, attributes and values. | |
Private Attributes | |
QString | m_stringListSeparator |
QStringList | m_knownElements |
QStringList | m_knownAttributeKeys |
QVariantList | m_newElementsToAdd |
QVariantList | m_newElementChildrenToAdd |
QVariantList | m_newElementAttributesToAdd |
QVariantList | m_elementsToUpdate |
QVariantList | m_elementChildrenToUpdate |
QVariantList | m_elementAttributesToUpdate |
QVariantList | m_newAttributeKeysToAdd |
QVariantList | m_newAssociatedElementsToAdd |
QVariantList | m_newAttributeValuesToAdd |
QVariantList | m_attributeKeysToUpdate |
QVariantList | m_associatedElementsToUpdate |
QVariantList | m_attributeValuesToUpdate |
QMultiHash< QString, ElementRecord > | m_unsorted |
QMap< QString, ElementRecord > | m_records |
Helper class assisting with batch updates to the database.
The purpose of this class is to (1) extract all the elements and their associated attributes and attribute values from the DOM document passed in as parameter to the constructor and (2) to consolidate the lot into QVariantLists that can be used as bind variables for prepared queries intended to be executed in batches (that's quite a mouthful, see "execBatch" in the Qt documentation for more information on this topic).
The idea is not really to have a long-lived instance of this object in the calling object (i.e. it isn't intended to be used as a member variable, although it isn't prevented either), but rather to create a scoped local variable that should be created and set up as follows: Create an instance. Call the getters to retrieve the bind variable lists.
This class has also been specifically designed to be used in conjunction with GCDatabaseInterface.
Definition at line 57 of file gcbatchprocessorhelper.h.
GCBatchProcessorHelper::GCBatchProcessorHelper | ( | const QDomDocument * | domDoc, |
const QString & | stringSeparator, | ||
const QStringList & | knownElements, | ||
const QStringList & | knownAttributes | ||
) |
Constructor.
domDoc | - the DOM document from which all information will be extracted. |
stringSeparator | - the string sequence by which list elements in the database are separated (attribute values are stored as lists in the database, separated by a special character sequence. In other words, although the database sees a list of attribute values as a single string, we can extract the list elements later if we know which string sequence was used in the creation of the string list). This value should be unusual and unique. |
knownElements | - the list of elements known to the active database. If empty, all the elements in the DOM will be assumed to be new. |
knownAttributes | - the list of attributes known to the active database, if empty, all the attributes in the DOM will be assumed to be new. |
Definition at line 35 of file gcbatchprocessorhelper.cpp.
const QVariantList & GCBatchProcessorHelper::associatedElementsToUpdate | ( | ) | const |
Returns a list of all the associated element names corresponding to existing attribute keys that should be updated.
All attributes are associated with specific elements (this allows us to save different values against attributes of the same name that are associated with different elements). Each item in this list is the specific element associated with an attribute in the "attribute keys to update" list.
Definition at line 381 of file gcbatchprocessorhelper.cpp.
const QVariantList & GCBatchProcessorHelper::attributeKeysToUpdate | ( | ) | const |
Returns a list of all the attribute keys that should be updated.
Definition at line 374 of file gcbatchprocessorhelper.cpp.
const QVariantList & GCBatchProcessorHelper::attributeValuesToUpdate | ( | ) | const |
Returns a list of lists of all attribute values associated with existing attributes that should be updated.
Each item in this list is a list of known attribute values corresponding to an attribute in the "attribute keys to update" list. In other words, for each item in the "attribute keys to update" list, there is a corresponding QVariant item in this list (with the same index number) that represents the list of the attribute's known values. Each QVariant consists of all these known values concatenated into a single string value with the individuals separated by the unique string separator that was passed in as constructor parameter.
Definition at line 388 of file gcbatchprocessorhelper.cpp.
void GCBatchProcessorHelper::createRecord | ( | const QDomElement & | element | ) | [private] |
Creates an "ElementRecord" from "element".
Called from within processElement, this function creates the records and adds them to the record map without checking for duplicates.
Definition at line 80 of file gcbatchprocessorhelper.cpp.
void GCBatchProcessorHelper::createVariantLists | ( | ) | [private] |
Creates the lists of QVariants representing elements, attributes and values.
Definition at line 182 of file gcbatchprocessorhelper.cpp.
const QVariantList & GCBatchProcessorHelper::elementAttributesToUpdate | ( | ) | const |
Returns a list of lists of all associated attribute names corresponding to existing elements that should be updated.
Each item in this list is a list of associated attributes corresponding to an element in the "elements to update" list. In other words, for each item in the "elements to update" list, there is a corresponding QVariant item in this list (with the same index number) that represents the list of the element's associated attributes. Each QVariant consists of all these associated attributes concatenated into a single string value with the individuals separated by the unique string separator that was passed in as constructor parameter. Where an element does not have associated attributes, a NULL QVariant value is added to the list to ensure that the indices of all lists are kept in synch.
Definition at line 347 of file gcbatchprocessorhelper.cpp.
const QVariantList & GCBatchProcessorHelper::elementChildrenToUpdate | ( | ) | const |
Returns a list of lists of all first level child element names corresponding to existing elements that should be updated.
Each item in this list is a list of first level child elements corresponding to an element in the "elements to update" list. In other words, for each item in the "elements to update" list, there is a corresponding QVariant item in this list (with the same index number) that represents the list of the element's first level children. Each QVariant consists of all these first level child elements concatenated into a single string value with the individuals separated by the unique string separator that was passed in as constructor parameter. Where an element does not have first level children, a NULL QVariant value is added to the list to ensure that the indices of all lists are kept in synch.
Definition at line 340 of file gcbatchprocessorhelper.cpp.
const QVariantList & GCBatchProcessorHelper::elementsToUpdate | ( | ) | const |
Returns a list of all the element names that should be updated.
Definition at line 333 of file gcbatchprocessorhelper.cpp.
const QVariantList & GCBatchProcessorHelper::newAssociatedElementsToAdd | ( | ) | const |
Returns a list of all the new associated element names that should be added to the database.
All attributes are associated with specific elements (this allows us to save different values against attributes of the same name that are associated with different elements). Each item in this list is the specific element associated with an attribute in the "new attribute keys to add" list.
Definition at line 361 of file gcbatchprocessorhelper.cpp.
const QVariantList & GCBatchProcessorHelper::newAttributeKeysToAdd | ( | ) | const |
Returns a list of all the new attribute names that should be added to the database.
Definition at line 354 of file gcbatchprocessorhelper.cpp.
const QVariantList & GCBatchProcessorHelper::newAttributeValuesToAdd | ( | ) | const |
Returns a list of lists of all new attribute values that should be added to the database.
Each item in this list is a list of known attribute values corresponding to an attribute in the "new attribute keys to add" list. In other words, for each item in the "new attribute keys to add" list, there is a corresponding QVariant item in this list (with the same index number) that represents the list of the attribute's known values. Each QVariant consists of all these known values concatenated into a single string value with the individuals separated by the unique string separator that was passed in as constructor parameter.
Definition at line 367 of file gcbatchprocessorhelper.cpp.
const QVariantList & GCBatchProcessorHelper::newElementAttributesToAdd | ( | ) | const |
Returns a list of lists of all new associated attribute names that should be added to the database.
Each item in this list is a list of associated attributes corresponding to an element in the "new elements to add" list. In other words, for each item in the "new elements to add" list, there is a corresponding QVariant item in this list (with the same index number) that represents the list of the element's associated attributes. Each QVariant consists of all these associated attributes concatenated into a single string value with the individuals separated by the unique string separator that was passed in as constructor parameter. Where an element does not have associated attributes, a NULL QVariant value is added to the list to ensure that the indices of all lists are kept in synch.
Definition at line 326 of file gcbatchprocessorhelper.cpp.
const QVariantList & GCBatchProcessorHelper::newElementChildrenToAdd | ( | ) | const |
Returns a list of lists of all new first level child element namess that should be added to the database.
Each item in this list is a list of first level child elements corresponding to an element in the "new elements to add" list. In other words, for each item in the "new elements to add" list, there is a corresponding QVariant item in this list (with the same index) that represents the list of the element's first level children. Each QVariant consists of all these first level child elements concatenated into a single string value with the individuals separated by the unique string separator that was passed in as constructor parameter. Where an element does not have first level children, a NULL QVariant value is added to the list to ensure that the indices of all lists are kept in synch.
Definition at line 319 of file gcbatchprocessorhelper.cpp.
const QVariantList & GCBatchProcessorHelper::newElementsToAdd | ( | ) | const |
Returns a list of all the new element names that should be added to the database.
Definition at line 312 of file gcbatchprocessorhelper.cpp.
void GCBatchProcessorHelper::processElement | ( | const QDomElement & | parentElement | ) | [private] |
Processes an element by extracting information related to its first level children, associated attributes and the values of these attributes.
This function is called recursively in order to traverse the DOM hierarchy.
Definition at line 66 of file gcbatchprocessorhelper.cpp.
void GCBatchProcessorHelper::sortRecords | ( | ) | [private] |
Sorts all the element records in the unsorted record map and consolidates values where duplicates are encountered.
Definition at line 116 of file gcbatchprocessorhelper.cpp.