Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Compound List | File List | Namespace Members | Compound Members | File Members | Related Pages | Examples

DBProperty Class Reference

General database-backend interface. More...

#include <vos/metaobjects/property/db_property.hh>

Inheritance diagram for DBProperty:

LocalProperty Property MetaObject ObjectExciseListener PGDBProperty List of all members.

Public Member Functions

Static Public Member Functions

Protected Attributes


Detailed Description

General database-backend interface.

By itself this doesn't do anything; use a subclass like PGDBProperty (For Postgres databases). This class is intended to be subclassed in order to implement VOS/database bridges with various SQL-based database systems. Subclasses will have to implement the actual updateToDB() and updateFromDB(), and methods, and the open() method to connect to the database. See database-specific classes for full usage details but the basic idea is that the constructor should open a connection to the database, and create the associated table and columns if they don't exist, or just fetch the existing values if they do. write() and replace() immediately update the database with new data, but read() only returns cached data. updateFromDB() will get values from the database and replace cached data, and send property-update messages to all property listeners and remote objects. Some mechanism should be set up to call this function when necesary If the database backend has no such functionality, then the the subclass should extend read() to do an update before a read, and also periodically call updateFromDB() in case it changes.

Use init() to set up the queries used to read and write to the database.

Subclasses of DBProperty should open the database connection (in init), and actually do the communication with the database.

Definition at line 60 of file db_property.hh.


Constructor & Destructor Documentation

DBProperty::DBProperty MetaObject superobject  )  [inline]
 

basic constructor

Definition at line 88 of file db_property.hh.

Referenced by new_DBProperty().


Member Function Documentation

void DBProperty::init const string &  select_all_q,
const string &  select_data_q,
const string &  select_type_q,
const string &  update_all_q,
const string &  update_data_q,
const string &  update_type_q
[virtual]
 

Set up query strings, for getting or changing both data value and data type.

In the update queries, d will be replaced by property data, and t will be replaced by the datatype. These query strings should be in the format applicable to the implementation subclass you are using.

Parameters:
select_all_q Query for getting data and type. (in that order)
select_data_q Query for getting just data.
select_type_q Query for getting type.
update_all_q Query for changing data and type. d will be replaced by property data, and t with type
update_data_q Query for changing data. d will be replaced by data.
update_type_q Query for changing type. Eventually will be removed, in favor of the update_all query
Deprecated:

Definition at line 53 of file db_property.cc.

void DBProperty::init const string &  select_query,
const string &  update_query,
const string &  type
[virtual]
 

Set up query strings, for getting or changing just data, with constant data type.

Parameters:
select_query Query for getting just data. Must return scalar.
update_query Query for setting the data. d is replaced with the new data.
type Data type to always use.

Definition at line 46 of file db_property.cc.

void DBProperty::init_components const string &  table,
const string &  name_col,
const string &  val_col,
const string &  type_col,
const string &  name_val
 

Use given values to construct standard (I think) SQL query strings.

Warning:
may be broken; untested by author; use at own risk..... but then send a patch, please :)
Parameters:
table Name of the table we are interested in.
name_col Column in the table used as primary key when looking up data.
val_col Column containing property value.
type_col Column containing property data type.
name_val Value to use to identify this property in the database, as primary key.

Definition at line 64 of file db_property.cc.

MetaObject* DBProperty::new_DBProperty MetaObject superobject,
const string &  type
[inline, static]
 

called by factory to create a new instance

Definition at line 94 of file db_property.hh.

Referenced by registerExtenders().

virtual void DBProperty::open string  dbinfo = ""  )  [inline, virtual]
 

open database.

this method must be overridden in implementation subclasses.

Definition at line 151 of file db_property.hh.

virtual string DBProperty::queryDB const string &  query  )  throw (DBAccessError) [inline, virtual]
 

perform a query on the database (in the implementation's language; e.g.

SQL) This method must be overridden in implementation subclasses. This method may throw range_error if there is an error in the query-string substiution. TODO: how shall non-scalars be returned?

Reimplemented in PGDBProperty.

Definition at line 160 of file db_property.hh.

void DBProperty::registerExtenders  )  [inline, static]
 

Register MetaObject extender for DBProperty.

You must also call Property::registerExtenders() for stuff to work!.

Reimplemented from Property.

Reimplemented in PGDBProperty.

Definition at line 100 of file db_property.hh.

virtual void DBProperty::replace const string &  newdata,
const string &  newtype = "?"
throw (DBAccessError) [inline, virtual]
 

change all the property data, and datatype (updated in DB)

Reimplemented from LocalProperty.

Definition at line 144 of file db_property.hh.

void DBProperty::updateFromDB  )  throw (DBAccessError) [virtual]
 

fetch stuff from database and do a replace.

Definition at line 73 of file db_property.cc.

void DBProperty::updateToDB  )  throw (DBAccessError) [virtual]
 

write current data and type to DB.

Definition at line 91 of file db_property.cc.

Referenced by replace(), and write().

virtual void DBProperty::write int  start,
const string &  newdata
throw (DBAccessError) [inline, virtual]
 

change property data, starting at given byte (updated in DB)

Reimplemented from LocalProperty.

Definition at line 138 of file db_property.hh.


Member Data Documentation

string DBProperty::force_type [protected]
 

Definition at line 76 of file db_property.hh.

Referenced by init().

string DBProperty::select_all_query [protected]
 

Definition at line 68 of file db_property.hh.

Referenced by init(), and init_components().

string DBProperty::select_data_query [protected]
 

Definition at line 66 of file db_property.hh.

Referenced by init(), and init_components().

string DBProperty::select_type_query [protected]
 

Definition at line 67 of file db_property.hh.

Referenced by init(), and init_components().

string DBProperty::update_all_query [protected]
 

Definition at line 73 of file db_property.hh.

Referenced by init(), and init_components().

string DBProperty::update_data_query [protected]
 

Definition at line 71 of file db_property.hh.

Referenced by init(), and init_components().

string DBProperty::update_type_query [protected]
 

Definition at line 72 of file db_property.hh.

Referenced by init().


The documentation for this class was generated from the following files:
Generated on Tue Aug 12 03:55:53 2003 for Interreality Project - VOS by doxygen 1.3.2