Workspace 6.21.5
Public Member Functions | List of all members
OneToManyRelation< T > Class Template Reference

One-to-many relationship type. More...

#include <DataAnalysis/DataStructures/onetomanyrelation.h>

Inheritance diagram for OneToManyRelation< T >:
[legend]

Public Member Functions

 OneToManyRelation (const OneToManyRelation &other)=default
 
 OneToManyRelation (DataExecution::TypedObject< DataExecution::TypedObjectArray< T > > &dataMember, const QString &foreignKey)
 
OneToManyRelation< T > * clone () const override
 
SqlBindingRelationdeepCopy (const SqlBoundObjectGroupData *owner, DataExecution::DataObject &boundObject) override
 
QStringList getAllRelationNames () const override
 
const DataExecution::DataObjectgetBoundObject () const override
 
const SqlBoundObjectClassDatagetBoundObjectClassData () const override
 
const DataExecution::DataFactorygetBoundType () const override
 
QString getJoinStatement () const override
 
SqlBindingRelationMap getRelationBindings (const QStringList &relationNames, bool recursive) override
 
QStringList getSqlValidFieldList () const override
 
bool isBoundObjectArray () const override
 
SqlDataModelResult populateDataImpl (SqlDataModel &model, const QSqlRecord &record, QSqlQuery &query, const QStringList &relations=QStringList()) override
 
SqlDataModelResult saveBoundObject (SqlDataModel &model, const QStringList &relations) const override
 
- Public Member Functions inherited from SqlBindingRelation
 SqlBindingRelation (const SqlBindingRelation &)=default
 
SqlBindingRelationclone () const override=0
 
virtual SqlBindingRelationdeepCopy (const SqlBoundObjectGroupData *owner, DataExecution::DataObject &boundObject)=0
 
virtual QStringList getAllRelationNames () const =0
 
DataExecution::DataObjectgetBoundObject ()
 
virtual const DataExecution::DataObjectgetBoundObject () const =0
 
virtual const SqlBoundObjectClassDatagetBoundObjectClassData () const =0
 
virtual const DataExecution::DataFactorygetBoundType () const =0
 
RelationCardinality getCardinality () const
 
const QString & getForeignKey () const
 
virtual QString getJoinStatement () const =0
 
virtual SqlBindingRelationMap getRelationBindings (const QStringList &relationNames, bool recursive)=0
 
virtual QStringList getSqlValidFieldList () const =0
 
virtual bool isBoundObjectArray () const =0
 
SqlBindingRelationoperator= (const SqlBindingRelation &)=default
 
SqlDataModelResult populateData (SqlDataModel &model, const QSqlRecord &record, QSqlQuery &query, const QStringList &relations=QStringList())
 
virtual SqlDataModelResult saveBoundObject (SqlDataModel &model, const QStringList &relations) const =0
 
- Public Member Functions inherited from Clonable
virtual ~Clonable ()=default
 
virtual Clonableclone () const =0
 
- Public Member Functions inherited from IsDerivedFrom< T, SqlBoundObjectGroup >
 IsDerivedFrom ()
 

Additional Inherited Members

- Protected Member Functions inherited from SqlBindingRelation
 SqlBindingRelation (RelationCardinality cardinality, const QString &foreignKey)
 
const SqlBoundObjectGroupDatagetOwner () const
 
virtual SqlDataModelResult populateDataImpl (SqlDataModel &model, const QSqlRecord &record, QSqlQuery &query, const QStringList &relations)=0
 
void setOwner (const SqlBoundObjectGroupData &owner)
 
- Protected Attributes inherited from SqlBindingRelation
RelationCardinality cardinality_
 
QString foreignKey_
 
const SqlBoundObjectGroupDataowner_
 
bool populating_
 

Detailed Description

template<typename T>
class CSIRO::DataAnalysis::OneToManyRelation< T >
Template Parameters
TThe specific type of bound object (derived from SqlBoundObjectGroup) that this relation refers to. Note that this relation type actually refers to an array of such types; TypedObjectArray<T>.

A one-to-many relation is where a single object is associated with multiple objects of the same type, and each target object itself is only associated with a single object of this type.

Conceptually, the relationship looks like this:

Owner --(has many)--> T
Owner <--(has one)--- T

And from a database perspective it looks like:

Owner_Table  <--(foreign key)--- T_Table

Constructor & Destructor Documentation

◆ OneToManyRelation() [1/2]

OneToManyRelation ( const OneToManyRelation< T > &  other)
default

◆ OneToManyRelation() [2/2]

OneToManyRelation ( DataExecution::TypedObject< DataExecution::TypedObjectArray< T > > &  dataMember,
const QString &  foreignKey 
)
inlineexplicit
Parameters
dataMemberThe array data member that this relationship is associated with, where each member of the array refers to an object of type T that the owner object is related to.
foreignKeyThe name of the foreign key in the bound object's (T) table.

Creates a new OneToManyRelation, binding to the object dataMember which will contain the related data sourced (or written to) the database. The string foreignKey is the name of the database column that refers from the bound table associated with T back to the bound table associated with the owning object.

Member Function Documentation

◆ clone()

OneToManyRelation< T > * clone ( ) const
inlineoverridevirtual
Returns
A shallow copy of this relation; one that refers to the same bound object and has the same owner.

Implements SqlBindingRelation.

◆ deepCopy()

SqlBindingRelation * deepCopy ( const SqlBoundObjectGroupData owner,
DataExecution::DataObject boundObject 
)
inlineoverridevirtual
Parameters
ownerThe SqlBoundObjectGroupData object that is to take ownership of the newly constructed relation object.
boundObjectThe new SqlBoundObjectGroup that is going to be the bound object in the newly constructed relation object.
Returns
A new SqlBindingRelation object that is identical to this one, except that it references the specified boundObject (provided by calling code, assumed to be already constructed), and the specified owner.

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).

Implements SqlBindingRelation.

◆ getAllRelationNames()

QStringList getAllRelationNames ( ) const
inlineoverridevirtual
Returns
A string list of all the relation field names associated with this relations bound object and its children.

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).

Implements SqlBindingRelation.

◆ getBoundObject()

const DataExecution::DataObject & getBoundObject ( ) const
inlineoverridevirtual
Returns
A reference to the bound object associated with this relation; i.e. the object that will store containing the referenced data.
Note
For some relation types, this DataObject may refer to a specify TypedObjectArray containing multiple individual related objects.

Implements SqlBindingRelation.

◆ getBoundObjectClassData()

const SqlBoundObjectClassData & getBoundObjectClassData ( ) const
inlineoverridevirtual
Returns
A reference to the class data associated with the relation's bound object.

Implements SqlBindingRelation.

◆ getBoundType()

const DataExecution::DataFactory & getBoundType ( ) const
inlineoverridevirtual
Returns
The data factory associated with the underlying data type that this relation is associated with; i.e. the bound object's type, or if the bound object is an array, the type of object stored in the array.

Implements SqlBindingRelation.

◆ getJoinStatement()

QString getJoinStatement ( ) const
inlineoverridevirtual
Returns
A QString containing the component of an SQL statement required to join the owner of this relation (i.e. the owner table) with the table associated with the bound object.

Implements SqlBindingRelation.

◆ getRelationBindings()

SqlBindingRelationMap getRelationBindings ( const QStringList relationNames,
bool  recursive 
)
inlineoverridevirtual
Parameters
relationNamesA list of relation names that we will follow when retrieving the related bindings. Callers may not be interested in all related bindings.
recursiveWhether or not to continue through the entire tree of relations, or to stop at the immedate level.
Returns
A map containing all SqlBindingRelations associated with this relation's bound object.

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.

Implements SqlBindingRelation.

◆ getSqlValidFieldList()

QStringList getSqlValidFieldList ( ) const
inlineoverridevirtual
Returns
A list of the field names from the relation's bound object. The field names are formatted ready for us in an SQL query and take the form:
tableName.fieldName fieldAlias
Note
Relation field names (i.e. those fields associated with other SqlBoundObjectGroups) are not contained in this list, as it is not valid to use these in an SQL query directly. That's what getJoinStatement() is for.

Implements SqlBindingRelation.

◆ isBoundObjectArray()

bool isBoundObjectArray ( ) const
inlineoverridevirtual

Implements SqlBindingRelation.

◆ populateDataImpl()

SqlDataModelResult populateDataImpl ( SqlDataModel model,
const QSqlRecord &  record,
QSqlQuery &  query,
const QStringList relations = QStringList() 
)
inlineoverridevirtual
Parameters
modelThe model being used to populate the data, which is attached to a database.
recordA valid record containing the column names of the records referred to by query.
queryA valid query object referring to one or more records.
relationsA list of relations to follow in the case that the bound object associated with this relation contains is own child objects.
Returns
A SqlDataModelResult object containing the results of the populate method.

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).

Note
The implementation does not need to move the query cursor forward in any way, the calling code will manage this for populating the next record.

Implements SqlBindingRelation.

◆ saveBoundObject()

SqlDataModelResult saveBoundObject ( SqlDataModel model,
const QStringList relations 
) const
inlineoverridevirtual
Parameters
modelThe SqlDataModel through which we are saving this relation.
relationsA list of relation names that we will follow when saving related data in the case that the bound object itself has its own relations.
Returns
An SqlDataModelResult containing the result of the save operation.

Saves this relation to the database underlying the specified model so that it is persistent.

Implements SqlBindingRelation.