Workspace 6.21.5
|
A simple structure for specifying relationship information between objects. More...
#include <DataAnalysis/DataStructures/sqlbindingrelation.h>
Protected Member Functions | |
SqlBindingRelation (RelationCardinality cardinality, const QString &foreignKey) | |
const SqlBoundObjectGroupData & | getOwner () const |
virtual SqlDataModelResult | populateDataImpl (SqlDataModel &model, const QSqlRecord &record, QSqlQuery &query, const QStringList &relations)=0 |
void | setOwner (const SqlBoundObjectGroupData &owner) |
Protected Attributes | |
RelationCardinality | cardinality_ |
QString | foreignKey_ |
const SqlBoundObjectGroupData * | owner_ |
bool | populating_ |
The SqlBindingRelation essentially represents a valid relationship between one SqlBoundObjectGroup derived class and another. When bound to a specific SqlBoundObjectGroup, a SqlBindingRelation object contains the necessary information to retrieve the relevant associative information from the underlying database and embed it in the related object.
SqlBindingRelations are bound to SqlBoundObjectGroups at the time the object group is constructed. For example, if we look at an example object constructor for an Author object, we see that it has two relationships - a many-to-one relation, and a many-to-many relation:
``` Author() : DataAnalysis::TypedSqlBoundObjectGroup<Author, int>() { bindField("Id", id); bindField("LastName", lastName); bindField("FirstName", firstName); bindField("Address", address); bindField("City", city); bindField("Publisher", publisher); bindField("Books", books); bindPrimaryKeyField(id); bindRelation(DataAnalysis::ManyToOneRelation<Testing::Publisher>(publisher, "Publisher_Id")); bindRelation(DataAnalysis::ManyToManyRelation<Testing::Book>(books, "Book_Id", "Author_Id", "Author_Book")); } ```
Each relation is constructed differently, but essentially we provide it a reference to the underlying object (which must already be bound to the object via 'bindField'), and a number of parameters specifying how the relation information is obtained via foreign keys and / or intersection tables.
As can be seen from the above code, relations are bound to an "owner" by invoking the bindRelation() function in the constructor of that owner object.
|
default |
|
protected |
cardinality | The cardinality of this relation type. |
foreignKey | The foreign key field associated with this relation. |
|
overridepure virtual |
Implements Clonable.
Implemented in ManyToManyRelation< T >, ManyToOneRelation< T >, OneToManyRelation< T >, and OneToOneRelation< T >.
|
pure virtual |
owner | The SqlBoundObjectGroupData object that is to take ownership of the newly constructed relation object. |
boundObject | The new SqlBoundObjectGroup that is going to be the bound object in the newly constructed relation object. |
Constructs a deep copy of the relation, setting the owner to owner and the bound object to boundObject. boundObject is assumed to have been created by the calling code and is assumed to be of the correct type (subclasses enforce this).
Implemented in ManyToManyRelation< T >, ManyToOneRelation< T >, OneToManyRelation< T >, and OneToOneRelation< T >.
|
pure virtual |
Recursively retrieves all the relations that exist below this relation; i.e. all of those field names on the bound object (as well as its child relations).
Implemented in ManyToManyRelation< T >, ManyToOneRelation< T >, OneToManyRelation< T >, and OneToOneRelation< T >.
|
inline |
|
pure virtual |
Implemented in ManyToManyRelation< T >, ManyToOneRelation< T >, OneToManyRelation< T >, and OneToOneRelation< T >.
|
pure virtual |
Implemented in ManyToManyRelation< T >, ManyToOneRelation< T >, OneToManyRelation< T >, and OneToOneRelation< T >.
|
pure virtual |
Implemented in ManyToManyRelation< T >, ManyToOneRelation< T >, OneToManyRelation< T >, and OneToOneRelation< T >.
RelationCardinality getCardinality | ( | ) | const |
|
inline |
|
pure virtual |
Implemented in ManyToManyRelation< T >, ManyToOneRelation< T >, OneToManyRelation< T >, and OneToOneRelation< T >.
|
inlineprotected |
|
pure virtual |
relationNames | A list of relation names that we will follow when retrieving the related bindings. Callers may not be interested in all related bindings. |
recursive | Whether or not to continue through the entire tree of relations, or to stop at the immedate level. |
Retrieves the set of SqlBindingRelations associated with this relation's bound object. This is necessary to retrieve multiple levels of relations from a single point in an object hierarchy.
Implemented in ManyToManyRelation< T >, ManyToOneRelation< T >, OneToManyRelation< T >, and OneToOneRelation< T >.
|
pure virtual |
Implemented in ManyToManyRelation< T >, ManyToOneRelation< T >, OneToManyRelation< T >, and OneToOneRelation< T >.
|
pure virtual |
Implemented in ManyToManyRelation< T >, ManyToOneRelation< T >, OneToManyRelation< T >, and OneToOneRelation< T >.
|
default |
SqlDataModelResult populateData | ( | SqlDataModel & | model, |
const QSqlRecord & | record, | ||
QSqlQuery & | query, | ||
const QStringList & | relations = QStringList() |
||
) |
model | The model being used to populate the data, which is attached to a database. |
record | A valid record containing the column names of the records referred to by query. |
query | A valid query object referring to one or more records. |
relations | A list of relations to follow in the case that the bound object associated with this relation contains is own child objects. |
Populates this relations data from the specified QSqlQuery, which is must be pointing at a valid record. For efficiency reasons, a record parameter is also provided which contains the column names.
If the bound object associated with this relation has its own child relations, this method will also follow and populate those that are included in the list relations.
|
protectedpure virtual |
model | The model being used to populate the data, which is attached to a database. |
record | A valid record containing the column names of the records referred to by query. |
query | A valid query object referring to one or more records. |
relations | A list of relations to follow in the case that the bound object associated with this relation contains is own child objects. |
Subclasses must implement this method in order to populate the data contained in this relation, and its associated bound object (as well as its children - the method is recursive).
Implemented in ManyToManyRelation< T >, ManyToOneRelation< T >, OneToManyRelation< T >, and OneToOneRelation< T >.
|
pure virtual |
model | The SqlDataModel through which we are saving this relation. |
relations | A list of relation names that we will follow when saving related data in the case that the bound object itself has its own relations. |
Saves this relation to the database underlying the specified model so that it is persistent.
Implemented in ManyToManyRelation< T >, ManyToOneRelation< T >, OneToManyRelation< T >, and OneToOneRelation< T >.
|
inlineprotected |
|
protected |
|
protected |
|
protected |
|
protected |