OpenStudioCore:project
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Pages
Public Member Functions | Protected Member Functions | List of all members
openstudio::project::Record Class Reference

#include <Record.hpp>

+ Inheritance diagram for openstudio::project::Record:

Public Member Functions

std::vector< ObjectRecordchildren () const
 Returns all child Records in the database. More...
 
bool connect (const std::string &signal, const QObject *qObject, const std::string &slot, Qt::ConnectionType type=Qt::AutoConnection) const
 Connect signal from this Records implementation object to slot on qObject. More...
 
std::string databaseTableName () const
 Returns the name of the database table. More...
 
std::vector< JoinRecordjoinRecords () const
 Returns all join Records in the database. More...
 
void moveToThread (QThread *targetThread)
 Move the implementation object to target thread. More...
 
ProjectDatabase projectDatabase () const
 Returns the ProjectDatabase, will throw if ProjectDatabase has been destructed. More...
 
std::vector< ObjectRecordresources () const
 Returns all resource Records in the database. More...
 
unsigned useCount () const
 Returns number of shared references to this Records implementation object. More...
 
Getters
int id () const
 Returns the id. More...
 
UUID handle () const
 Returns the handle. More...
 
Template Methods
template<typename T >
cast () const
 Cast to Record of type T, can throw std::bad_cast. More...
 
template<typename T >
boost::optional< T > optionalCast () const
 Cast to optional Record of type T. More...
 

Protected Member Functions

void bindValues (QSqlQuery &query) const
 Bind values to a query for saving. More...
 
bool compareValues (const QSqlQuery &query) const
 Checks that values (except id) are same as query. More...
 
bool databaseCompare (const ProjectDatabase &projectDatabase) const
 Compares just this Record to the one in the database and check if they are exactly equal except for id, does not check children. More...
 
boost::optional< int > findIdByHandle () const
 Try to find this Record's id in the database by using its handle. More...
 
bool haveLastValues () const
 Checks if last values are set for this Record to revert back to. More...
 
void insertRow (ProjectDatabase &projectDatabase)
 Inserts a row in the database for this Record and sets id. More...
 
void insertRow (const std::shared_ptr< QSqlDatabase > &db)
 Inserts a row in the database for this Record and sets id. More...
 
void makeDeleteByHandleQuery (QSqlQuery &query) const
 Makes a query to delete Record with this handle from this Record's database table. More...
 
void makeDeleteByIdQuery (QSqlQuery &query) const
 Makes a query to delete Record with this id from this Record's database table. More...
 
void makeSelectAllQuery (QSqlQuery &query) const
 Makes a query to select all Records in this Record's database table. More...
 
void makeSelectByHandleQuery (QSqlQuery &query) const
 Makes a query to select Record with this handle in this Record's database table. More...
 
void makeSelectByIdQuery (QSqlQuery &query) const
 Makes a query to select Record with this id in this Record's database table. More...
 
void onChange ()
 Method called whenever the Record changes, emits onChange signal. More...
 
void removeRow (ProjectDatabase &projectDatabase)
 Removes just this Record from the database, does not remove children. More...
 
void removeRow (const std::shared_ptr< QSqlDatabase > &db)
 Removes just this Record from the database, does not remove children. More...
 
bool revertRow (ProjectDatabase &projectDatabase)
 Reverts just this Record then saves it in the database, does not revert children. More...
 
void revertToLastValues ()
 Revert values back to last state. More...
 
void saveLastValues ()
 Saves current values as last state. More...
 
void saveRow (ProjectDatabase &projectDatabase)
 Saves just this Record in the database, does not save children. More...
 
void saveRow (const std::shared_ptr< QSqlDatabase > &db)
 Saves just this Record in the database, does not save children. More...
 
void setLastValues (const QSqlQuery &query, ProjectDatabase &projectDatabase)
 Set the last state of this object from the query (including id). More...
 
void setLastValues (ProjectDatabase &projectDatabase)
 Sets the last state of just this Record from the database (including id), does not affect children. More...
 

Constructors and Destructors

virtual ~Record ()
 
 Record (std::shared_ptr< detail::Record_Impl > impl, ProjectDatabase projectDatabase)
 Constructs a new Record. More...
 
 Record (std::shared_ptr< detail::Record_Impl > impl)
 Constructs a new Record but does not create or save to a row in the database, use with caution. More...
 

Detailed Description

Record is the base class for saving and retrieving objects in a ProjectDatabase.

Constructor & Destructor Documentation

virtual openstudio::project::Record::~Record ( )
inlinevirtual
openstudio::project::Record::Record ( std::shared_ptr< detail::Record_Impl >  impl,
ProjectDatabase  projectDatabase 
)
protected

Constructs a new Record.

If an implementation object for the same row already exists in the projectDatabase passed in, then the implementation object passed in will be discarded and the new Record will refer to the existing implementation object.

openstudio::project::Record::Record ( std::shared_ptr< detail::Record_Impl >  impl)
protected

Constructs a new Record but does not create or save to a row in the database, use with caution.

Member Function Documentation

void openstudio::project::Record::bindValues ( QSqlQuery &  query) const
protected

Bind values to a query for saving.

template<typename T >
T openstudio::project::Record::cast ( ) const
inline

Cast to Record of type T, can throw std::bad_cast.

std::vector<ObjectRecord> openstudio::project::Record::children ( ) const

Returns all child Records in the database.

Note, will not find child Records which have been removed.

bool openstudio::project::Record::compareValues ( const QSqlQuery &  query) const
protected

Checks that values (except id) are same as query.

bool openstudio::project::Record::connect ( const std::string &  signal,
const QObject qObject,
const std::string &  slot,
Qt::ConnectionType  type = Qt::AutoConnection 
) const

Connect signal from this Records implementation object to slot on qObject.

bool openstudio::project::Record::databaseCompare ( const ProjectDatabase projectDatabase) const
protected

Compares just this Record to the one in the database and check if they are exactly equal except for id, does not check children.

std::string openstudio::project::Record::databaseTableName ( ) const

Returns the name of the database table.

boost::optional<int> openstudio::project::Record::findIdByHandle ( ) const
protected

Try to find this Record's id in the database by using its handle.

UUID openstudio::project::Record::handle ( ) const

Returns the handle.

bool openstudio::project::Record::haveLastValues ( ) const
protected

Checks if last values are set for this Record to revert back to.

int openstudio::project::Record::id ( ) const

Returns the id.

void openstudio::project::Record::insertRow ( ProjectDatabase projectDatabase)
protected

Inserts a row in the database for this Record and sets id.

void openstudio::project::Record::insertRow ( const std::shared_ptr< QSqlDatabase > &  db)
protected

Inserts a row in the database for this Record and sets id.

std::vector<JoinRecord> openstudio::project::Record::joinRecords ( ) const

Returns all join Records in the database.

Note, will not find join Records which have been removed.

void openstudio::project::Record::makeDeleteByHandleQuery ( QSqlQuery &  query) const
protected

Makes a query to delete Record with this handle from this Record's database table.

void openstudio::project::Record::makeDeleteByIdQuery ( QSqlQuery &  query) const
protected

Makes a query to delete Record with this id from this Record's database table.

void openstudio::project::Record::makeSelectAllQuery ( QSqlQuery &  query) const
protected

Makes a query to select all Records in this Record's database table.

void openstudio::project::Record::makeSelectByHandleQuery ( QSqlQuery &  query) const
protected

Makes a query to select Record with this handle in this Record's database table.

void openstudio::project::Record::makeSelectByIdQuery ( QSqlQuery &  query) const
protected

Makes a query to select Record with this id in this Record's database table.

void openstudio::project::Record::moveToThread ( QThread *  targetThread)

Move the implementation object to target thread.

void openstudio::project::Record::onChange ( )
protected

Method called whenever the Record changes, emits onChange signal.

template<typename T >
boost::optional<T> openstudio::project::Record::optionalCast ( ) const
inline

Cast to optional Record of type T.

ProjectDatabase openstudio::project::Record::projectDatabase ( ) const

Returns the ProjectDatabase, will throw if ProjectDatabase has been destructed.

void openstudio::project::Record::removeRow ( ProjectDatabase projectDatabase)
protected

Removes just this Record from the database, does not remove children.

void openstudio::project::Record::removeRow ( const std::shared_ptr< QSqlDatabase > &  db)
protected

Removes just this Record from the database, does not remove children.

std::vector<ObjectRecord> openstudio::project::Record::resources ( ) const

Returns all resource Records in the database.

Note, will not find resource Records which have been removed.

bool openstudio::project::Record::revertRow ( ProjectDatabase projectDatabase)
protected

Reverts just this Record then saves it in the database, does not revert children.

void openstudio::project::Record::revertToLastValues ( )
protected

Revert values back to last state.

void openstudio::project::Record::saveLastValues ( )
protected

Saves current values as last state.

void openstudio::project::Record::saveRow ( ProjectDatabase projectDatabase)
protected

Saves just this Record in the database, does not save children.

void openstudio::project::Record::saveRow ( const std::shared_ptr< QSqlDatabase > &  db)
protected

Saves just this Record in the database, does not save children.

void openstudio::project::Record::setLastValues ( const QSqlQuery &  query,
ProjectDatabase projectDatabase 
)
protected

Set the last state of this object from the query (including id).

void openstudio::project::Record::setLastValues ( ProjectDatabase projectDatabase)
protected

Sets the last state of just this Record from the database (including id), does not affect children.

unsigned openstudio::project::Record::useCount ( ) const

Returns number of shared references to this Records implementation object.