CARMA C++
carma::dbms::ResultsCache Class Reference

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::TablegetCurrentMonitorConfigurationTable ()
 get a table containing the current monitor configurations, This table is guaranteed to have exactly one entry per tagID More...
 
const carma::dbms::TablegetFullMonitorConfigurationTable ()
 return (and cache if not already done) a mapping of all tagIDs in the database to their corresponding monitor configurations More...
 
const carma::dbms::TablegetTable (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 ResultsCachegetCache (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)
 

Detailed Description

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.

Todo:
need to set (and check for) upper bound to the amount of memory that can be used by cached objects. <

Definition at line 50 of file ResultsCache.h.

Member Function Documentation

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

Returns
all the tagIDs in the DB return (and cache if not already done) the MonitorDataTableIndex table
the MonitorDataTableIndex table add an object to the cache of results tables
Parameters
idthe string identifier for this table for later retrieval
tablethe table to cache
Exceptions
IllegalArgumentExceptionif the identifier already exists in this cache
static bool carma::dbms::ResultsCache::cacheExists ( )
static

does the singleton currently exist?

Returns
true if the singleton exists
static void carma::dbms::ResultsCache::closeCache ( )
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 ResultsCache& carma::dbms::ResultsCache::getCache ( const DBConnection *const  dbc = NULL)
static

get the singleton instance of the ResultsCache, the specified (valid) DBConnection object will be used for database queries

Parameters
dbca valid database connection, in the case where the singleton ResultsCache object already exists, this parameter is ignored
Returns
the single instance of the results cache
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

Returns
the table of current configurations
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

Returns
the map of tagIDs to monitor configurations REMOVING BECAUSE VERY EXPENSIVE return (and cache if not already done) the full monitor configuration table. This table includes all configurations, past and present, which means there may be multiple entries for some tagIDs. To get just the current configurations, use getCurrentMonitorConfigurationTable() instead.
the full monitor configuration table
const carma::dbms::Table& carma::dbms::ResultsCache::getTable ( const std::string &  identifier) const

get a cached table from the table cache

Parameters
identifierthe table identifier
Returns
the table corresponding to the identifier
Exceptions
carma::util::NotFoundExceptionif 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?

Parameters
identifierthe table identifier
Returns
true if the id exists in the table cache

The documentation for this class was generated from the following file: