CARMA C++
|
A class for caching and retrieving results of database queries. More...
#include <carma/dbms/ResultsCache.h>
Public Member Functions | |
void | cache (const std::string &identifier, const carma::dbms::Table &table) |
return (and cache if not already done) a column listing all the tagIDs in the DB More... | |
const carma::dbms::Table & | getCurrentMonitorConfigurationTable () |
get a table containing the current monitor configurations, This table is guaranteed to have exactly one entry per tagID More... | |
const carma::dbms::Table & | getFullMonitorConfigurationTable () |
return (and cache if not already done) a mapping of all tagIDs in the database to their corresponding monitor configurations More... | |
const carma::dbms::Table & | getTable (const std::string &identifier) const |
get a cached table from the table cache More... | |
const std::map< int, std::string > & | getTagIDToNameMap () const |
return the map of tagIDs to canonical names More... | |
bool | tableIDExists (const std::string identifier) const |
does the specified id (and hence table) exist in the table cache? More... | |
Static Public Member Functions | |
static bool | cacheExists () |
does the singleton currently exist? More... | |
static void | closeCache () |
indicate that one's use of the cache is complete. More... | |
static ResultsCache & | getCache (const DBConnection *const dbc=NULL) |
get the singleton instance of the ResultsCache, the specified (valid) DBConnection object will be used for database queries More... | |
Protected Member Functions | |
ResultsCache (const carma::dbms::DBConnection *const dbc) | |
A class for caching and retrieving results of database queries.
This class is instantiated as a singleton via a factory method. Usage: to get the singleton instance of this object, use
ResultsCache &rc = ResultsCache::getCache()
To indicate that the application is finished with the singleton (and to free the memory it is using), use
ResultsCache::closeCache()
Note the recommended usage of these methods is from the parent application (rather than by the objects it instantiates), since a call to
closeCache()
will delete the singleton, so that any objects still using it will get a shock. Similarly, no object should rely solely on the existance of singleton. If they wish to use it, they should check for its existence by calling
ResultsCache::cacheExists()
and if it doesn't exist create it (not recommended) or run alternative code to submit the necessary db query. This class is thread-safe, all methods which alter the singleton or other static data members are wrapped in carma::util::Mutex lock()/unlock() calls.
Definition at line 50 of file ResultsCache.h.
void carma::dbms::ResultsCache::cache | ( | const std::string & | identifier, |
const carma::dbms::Table & | table | ||
) |
return (and cache if not already done) a column listing all the tagIDs in the DB
id | the string identifier for this table for later retrieval |
table | the table to cache |
IllegalArgumentException | if the identifier already exists in this cache |
|
static |
does the singleton currently exist?
|
static |
indicate that one's use of the cache is complete.
If we are The singleton instance will be deleted. It is safe to call getCache() at anytime before or after this function is called. However, calling this method deletes all cached results
|
static |
get the singleton instance of the ResultsCache, the specified (valid) DBConnection object will be used for database queries
dbc | a valid database connection, in the case where the singleton ResultsCache object already exists, this parameter is ignored |
const carma::dbms::Table& carma::dbms::ResultsCache::getCurrentMonitorConfigurationTable | ( | ) |
get a table containing the current monitor configurations, This table is guaranteed to have exactly one entry per tagID
const carma::dbms::Table& carma::dbms::ResultsCache::getFullMonitorConfigurationTable | ( | ) |
return (and cache if not already done) a mapping of all tagIDs in the database to their corresponding monitor configurations
const carma::dbms::Table& carma::dbms::ResultsCache::getTable | ( | const std::string & | identifier | ) | const |
get a cached table from the table cache
identifier | the table identifier |
carma::util::NotFoundException | if the identifier does not exist in the table cache |
const std::map<int,std::string>& carma::dbms::ResultsCache::getTagIDToNameMap | ( | ) | const |
return the map of tagIDs to canonical names
bool carma::dbms::ResultsCache::tableIDExists | ( | const std::string | identifier | ) | const |
does the specified id (and hence table) exist in the table cache?
identifier | the table identifier |