GWE::GStorage Class Reference

Provides persistent data storage, using a DBMS. More...

Inheritance diagram for GWE::GStorage:

Inheritance graph
[legend]
Collaboration diagram for GWE::GStorage:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 GStorage (QObject *parent=0)
virtual ~GStorage ()
void setDatabaseDriver (QString driver)
void setDatabaseName (QString connection)
void setDatabaseHost (QString host)
void setDatabasePort (int port)
void setDatabaseUser (QString user)
void setDatabasePassword (QString password)
void setDatabase (QString driver, QString name, QString user, QString password, QString host="", int port=0)
bool connectDatabase ()
bool isDatabaseConnected ()
bool initializeDatabase ()
bool disconnectDatabase ()
QString getLastDatabaseError ()
QStringList getAllElementOwners () throw (GStorageException)
QStringList getAllServers () throw (GStorageException)
bool getServerExists (const QString &server) throw (GStorageException)
QStringList getServersForElementChildren (const GCS::GElementID &parent) throw (GStorageException)
QList< GCS::GElementIDgetElementsForServer (const QString &server) throw (GStorageException)
QString getManagingServerForElement (const GCS::GElementID &id) throw (GStorageException)
QString getServerPresence (const QString &server) throw (GStorageException)
QStringList getServersSubscribedToElementUpdates (const GCS::GElementID &id) throw (GStorageException)
QStringList getServersSubscribedToDataUpdates (const GCS::GElementID &id) throw (GStorageException)
QStringList getServersSubscribedToEnergyUpdates (const GCS::GElementID &id) throw (GStorageException)
QStringList getServersSubscribedToFormUpdates (const GCS::GElementID &id) throw (GStorageException)
void addServer (const QString &server, const QString &presence) throw (GStorageException)
void updateServerPresence (const QString &server, const QString &presence) throw (GStorageException)
void removeServer (const QString &server) throw (GStorageException)
void setSubscription (const GCS::GElementID &element, const QString &server, const QString &type) throw (GStorageException)
void clearSubscription (const GCS::GElementID &element, const QString &server, const QString &type) throw (GStorageException)
void updateManagingServer (const GCS::GElementID &element, const QString &new_server) throw (GStorageException)
bool getElementExists (const GCS::GElementID &id) throw (GStorageException)
QList< GCS::GElementIDgetAllElementIDs () throw (GStorageException)
QList< GCS::GElementIDgetAllElementIDsByServer (const QString &managing_server) throw (GStorageException)
GCS::GElementgetElement (const GCS::GElementID &id, const GCS::GWorldData *data) throw (GStorageException)
QList< GCS::GElement * > getElements (QList< GCS::GElementID > id_list, const GCS::GWorldData *worlddata) throw (GStorageException)
GCS::GElementData * getElementData (const GCS::GElementID &id) throw (GStorageException)
GCS::GEnergygetElementEnergy (const GCS::GElementID &id) throw (GStorageException)
GCS::GFormgetElementForm (const GCS::GElementID &id) throw (GStorageException)
QList< GCS::GElementIDgetChildren (const GCS::GElementID &id) throw (GStorageException)
GCS::GElementID getParent (const GCS::GElementID &id) throw (GStorageException)
QStringList getElementAgents (const GCS::GElementID &id) throw (GStorageException)
GCS::GElementID getConnection (const GCS::GElementID &id) throw (GStorageException)
QStringList getAllAgents () throw (GStorageException)
QString getAgent (const QString &agent) throw (GStorageException)
void addElement (const GCS::GElement *element, const QString &managing_server) throw (GStorageException)
void updateElement (const GCS::GElement *element) throw (GStorageException)
void removeElement (const GCS::GElementID &id) throw (GStorageException)
void removeElements (QList< GCS::GElementID > id_list) throw (GStorageException)
void reparentElement (const GCS::GElementID &element, const GCS::GElementID &old_parent, const GCS::GElementID &new_parent) throw (GStorageException)
void changeConnection (const GCS::GElementID &element, const GCS::GElementID &connection) throw (GStorageException)
void addElementAgent (const GCS::GElementID &element, const QString &agent) throw (GStorageException)
void removeElementAgent (const GCS::GElementID &element, const QString &agent) throw (GStorageException)
QStringList removeAllElementAgents (const GCS::GElementID &element) throw (GStorageException)
QList< GCS::GElementIDremoveAgentFromAllElements (const QString &agent) throw (GStorageException)
void updateElementData (const GCS::GElementID &element, const GCS::GElementData *data) throw (GStorageException)
void updateEnergy (const GCS::GElementID &element, const GCS::GEnergy *energy) throw (GStorageException)
void updateForm (const GCS::GElementID &element, const GCS::GForm *form) throw (GStorageException)
void removeAllAgents () throw (GStorageException)
void addAgent (const QString &agent) throw (GStorageException)
void removeAgent (const QString &agent) throw (GStorageException)

Protected Member Functions

GCS::GVector3 getVector3 (unsigned long id) throw (GStorageException)

Protected Attributes

QSqlDatabase Database
QString DbDriver
QString DbName
QString DbHost
int DbPort
QString DbUser
QString DbPassword

Detailed Description

Provides persistent data storage, using a DBMS.

Author:
Raphael Langerhorst
Usually this class is used like this:

 GStorage* storage = new GStorage();
 storage->setDatabase("QSQLITE",":memory:","user","password");
 storage->connectDatabase();  //returns false on failure
 storage->initializeDatabase();  //returns false on failure
 
 GXmlDataController* dc = new GXmlDataController(storage,network);

Please consult the G System Architecture for the DB layout.

Note:
GStorage inherits QMutex, the application is responsible of serializing access to GStorage objects!
Todo:
Improve MySQL support and avoid special case handling (driver) (might already work, due to Qt4 porting)

reuse existing database on init, see GXmlDataController to init with existing elements

Todo:
datafile of form is not taken care of
Todo:
check all args to be really strings (QString::number())


Constructor & Destructor Documentation

GWE::GStorage::GStorage ( QObject *  parent = 0  ) 

Constructor.

GWE::GStorage::~GStorage (  )  [virtual]

Destructor.


Member Function Documentation

void GWE::GStorage::addServer ( const QString &  server,
const QString &  presence 
) throw (GStorageException)

A new server is added on registration.

void GWE::GStorage::clearSubscription ( const GCS::GElementID element,
const QString &  server,
const QString &  type 
) throw (GStorageException)

Parameters:
type must be either element, data, energy or form

bool GWE::GStorage::connectDatabase (  ) 

Connects to database. You must set all database parameters before connecting.

See also:
setDatabase()
Returns:
true on success.

bool GWE::GStorage::disconnectDatabase (  ) 

Disconnects from database.

Returns:
true if connection was already closed or if closing was successfull.

QString GWE::GStorage::getAgent ( const QString &  agent  )  throw (GStorageException)

Returns:
empty string if agent does not exist

QStringList GWE::GStorage::getAllElementOwners (  )  throw (GStorageException)

Returns:
list of distinct servers assoziated with an element

GCS::GElement * GWE::GStorage::getElement ( const GCS::GElementID id,
const GCS::GWorldData data 
) throw (GStorageException)

Todo:
use views if the database supports it to select a whole element with one select!
Parameters:
data pointer to the used data controller, like the GXmlDataController

QString GWE::GStorage::getLastDatabaseError (  ) 

Returns:
the last SQL error.

bool GWE::GStorage::initializeDatabase (  ) 

Creates all tables, ... You must connect to the database before initializing.

See also:
connectDatabase()
Returns:
true if it was possible to prepare the database for real usage.

bool GWE::GStorage::isDatabaseConnected (  ) 

Returns:
true if database is open.

void GWE::GStorage::removeAgent ( const QString &  agent  )  throw (GStorageException)

Note:
you should make sure that the removed agent is not used by any element, see removeAgentFromAllElements()

QList< GCS::GElementID > GWE::GStorage::removeAgentFromAllElements ( const QString &  agent  )  throw (GStorageException)

Returns:
list of elements that had the agent included.

QStringList GWE::GStorage::removeAllElementAgents ( const GCS::GElementID element  )  throw (GStorageException)

Returns:
list of agents that were removed.

void GWE::GStorage::removeServer ( const QString &  server  )  throw (GStorageException)

Also removes all associated subscriptions of course. A server is generally removed when it unregisters.

void GWE::GStorage::setDatabase ( QString  driver,
QString  name,
QString  user,
QString  password,
QString  host = "",
int  port = 0 
)

Set all database parameters at once.

Note:
this does not connect to the database, use connectDatabase() for this purpose.

void GWE::GStorage::setDatabaseDriver ( QString  driver  ) 

Sets the database type or driver to use. You can get all available drivers with QSqlDatabase::drivers().

See also:
QSqlDatabase::drivers()

DbDriver

void GWE::GStorage::setDatabaseHost ( QString  host  ) 

Sets the host where the DBMS is running. Leave empty for local connections.

See also:
DbHost

void GWE::GStorage::setDatabaseName ( QString  connection  ) 

Set the actual database connection string. The form of the string usually differs depending on the database driver that is used.

See also:
DbName

void GWE::GStorage::setDatabasePassword ( QString  password  ) 

Set the user's password.

See also:
DbPassword

void GWE::GStorage::setDatabasePort ( int  port  ) 

Sets the port on which the DBMS is listening. Leave empty or set to 0 for the default port.

See also:
DbPort

void GWE::GStorage::setDatabaseUser ( QString  user  ) 

Set the user with which to connect to the database.

See also:
DbUser

void GWE::GStorage::setSubscription ( const GCS::GElementID element,
const QString &  server,
const QString &  type 
) throw (GStorageException)

Parameters:
type must be either element, data, energy or form


Member Data Documentation

QSqlDatabase GWE::GStorage::Database [protected]

The database itself.

See also:
connectDatabase()

QString GWE::GStorage::DbDriver [protected]

The database type or driver.

See also:
setDatabaseDriver()

QString GWE::GStorage::DbHost [protected]

The host where the DBMS is running. If no host is given, a local connection is used.

See also:
setDatabaseHost()

QString GWE::GStorage::DbName [protected]

The database name.

See also:
setDatabaseName()

QString GWE::GStorage::DbPassword [protected]

The database password.

See also:
setDatabasePassword()

int GWE::GStorage::DbPort [protected]

The port on which the DBMS is listening. If the port is set to 0 (the default) then the default port of the database driver is used instead.

See also:
setDatabasePort()

QString GWE::GStorage::DbUser [protected]

The database user.

See also:
setDatabaseUser()


The documentation for this class was generated from the following files:
Generated on Thu Nov 16 07:49:37 2006 for G System by  doxygen 1.4.7