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

#include <ProjectDatabase.hpp>

Public Member Functions

void commitRemove (const RemoveUndo &removeUndo)
 Finalizes removal of removed objects, necessary to do before importing objects with same UUID. More...
 
bool commitTransaction () const
 Commit a transaction. Will return false if there is no active transaction. More...
 
boost::optional< RecordfindLoadedRecord (const UUID &handle) const
 Finds Record by handle, will check all maps but does not query database. More...
 
bool includesRecord (const Record &record) const
 Checks if this database includes this Record. More...
 
bool isCleanRecord (const Record &record) const
 Checks if this Record is currently marked as clean. More...
 
bool isDirty () const
 Returns true if the database is dirty, e.g. has unsaved Records. More...
 
bool isDirtyRecord (const Record &record) const
 Checks if this Record is currently marked as dirty. More...
 
bool isNewRecord (const Record &record) const
 Checks if this Record is currently marked as new. More...
 
bool isRemovedRecord (const Record &record) const
 Checks if this Record is currently marked as removed. More...
 
std::shared_ptr< QSqlDatabase > qSqlDatabase () const
 Returns the QSqlDatabase. More...
 
boost::optional< RemoveUndoremoveRecord (Record &record)
 Remove a single Record and its children. More...
 
bool save ()
 Save pending changes to all Records. More...
 
bool saveRecord (Record &record)
 Save pending changes to single Record and its children. More...
 
bool startTransaction () const
 Start a transaction. Will return false if another transaction is already active. More...
 
void unloadUnusedCleanRecords ()
 Unload any unused Records from the clean record map. More...
 
void updatePathData (const openstudio::path &originalBase, const openstudio::path &newBase)
 Relocate path data from originalBase to newBase. More...
 
std::vector< VariableRecordvariableRecords ()
 Returns all VariableRecords . More...
 
std::vector< WorkflowRecordworkflowRecords ()
 Returns all WorkflowRecords . More...
 
Getters
ProjectDatabaseRecord projectDatabaseRecord () const
 Returns this database's ProjectDatabaseRecord. More...
 
UUID handle () const
 Returns the handle for the ProjectDatabase. More...
 
std::string name () const
 Returns the name of the ProjectDatabase. More...
 
std::string displayName () const
 Returns the display name of the ProjectDatabase. More...
 
std::string description () const
 Returns the description of the ProjectDatabase. More...
 
DateTime timestampCreate () const
 Returns the timestamp the ProjectDatabase was created at. More...
 
DateTime timestampLast () const
 Returns the timestamp the ProjectDatabase was last saved at. More...
 
UUID uuidLast () const
 Returns the UUID identifying the last ProjectDatabase save. More...
 
std::string version () const
 Returns the ProjectDatabase version. More...
 
openstudio::path path () const
 Returns the path to the ProjectDatabase. More...
 
openstudio::path originalBasePath () const
 Returns the path().parent_path() for the previous location of this database. More...
 
openstudio::path newBasePath () const
 Returns path().parent_path(). More...
 
openstudio::path runManagerDBPath () const
 Returns the path to the RunManager. More...
 
openstudio::runmanager::RunManager runManager () const
 Returns the RunManager. More...
 
Setters
bool setName (const std::string &name)
 Sets the name of the ProjectDatabase. More...
 
bool setDisplayName (const std::string &displayName)
 Sets the display name of the ProjectDatabase. More...
 
bool setDescription (const std::string &description)
 Sets the description of the ProjectDatabase. More...
 
Template Methods
template<typename T >
getFromQuery (const QSqlQuery &query)
 Gets Record from a query, checking maps first to prevent duplicate Records for the same entry. More...
 
template<typename T >
boost::optional< T > getObjectRecordByName (const std::string &name)
 Gets an ObjectRecord by name. More...
 
template<typename T >
boost::optional< T > getObjectRecordByHandle (const openstudio::UUID &handle)
 Gets an ObjectRecord by handle. More...
 

Protected Member Functions

void addCleanRecord (const Record &record)
 Add a clean Record. More...
 
void addDirtyRecord (const Record &record)
 Add a dirty Record. More...
 
void addNewRecord (Record &record)
 Add a new Record, will set id on the object record. More...
 
 ProjectDatabase (std::shared_ptr< detail::ProjectDatabase_Impl > impl)
 Constructor from implementation object. More...
 
void updateDatabase (const std::string &dbVersion)
 Update database to latest schema. More...
 

Constructors and Destructors

 ProjectDatabase (const openstudio::path &path, const openstudio::runmanager::RunManager &runManager, bool forceNew=false)
 Construct a ProjectDatabase at path using runManager. More...
 
 ProjectDatabase (const openstudio::path &path, bool forceNew=false, bool pauseRunManager=false, bool initializeRunManagerUI=false)
 Construct a ProjectDatabase and its RunManager. More...
 
 ProjectDatabase (const ProjectDatabase &other)
 Copy constructor, shares implementation object with other. More...
 
virtual ~ProjectDatabase ()
 
static boost::optional
< ProjectDatabase
open (const openstudio::path &path, bool pauseRunManager=false, bool initializeRunManagerUI=false)
 Attempt to open an existing ProjectDatabase. More...
 
static bool isExistingProjectDatabase (const openstudio::path &path)
 Returns true if the directory contains an existing ProjectDatabase. More...
 
static bool requiresUpdate (const openstudio::path &path)
 Returns true if the directory contains an existing ProjectDatabase and the project requires version translation. More...
 

Detailed Description

ProjectDatabase.

Constructor & Destructor Documentation

openstudio::project::ProjectDatabase::ProjectDatabase ( const openstudio::path &  path,
const openstudio::runmanager::RunManager &  runManager,
bool  forceNew = false 
)

Construct a ProjectDatabase at path using runManager.

If forceNew is true will remove existing database otherwise will try to open existing database. Throws if bad path or open fails.

openstudio::project::ProjectDatabase::ProjectDatabase ( const openstudio::path &  path,
bool  forceNew = false,
bool  pauseRunManager = false,
bool  initializeRunManagerUI = false 
)

Construct a ProjectDatabase and its RunManager.

The corresponding RunManager database location is path, but with the .db, rather than the .osp extension. If forceNew will remove any existing databases; otherwise will try to open existing databases. Throws if bad path or if open fails for any reason.

openstudio::project::ProjectDatabase::ProjectDatabase ( const ProjectDatabase other)

Copy constructor, shares implementation object with other.

virtual openstudio::project::ProjectDatabase::~ProjectDatabase ( )
inlinevirtual
openstudio::project::ProjectDatabase::ProjectDatabase ( std::shared_ptr< detail::ProjectDatabase_Impl >  impl)
protected

Constructor from implementation object.

Member Function Documentation

void openstudio::project::ProjectDatabase::addCleanRecord ( const Record record)
protected

Add a clean Record.

void openstudio::project::ProjectDatabase::addDirtyRecord ( const Record record)
protected

Add a dirty Record.

void openstudio::project::ProjectDatabase::addNewRecord ( Record record)
protected

Add a new Record, will set id on the object record.

void openstudio::project::ProjectDatabase::commitRemove ( const RemoveUndo removeUndo)

Finalizes removal of removed objects, necessary to do before importing objects with same UUID.

Undoing a removal will no longer be possible after this.

bool openstudio::project::ProjectDatabase::commitTransaction ( ) const

Commit a transaction. Will return false if there is no active transaction.

std::string openstudio::project::ProjectDatabase::description ( ) const

Returns the description of the ProjectDatabase.

std::string openstudio::project::ProjectDatabase::displayName ( ) const

Returns the display name of the ProjectDatabase.

boost::optional<Record> openstudio::project::ProjectDatabase::findLoadedRecord ( const UUID &  handle) const

Finds Record by handle, will check all maps but does not query database.

template<typename T >
T openstudio::project::ProjectDatabase::getFromQuery ( const QSqlQuery &  query)
inline

Gets Record from a query, checking maps first to prevent duplicate Records for the same entry.

template<typename T >
boost::optional<T> openstudio::project::ProjectDatabase::getObjectRecordByHandle ( const openstudio::UUID &  handle)
inline

Gets an ObjectRecord by handle.

template<typename T >
boost::optional<T> openstudio::project::ProjectDatabase::getObjectRecordByName ( const std::string &  name)
inline

Gets an ObjectRecord by name.

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

Returns the handle for the ProjectDatabase.

bool openstudio::project::ProjectDatabase::includesRecord ( const Record record) const

Checks if this database includes this Record.

bool openstudio::project::ProjectDatabase::isCleanRecord ( const Record record) const

Checks if this Record is currently marked as clean.

bool openstudio::project::ProjectDatabase::isDirty ( ) const

Returns true if the database is dirty, e.g. has unsaved Records.

bool openstudio::project::ProjectDatabase::isDirtyRecord ( const Record record) const

Checks if this Record is currently marked as dirty.

static bool openstudio::project::ProjectDatabase::isExistingProjectDatabase ( const openstudio::path &  path)
static

Returns true if the directory contains an existing ProjectDatabase.

DLM: calling this on an existing database issues a Qt warning and may mess up the existing database

bool openstudio::project::ProjectDatabase::isNewRecord ( const Record record) const

Checks if this Record is currently marked as new.

bool openstudio::project::ProjectDatabase::isRemovedRecord ( const Record record) const

Checks if this Record is currently marked as removed.

std::string openstudio::project::ProjectDatabase::name ( ) const

Returns the name of the ProjectDatabase.

openstudio::path openstudio::project::ProjectDatabase::newBasePath ( ) const

Returns path().parent_path().

Provided so users can finish repairing their path data after calling open.

static boost::optional<ProjectDatabase> openstudio::project::ProjectDatabase::open ( const openstudio::path &  path,
bool  pauseRunManager = false,
bool  initializeRunManagerUI = false 
)
static

Attempt to open an existing ProjectDatabase.

By default, will try to replace saved ProjectDatabase.path().parent_path() with path.parent_path().

openstudio::path openstudio::project::ProjectDatabase::originalBasePath ( ) const

Returns the path().parent_path() for the previous location of this database.

Provided so users can finish repairing their path data after calling open.

openstudio::path openstudio::project::ProjectDatabase::path ( ) const

Returns the path to the ProjectDatabase.

ProjectDatabaseRecord openstudio::project::ProjectDatabase::projectDatabaseRecord ( ) const

Returns this database's ProjectDatabaseRecord.

std::shared_ptr<QSqlDatabase> openstudio::project::ProjectDatabase::qSqlDatabase ( ) const

Returns the QSqlDatabase.

boost::optional<RemoveUndo> openstudio::project::ProjectDatabase::removeRecord ( Record record)

Remove a single Record and its children.

Will start and commit a transaction if a transaction is not already active. If Records were removed during this operation the returned RemoveUndo object can be used to revert or commit the remove operation.

static bool openstudio::project::ProjectDatabase::requiresUpdate ( const openstudio::path &  path)
static

Returns true if the directory contains an existing ProjectDatabase and the project requires version translation.

DLM: calling this on an existing database issues a Qt warning and may mess up the existing database

openstudio::runmanager::RunManager openstudio::project::ProjectDatabase::runManager ( ) const

Returns the RunManager.

openstudio::path openstudio::project::ProjectDatabase::runManagerDBPath ( ) const

Returns the path to the RunManager.

bool openstudio::project::ProjectDatabase::save ( )

Save pending changes to all Records.

Will start and commit a transaction if a transaction is not already active.

bool openstudio::project::ProjectDatabase::saveRecord ( Record record)

Save pending changes to single Record and its children.

Will start and commit a transaction if a transaction is not already active.

bool openstudio::project::ProjectDatabase::setDescription ( const std::string &  description)

Sets the description of the ProjectDatabase.

bool openstudio::project::ProjectDatabase::setDisplayName ( const std::string &  displayName)

Sets the display name of the ProjectDatabase.

bool openstudio::project::ProjectDatabase::setName ( const std::string &  name)

Sets the name of the ProjectDatabase.

bool openstudio::project::ProjectDatabase::startTransaction ( ) const

Start a transaction. Will return false if another transaction is already active.

DateTime openstudio::project::ProjectDatabase::timestampCreate ( ) const

Returns the timestamp the ProjectDatabase was created at.

DateTime openstudio::project::ProjectDatabase::timestampLast ( ) const

Returns the timestamp the ProjectDatabase was last saved at.

void openstudio::project::ProjectDatabase::unloadUnusedCleanRecords ( )

Unload any unused Records from the clean record map.

Todo:
Want to have a timer that periodically calls this.
void openstudio::project::ProjectDatabase::updateDatabase ( const std::string &  dbVersion)
protected

Update database to latest schema.

void openstudio::project::ProjectDatabase::updatePathData ( const openstudio::path &  originalBase,
const openstudio::path &  newBase 
)

Relocate path data from originalBase to newBase.

UUID openstudio::project::ProjectDatabase::uuidLast ( ) const

Returns the UUID identifying the last ProjectDatabase save.

std::vector<VariableRecord> openstudio::project::ProjectDatabase::variableRecords ( )

Returns all VariableRecords .

std::string openstudio::project::ProjectDatabase::version ( ) const

Returns the ProjectDatabase version.

std::vector<WorkflowRecord> openstudio::project::ProjectDatabase::workflowRecords ( )

Returns all WorkflowRecords .