![]() |
XML Mill
1.0.0
A GUI based XML editor with a memory.
|
Provides a Singleton interface to the SQLite databases used to profile XML documents. More...
#include <gcdatabaseinterface.h>
Public Slots | |
bool | setActiveDatabase (const QString &dbName) |
Sets the database connection corresponding to "dbName" as the active database. | |
bool | addDatabase (const QString &dbName) |
Adds "dbName" to the list of known database connections. | |
bool | removeDatabase (const QString &dbName) |
Removes "dbName" from the list of known database connections. | |
Public Member Functions | |
bool | isInitialised () const |
bool | batchProcessDomDocument (const QDomDocument *domDoc) const |
Batch process an entire DOM document. | |
bool | addElement (const QString &element, const QStringList &children, const QStringList &attributes) const |
Adds a single new element to the active database. | |
bool | addRootElement (const QString &root) const |
Marks an element as a known document root element. | |
bool | updateElementChildren (const QString &element, const QStringList &children, bool replace=false) const |
Updates the list of known first level children associated with "element" by appending the new children to the existing list (nothing is deleted). | |
bool | updateElementAttributes (const QString &element, const QStringList &attributes, bool replace=false) const |
Updates the list of known attributes associated with "element" by appending the new attributes to the existing list (nothing is deleted). | |
bool | updateAttributeValues (const QString &element, const QString &attribute, const QStringList &attributeValues, bool replace=false) const |
Updates the list of known attribute values that is associated with "element" and its corresponding "attribute" by appending the new attribute values to the existing list (nothing is deleted). | |
bool | removeElement (const QString &element) const |
Removes "element" from the active database. | |
bool | removeRootElement (const QString &element) const |
Removes "element" from the list of known root elements for the active database. | |
bool | removeChildElement (const QString &element, const QString &child) const |
Removes "child" from the list of first level element children associated with "element" in the active database. | |
bool | removeAttribute (const QString &element, const QString &attribute) const |
Removes "attribute" from the list of attributes associated with "element" in the active database. | |
bool | hasActiveSession () const |
Returns "true" if an active database session exists, "false" if not. | |
bool | isProfileEmpty () const |
Returns "true" if the active database is empty, "false" if not. | |
bool | containsKnownRootElement (const QString &dbName, const QString &root) const |
Returns "true" if the database named "dbName" knows about "root". | |
bool | isUniqueChildElement (const QString &parentElement, const QString &element) const |
Returns true if "element" is a child of "parentElement" only (i.e. | |
bool | isDocumentCompatible (const QDomDocument *doc) const |
Recursively scans the "doc"'s element hierarchy to ensure that all the document's elements, element relationships and attributes are known to the active profile. | |
QStringList | knownElements () const |
Returns a sorted (case sensitive, ascending) list of all the element names known to the current database connection (the active session). | |
QStringList | children (const QString &element) const |
Returns a sorted (case sensitive, ascending) list of all the first level children associated with "element" in the active database, or an empty QStringList if unsuccessful/none exist. | |
QStringList | attributes (const QString &element) const |
Returns an UNSORTED list of all the attribute names associated with "element" in the active database (the reason this list is unsorted is that all the other lists are used to populate combo boxes, where ordering makes sense, but this particular list is used to populate a table), or an empty QStringList if unsuccessful/none exist. | |
QStringList | attributeValues (const QString &element, const QString &attribute) const |
Returns a sorted (case sensitive, ascending) list of all the attribute values associated with "element" and its corresponding "attribute" in the active database or, an empty QStringList if unsuccessful/none exist. | |
QStringList | knownRootElements () const |
Returns a sorted (case sensitive, ascending) list of all the document root elements known to the the active database. | |
QStringList | connectionList () const |
Returns a list of all known database connections. | |
const QString & | lastError () const |
Returns the last known error message. | |
QString | activeSessionName () const |
Returns the active database session if one exists, or an empty string if not. | |
Static Public Member Functions | |
static GCDataBaseInterface * | instance () |
Singleton accessor. | |
Private Member Functions | |
GCDataBaseInterface () | |
Private constructor. | |
GCDataBaseInterface (const GCDataBaseInterface &) | |
Closes copy constructor Singleton "loophole" by making it inaccessible. | |
GCDataBaseInterface & | operator= (const GCDataBaseInterface &) |
Closes assignment operator Singleton "loophole" by making it inaccessible. | |
QStringList | knownAttributeKeys () const |
Returns a list of known attributes. | |
QSqlQuery | selectElement (const QString &element) const |
Selects "element" from the database. | |
QSqlQuery | selectAllElements () const |
Selects all the known elements from the database and returns the active query. | |
QSqlQuery | selectAttribute (const QString &attribute, const QString &associatedElement) const |
Selects the "attribute" corresponding to "associatedElement" from the database. | |
QSqlQuery | selectAllAttributes () const |
Selects all the known attributes from the database and returns the active query. | |
QStringList | knownRootElements (QSqlDatabase db) const |
Overloaded for private use. | |
bool | removeDuplicatesFromFields () const |
Removes all duplicates that may have been introduced during batch processing. | |
bool | openConnection (const QString &dbConName) |
Opens the database connection corresponding to "dbConName". | |
bool | createTables () const |
Creates all the relevant database tables. | |
void | saveDatabaseFile () const |
Saves the list of known databases to a text file. | |
Private Attributes | |
QSqlDatabase | m_sessionDB |
QString | m_lastErrorMsg |
bool | m_hasActiveSession |
bool | m_initialised |
QMap< QString, QString > | m_dbMap |
Static Private Attributes | |
static GCDataBaseInterface * | m_instance = NULL |
Provides a Singleton interface to the SQLite databases used to profile XML documents.
This class is designed to set up and manage embedded SQLite databases used to profile XML documents. Databases created by this class will consist of three tables:
"xmlelements" - accepts element names as unique primary keys and associates two fields with each record: "children" represents all the first level children of the element in question and "attributes" contain all the attributes known to be associated with the element (these will be ALL the children and attribute names ever associated with any particular unique element name in any particular database so it is best not to mix vastly different XML profiles in the same database).
"xmlattributes" - accepts an attribute name as primary key and references the unique element it is known to be associated with as foreign key. Only one additional field exists for each record: "attributevalues" contains all the values ever associated with this particular attribute when assigned to the specific element it references as foreign key. In other words, if element "x" is known to have had attribute "y" associated with it, then "attributevalues" will contain all the values ever assigned to "y" when associated with "x" across all XML profiles stored in a particular database.
"rootelements" - consists of a single field containing all known root elements stored in a specific database. If more than one XML profile has been loaded into the database in question, the database will have all their root elements listed in this table.
Definition at line 66 of file gcdatabaseinterface.h.
GCDataBaseInterface::GCDataBaseInterface | ( | ) | [private] |
Private constructor.
Definition at line 108 of file gcdatabaseinterface.cpp.
GCDataBaseInterface::GCDataBaseInterface | ( | const GCDataBaseInterface & | ) | [private] |
Closes copy constructor Singleton "loophole" by making it inaccessible.
QString GCDataBaseInterface::activeSessionName | ( | ) | const |
Returns the active database session if one exists, or an empty string if not.
Definition at line 709 of file gcdatabaseinterface.cpp.
bool GCDataBaseInterface::addDatabase | ( | const QString & | dbName | ) | [slot] |
Adds "dbName" to the list of known database connections.
Definition at line 962 of file gcdatabaseinterface.cpp.
bool GCDataBaseInterface::addElement | ( | const QString & | element, |
const QStringList & | children, | ||
const QStringList & | attributes | ||
) | const |
Adds a single new element to the active database.
This function does nothing if an element with the same name already exists.
element | - the unique element name |
children | - a list of the element's first level child elements' names |
attributes | - a list of all the element's associated attribute names. |
Definition at line 305 of file gcdatabaseinterface.cpp.
bool GCDataBaseInterface::addRootElement | ( | const QString & | root | ) | const |
Marks an element as a known document root element.
This function does nothing if the root already exists in the relevant table.
root | - the name of the unique root element |
Definition at line 345 of file gcdatabaseinterface.cpp.
QStringList GCDataBaseInterface::attributes | ( | const QString & | element | ) | const |
Returns an UNSORTED list of all the attribute names associated with "element" in the active database (the reason this list is unsorted is that all the other lists are used to populate combo boxes, where ordering makes sense, but this particular list is used to populate a table), or an empty QStringList if unsuccessful/none exist.
Definition at line 843 of file gcdatabaseinterface.cpp.
QStringList GCDataBaseInterface::attributeValues | ( | const QString & | element, |
const QString & | attribute | ||
) | const |
Returns a sorted (case sensitive, ascending) list of all the attribute values associated with "element" and its corresponding "attribute" in the active database or, an empty QStringList if unsuccessful/none exist.
Definition at line 864 of file gcdatabaseinterface.cpp.
bool GCDataBaseInterface::batchProcessDomDocument | ( | const QDomDocument * | domDoc | ) | const |
Batch process an entire DOM document.
This function processes an entire DOM document by adding new (or updating existing) elements with their corresponding first level children and associated attributes and known attribute values to the active database in batches.
Definition at line 155 of file gcdatabaseinterface.cpp.
QStringList GCDataBaseInterface::children | ( | const QString & | element | ) | const |
Returns a sorted (case sensitive, ascending) list of all the first level children associated with "element" in the active database, or an empty QStringList if unsuccessful/none exist.
Definition at line 821 of file gcdatabaseinterface.cpp.
QStringList GCDataBaseInterface::connectionList | ( | ) | const |
Returns a list of all known database connections.
Definition at line 948 of file gcdatabaseinterface.cpp.
bool GCDataBaseInterface::containsKnownRootElement | ( | const QString & | dbName, |
const QString & | root | ||
) | const |
Returns "true" if the database named "dbName" knows about "root".
Definition at line 919 of file gcdatabaseinterface.cpp.
bool GCDataBaseInterface::createTables | ( | ) | const [private] |
Creates all the relevant database tables.
Definition at line 1337 of file gcdatabaseinterface.cpp.
bool GCDataBaseInterface::hasActiveSession | ( | ) | const |
Returns "true" if an active database session exists, "false" if not.
Definition at line 702 of file gcdatabaseinterface.cpp.
GCDataBaseInterface * GCDataBaseInterface::instance | ( | ) | [static] |
Singleton accessor.
Definition at line 96 of file gcdatabaseinterface.cpp.
bool GCDataBaseInterface::isDocumentCompatible | ( | const QDomDocument * | doc | ) | const |
Recursively scans the "doc"'s element hierarchy to ensure that all the document's elements, element relationships and attributes are known to the active profile.
Definition at line 746 of file gcdatabaseinterface.cpp.
bool GCDataBaseInterface::isInitialised | ( | ) | const |
Definition at line 148 of file gcdatabaseinterface.cpp.
bool GCDataBaseInterface::isProfileEmpty | ( | ) | const |
Returns "true" if the active database is empty, "false" if not.
Definition at line 721 of file gcdatabaseinterface.cpp.
bool GCDataBaseInterface::isUniqueChildElement | ( | const QString & | parentElement, |
const QString & | element | ||
) | const |
Returns true if "element" is a child of "parentElement" only (i.e.
it doesn't exist in any other first level child list).
Definition at line 728 of file gcdatabaseinterface.cpp.
QStringList GCDataBaseInterface::knownAttributeKeys | ( | ) | const [private] |
Returns a list of known attributes.
Definition at line 1075 of file gcdatabaseinterface.cpp.
QStringList GCDataBaseInterface::knownElements | ( | ) | const |
Returns a sorted (case sensitive, ascending) list of all the element names known to the current database connection (the active session).
Definition at line 801 of file gcdatabaseinterface.cpp.
QStringList GCDataBaseInterface::knownRootElements | ( | ) | const |
Returns a sorted (case sensitive, ascending) list of all the document root elements known to the the active database.
Definition at line 886 of file gcdatabaseinterface.cpp.
QStringList GCDataBaseInterface::knownRootElements | ( | QSqlDatabase | db | ) | const [private] |
Overloaded for private use.
Definition at line 893 of file gcdatabaseinterface.cpp.
const QString & GCDataBaseInterface::lastError | ( | ) | const |
Returns the last known error message.
Definition at line 955 of file gcdatabaseinterface.cpp.
bool GCDataBaseInterface::openConnection | ( | const QString & | dbConName | ) | [private] |
Opens the database connection corresponding to "dbConName".
This function will also close current sessions (if any) before opening the new one.
Definition at line 1294 of file gcdatabaseinterface.cpp.
GCDataBaseInterface& GCDataBaseInterface::operator= | ( | const GCDataBaseInterface & | ) | [private] |
Closes assignment operator Singleton "loophole" by making it inaccessible.
bool GCDataBaseInterface::removeAttribute | ( | const QString & | element, |
const QString & | attribute | ||
) | const |
Removes "attribute" from the list of attributes associated with "element" in the active database.
Definition at line 632 of file gcdatabaseinterface.cpp.
bool GCDataBaseInterface::removeChildElement | ( | const QString & | element, |
const QString & | child | ||
) | const |
Removes "child" from the list of first level element children associated with "element" in the active database.
Definition at line 614 of file gcdatabaseinterface.cpp.
bool GCDataBaseInterface::removeDatabase | ( | const QString & | dbName | ) | [slot] |
Removes "dbName" from the list of known database connections.
Definition at line 999 of file gcdatabaseinterface.cpp.
bool GCDataBaseInterface::removeDuplicatesFromFields | ( | ) | const [private] |
Removes all duplicates that may have been introduced during batch processing.
After batch processing a DOM document, we concatenate new values to existing values in the record fields. This function removes all duplicates that may have been introduced in this way by consolidating the values and updating the records.
Definition at line 1184 of file gcdatabaseinterface.cpp.
bool GCDataBaseInterface::removeElement | ( | const QString & | element | ) | const |
Removes "element" from the active database.
Definition at line 582 of file gcdatabaseinterface.cpp.
bool GCDataBaseInterface::removeRootElement | ( | const QString & | element | ) | const |
Removes "element" from the list of known root elements for the active database.
Definition at line 674 of file gcdatabaseinterface.cpp.
void GCDataBaseInterface::saveDatabaseFile | ( | ) | const [private] |
Saves the list of known databases to a text file.
Definition at line 1384 of file gcdatabaseinterface.cpp.
QSqlQuery GCDataBaseInterface::selectAllAttributes | ( | ) | const [private] |
Selects all the known attributes from the database and returns the active query.
Definition at line 1169 of file gcdatabaseinterface.cpp.
QSqlQuery GCDataBaseInterface::selectAllElements | ( | ) | const [private] |
Selects all the known elements from the database and returns the active query.
Definition at line 1124 of file gcdatabaseinterface.cpp.
QSqlQuery GCDataBaseInterface::selectAttribute | ( | const QString & | attribute, |
const QString & | associatedElement | ||
) | const [private] |
Selects the "attribute" corresponding to "associatedElement" from the database.
The active query for the command is returned (the function does not care whether or not the record exists).
Definition at line 1139 of file gcdatabaseinterface.cpp.
QSqlQuery GCDataBaseInterface::selectElement | ( | const QString & | element | ) | const [private] |
Selects "element" from the database.
The active query for the command is returned (the function does not care whether or not the record exists).
Definition at line 1098 of file gcdatabaseinterface.cpp.
bool GCDataBaseInterface::setActiveDatabase | ( | const QString & | dbName | ) | [slot] |
Sets the database connection corresponding to "dbName" as the active database.
Definition at line 1039 of file gcdatabaseinterface.cpp.
bool GCDataBaseInterface::updateAttributeValues | ( | const QString & | element, |
const QString & | attribute, | ||
const QStringList & | attributeValues, | ||
bool | replace = false |
||
) | const |
Updates the list of known attribute values that is associated with "element" and its corresponding "attribute" by appending the new attribute values to the existing list (nothing is deleted).
If "replace" is true, the existing values are replaced by those in the parameter list
element | - the unique name of the element to be updated |
attribute | - the name of the associated attribute to te updated |
attributeValues | - a list of the attribute values associated with the attribute |
replace | - if true, the attribute value list is replaced, if false, "attributeValues" is merged with the existing list. |
Definition at line 508 of file gcdatabaseinterface.cpp.
bool GCDataBaseInterface::updateElementAttributes | ( | const QString & | element, |
const QStringList & | attributes, | ||
bool | replace = false |
||
) | const |
Updates the list of known attributes associated with "element" by appending the new attributes to the existing list (nothing is deleted).
If "replace" is true, the existing values are replaced by those in the parameter list.
element | - the unique name of the element to be updated |
attributes | - a list of the attribute names associated with the element |
replace | - if true, the attribute list is replaced, if false, "attributes" is merged with the existing list. |
Definition at line 453 of file gcdatabaseinterface.cpp.
bool GCDataBaseInterface::updateElementChildren | ( | const QString & | element, |
const QStringList & | children, | ||
bool | replace = false |
||
) | const |
Updates the list of known first level children associated with "element" by appending the new children to the existing list (nothing is deleted).
If "replace" is true, the existing values are replaced by those in the parameter list.
element | - the unique name of the element to be updated |
children | - a list of the element's first level child elements' names |
replace | - if true, the child list is replaced, if false, "children" is merged with the existing list. |
Definition at line 401 of file gcdatabaseinterface.cpp.