#include <Database.hpp>
Inherits pion::platform::PlatformPlugin.
Inherited by pion::plugins::SQLiteDatabase.
Definition at line 41 of file Database.hpp.
Public Types | |
| CACHE_INDEX_ROW_OVERHEAD | |
| CACHE_PAGE_CACHE_SIZE | |
| CACHE_PAGE_UTILIZATION | |
| DB_FILE_SIZE | |
| IL_LevelUnknown = -1 | |
| IL_ReadUncommitted | |
| IL_ReadCommitted | |
| IL_RepeatableRead | |
| IL_Serializable | |
| enum | CACHEPARAM { CACHE_INDEX_ROW_OVERHEAD, CACHE_PAGE_CACHE_SIZE, CACHE_PAGE_UTILIZATION, DB_FILE_SIZE } |
| Cache related queries. | |
| enum | IsolationLevel_t { IL_LevelUnknown = -1, IL_ReadUncommitted, IL_ReadCommitted, IL_RepeatableRead, IL_Serializable } |
| Database Isolation Levels. | |
Public Member Functions | |
| Database (const std::string &logger_name) | |
| constructs a new Database object | |
| virtual | ~Database () |
| virtual destructor: this class is meant to be extended | |
| QueryPtr | getQuery (QueryID query_id) const |
| virtual boost::shared_ptr< Database > | clone (void) const =0 |
| virtual void | open (unsigned partition=0)=0 |
| virtual void | close (void)=0 |
| closes the database connection | |
| virtual boost::uint64_t | getCache (CACHEPARAM what)=0 |
| Get various cache related parameters. | |
| virtual bool | is_open (void) const =0 |
| returns true if the database connection is open | |
| virtual void | runQuery (const std::string &sql_query, const boost::regex &suppress)=0 |
| void | runQuery (const std::string &sql_query) |
| Same as runQuery, but no errors are suppressed. | |
| virtual QueryPtr | addQuery (QueryID query_id, const std::string &sql_query)=0 |
| virtual void | createTable (const Query::FieldMap &field_map, std::string &table_name, const Query::IndexMap &index_map, unsigned partition=0)=0 |
| virtual void | dropTable (std::string &table_name, unsigned partition=0)=0 |
| virtual bool | tableExists (std::string &table_name, unsigned partition=0)=0 |
| virtual QueryPtr | prepareInsertQuery (const Query::FieldMap &field_map, const std::string &table_name)=0 |
| virtual QueryPtr | prepareInsertIgnoreQuery (const Query::FieldMap &field_map, const std::string &table_name)=0 |
| virtual pion::platform::QueryPtr | prepareFullQuery (const std::string &query, const boost::regex &suppress)=0 |
| pion::platform::QueryPtr | prepareFullQuery (const std::string &query) |
| same as prepareFullQuery, but no errors are suppressed | |
| virtual QueryPtr | getBeginTransactionQuery (void)=0 |
| virtual QueryPtr | getCommitTransactionQuery (void)=0 |
| virtual void | setConfig (const Vocabulary &v, const xmlNodePtr config_ptr) |
| void | stringReplace (std::string &src, const char *search, const std::string &substitute) |
| Only used by stringSubstitutes, so non-inlined is fine for performance. | |
| std::string & | stringSubstitutes (std::string &query, const pion::platform::Query::FieldMap &field_map, const std::string &table_name, const std::string &columns_override="") |
| Since stringSubstitutes is only used at setup, its speed is not critical... | |
Protected Types | |
|
typedef std::map< QueryID, QueryPtr > | QueryMap |
| data type that maps query identifiers to pointers of compiled queries | |
Protected Member Functions | |
| void | copyDatabase (const Database &d) |
| protected copy function (use clone() instead) | |
| void | readConfig (const xmlNodePtr config_ptr, std::string engine_str) |
| Find Queries, Isolation level and Mapping Pairs from reactors.xml OR dbengines.xml. | |
| void | readConfigDetails (const xmlNodePtr config_ptr) |
Protected Attributes | |
| std::string | m_database_engine |
| std::string | m_database_client |
| name of database client, e.g. MySQL | |
| std::string | m_begin_insert |
| begin & commit insert strings | |
| std::string | m_commit_insert |
| std::string | m_create_log |
| Database create/insert statements, and their optional ignore attributes. | |
| boost::regex | m_create_log_attr |
| std::string | m_insert_log |
| boost::regex | m_insert_log_attr |
| std::string | m_create_stat |
| boost::regex | m_create_stat_attr |
| std::string | m_update_stat |
| boost::regex | m_update_stat_attr |
| std::string | m_select_stat |
| boost::regex | m_select_stat_attr |
| std::string | m_drop_index |
| boost::regex | m_drop_index_attr |
| std::string | m_create_index_normal |
| boost::regex | m_create_index_normal_attr |
| std::string | m_create_index_unique |
| boost::regex | m_create_index_unique_attr |
| std::string | m_create_index_custom |
| boost::regex | m_create_index_custom_attr |
| std::string | m_insert_ignore |
| boost::regex | m_insert_ignore_attr |
| std::string | m_drop_table |
| boost::regex | m_drop_table_attr |
| IsolationLevel_t | m_isolation_level |
| Isolation level, default is SA_ReadUncommitted (for speed/ease). | |
| QueryMap | m_query_map |
| used to keep track of all the database's pre-compiled queries | |
| std::vector< std::string > | m_sql_affinity |
| Affinity map; index is term_type, value should be compatible SQL type. | |
| std::vector< std::string > | m_pre_sql |
| PreSQL statements, to be executed before table operations. | |
| std::vector< boost::regex > | m_pre_sql_attr |
| Optional "ignore" attributes for PreSQL statements. | |
| std::vector< std::string > | m_options |
| SQLAPI Options to be executed before connecting. | |
| std::vector< std::string > | m_options_values |
| SQLAPI Options values to be executed before connecting. | |
| PionLogger | m_logger |
| primary logging interface used by this class | |
Static Protected Attributes | |
| static const std::string | INSERT_QUERY_ID = "urn:sql:insert-event" |
| unique identifier used to represent the "insert event" query | |
| static const std::string | INSERT_IGNORE_QUERY_ID = "urn:sql:insert-ignore-event" |
| static const std::string | BEGIN_QUERY_ID = "urn:sql:begin-transaction" |
| unique identifier used to represent the "begin transaction" query | |
| static const std::string | COMMIT_QUERY_ID = "urn:sql:commit-transaction" |
| unique identifier used to represent the "commit transaction" query | |
| static const std::string | MAP_ELEMENT_NAME = "TypeMap" |
| static const std::string | PAIR_ELEMENT_NAME = "Pair" |
| static const std::string | CLIENT_ELEMENT_NAME = "Client" |
| static const std::string | BEGIN_ELEMENT_NAME = "BeginInsert" |
| static const std::string | COMMIT_ELEMENT_NAME = "CommitInsert" |
| static const std::string | CREATE_LOG_ELEMENT_NAME = "CreateLog" |
| static const std::string | INSERT_LOG_ELEMENT_NAME = "InsertLog" |
| static const std::string | ISOLATION_ELEMENT_NAME = "IsolationLevel" |
| static const std::string | PRESQL_ELEMENT_NAME = "PreSQL" |
| static const std::string | OPTION_ELEMENT_NAME = "Option" |
| static const std::string | CREATE_STAT_ELEMENT_NAME = "CreateStat" |
| static const std::string | UPDATE_STAT_ELEMENT_NAME = "UpdateStat" |
| static const std::string | SELECT_STAT_ELEMENT_NAME = "SelectStat" |
| static const std::string | DROP_INDEX_ELEMENT_NAME = "DropIndex" |
| static const std::string | CREATE_INDEX_NORMAL_ELEMENT_NAME = "CreateIndexNormal" |
| static const std::string | CREATE_INDEX_UNIQUE_ELEMENT_NAME = "CreateIndexUnique" |
| static const std::string | CREATE_INDEX_CUSTOM_ELEMENT_NAME = "CreateIndexCustom" |
| static const std::string | IGNORE_ATTRIBUTE_NAME = "ignore" |
| static const std::string | OPTION_ATTRIBUTE_NAME = "option" |
| static const std::string | INSERT_IGNORE_ELEMENT_NAME = "InsertIgnore" |
| static const std::string | DROP_TABLE_ELEMENT_NAME = "DropTable" |
Classes | |
| class | BadTypePair |
| Bad type pair in Vocabulary-to-SQL map. More... | |
| class | DatabaseBusyException |
| exception thrown if the database is busy & the query should be tried again later More... | |
| class | DatabaseClientException |
| class | DatabaseConfigMissing |
| exception for missing configuration element More... | |
| class | InvalidIsolationLevel |
| Isolation level must be: ReadUncommitted (default), ReadCommitted, RepeatableRead, Serializable. More... | |
| class | MissingRootElementException |
| class | MissingTemplateException |
| class | MissingTypeMap |
| Every database engine must have Vocabulary-to-SQL map. More... | |
| class | OpenDatabaseException |
| exception thrown if there is an error opening a Database More... | |
| class | QueryNotFoundException |
| exception thrown if a Query cannot be found More... | |
| class | ReadConfigException |
| virtual QueryPtr pion::platform::Database::addQuery | ( | QueryID | query_id, | |
| const std::string & | sql_query | |||
| ) | [pure virtual] |
adds a compiled SQL query to the database
| query_id | string used to uniquely identify the type of query | |
| sql_query | SQL query to compile and cache for later use |
Implemented in pion::plugins::SQLiteDatabase.
| virtual boost::shared_ptr<Database> pion::platform::Database::clone | ( | void | ) | const [pure virtual] |
clones the Database, returning a pointer to the cloned copy
Implemented in pion::plugins::SQLiteDatabase.
Referenced by pion::platform::DatabaseManager::getDatabase().
| virtual void pion::platform::Database::createTable | ( | const Query::FieldMap & | field_map, | |
| std::string & | table_name, | |||
| const Query::IndexMap & | index_map, | |||
| unsigned | partition = 0 | |||
| ) | [pure virtual] |
creates a database table for output, if it does not already exist
| field_map | mapping of Vocabulary Terms to Database fields | |
| table_name | name of the table to create (modified to reflect partition) | |
| index_map | table of indexes, matches field_map |
Implemented in pion::plugins::SQLiteDatabase.
| virtual void pion::platform::Database::dropTable | ( | std::string & | table_name, | |
| unsigned | partition = 0 | |||
| ) | [pure virtual] |
drops table, fastest way
| table_name | name of the table to drop | |
| partition | optional partition number |
Implemented in pion::plugins::SQLiteDatabase.
| virtual QueryPtr pion::platform::Database::getBeginTransactionQuery | ( | void | ) | [pure virtual] |
returns the query that is used to begin new transactions
Implemented in pion::plugins::SQLiteDatabase.
| virtual QueryPtr pion::platform::Database::getCommitTransactionQuery | ( | void | ) | [pure virtual] |
returns the query that is used to end and commit transactions
Implemented in pion::plugins::SQLiteDatabase.
retrieves a pre-compiled query for the database
| query_id | string used to uniquely identify the type of query |
Definition at line 134 of file Database.hpp.
| virtual void pion::platform::Database::open | ( | unsigned | partition = 0 |
) | [pure virtual] |
opens the database connection
| partition | partition number, if non-zero |
Implemented in pion::plugins::SQLiteDatabase.
| virtual pion::platform::QueryPtr pion::platform::Database::prepareFullQuery | ( | const std::string & | query, | |
| const boost::regex & | suppress | |||
| ) | [pure virtual] |
prepares a generic query
| query | the SQL for the query | |
| suppress | regex containing pattern of suppressable errors |
Implemented in pion::plugins::SQLiteDatabase.
| virtual QueryPtr pion::platform::Database::prepareInsertQuery | ( | const Query::FieldMap & | field_map, | |
| const std::string & | table_name | |||
| ) | [pure virtual] |
prepares the query that is used to insert events
| field_map | mapping of Vocabulary Terms to Database fields | |
| table_name | name of the table to insert events into |
Implemented in pion::plugins::SQLiteDatabase.
| void pion::platform::Database::readConfig | ( | const xmlNodePtr | config_ptr, | |
| std::string | engine_str | |||
| ) | [protected] |
Find Queries, Isolation level and Mapping Pairs from reactors.xml OR dbengines.xml.
readConfig must be called by a Database implementation as soon as it has called setConfig
| config_ptr | Pointer to XML configuration (passed in as config_ptr) | |
| engine_str | String identifying the database/engine that is being initialized |
Definition at line 209 of file Database.cpp.
References CLIENT_ELEMENT_NAME, pion::platform::ConfigManager::getConfigOption(), pion::platform::PlatformPlugin::getDatabaseManager(), pion::platform::PlatformPlugin::getId(), m_database_client, m_database_engine, and readConfigDetails().
Referenced by pion::plugins::SQLiteDatabase::setConfig().
| void pion::platform::Database::readConfigDetails | ( | const xmlNodePtr | config_ptr | ) | [protected] |
readConfigDetails is called by readConfig, once it locates the SQL details for an engine
| config_ptr | XML file & pointer to where SQL details are found |
Definition at line 76 of file Database.cpp.
References BEGIN_ELEMENT_NAME, CLIENT_ELEMENT_NAME, COMMIT_ELEMENT_NAME, CREATE_INDEX_CUSTOM_ELEMENT_NAME, CREATE_INDEX_NORMAL_ELEMENT_NAME, CREATE_INDEX_UNIQUE_ELEMENT_NAME, CREATE_LOG_ELEMENT_NAME, CREATE_STAT_ELEMENT_NAME, DROP_INDEX_ELEMENT_NAME, DROP_TABLE_ELEMENT_NAME, pion::platform::ConfigManager::findConfigNodeByName(), pion::platform::ConfigManager::getAttribute(), pion::platform::ConfigManager::getConfigOption(), pion::platform::PlatformPlugin::getId(), pion::platform::getRegex(), IGNORE_ATTRIBUTE_NAME, INSERT_IGNORE_ELEMENT_NAME, INSERT_LOG_ELEMENT_NAME, ISOLATION_ELEMENT_NAME, m_begin_insert, m_commit_insert, m_create_index_custom, m_create_index_custom_attr, m_create_index_normal, m_create_index_normal_attr, m_create_index_unique, m_create_index_unique_attr, m_create_log, m_create_log_attr, m_create_stat, m_create_stat_attr, m_database_client, m_drop_index, m_drop_index_attr, m_drop_table, m_drop_table_attr, m_insert_ignore, m_insert_ignore_attr, m_insert_log, m_insert_log_attr, m_isolation_level, m_options, m_options_values, m_pre_sql, m_pre_sql_attr, m_select_stat, m_select_stat_attr, m_sql_affinity, m_update_stat, m_update_stat_attr, MAP_ELEMENT_NAME, OPTION_ATTRIBUTE_NAME, OPTION_ELEMENT_NAME, PAIR_ELEMENT_NAME, pion::platform::Vocabulary::parseDataType(), PRESQL_ELEMENT_NAME, SELECT_STAT_ELEMENT_NAME, pion::platform::Vocabulary::TYPE_OBJECT, and UPDATE_STAT_ELEMENT_NAME.
Referenced by readConfig().
| virtual void pion::platform::Database::runQuery | ( | const std::string & | sql_query, | |
| const boost::regex & | suppress | |||
| ) | [pure virtual] |
runs a simple query, ignoring any results returned
| sql_query | SQL query to execute | |
| suppress | Regex to describe what errors/exceptions to suppress |
Implemented in pion::plugins::SQLiteDatabase.
| void pion::platform::Database::setConfig | ( | const Vocabulary & | v, | |
| const xmlNodePtr | config_ptr | |||
| ) | [virtual] |
sets configuration parameters for this Database
| v | the Vocabulary that this Database will use to describe Terms | |
| config_ptr | pointer to a list of XML nodes containing Database configuration parameters |
Reimplemented from pion::platform::PlatformPlugin.
Reimplemented in pion::plugins::SQLiteDatabase.
Definition at line 65 of file Database.cpp.
References pion::platform::PlatformPlugin::setConfig().
Referenced by pion::platform::DatabaseManager::addPluginNoLock().
| void pion::platform::Database::stringReplace | ( | std::string & | src, | |
| const char * | search, | |||
| const std::string & | substitute | |||
| ) |
Only used by stringSubstitutes, so non-inlined is fine for performance.
generic simple, non-escaped, string-replace function; replace every instance of search with substitute
| src | string to modify | |
| search | string to find (and substitute) | |
| substitute | string to put in place of search in src |
Definition at line 233 of file Database.cpp.
Referenced by stringSubstitutes().
| std::string & pion::platform::Database::stringSubstitutes | ( | std::string & | query, | |
| const pion::platform::Query::FieldMap & | field_map, | |||
| const std::string & | table_name, | |||
| const std::string & | columns_override = "" | |||
| ) |
Since stringSubstitutes is only used at setup, its speed is not critical...
replace TABLE/FIELD/COLUMNS/QUESTIONS/PARAMS with appropriate values in pseudo-SQL
| query | string to modify, contains the original pseudo-SQL | |
| field_map | fieldMap to use for substitutions of COLUMNS/PARAMS | |
| table_name | name of table to use to substitute TABLE | |
| columns_override | is the optional columns list override (for custom indexes) |
Definition at line 241 of file Database.cpp.
References m_sql_affinity, and stringReplace().
Referenced by pion::plugins::SQLiteDatabase::createTable(), pion::plugins::SQLiteDatabase::prepareInsertIgnoreQuery(), and pion::plugins::SQLiteDatabase::prepareInsertQuery().
| virtual bool pion::platform::Database::tableExists | ( | std::string & | table_name, | |
| unsigned | partition = 0 | |||
| ) | [pure virtual] |
table exists?
| table_name | name of the table to drop | |
| partition | optional partition number |
Implemented in pion::plugins::SQLiteDatabase.
std::string pion::platform::Database::m_database_engine [protected] |
Database engine name, e.g. MySQL-MyISAM This is used to find a matching set of SQL from configuation file
Definition at line 408 of file Database.hpp.
Referenced by copyDatabase(), and readConfig().
1.4.7