LSSTApplications
11.0-24-g0a022a1,14.0+77,15.0,15.0+1
LSSTDataManagementBasePackage
|
Class for database storage with data loading from TSV files. More...
#include <DbTsvStorage.h>
Public Types | |
typedef std::shared_ptr< DbTsvStorage > | Ptr |
typedef std::vector< Ptr > | List |
enum | { magicSentinel = 0xdeadbeef } |
typedef unsigned long | memId |
Type of the block's ID. More... | |
typedef memId(* | memNewCallback) (const memId cid) |
A function used to register a callback. More... | |
typedef memId(* | memCallback) (const Citizen *ptr) |
Public Member Functions | |
DbTsvStorage (void) | |
Constructor. More... | |
~DbTsvStorage (void) | |
Minimal destructor. More... | |
virtual void | setPolicy (lsst::pex::policy::Policy::Ptr policy) |
Allow a policy to be used to configure the DbTsvStorage. More... | |
virtual void | setPersistLocation (LogicalLocation const &location) |
Set the database location to persist to. More... | |
virtual void | setRetrieveLocation (LogicalLocation const &location) |
Set the database location to retrieve from. More... | |
virtual void | startTransaction (void) |
Start a transaction. More... | |
virtual void | endTransaction (void) |
End a transaction. More... | |
virtual void | createTableFromTemplate (std::string const &tableName, std::string const &templateName, bool mayAlreadyExist=false) |
Create a new table from an existing template table. More... | |
virtual void | dropTable (std::string const &tableName) |
Drop a table. More... | |
virtual void | truncateTable (std::string const &tableName) |
Truncate a table. More... | |
virtual void | setTableForInsert (std::string const &tableName) |
Set the table to insert rows into. More... | |
template<typename T > | |
void | setColumn (std::string const &columnName, T const &value) |
Set the value to insert in a given column. More... | |
virtual void | setColumnToNull (std::string const &columnName) |
Set a given column to NULL. More... | |
virtual void | insertRow (void) |
Insert the row. More... | |
template<typename T > | |
void | outParam (std::string const &columnName, T *location, bool isExpr=false) |
Request a column in the query output and bind a destination location. More... | |
template<typename T > | |
void | condParam (std::string const ¶mName, T const &value) |
Bind a value to a WHERE condition parameter. More... | |
template<typename T > | |
T const & | getColumnByPos (int pos) |
Get the value of a column of the query result row by position. More... | |
template<> | |
void | setColumn (std::string const &columnName, char const &value) |
template<> | |
void | setColumn (std::string const &columnName, double const &value) |
template<> | |
void | setColumn (std::string const &columnName, float const &value) |
template<> | |
void | setColumn (std::string const &columnName, DateTime const &value) |
virtual void | executeSql (std::string const &sqlStatement) |
Execute an arbitrary SQL statement. More... | |
virtual void | setTableForQuery (std::string const &tableName, bool isExpr=false) |
Set the table to query (single-table queries only). More... | |
virtual void | setTableListForQuery (std::vector< std::string > const &tableNameList) |
Set a list of tables to query (multiple-table queries). More... | |
virtual void | outColumn (std::string const &columnName, bool isExpr=false) |
Request a column in the query output. More... | |
virtual void | orderBy (std::string const &expression) |
Request that the query output be sorted by an expression. More... | |
virtual void | groupBy (std::string const &expression) |
Request that the query output be grouped by an expression. More... | |
virtual void | setQueryWhere (std::string const &whereClause) |
Set the condition for the WHERE clause of the query. More... | |
virtual void | query (void) |
Execute the query. More... | |
virtual bool | next (void) |
Move to the next (first) row of the query result. More... | |
bool | columnIsNull (int pos) |
Determine if the value of a column is NULL. More... | |
virtual void | finishQuery (void) |
Indicate that query processing is finished. More... | |
std::string | repr () const |
Return a string representation of a Citizen. More... | |
void | markPersistent (void) |
Mark a Citizen as persistent and not destroyed until process end. More... | |
memId | getId () const |
Return the Citizen's ID. More... | |
Static Public Member Functions | |
static Ptr | createInstance (std::string const &name, LogicalLocation const &location, bool persist, lsst::pex::policy::Policy::Ptr policy) |
Create and configure a FormatterStorage subclass instance. More... | |
static bool | hasBeenCorrupted () |
Check all allocated blocks for corruption. More... | |
static memId | getNextMemId () |
Return the memId of the next object to be allocated. More... | |
static int | init () |
Called once when the memory system is being initialised. More... | |
Census | |
Provide a list of current Citizens | |
static int | census (int, memId startingMemId=0) |
How many active Citizens are there? More... | |
static void | census (std::ostream &stream, memId startingMemId=0) |
Print a list of all active Citizens to stream, sorted by ID. More... | |
static const std::vector< const Citizen * > * | census () |
Return a (newly allocated) std::vector of active Citizens sorted by ID. More... | |
callbackIDs | |
Set callback Ids. The old Id is returned | |
static memId | setNewCallbackId (memId id) |
Call the NewCallback when block is allocated. More... | |
static memId | setDeleteCallbackId (memId id) |
Call the current DeleteCallback when block is deleted. More... | |
callbacks | |
Set the New/Delete callback functions; in each case the previously installed callback is returned. These callback functions return a value which is Added to the previously registered id. The default callback functions are called default{New,Delete}Callback; you may want to set a break point in these callbacks from your favourite debugger | |
static memNewCallback | setNewCallback (memNewCallback func) |
Set the NewCallback function. More... | |
static memCallback | setDeleteCallback (memCallback func) |
Set the DeleteCallback function. More... | |
static memCallback | setCorruptionCallback (memCallback func) |
Set the CorruptionCallback function. More... | |
Protected Member Functions | |
void | verifyPathName (std::string const &pathName) |
Ensure that all directories along a path exist, creating them if necessary. More... | |
Private Member Functions | |
int | _getColumnIndex (std::string const &columnName) |
Get the index of a given column. More... | |
Private Attributes | |
bool | _persisting |
bool | _saveTemp |
Do not delete temporary TSV file if true. More... | |
std::string | _tempPath |
Directory pathname for temporary TSV file. More... | |
char * | _fileName |
Full pathname for temporary TSV file. More... | |
std::string | _location |
Database location URL. More... | |
std::string | _tableName |
std::map< std::string, int > | _colMap |
Map from column names to positions. More... | |
std::ostringstream | _convertStream |
Stream to convert to text. More... | |
std::vector< std::string > | _rowBuffer |
std::unique_ptr< std::ofstream > | _osp |
Output TSV stream. More... | |
Class for database storage with data loading from TSV files.
Subclass of DbStorage, overriding persistence methods.
Persists data to a database using TSV files as an intermediary for performance. Provides methods for writing rows to a table and retrieving rows from a query.
Definition at line 66 of file DbTsvStorage.h.
|
inherited |
Definition at line 63 of file FormatterStorage.h.
|
inherited |
Definition at line 68 of file DbTsvStorage.h.
lsst::daf::persistence::DbTsvStorage::DbTsvStorage | ( | void | ) |
Constructor.
Definition at line 67 of file DbTsvStorage.cc.
lsst::daf::persistence::DbTsvStorage::~DbTsvStorage | ( | void | ) |
|
private |
Get the index of a given column.
Create a new entry in the row buffer if the column hasn't already been seen. May modify the row buffer, so do not call this inside "_rowBuffer[]".
[in] | columnName | Name of the column |
Definition at line 252 of file DbTsvStorage.cc.
|
staticinherited |
How many active Citizens are there?
startingMemId | Don't print Citizens with lower IDs |
Definition at line 267 of file Citizen.cc.
|
staticinherited |
Print a list of all active Citizens to stream, sorted by ID.
stream | stream to print to |
startingMemId | Don't print Citizens with lower IDs |
Definition at line 290 of file Citizen.cc.
|
staticinherited |
Return a (newly allocated) std::vector of active Citizens sorted by ID.
You are responsible for deleting it; or you can say std::unique_ptr<std::vector<Citizen const*> const> leaks(Citizen::census()); and not bother (that becomes std::unique_ptr in C++11)
Definition at line 322 of file Citizen.cc.
|
inherited |
Determine if the value of a column is NULL.
[in] | pos | Position of the column (starts at 0) |
Definition at line 270 of file DbStorage.cc.
void lsst::daf::persistence::DbTsvStorage::condParam | ( | std::string const & | paramName, |
T const & | value | ||
) |
Bind a value to a WHERE condition parameter.
[in] | paramName | Name of the parameter (prefixed by ":" in the WHERE clause) |
[in] | value | Value to be bound to the parameter. |
Definition at line 368 of file DbTsvStorage.cc.
|
staticinherited |
Create and configure a FormatterStorage subclass instance.
[in] | name | Name of subclass |
[in] | location | Location to persist to or retrieve from |
[in] | persist | True if persisting, false if retrieving |
[in] | policy | Policy used to configure the FormatterStorage |
Definition at line 75 of file FormatterStorage.cc.
|
virtual |
Create a new table from an existing template table.
[in] | tableName | Name of the new table |
[in] | templateName | Name of the existing template table |
[in] | mayAlreadyExist | False (default) if the table must not be present |
Reimplemented from lsst::daf::persistence::DbStorage.
Definition at line 183 of file DbTsvStorage.cc.
|
virtual |
Drop a table.
[in] | tableName | Name of the table to drop |
Reimplemented from lsst::daf::persistence::DbStorage.
Definition at line 202 of file DbTsvStorage.cc.
|
virtual |
End a transaction.
Reimplemented from lsst::daf::persistence::DbStorage.
Definition at line 114 of file DbTsvStorage.cc.
|
virtualinherited |
Execute an arbitrary SQL statement.
Use primarily to perform server-side computations or complex DDL.
[in] | sqlStatement | SQL statement to be executed. Must not end in ";". |
Definition at line 136 of file DbStorage.cc.
|
virtualinherited |
Indicate that query processing is finished.
Must be called after next() returns false; no getColumnByPos() or columnIsNull() calls may be made after this method is called.
Definition at line 278 of file DbStorage.cc.
T const & lsst::daf::persistence::DbTsvStorage::getColumnByPos | ( | int | pos | ) |
Get the value of a column of the query result row by position.
[in] | pos | Position of the column (starts at 0) |
Definition at line 376 of file DbTsvStorage.cc.
|
inherited |
|
staticinherited |
Return the memId of the next object to be allocated.
Definition at line 229 of file Citizen.cc.
|
virtualinherited |
Request that the query output be grouped by an expression.
[in] | expression | Text of the SQL expression |
Definition at line 233 of file DbStorage.cc.
|
staticinherited |
Check all allocated blocks for corruption.
Definition at line 353 of file Citizen.cc.
|
staticinherited |
Called once when the memory system is being initialised.
Definition at line 214 of file Citizen.cc.
|
virtual |
Insert the row.
Row values must have been set with setColumn() calls.
Reimplemented from lsst::daf::persistence::DbStorage.
Definition at line 334 of file DbTsvStorage.cc.
|
inherited |
Mark a Citizen as persistent and not destroyed until process end.
Definition at line 254 of file Citizen.cc.
|
virtualinherited |
Move to the next (first) row of the query result.
Definition at line 255 of file DbStorage.cc.
|
virtualinherited |
Request that the query output be sorted by an expression.
Multiple expressions may be specified, in order.
[in] | expression | Text of the SQL expression |
Definition at line 226 of file DbStorage.cc.
|
virtualinherited |
Request a column in the query output.
[in] | columnName | Name of the column |
[in] | isExpr | True if the name is actually an expression |
The order of outColumn() calls is the order of appearance in the output row. Use either outColumn() or outParam() but not both.
Definition at line 194 of file DbStorage.cc.
void lsst::daf::persistence::DbTsvStorage::outParam | ( | std::string const & | columnName, |
T * | location, | ||
bool | isExpr = false |
||
) |
Request a column in the query output and bind a destination location.
[in] | columnName | Name of the column |
[in] | location | Pointer to the destination |
[in] | isExpr | True if the name is actually an expression |
The order of outParam() calls is the order of appearance in the output row. Use either outColumn() or outParam() but not both.
Definition at line 357 of file DbTsvStorage.cc.
|
virtualinherited |
Execute the query.
Definition at line 248 of file DbStorage.cc.
|
inherited |
Return a string representation of a Citizen.
Definition at line 245 of file Citizen.cc.
void lsst::daf::persistence::DbTsvStorage::setColumn | ( | std::string const & | columnName, |
T const & | value | ||
) |
Set the value to insert in a given column.
[in] | columnName | Name of the column |
[in] | value | Value to set in the column |
Definition at line 270 of file DbTsvStorage.cc.
void lsst::daf::persistence::DbTsvStorage::setColumn | ( | std::string const & | columnName, |
char const & | value | ||
) |
Definition at line 284 of file DbTsvStorage.cc.
void lsst::daf::persistence::DbTsvStorage::setColumn | ( | std::string const & | columnName, |
double const & | value | ||
) |
Definition at line 294 of file DbTsvStorage.cc.
void lsst::daf::persistence::DbTsvStorage::setColumn | ( | std::string const & | columnName, |
float const & | value | ||
) |
Definition at line 303 of file DbTsvStorage.cc.
void lsst::daf::persistence::DbTsvStorage::setColumn | ( | std::string const & | columnName, |
DateTime const & | value | ||
) |
Definition at line 313 of file DbTsvStorage.cc.
|
virtual |
Set a given column to NULL.
[in] | columnName | Name of the column |
Reimplemented from lsst::daf::persistence::DbStorage.
Definition at line 326 of file DbTsvStorage.cc.
|
staticinherited |
Set the CorruptionCallback function.
func | function be called when block is found to be corrupted |
Definition at line 432 of file Citizen.cc.
|
staticinherited |
Set the DeleteCallback function.
func | function be called when desired block is deleted |
Definition at line 422 of file Citizen.cc.
|
staticinherited |
Call the current DeleteCallback when block is deleted.
id | Desired ID |
Definition at line 387 of file Citizen.cc.
|
staticinherited |
Set the NewCallback function.
func | The new function to be called when a designated block is allocated |
Definition at line 412 of file Citizen.cc.
|
staticinherited |
Call the NewCallback when block is allocated.
id | Desired ID |
Definition at line 376 of file Citizen.cc.
|
virtual |
Set the database location to persist to.
[in] | location | Database connection string to insert to. |
Reimplemented from lsst::daf::persistence::DbStorage.
Definition at line 91 of file DbTsvStorage.cc.
|
virtual |
Allow a policy to be used to configure the DbTsvStorage.
[in] | policy |
Reimplemented from lsst::daf::persistence::DbStorage.
Definition at line 78 of file DbTsvStorage.cc.
|
virtualinherited |
Set the condition for the WHERE clause of the query.
[in] | whereClause | SQL text of the WHERE clause |
May include join conditions.
Definition at line 242 of file DbStorage.cc.
|
virtual |
Set the database location to retrieve from.
[in] | location | Database connection string to retrieve from. |
Reimplemented from lsst::daf::persistence::DbStorage.
Definition at line 101 of file DbTsvStorage.cc.
|
virtual |
Set the table to insert rows into.
[in] | tableName | Name of the table |
Reimplemented from lsst::daf::persistence::DbStorage.
Definition at line 234 of file DbTsvStorage.cc.
|
virtualinherited |
Set the table to query (single-table queries only).
[in] | tableName | Name of the table |
[in] | isExpr | True if the name is actually a table expression |
Definition at line 175 of file DbStorage.cc.
|
virtualinherited |
Set a list of tables to query (multiple-table queries).
[in] | tableNameList | Vector of names of tables |
Definition at line 182 of file DbStorage.cc.
|
virtual |
Start a transaction.
Reimplemented from lsst::daf::persistence::DbStorage.
Definition at line 108 of file DbTsvStorage.cc.
|
virtual |
Truncate a table.
[in] | tableName | Name of the table to truncate |
Reimplemented from lsst::daf::persistence::DbStorage.
Definition at line 218 of file DbTsvStorage.cc.
|
protectedinherited |
Ensure that all directories along a path exist, creating them if necessary.
[in] | name | Pathname to file to be created |
Definition at line 93 of file FormatterStorage.cc.
|
private |
Map from column names to positions.
Definition at line 106 of file DbTsvStorage.h.
|
private |
Stream to convert to text.
Definition at line 107 of file DbTsvStorage.h.
|
private |
Full pathname for temporary TSV file.
Definition at line 103 of file DbTsvStorage.h.
|
private |
Database location URL.
Definition at line 104 of file DbTsvStorage.h.
|
private |
Output TSV stream.
Definition at line 109 of file DbTsvStorage.h.
|
private |
Definition at line 100 of file DbTsvStorage.h.
|
private |
Definition at line 108 of file DbTsvStorage.h.
|
private |
Do not delete temporary TSV file if true.
Definition at line 101 of file DbTsvStorage.h.
|
private |
Definition at line 105 of file DbTsvStorage.h.
|
private |
Directory pathname for temporary TSV file.
Definition at line 102 of file DbTsvStorage.h.