LSSTApplications  11.0-24-g0a022a1,14.0+77,15.0,15.0+1
LSSTDataManagementBasePackage
Public Types | Public Member Functions | Static 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::FormatterStorage lsst::daf::base::Citizen lsst::daf::persistence::DbTsvStorage

Public Types

typedef std::shared_ptr< DbStoragePtr
 
typedef std::vector< PtrList
 
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)
 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
 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

 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...
 

Private Attributes

std::unique_ptr< DbStorageImpl_impl
 Implementation class for isolation. 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.

◆ memCallback

typedef memId(* lsst::daf::base::Citizen::memCallback) (const Citizen *ptr)
inherited

Definition at line 59 of file Citizen.h.

◆ memId

typedef unsigned long lsst::daf::base::Citizen::memId
inherited

Type of the block's ID.

Definition at line 56 of file Citizen.h.

◆ memNewCallback

typedef memId(* lsst::daf::base::Citizen::memNewCallback) (const memId cid)
inherited

A function used to register a callback.

Definition at line 58 of file Citizen.h.

◆ Ptr

Definition at line 65 of file DbStorage.h.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum
inherited
Enumerator
magicSentinel 

Definition at line 86 of file Citizen.h.

Constructor & Destructor Documentation

◆ DbStorage() [1/2]

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

Constructor.

Definition at line 57 of file DbStorage.cc.

57  : FormatterStorage(typeid(*this)), _impl(new DbStorageImpl) {
58 }
std::unique_ptr< DbStorageImpl > _impl
Implementation class for isolation.
Definition: DbStorage.h:113
FormatterStorage(std::type_info const &type)
Constructor.

◆ ~DbStorage()

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

Minimal destructor.

Definition at line 69 of file DbStorage.cc.

69  {
70 }

◆ 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.

63  :
64  FormatterStorage(type), _impl(new DbStorageImpl) {
65 }
std::unique_ptr< DbStorageImpl > _impl
Implementation class for isolation.
Definition: DbStorage.h:113
FormatterStorage(std::type_info const &type)
Constructor.

Member Function Documentation

◆ census() [1/3]

int lsst::daf::base::Citizen::census ( int  ,
memId  startingMemId = 0 
)
staticinherited

How many active Citizens are there?

Parameters
startingMemIdDon't print Citizens with lower IDs

Definition at line 267 of file Citizen.cc.

270  {
271  if (startingMemId == 0) { // easy
272  ReadGuard guard(citizenLock);
273  return _activeCitizens.size();
274  }
275 
276  int n = 0;
277  ReadGuard guard(citizenLock);
278  for (table::iterator cur = _activeCitizens.begin();
279  cur != _activeCitizens.end(); cur++) {
280  if (cur->first->_CitizenId >= startingMemId) {
281  n++;
282  }
283  }
284 
285  return n;
286 }
T end(T... args)
static table _activeCitizens
Definition: Citizen.h:102
T size(T... args)
T begin(T... args)

◆ census() [2/3]

void lsst::daf::base::Citizen::census ( std::ostream stream,
memId  startingMemId = 0 
)
staticinherited

Print a list of all active Citizens to stream, sorted by ID.

Parameters
streamstream to print to
startingMemIdDon't print Citizens with lower IDs

Definition at line 290 of file Citizen.cc.

293  {
294  ReadGuard guard(citizenLock);
295 
297 
298  for (std::vector<Citizen const *>::const_iterator citizen = leaks->begin(), end = leaks->end();
299  citizen != end; ++citizen) {
300  if ((*citizen)->getId() >= startingMemId) {
301  stream << (*citizen)->repr() << "\n";
302  }
303  }
304 }
int end
STL class.
STL class.
T begin(T... args)
static const std::vector< const Citizen * > * census()
Return a (newly allocated) std::vector of active Citizens sorted by ID.
Definition: Citizen.cc:322

◆ census() [3/3]

std::vector< dafBase::Citizen const * > const * lsst::daf::base::Citizen::census ( )
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.

322  {
325  ReadGuard guard(citizenLock);
326  vec->reserve(_activeCitizens.size());
327 
328  for (table::iterator cur = _activeCitizens.begin();
329  cur != _activeCitizens.end(); cur++) {
330  vec->push_back(dynamic_cast<Citizen const*>(cur->first));
331  }
332 
333  std::sort(vec->begin(), vec->end(), cmpId);
334 
335  return vec;
336 }
T end(T... args)
static table _activeCitizens
Definition: Citizen.h:102
T push_back(T... args)
T size(T... args)
STL class.
T begin(T... args)
T sort(T... args)
T reserve(T... args)

◆ 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.

270  {
271  return _impl->columnIsNull(pos);
272 }
std::unique_ptr< DbStorageImpl > _impl
Implementation class for isolation.
Definition: DbStorage.h:113

◆ 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.

218  {
219  _impl->condParam(paramName, value);
220 }
std::unique_ptr< DbStorageImpl > _impl
Implementation class for isolation.
Definition: DbStorage.h:113

◆ 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.

77  {
79  storage->setPolicy(policy);
80  if (persist) {
81  storage->setPersistLocation(location);
82  }
83  else {
84  storage->setRetrieveLocation(location);
85  }
86  return storage;
87 }
table::Key< std::string > name
Definition: ApCorrMap.cc:71
static StorageRegistry & getRegistry(void)
Return a reference to a subclass registry.
FormatterStorage::Ptr createInstance(std::string const &name)
Create a FormatterStorage subclass instance by name.
std::shared_ptr< FormatterStorage > Ptr

◆ 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.

114  {
115  _impl->createTableFromTemplate(tableName, templateName, mayAlreadyExist);
116 }
std::unique_ptr< DbStorageImpl > _impl
Implementation class for isolation.
Definition: DbStorage.h:113

◆ 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.

121  {
122  _impl->dropTable(tableName);
123 }
std::unique_ptr< DbStorageImpl > _impl
Implementation class for isolation.
Definition: DbStorage.h:113

◆ 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.

101  {
102  _impl->endTransaction();
103 }
std::unique_ptr< DbStorageImpl > _impl
Implementation class for isolation.
Definition: DbStorage.h:113

◆ 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.

136  {
137  _impl->executeSql(sqlStatement);
138 }
std::unique_ptr< DbStorageImpl > _impl
Implementation class for isolation.
Definition: DbStorage.h:113

◆ 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.

278  {
279  _impl->finishQuery();
280 }
std::unique_ptr< DbStorageImpl > _impl
Implementation class for isolation.
Definition: DbStorage.h:113

◆ 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.

263  {
264  return _impl->getColumnByPos<T>(pos);
265 }
std::unique_ptr< DbStorageImpl > _impl
Implementation class for isolation.
Definition: DbStorage.h:113

◆ getId()

dafBase::Citizen::memId lsst::daf::base::Citizen::getId ( ) const
inherited

Return the Citizen's ID.

Definition at line 224 of file Citizen.cc.

224  {
225  return _CitizenId;
226 }

◆ getNextMemId()

dafBase::Citizen::memId lsst::daf::base::Citizen::getNextMemId ( )
staticinherited

Return the memId of the next object to be allocated.

Definition at line 229 of file Citizen.cc.

229  {
230  return _nextMemId();
231 }
static memId _nextMemId(void)
Return the memId of the next object to be allocated.
Definition: Citizen.cc:234

◆ 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.

233  {
234  _impl->groupBy(expression);
235 }
std::unique_ptr< DbStorageImpl > _impl
Implementation class for isolation.
Definition: DbStorage.h:113

◆ hasBeenCorrupted()

bool lsst::daf::base::Citizen::hasBeenCorrupted ( )
staticinherited

Check all allocated blocks for corruption.

Definition at line 353 of file Citizen.cc.

353  {
354  ReadGuard guard(citizenLock);
355  for (table::iterator cur = _activeCitizens.begin();
356  cur != _activeCitizens.end(); cur++) {
357  if (cur->first->_hasBeenCorrupted()) {
358  return true;
359  }
360  }
361  for (table::iterator cur = _persistentCitizens.begin();
362  cur != _persistentCitizens.end(); cur++) {
363  if (cur->first->_hasBeenCorrupted()) {
364  return true;
365  }
366  }
367 
368  return false;
369 }
T end(T... args)
static table _activeCitizens
Definition: Citizen.h:102
static table _persistentCitizens
Definition: Citizen.h:103
T begin(T... args)

◆ init()

int lsst::daf::base::Citizen::init ( )
staticinherited

Called once when the memory system is being initialised.

Definition at line 214 of file Citizen.cc.

214  {
215  volatile int dummy = 1;
216  return dummy;
217 }

◆ 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.

166  {
167  _impl->insertRow();
168 }
std::unique_ptr< DbStorageImpl > _impl
Implementation class for isolation.
Definition: DbStorage.h:113

◆ markPersistent()

void lsst::daf::base::Citizen::markPersistent ( void  )
inherited

Mark a Citizen as persistent and not destroyed until process end.

Definition at line 254 of file Citizen.cc.

254  {
255  WriteGuard guard(citizenLock);
256  _persistentCitizens[this] = _activeCitizens[this];
257  _activeCitizens.erase(this);
258 }
static table _activeCitizens
Definition: Citizen.h:102
T erase(T... args)
static table _persistentCitizens
Definition: Citizen.h:103

◆ 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.

255  {
256  return _impl->next();
257 }
std::unique_ptr< DbStorageImpl > _impl
Implementation class for isolation.
Definition: DbStorage.h:113

◆ 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.

226  {
227  _impl->orderBy(expression);
228 }
std::unique_ptr< DbStorageImpl > _impl
Implementation class for isolation.
Definition: DbStorage.h:113

◆ 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.

194  {
195  _impl->outColumn(columnName, isExpr);
196 }
std::unique_ptr< DbStorageImpl > _impl
Implementation class for isolation.
Definition: DbStorage.h:113

◆ 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.

208  {
209  _impl->outParam(columnName, location, isExpr);
210 }
std::unique_ptr< DbStorageImpl > _impl
Implementation class for isolation.
Definition: DbStorage.h:113

◆ query()

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

Execute the query.

Definition at line 248 of file DbStorage.cc.

248  {
249  _impl->query();
250 }
std::unique_ptr< DbStorageImpl > _impl
Implementation class for isolation.
Definition: DbStorage.h:113

◆ repr()

std::string lsst::daf::base::Citizen::repr ( ) const
inherited

Return a string representation of a Citizen.

Definition at line 245 of file Citizen.cc.

245  {
246  return boost::str(boost::format("%d: %08x %s")
247  % _CitizenId
248  % this
250  );
251 }
std::string demangleType(std::string const _typeName)
Definition: Demangle.cc:113
def format(config, name=None, writeSourceLine=True, prefix="", verbose=False)
Definition: history.py:134
const char * _typeName
Definition: Citizen.h:94

◆ 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.

152  {
153  _impl->setColumn(columnName, value);
154 }
std::unique_ptr< DbStorageImpl > _impl
Implementation class for isolation.
Definition: DbStorage.h:113

◆ 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.

159  {
160  _impl->setColumnToNull(columnName);
161 }
std::unique_ptr< DbStorageImpl > _impl
Implementation class for isolation.
Definition: DbStorage.h:113

◆ setCorruptionCallback()

dafBase::Citizen::memCallback lsst::daf::base::Citizen::setCorruptionCallback ( Citizen::memCallback  func)
staticinherited

Set the CorruptionCallback function.

Parameters
funcfunction be called when block is found to be corrupted

Definition at line 432 of file Citizen.cc.

434  {
436  _corruptionCallback = func;
437 
438  return old;
439 }
memId(* memCallback)(const Citizen *ptr)
Definition: Citizen.h:59
static memCallback _corruptionCallback
Definition: Citizen.h:113

◆ setDeleteCallback()

dafBase::Citizen::memCallback lsst::daf::base::Citizen::setDeleteCallback ( Citizen::memCallback  func)
staticinherited

Set the DeleteCallback function.

Parameters
funcfunction be called when desired block is deleted

Definition at line 422 of file Citizen.cc.

424  {
426  _deleteCallback = func;
427 
428  return old;
429 }
static memCallback _deleteCallback
Definition: Citizen.h:112
memId(* memCallback)(const Citizen *ptr)
Definition: Citizen.h:59

◆ setDeleteCallbackId()

dafBase::Citizen::memId lsst::daf::base::Citizen::setDeleteCallbackId ( Citizen::memId  id)
staticinherited

Call the current DeleteCallback when block is deleted.

Parameters
idDesired ID

Definition at line 387 of file Citizen.cc.

389  {
390  WriteGuard guard(citizenLock);
391  Citizen::memId oldId = _deleteId;
392  _deleteId = id;
393 
394  return oldId;
395 }
unsigned long memId
Type of the block&#39;s ID.
Definition: Citizen.h:56
int id
Definition: CR.cc:155
static memId _deleteId
Definition: Citizen.h:109

◆ setNewCallback()

dafBase::Citizen::memNewCallback lsst::daf::base::Citizen::setNewCallback ( Citizen::memNewCallback  func)
staticinherited

Set the NewCallback function.

Parameters
funcThe new function to be called when a designated block is allocated

Definition at line 412 of file Citizen.cc.

414  {
416  _newCallback = func;
417 
418  return old;
419 }
memId(* memNewCallback)(const memId cid)
A function used to register a callback.
Definition: Citizen.h:58
static memNewCallback _newCallback
Definition: Citizen.h:111

◆ setNewCallbackId()

dafBase::Citizen::memId lsst::daf::base::Citizen::setNewCallbackId ( Citizen::memId  id)
staticinherited

Call the NewCallback when block is allocated.

Parameters
idDesired ID

Definition at line 376 of file Citizen.cc.

378  {
379  WriteGuard guard(citizenLock);
380  Citizen::memId oldId = _newId;
381  _newId = id;
382 
383  return oldId;
384 }
unsigned long memId
Type of the block&#39;s ID.
Definition: Citizen.h:56
static memId _newId
Definition: Citizen.h:108
int id
Definition: CR.cc:155

◆ 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.

82  {
83  _impl->setPersistLocation(location);
84 }
std::unique_ptr< DbStorageImpl > _impl
Implementation class for isolation.
Definition: DbStorage.h:113

◆ 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.

75  {
76  _impl->setPolicy(policy);
77 }
std::unique_ptr< DbStorageImpl > _impl
Implementation class for isolation.
Definition: DbStorage.h:113

◆ 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.

242  {
243  _impl->setQueryWhere(whereClause);
244 }
std::unique_ptr< DbStorageImpl > _impl
Implementation class for isolation.
Definition: DbStorage.h:113

◆ 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.

89  {
90  _impl->setRetrieveLocation(location);
91 }
std::unique_ptr< DbStorageImpl > _impl
Implementation class for isolation.
Definition: DbStorage.h:113

◆ 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.

143  {
144  _impl->setTableForInsert(tableName);
145 }
std::unique_ptr< DbStorageImpl > _impl
Implementation class for isolation.
Definition: DbStorage.h:113

◆ 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.

175  {
176  _impl->setTableForQuery(tableName, isExpr);
177 }
std::unique_ptr< DbStorageImpl > _impl
Implementation class for isolation.
Definition: DbStorage.h:113

◆ 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.

183  {
184  _impl->setTableListForQuery(tableNameList);
185 }
std::unique_ptr< DbStorageImpl > _impl
Implementation class for isolation.
Definition: DbStorage.h:113

◆ 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.

95  {
96  _impl->startTransaction();
97 }
std::unique_ptr< DbStorageImpl > _impl
Implementation class for isolation.
Definition: DbStorage.h:113

◆ 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.

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

◆ 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.

93  {
94  // Get the directory by stripping off anything after the last slash.
95  std::string::size_type pos = name.find_last_of('/');
96  if (pos == std::string::npos) return;
97  std::string dirName = name.substr(0, pos);
98 
99  // Check to see if the directory exists.
100  struct stat buf;
101  int ret = ::stat(dirName.c_str(), &buf);
102 
103  if (ret == -1 && errno == ENOENT) {
104  // It doesn't; check its parent and then create it.
105  verifyPathName(dirName);
106 
107  ret = ::mkdir(dirName.c_str(), 0777);
108 
109  // If it already exists, we're OK; otherwise, throw an exception.
110  if (ret == -1 && errno != EEXIST) {
112  dirName + ": Error creating directory = " + std::strerror(errno));
113  }
114  }
115  else if (ret == -1) {
116  // We couldn't read the (existing) directory for some reason.
118  dirName + ": Error searching for directory = " + std::strerror(errno));
119  }
120  else if (!S_ISDIR(buf.st_mode)) {
121  // It's not a directory.
123  dirName + ": Non-directory in path");
124  }
125 }
table::Key< std::string > name
Definition: ApCorrMap.cc:71
T strerror(T... args)
STL class.
#define LSST_EXCEPT(type,...)
Create an exception with a given type and message and optionally other arguments (dependent on the ty...
Definition: Exception.h:46
T c_str(T... args)
void verifyPathName(std::string const &pathName)
Ensure that all directories along a path exist, creating them if necessary.

Member Data Documentation

◆ _impl

std::unique_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: