#include <driver.h>
Public Member Functions | |
const std::string & | getName () |
Returns name of this driver. | |
Database * | getDatabase (const std::string &dbName) |
Returns an 'Database' object representing a physical database identified by the dbName in the DBMS. | |
void | returnDatabase (Database *db) |
Deallocates the database object and all related resources. | |
void | init (std::map< std::string, DriverExtension * > &extensions) |
Runs the driver initialization block. | |
void | shutdown () |
Runs the driver termination block. | |
template<typename T> | |
void | registerFeature (T &feature) |
Registers a new driver feature with implementation. | |
void | setSupportsFeature (const std::string &feature) |
Registers a new driver feature without implementation. | |
bool | supportsFeature (const std::string &feature) |
Checks if the driver supports a feature identified by the name. | |
template<typename T> | |
bool | supportsFeature () |
Checks if the driver supports a feature identified by the template parameter. | |
template<typename T> | |
T & | getFeature () const |
Returns implementation of the feature T. | |
Protected Member Functions | |
Driver (const std::string &driverName) | |
This constructor registers the driver at the DriverManager. | |
virtual DatabaseImpl * | getDatabaseImpl (const std::string &dbName)=0 |
Each database driver must implement this method which returns implementation of an object representing a database instance. | |
virtual void | returnDatabaseImpl (DatabaseImpl *dbImpl)=0 |
DatabaseImpl instances created usign getDatabaseImpl are released using this method. | |
virtual void | doInit ()=0 |
Driver initialization routine. | |
virtual void | doShutdown ()=0 |
Driver termination routine. |
Drivers are managed by the DriverManager class. A Driver is always implemented as a singleton. Its role is to setup and configure underlying libraries and to provide acces to instance of the Database class.
This class is thread safe and its method can be called by more threads concurrently.
const std::string& iopc::Driver::getName | ( | ) | [inline] |
Returns name of this driver.
Database * iopc::Driver::getDatabase | ( | const std::string & | dbName | ) |
Returns an 'Database' object representing a physical database identified by the dbName in the DBMS.
Just calling getDatabase doesn't create connection to the db, but some drivers may do platform-dependent resource allocation and/or environment preparation here.
dbName | Name of the physical database |
void iopc::Driver::returnDatabase | ( | Database * | db | ) |
Deallocates the database object and all related resources.
This method accepts also decorated instances returned by the Driver::getDatabase(const std::string& dbName) method. Example:
Database* db = new CachedDatabase(driver.getDatabase(""), cache); ... driver.returnDatabase(db); // deletes CachedDatabase instance
Closes all connections to the db database and destroys the Database instance with all decorators.
db | Database to be deallocated. |
void iopc::Driver::init | ( | std::map< std::string, DriverExtension * > & | extensions | ) |
Runs the driver initialization block.
This method is called automatically from inside the iopcdb
initialization routine (IopcDb::init()) Calls the doInit() method which must be implemented in the database driver.
void iopc::Driver::shutdown | ( | ) |
Runs the driver termination block.
This method is called automatically from inside the iopcdb
termination routine (IopcDb::shutdown()) Calls the doShutdown() method which must be implemented in the database driver.
void iopc::Driver::registerFeature | ( | T & | feature | ) | [inline] |
Registers a new driver feature with implementation.
Called usually from driver extension's initialization routine (DriverExtension::doInit(Driver& driver))
feature | Pointer to a feature that this driver will support. The pointer points directly to the implementation of the feature. |
void iopc::Driver::setSupportsFeature | ( | const std::string & | feature | ) | [inline] |
Registers a new driver feature without implementation.
This method is used for setting a flag that the driver supports some feature but the feature doesn't need physical implementation.
feature | Name of the supported feature |
bool iopc::Driver::supportsFeature | ( | const std::string & | feature | ) | [inline] |
Checks if the driver supports a feature identified by the name.
feature | The name of the feature |
bool iopc::Driver::supportsFeature | ( | ) | [inline] |
Checks if the driver supports a feature identified by the template parameter.
T& iopc::Driver::getFeature | ( | ) | const [inline] |
virtual DatabaseImpl* iopc::Driver::getDatabaseImpl | ( | const std::string & | dbName | ) | [protected, pure virtual] |
Each database driver must implement this method which returns implementation of an object representing a database instance.
dbName | Name of the database instance. Format is defined by a database driver. |
virtual void iopc::Driver::returnDatabaseImpl | ( | DatabaseImpl * | dbImpl | ) | [protected, pure virtual] |
DatabaseImpl instances created usign getDatabaseImpl are released using this method.
dbImpl | The driver implementation object. |
virtual void iopc::Driver::doInit | ( | ) | [protected, pure virtual] |
Driver initialization routine.
Called from the method DriverManager::initDrivers() which is called from IopcDb::init()
virtual void iopc::Driver::doShutdown | ( | ) | [protected, pure virtual] |
Driver termination routine.
Called from the method DriverManager::shutdownDrivers() which is called from IopcDb::shutdown()