lsst.daf.persistence  14.0-10-g024c5b6
Public Types | Public Member Functions | Static Public Member Functions | Public Attributes | Protected Member Functions | List of all members
lsst::daf::persistence::DbStorage Class Reference

Class for database storage. More...

#include <DbStorage.h>

Inheritance diagram for lsst::daf::persistence::DbStorage:
lsst::daf::persistence::FormatterStorage lsst::daf::base::Citizen lsst::daf::persistence::DbTsvStorage

Public Types

typedef std::shared_ptr< DbStoragePtr
 
typedef std::vector< PtrList
 
typedef unsigned long memId
 
typedef memId(* memNewCallback) (const memId cid)
 
typedef memId(* memCallback) (const Citizen *ptr)
 

Public Member Functions

 DbStorage (void)
 Constructor. More...
 
 ~DbStorage (void)
 Minimal destructor. More...
 
virtual void setPolicy (lsst::pex::policy::Policy::Ptr policy)
 Allow a policy to be used to configure the DbStorage. 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 executeSql (std::string const &sqlStatement)
 Execute an arbitrary SQL statement. 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...
 
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...
 
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 &paramName, T const &value)
 Bind a value to a WHERE condition parameter. 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...
 
template<typename T >
T const & getColumnByPos (int pos)
 Get the value of a column of the query result row by position. 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
 
void markPersistent (void)
 
memId getId () const
 

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 ()
 
static memId getNextMemId ()
 
static int init ()
 
static int census (int, memId startingMemId=0)
 
static void census (std::ostream &stream, memId startingMemId=0)
 
static const std::vector< const Citizen *> * census ()
 
static int census (int, memId startingMemId=0)
 
static void census (std::ostream &stream, memId startingMemId=0)
 
static const std::vector< const Citizen *> * census ()
 
static memId setNewCallbackId (memId id)
 
static memId setNewCallbackId (memId id)
 
static memId setDeleteCallbackId (memId id)
 
static memId setDeleteCallbackId (memId id)
 
static memNewCallback setNewCallback (memNewCallback func)
 
static memCallback setDeleteCallback (memCallback func)
 
static memCallback setCorruptionCallback (memCallback func)
 

Public Attributes

 magicSentinel
 

Protected Member Functions

 DbStorage (std::type_info const &type)
 Constructor with subclass type. More...
 
void verifyPathName (std::string const &pathName)
 Ensure that all directories along a path exist, creating them if necessary. More...
 

Detailed Description

Class for database storage.

Persists data to a database. Provides methods for writing rows to a table and retrieving rows from a query.

Definition at line 63 of file DbStorage.h.

Member Typedef Documentation

◆ List

Definition at line 63 of file FormatterStorage.h.

◆ Ptr

Definition at line 65 of file DbStorage.h.

Constructor & Destructor Documentation

◆ DbStorage() [1/2]

lsst::daf::persistence::DbStorage::DbStorage ( void  )

Constructor.

Definition at line 57 of file DbStorage.cc.

◆ ~DbStorage()

lsst::daf::persistence::DbStorage::~DbStorage ( void  )

Minimal destructor.

Definition at line 69 of file DbStorage.cc.

◆ DbStorage() [2/2]

lsst::daf::persistence::DbStorage::DbStorage ( std::type_info const &  type)
explicitprotected

Constructor with subclass type.

Parameters
[in]typetypeid() of subclass

Definition at line 63 of file DbStorage.cc.

Member Function Documentation

◆ columnIsNull()

bool lsst::daf::persistence::DbStorage::columnIsNull ( int  pos)

Determine if the value of a column is NULL.

Parameters
[in]posPosition of the column (starts at 0)

Definition at line 270 of file DbStorage.cc.

◆ condParam()

template<typename T >
void lsst::daf::persistence::DbStorage::condParam ( std::string const &  paramName,
T const &  value 
)

Bind a value to a WHERE condition parameter.

Parameters
[in]paramNameName of the parameter (prefixed by ":" in the WHERE clause)
[in]valueValue to be bound to the parameter.

Definition at line 218 of file DbStorage.cc.

◆ createInstance()

FormatterStorage::Ptr lsst::daf::persistence::FormatterStorage::createInstance ( std::string const &  name,
LogicalLocation const &  location,
bool  persist,
lsst::pex::policy::Policy::Ptr  policy 
)
staticinherited

Create and configure a FormatterStorage subclass instance.

Parameters
[in]nameName of subclass
[in]locationLocation to persist to or retrieve from
[in]persistTrue if persisting, false if retrieving
[in]policyPolicy used to configure the FormatterStorage
Returns
Shared pointer to FormatterStorage subclass instance

Definition at line 75 of file FormatterStorage.cc.

◆ createTableFromTemplate()

void lsst::daf::persistence::DbStorage::createTableFromTemplate ( std::string const &  tableName,
std::string const &  templateName,
bool  mayAlreadyExist = false 
)
virtual

Create a new table from an existing template table.

Parameters
[in]tableNameName of the new table
[in]templateNameName of the existing template table
[in]mayAlreadyExistFalse (default) if the table must not be present

Note: currently works with MySQL only.

Reimplemented in lsst::daf::persistence::DbTsvStorage.

Definition at line 112 of file DbStorage.cc.

◆ dropTable()

void lsst::daf::persistence::DbStorage::dropTable ( std::string const &  tableName)
virtual

Drop a table.

Parameters
[in]tableNameName of the table to drop

Reimplemented in lsst::daf::persistence::DbTsvStorage.

Definition at line 121 of file DbStorage.cc.

◆ endTransaction()

void lsst::daf::persistence::DbStorage::endTransaction ( void  )
virtual

End a transaction.

Implements lsst::daf::persistence::FormatterStorage.

Reimplemented in lsst::daf::persistence::DbTsvStorage.

Definition at line 101 of file DbStorage.cc.

◆ executeSql()

void lsst::daf::persistence::DbStorage::executeSql ( std::string const &  sqlStatement)
virtual

Execute an arbitrary SQL statement.

Use primarily to perform server-side computations or complex DDL.

Parameters
[in]sqlStatementSQL statement to be executed. Must not end in ";".

Definition at line 136 of file DbStorage.cc.

◆ finishQuery()

void lsst::daf::persistence::DbStorage::finishQuery ( void  )
virtual

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.

◆ getColumnByPos()

template<typename T >
T const & lsst::daf::persistence::DbStorage::getColumnByPos ( int  pos)

Get the value of a column of the query result row by position.

Parameters
[in]posPosition of the column (starts at 0)

Definition at line 263 of file DbStorage.cc.

◆ groupBy()

void lsst::daf::persistence::DbStorage::groupBy ( std::string const &  expression)
virtual

Request that the query output be grouped by an expression.

Parameters
[in]expressionText of the SQL expression

Definition at line 233 of file DbStorage.cc.

◆ insertRow()

void lsst::daf::persistence::DbStorage::insertRow ( void  )
virtual

Insert the row.

Row values must have been set with setColumn() calls.

Reimplemented in lsst::daf::persistence::DbTsvStorage.

Definition at line 166 of file DbStorage.cc.

◆ next()

bool lsst::daf::persistence::DbStorage::next ( void  )
virtual

Move to the next (first) row of the query result.

Returns
false if no more rows

Definition at line 255 of file DbStorage.cc.

◆ orderBy()

void lsst::daf::persistence::DbStorage::orderBy ( std::string const &  expression)
virtual

Request that the query output be sorted by an expression.

Multiple expressions may be specified, in order.

Parameters
[in]expressionText of the SQL expression

Definition at line 226 of file DbStorage.cc.

◆ outColumn()

void lsst::daf::persistence::DbStorage::outColumn ( std::string const &  columnName,
bool  isExpr = false 
)
virtual

Request a column in the query output.

Parameters
[in]columnNameName of the column
[in]isExprTrue 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.

◆ outParam()

template<typename T >
void lsst::daf::persistence::DbStorage::outParam ( std::string const &  columnName,
T *  location,
bool  isExpr = false 
)

Request a column in the query output and bind a destination location.

Parameters
[in]columnNameName of the column
[in]locationPointer to the destination
[in]isExprTrue 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 207 of file DbStorage.cc.

◆ query()

void lsst::daf::persistence::DbStorage::query ( void  )
virtual

Execute the query.

Definition at line 248 of file DbStorage.cc.

◆ setColumn()

template<typename T >
void lsst::daf::persistence::DbStorage::setColumn ( std::string const &  columnName,
T const &  value 
)

Set the value to insert in a given column.

Parameters
[in]columnNameName of the column
[in]valueValue to set in the column

Definition at line 152 of file DbStorage.cc.

◆ setColumnToNull()

void lsst::daf::persistence::DbStorage::setColumnToNull ( std::string const &  columnName)
virtual

Set a given column to NULL.

Parameters
[in]columnNameName of the column

Reimplemented in lsst::daf::persistence::DbTsvStorage.

Definition at line 159 of file DbStorage.cc.

◆ setPersistLocation()

void lsst::daf::persistence::DbStorage::setPersistLocation ( LogicalLocation const &  location)
virtual

Set the database location to persist to.

Parameters
[in]locationDatabase connection string to insert to.

Implements lsst::daf::persistence::FormatterStorage.

Reimplemented in lsst::daf::persistence::DbTsvStorage.

Definition at line 82 of file DbStorage.cc.

◆ setPolicy()

void lsst::daf::persistence::DbStorage::setPolicy ( lsst::pex::policy::Policy::Ptr  policy)
virtual

Allow a policy to be used to configure the DbStorage.

Parameters
[in]policy

Implements lsst::daf::persistence::FormatterStorage.

Reimplemented in lsst::daf::persistence::DbTsvStorage.

Definition at line 75 of file DbStorage.cc.

◆ setQueryWhere()

void lsst::daf::persistence::DbStorage::setQueryWhere ( std::string const &  whereClause)
virtual

Set the condition for the WHERE clause of the query.

Parameters
[in]whereClauseSQL text of the WHERE clause

May include join conditions.

Definition at line 242 of file DbStorage.cc.

◆ setRetrieveLocation()

void lsst::daf::persistence::DbStorage::setRetrieveLocation ( LogicalLocation const &  location)
virtual

Set the database location to retrieve from.

Parameters
[in]locationDatabase connection string to query.

Implements lsst::daf::persistence::FormatterStorage.

Reimplemented in lsst::daf::persistence::DbTsvStorage.

Definition at line 89 of file DbStorage.cc.

◆ setTableForInsert()

void lsst::daf::persistence::DbStorage::setTableForInsert ( std::string const &  tableName)
virtual

Set the table to insert rows into.

Parameters
[in]tableNameName of the table

Reimplemented in lsst::daf::persistence::DbTsvStorage.

Definition at line 143 of file DbStorage.cc.

◆ setTableForQuery()

void lsst::daf::persistence::DbStorage::setTableForQuery ( std::string const &  tableName,
bool  isExpr = false 
)
virtual

Set the table to query (single-table queries only).

Parameters
[in]tableNameName of the table
[in]isExprTrue if the name is actually a table expression

Definition at line 175 of file DbStorage.cc.

◆ setTableListForQuery()

void lsst::daf::persistence::DbStorage::setTableListForQuery ( std::vector< std::string > const &  tableNameList)
virtual

Set a list of tables to query (multiple-table queries).

Parameters
[in]tableNameListVector of names of tables

Definition at line 182 of file DbStorage.cc.

◆ startTransaction()

void lsst::daf::persistence::DbStorage::startTransaction ( void  )
virtual

Start a transaction.

Implements lsst::daf::persistence::FormatterStorage.

Reimplemented in lsst::daf::persistence::DbTsvStorage.

Definition at line 95 of file DbStorage.cc.

◆ truncateTable()

void lsst::daf::persistence::DbStorage::truncateTable ( std::string const &  tableName)
virtual

Truncate a table.

Parameters
[in]tableNameName of the table to truncate

Reimplemented in lsst::daf::persistence::DbTsvStorage.

Definition at line 128 of file DbStorage.cc.

◆ verifyPathName()

void lsst::daf::persistence::FormatterStorage::verifyPathName ( std::string const &  name)
protectedinherited

Ensure that all directories along a path exist, creating them if necessary.

Parameters
[in]namePathname to file to be created

Definition at line 93 of file FormatterStorage.cc.


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