LSSTApplications  10.0+286,10.0+36,10.0+46,10.0-2-g4f67435,10.1+152,10.1+37,11.0,11.0+1,11.0-1-g47edd16,11.0-1-g60db491,11.0-1-g7418c06,11.0-2-g04d2804,11.0-2-g68503cd,11.0-2-g818369d,11.0-2-gb8b8ce7
LSSTDataManagementBasePackage
Public Types | Public Member Functions | Protected Member Functions | Private Attributes | 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::Storage lsst::daf::base::Citizen lsst::daf::persistence::DbTsvStorage

Public Types

typedef boost::shared_ptr
< DbStorage
Ptr
 
- Public Types inherited from lsst::daf::persistence::Storage
typedef boost::shared_ptr
< Storage
Ptr
 
typedef std::vector< PtrList
 
- Public Types inherited from lsst::daf::base::Citizen
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

 DbStorage (void)
 
 ~DbStorage (void)
 
virtual void setPolicy (lsst::pex::policy::Policy::Ptr policy)
 
virtual void setPersistLocation (LogicalLocation const &location)
 
virtual void setRetrieveLocation (LogicalLocation const &location)
 
virtual void startTransaction (void)
 
virtual void endTransaction (void)
 
virtual void createTableFromTemplate (std::string const &tableName, std::string const &templateName, bool mayAlreadyExist=false)
 
virtual void dropTable (std::string const &tableName)
 
virtual void truncateTable (std::string const &tableName)
 
virtual void executeSql (std::string const &sqlStatement)
 
virtual void setTableForInsert (std::string const &tableName)
 
template<typename T >
void setColumn (std::string const &columnName, T const &value)
 
virtual void setColumnToNull (std::string const &columnName)
 
virtual void insertRow (void)
 
virtual void setTableForQuery (std::string const &tableName, bool isExpr=false)
 
virtual void setTableListForQuery (std::vector< std::string > const &tableNameList)
 
virtual void outColumn (std::string const &columnName, bool isExpr=false)
 
template<typename T >
void outParam (std::string const &columnName, T *location, bool isExpr=false)
 
template<typename T >
void condParam (std::string const &paramName, T const &value)
 
virtual void orderBy (std::string const &expression)
 
virtual void groupBy (std::string const &expression)
 
virtual void setQueryWhere (std::string const &whereClause)
 
virtual void query (void)
 
virtual bool next (void)
 
template<typename T >
T const & getColumnByPos (int pos)
 
bool columnIsNull (int pos)
 
virtual void finishQuery (void)
 
- Public Member Functions inherited from lsst::daf::persistence::Storage
virtual ~Storage (void)
 
- Public Member Functions inherited from lsst::daf::base::Citizen
 Citizen (const std::type_info &)
 
 Citizen (Citizen const &)
 
 ~Citizen ()
 
Citizenoperator= (Citizen const &)
 
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...
 

Protected Member Functions

 DbStorage (std::type_info const &type)
 
- Protected Member Functions inherited from lsst::daf::persistence::Storage
 Storage (std::type_info const &type)
 
void verifyPathName (std::string const &pathName)
 

Private Attributes

boost::scoped_ptr< DbStorageImpl_impl
 Implementation class for isolation. More...
 

Additional Inherited Members

- Static Public Member Functions inherited from lsst::daf::persistence::Storage
static Ptr createInstance (std::string const &name, LogicalLocation const &location, bool persist, lsst::pex::policy::Policy::Ptr policy)
 
- Static Public Member Functions inherited from lsst::daf::base::Citizen
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...
 
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...
 
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...
 
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...
 

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

Definition at line 65 of file DbStorage.h.

Constructor & Destructor Documentation

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

Constructor.

Definition at line 57 of file DbStorage.cc.

57  : Storage(typeid(*this)), _impl(new DbStorageImpl) {
58 }
boost::scoped_ptr< DbStorageImpl > _impl
Implementation class for isolation.
Definition: DbStorage.h:113
Storage(std::type_info const &type)
Definition: Storage.cc:60
lsst::daf::persistence::DbStorage::~DbStorage ( void  )

Minimal destructor.

Definition at line 69 of file DbStorage.cc.

69  {
70 }
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.

63  :
64  Storage(type), _impl(new DbStorageImpl) {
65 }
boost::scoped_ptr< DbStorageImpl > _impl
Implementation class for isolation.
Definition: DbStorage.h:113
Storage(std::type_info const &type)
Definition: Storage.cc:60

Member Function Documentation

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.

270  {
271  return _impl->columnIsNull(pos);
272 }
boost::scoped_ptr< DbStorageImpl > _impl
Implementation class for isolation.
Definition: DbStorage.h:113
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.

218  {
219  _impl->condParam(paramName, value);
220 }
boost::scoped_ptr< DbStorageImpl > _impl
Implementation class for isolation.
Definition: DbStorage.h:113
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.

114  {
115  _impl->createTableFromTemplate(tableName, templateName, mayAlreadyExist);
116 }
boost::scoped_ptr< DbStorageImpl > _impl
Implementation class for isolation.
Definition: DbStorage.h:113
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.

121  {
122  _impl->dropTable(tableName);
123 }
boost::scoped_ptr< DbStorageImpl > _impl
Implementation class for isolation.
Definition: DbStorage.h:113
void lsst::daf::persistence::DbStorage::endTransaction ( void  )
virtual

End a transaction.

Implements lsst::daf::persistence::Storage.

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

Definition at line 101 of file DbStorage.cc.

101  {
102  _impl->endTransaction();
103 }
boost::scoped_ptr< DbStorageImpl > _impl
Implementation class for isolation.
Definition: DbStorage.h:113
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.

136  {
137  _impl->executeSql(sqlStatement);
138 }
boost::scoped_ptr< DbStorageImpl > _impl
Implementation class for isolation.
Definition: DbStorage.h:113
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.

278  {
279  _impl->finishQuery();
280 }
boost::scoped_ptr< DbStorageImpl > _impl
Implementation class for isolation.
Definition: DbStorage.h:113
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.

263  {
264  return _impl->getColumnByPos<T>(pos);
265 }
boost::scoped_ptr< DbStorageImpl > _impl
Implementation class for isolation.
Definition: DbStorage.h:113
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.

233  {
234  _impl->groupBy(expression);
235 }
boost::scoped_ptr< DbStorageImpl > _impl
Implementation class for isolation.
Definition: DbStorage.h:113
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.

166  {
167  _impl->insertRow();
168 }
boost::scoped_ptr< DbStorageImpl > _impl
Implementation class for isolation.
Definition: DbStorage.h:113
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.

255  {
256  return _impl->next();
257 }
boost::scoped_ptr< DbStorageImpl > _impl
Implementation class for isolation.
Definition: DbStorage.h:113
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.

226  {
227  _impl->orderBy(expression);
228 }
boost::scoped_ptr< DbStorageImpl > _impl
Implementation class for isolation.
Definition: DbStorage.h:113
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.

194  {
195  _impl->outColumn(columnName, isExpr);
196 }
boost::scoped_ptr< DbStorageImpl > _impl
Implementation class for isolation.
Definition: DbStorage.h:113
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.

208  {
209  _impl->outParam(columnName, location, isExpr);
210 }
boost::scoped_ptr< DbStorageImpl > _impl
Implementation class for isolation.
Definition: DbStorage.h:113
void lsst::daf::persistence::DbStorage::query ( void  )
virtual

Execute the query.

Definition at line 248 of file DbStorage.cc.

248  {
249  _impl->query();
250 }
boost::scoped_ptr< DbStorageImpl > _impl
Implementation class for isolation.
Definition: DbStorage.h:113
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.

152  {
153  _impl->setColumn(columnName, value);
154 }
boost::scoped_ptr< DbStorageImpl > _impl
Implementation class for isolation.
Definition: DbStorage.h:113
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.

159  {
160  _impl->setColumnToNull(columnName);
161 }
boost::scoped_ptr< DbStorageImpl > _impl
Implementation class for isolation.
Definition: DbStorage.h:113
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::Storage.

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

Definition at line 82 of file DbStorage.cc.

82  {
83  _impl->setPersistLocation(location);
84 }
boost::scoped_ptr< DbStorageImpl > _impl
Implementation class for isolation.
Definition: DbStorage.h:113
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::Storage.

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

Definition at line 75 of file DbStorage.cc.

75  {
76  _impl->setPolicy(policy);
77 }
boost::scoped_ptr< DbStorageImpl > _impl
Implementation class for isolation.
Definition: DbStorage.h:113
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.

242  {
243  _impl->setQueryWhere(whereClause);
244 }
boost::scoped_ptr< DbStorageImpl > _impl
Implementation class for isolation.
Definition: DbStorage.h:113
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::Storage.

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

Definition at line 89 of file DbStorage.cc.

89  {
90  _impl->setRetrieveLocation(location);
91 }
boost::scoped_ptr< DbStorageImpl > _impl
Implementation class for isolation.
Definition: DbStorage.h:113
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.

143  {
144  _impl->setTableForInsert(tableName);
145 }
boost::scoped_ptr< DbStorageImpl > _impl
Implementation class for isolation.
Definition: DbStorage.h:113
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.

175  {
176  _impl->setTableForQuery(tableName, isExpr);
177 }
boost::scoped_ptr< DbStorageImpl > _impl
Implementation class for isolation.
Definition: DbStorage.h:113
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.

183  {
184  _impl->setTableListForQuery(tableNameList);
185 }
boost::scoped_ptr< DbStorageImpl > _impl
Implementation class for isolation.
Definition: DbStorage.h:113
void lsst::daf::persistence::DbStorage::startTransaction ( void  )
virtual

Start a transaction.

Implements lsst::daf::persistence::Storage.

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

Definition at line 95 of file DbStorage.cc.

95  {
96  _impl->startTransaction();
97 }
boost::scoped_ptr< DbStorageImpl > _impl
Implementation class for isolation.
Definition: DbStorage.h:113
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.

128  {
129  _impl->truncateTable(tableName);
130 }
boost::scoped_ptr< DbStorageImpl > _impl
Implementation class for isolation.
Definition: DbStorage.h:113

Member Data Documentation

boost::scoped_ptr<DbStorageImpl> lsst::daf::persistence::DbStorage::_impl
private

Implementation class for isolation.

Definition at line 113 of file DbStorage.h.


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