Workspace 6.21.5
Public Types | Public Member Functions | Protected Member Functions | List of all members
TypedSqlBoundObjectGroup< Derived, PrimaryKeyType > Class Template Reference

Typed derived class of SqlBoundObjectGroup from which all implementations of SqlBoundObjectGroup should extend. Uses CRTP to implement most methods. More...

#include <DataAnalysis/DataStructures/typedsqlboundobjectgroup.h>

Inheritance diagram for TypedSqlBoundObjectGroup< Derived, PrimaryKeyType >:
[legend]

Public Types

typedef PrimaryKeyType IdType
 

Public Member Functions

bool bindPrimaryKeyField (const DataExecution::TypedObject< PrimaryKeyType > &pkObj, bool autoIncrement=false)
 
TypedSqlBoundObjectGroupclone () const override
 
TypedSqlBoundObjectGroupdeepCopy () const override
 
Derived & operator= (const Derived &obj)
 
TypedSqlBoundObjectGroupoperator= (const TypedSqlBoundObjectGroup &obj)
 
Derived * shallowCopy () const
 
- Public Member Functions inherited from SqlBoundObjectGroup
 ~SqlBoundObjectGroup () override
 
SqlBoundObjectGroupclone () const override=0
 
virtual SqlBoundObjectGroupdeepCopy () const =0
 
void detach (bool recursive=false)
 
QStringList getAutoIncrementFieldNames () const
 
QString getBoundTableName () const
 
QStringList getCompositePrimaryKeyFieldNames () const
 
QStringList getCompositePrimaryKeyFieldNamesAliased () const
 
QString getFieldName (const DataExecution::DataObject &object) const
 
QStringList getNonRelationFieldAliases () const
 
QStringList getNonRelationFieldNames () const
 
DataExecution::DataObjectgetPrimaryKeyField ()
 
const DataExecution::DataObjectgetPrimaryKeyField () const
 
QString getPrimaryKeyFieldName () const
 
QString getPrimaryKeyFieldNameAliased () const
 
SqlBindingRelationMap getRelationBindings (const QStringList &relationNames=QStringList(), bool recursive=false) const
 
QStringList getRelationFieldNames (bool recursive) const
 
QStringList getSqlValidCompositePrimaryKeyFieldNames () const
 
QStringList getSqlValidFieldList () const
 
bool hasCompositePrimaryKey () const
 
bool isPersistent () const
 
bool isPrimaryKeyField (const DataExecution::DataObject &obj) const
 
bool isRelationField (const QString &fieldName) const
 
void setPersistent (bool b)
 
- Public Member Functions inherited from ObjectGroup
 ~ObjectGroup () override
 
bool add (const QString &name, DataObject &obj)
 
bool canSerialize () const override
 
ObjectGroupclone () const override=0
 
bool empty () const
 
void ensureGroupHasData ()
 
void erase (int index)
 
DataObjectgetChild (const QString &name)
 
const DataObjectgetChild (const QString &name) const
 
DataObjectgetDataObject (int index)
 
const DataObjectgetDataObject (int index) const
 
int getIndex (const QString &name) const
 
const QString & getName (int index) const
 
virtual QString getPreferedWidget (const QString &name) const
 
bool hasData () const
 
bool haveName (const QString &name) const
 
bool insert (const QString &name, DataObject &obj, int index=-1)
 
bool load (const QJsonDocument &doc)
 
bool load (const SerializedItem &item) override
 
bool save (QJsonDocument &doc) const
 
bool save (SerializedItem &item) const override
 
unsigned size () const
 
- Public Member Functions inherited from Clonable
virtual ~Clonable ()=default
 
virtual Clonableclone () const =0
 
- Public Member Functions inherited from Serialize
virtual ~Serialize ()=default
 
virtual bool canSerialize () const =0
 
virtual bool load (const SerializedItem &item)=0
 
virtual bool save (SerializedItem &item) const =0
 

Protected Member Functions

 TypedSqlBoundObjectGroup ()
 
 TypedSqlBoundObjectGroup (const TypedSqlBoundObjectGroup &other)
 
const SqlBoundObjectClassDatagetClassData () const override
 
QSqlQuery getInsertQuery (const SqlDataModel &model, const QStringList &relations, const QString &foreignKeyName, const QVariant &foreignKeyValue) const override
 
QSqlQuery getUpdateQuery (const SqlDataModel &model, const QStringList &relations, const QString &foreignKeyName, const QVariant &foreignKeyValue) const override
 
- Protected Member Functions inherited from SqlBoundObjectGroup
 SqlBoundObjectGroup (const SqlBoundObjectGroup &other)
 
 SqlBoundObjectGroup (SqlBoundObjectGroupData *data)
 
bool bindCompositePrimaryKey (const QList< const DataExecution::DataObject * > &objects)
 
bool bindField (const QString &fieldName, DataExecution::DataObject &object)
 
bool bindRelation (const SqlBindingRelation &relation)
 
virtual const SqlBoundObjectClassDatagetClassData () const =0
 
virtual QSqlQuery getInsertQuery (const SqlDataModel &model, const QStringList &relations, const QString &foreignKeyName=QString(), const QVariant &foreignKeyValue=QVariant()) const =0
 
virtual QSqlQuery getUpdateQuery (const SqlDataModel &model, const QStringList &relations, const QString &foreignKeyName=QString(), const QVariant &foreignKeyValue=QVariant()) const =0
 
SqlBoundObjectGroupoperator= (const SqlBoundObjectGroup &)
 
bool operator== (const SqlBoundObjectGroup &rhs) const
 
bool setPrimaryKeyField (const DataExecution::DataObject &obj, bool autoIncrement)
 
- Protected Member Functions inherited from ObjectGroup
 ObjectGroup ()
 
void clear ()
 
ObjectGroupoperator= (const ObjectGroup &rhs)
 
bool operator== (const ObjectGroup &rhs) const
 
void swap (ObjectGroup &rhs)
 

Detailed Description

template<typename Derived, typename PrimaryKeyType>
class CSIRO::DataAnalysis::TypedSqlBoundObjectGroup< Derived, PrimaryKeyType >
Template Parameters
DerivedThe derived class itself.
PrimaryKeyTypeThe type of the primary key data stored in Derived.

TypedSqlBoundObjectGroup provides a set of utility functions as well as guaranteed type safety between SqlBoundObjectGroup derived classes. It allows the SqlDataModel to make reasonable assumptions about bound objects, most notably the data type of their primary key (and therefore foreign keys of relation types).

The class also provides virtual function implementations for all of the pure-virtual methods of the SqlBoundObjectGroup class, as well as a number of convenience "typed" methods to make interacting with derived classes simpler in the SqlDataModel methods.

Member Typedef Documentation

◆ IdType

typedef PrimaryKeyType IdType

Constructor & Destructor Documentation

◆ TypedSqlBoundObjectGroup() [1/2]

TypedSqlBoundObjectGroup ( )
inlineprotected

Constructs a new TypedSqlBoundObjectGroup (internal constructor only, intended for derived classes), which will create a new explicitly shared data object and provide it to the SqlBoundObjectGroup base class, along with a reference to the static class data associated with the type (e.g. the bound table name, for example).

All derived class constructors will call this constructor in their initialisation list.

◆ TypedSqlBoundObjectGroup() [2/2]

TypedSqlBoundObjectGroup ( const TypedSqlBoundObjectGroup< Derived, PrimaryKeyType > &  other)
inlineprotected
Parameters
otherThe other TypedSqlBoundObjectGroup to copy from.

Member Function Documentation

◆ bindPrimaryKeyField()

bool bindPrimaryKeyField ( const DataExecution::TypedObject< PrimaryKeyType > &  pkObj,
bool  autoIncrement = false 
)
inline
Parameters
pkObjThe data object containing the primary key data.
autoIncrementSet to true if this field is set to auto-increment in the database.
Returns
True if the binding was successful, false otherwise (e.g. if pkObj is not a child of this object).

Typed method for binding the primary key object. Note that pkObj is of the same primary key type as this object.

◆ clone()

TypedSqlBoundObjectGroup * clone ( ) const
inlineoverridevirtual
Returns
A shallow copy of our object: i.e. our data is shared between all objects of the same type. This is the default in order to allow easy distribution of the same object throughout an object hierarchy retrieved from a database.
See also
shallowCopy
deepCopy

Implements SqlBoundObjectGroup.

◆ deepCopy()

TypedSqlBoundObjectGroup * deepCopy ( ) const
inlineoverridevirtual
Returns
A deep copy of the object, with copies of of all underlying objects right down the entire object hierarchy. Use this when you want to copy an entire tree but deliberately do not want to modify any shared data.

Implements SqlBoundObjectGroup.

◆ getClassData()

const SqlBoundObjectClassData & getClassData ( ) const
inlineoverrideprotectedvirtual
Returns
The class data associated with this object.

Implements SqlBoundObjectGroup.

◆ getInsertQuery()

QSqlQuery getInsertQuery ( const SqlDataModel model,
const QStringList relations,
const QString &  foreignKeyName,
const QVariant &  foreignKeyValue 
) const
inlineoverrideprotectedvirtual
Parameters
modelThe SqlDataModel responsible for the insertion operation.
relationsA list of relations to follow when generating the insert.
foreignKeyName(optional) The name of a foreign key field attached to the table that this object is bound to. Important for inserting objects with bi-directional relations.
foreignKeyValueThe value to store in the field named foreignKeyName when inserting this object.
Returns
A QSqlQuery that can be executed to insert this object into the database associated with model.

Returns the SQL query required to insert this particular object into a database. Callers should never need to invoke this method directly.

Implements SqlBoundObjectGroup.

◆ getUpdateQuery()

QSqlQuery getUpdateQuery ( const SqlDataModel model,
const QStringList relations,
const QString &  foreignKeyName,
const QVariant &  foreignKeyValue 
) const
inlineoverrideprotectedvirtual
Parameters
modelThe SqlDataModel responsible for the update operation.
relationsA list of relations to follow when generating the update.
foreignKeyName(optional) The name of a foreign key field attached to the table that this object is bound to. Important for updating objects with bi-directional relations.
foreignKeyValueThe value to store in the field named foreignKeyName when updating this object.
Returns
A QSqlQuery that can be executed to update this object in the database associated with model.

Implements SqlBoundObjectGroup.

◆ operator=() [1/2]

Derived & operator= ( const Derived &  obj)
inline

◆ operator=() [2/2]

TypedSqlBoundObjectGroup & operator= ( const TypedSqlBoundObjectGroup< Derived, PrimaryKeyType > &  obj)
inline
Parameters
objThe object to assign to this one.
Returns
A reference to this object for assignment chaining purposes.

◆ shallowCopy()

Derived * shallowCopy ( ) const
inline
Returns
A shallow copy of the object referring to the same underlying data as this object.