LSSTApplications  11.0-24-g0a022a1,14.0+77,15.0,15.0+1
LSSTDataManagementBasePackage
DbStorage.cc
Go to the documentation of this file.
1 // -*- lsst-c++ -*-
2 
3 /*
4  * LSST Data Management System
5  * Copyright 2008, 2009, 2010 LSST Corporation.
6  *
7  * This product includes software developed by the
8  * LSST Project (http://www.lsst.org/).
9  *
10  * This program is free software: you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation, either version 3 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the LSST License Statement and
21  * the GNU General Public License along with this program. If not,
22  * see <http://www.lsstcorp.org/LegalNotices/>.
23  */
24 
25 
40 #ifndef __GNUC__
41 # define __attribute__(x) /*NOTHING*/
42 #endif
43 static char const* SVNid __attribute__((unused)) = "$Id$";
44 
45 #include "lsst/daf/base/DateTime.h"
48 
50 
51 namespace lsst {
52 namespace daf {
53 namespace persistence {
54 
58 }
59 
65 }
66 
70 }
71 
76  _impl->setPolicy(policy);
77 }
78 
83  _impl->setPersistLocation(location);
84 }
85 
90  _impl->setRetrieveLocation(location);
91 }
92 
96  _impl->startTransaction();
97 }
98 
102  _impl->endTransaction();
103 }
104 
113  std::string const& templateName,
114  bool mayAlreadyExist) {
115  _impl->createTableFromTemplate(tableName, templateName, mayAlreadyExist);
116 }
117 
121 void DbStorage::dropTable(std::string const& tableName) {
122  _impl->dropTable(tableName);
123 }
124 
128 void DbStorage::truncateTable(std::string const& tableName) {
129  _impl->truncateTable(tableName);
130 }
131 
136 void DbStorage::executeSql(std::string const& sqlStatement) {
137  _impl->executeSql(sqlStatement);
138 }
139 
144  _impl->setTableForInsert(tableName);
145 }
146 
151 template <typename T>
152 void DbStorage::setColumn(std::string const& columnName, T const& value) {
153  _impl->setColumn(columnName, value);
154 }
155 
159 void DbStorage::setColumnToNull(std::string const& columnName) {
160  _impl->setColumnToNull(columnName);
161 }
162 
167  _impl->insertRow();
168 }
169 
170 
175 void DbStorage::setTableForQuery(std::string const& tableName, bool isExpr) {
176  _impl->setTableForQuery(tableName, isExpr);
177 }
178 
183  std::vector<std::string> const& tableNameList) {
184  _impl->setTableListForQuery(tableNameList);
185 }
186 
194 void DbStorage::outColumn(std::string const& columnName, bool isExpr) {
195  _impl->outColumn(columnName, isExpr);
196 }
197 
206 template <typename T>
207 void DbStorage::outParam(std::string const& columnName, T* location,
208  bool isExpr) {
209  _impl->outParam(columnName, location, isExpr);
210 }
211 
217 template <typename T>
218 void DbStorage::condParam(std::string const& paramName, T const& value) {
219  _impl->condParam(paramName, value);
220 }
221 
226 void DbStorage::orderBy(std::string const& expression) {
227  _impl->orderBy(expression);
228 }
229 
233 void DbStorage::groupBy(std::string const& expression) {
234  _impl->groupBy(expression);
235 }
236 
242 void DbStorage::setQueryWhere(std::string const& whereClause) {
243  _impl->setQueryWhere(whereClause);
244 }
245 
248 void DbStorage::query(void) {
249  _impl->query();
250 }
251 
255 bool DbStorage::next(void) {
256  return _impl->next();
257 }
258 
262 template <typename T>
263 T const& DbStorage::getColumnByPos(int pos) {
264  return _impl->getColumnByPos<T>(pos);
265 }
266 
270 bool DbStorage::columnIsNull(int pos) {
271  return _impl->columnIsNull(pos);
272 }
273 
279  _impl->finishQuery();
280 }
281 
282 // Explicit template member function instantiations.
283 // Ignore for doxygen processing.
285 template void DbStorage::setColumn<>(std::string const& columnName, char const& value);
286 template void DbStorage::setColumn<>(std::string const& columnName, short const& value);
287 template void DbStorage::setColumn<>(std::string const& columnName, int const& value);
288 template void DbStorage::setColumn<>(std::string const& columnName, long const& value);
289 template void DbStorage::setColumn<>(std::string const& columnName, long long const& value);
290 template void DbStorage::setColumn<>(std::string const& columnName, float const& value);
291 template void DbStorage::setColumn<>(std::string const& columnName, double const& value);
292 template void DbStorage::setColumn<>(std::string const& columnName, std::string const& value);
293 template void DbStorage::setColumn<>(std::string const& columnName, bool const& value);
294 template void DbStorage::setColumn<>(std::string const& columnName, DateTime const& value);
295 
296 template void DbStorage::outParam<>(std::string const& columnName, char* location, bool isExpr);
297 template void DbStorage::outParam<>(std::string const& columnName, short* location, bool isExpr);
298 template void DbStorage::outParam<>(std::string const& columnName, int* location, bool isExpr);
299 template void DbStorage::outParam<>(std::string const& columnName, long* location, bool isExpr);
300 template void DbStorage::outParam<>(std::string const& columnName, long long* location, bool isExpr);
301 template void DbStorage::outParam<>(std::string const& columnName, float* location, bool isExpr);
302 template void DbStorage::outParam<>(std::string const& columnName, double* location, bool isExpr);
303 template void DbStorage::outParam<>(std::string const& columnName, std::string* location, bool isExpr);
304 template void DbStorage::outParam<>(std::string const& columnName, bool* location, bool isExpr);
305 template void DbStorage::outParam<>(std::string const& columnName, DateTime* location, bool isExpr);
306 
307 template void DbStorage::condParam<>(std::string const& paramName, char const& value);
308 template void DbStorage::condParam<>(std::string const& paramName, short const& value);
309 template void DbStorage::condParam<>(std::string const& paramName, int const& value);
310 template void DbStorage::condParam<>(std::string const& paramName, long const& value);
311 template void DbStorage::condParam<>(std::string const& paramName, long long const& value);
312 template void DbStorage::condParam<>(std::string const& paramName, float const& value);
313 template void DbStorage::condParam<>(std::string const& paramName, double const& value);
314 template void DbStorage::condParam<>(std::string const& paramName, std::string const& value);
315 template void DbStorage::condParam<>(std::string const& paramName, bool const& value);
316 template void DbStorage::condParam<>(std::string const& paramName, DateTime const& value);
317 
318 template char const& DbStorage::getColumnByPos<>(int pos);
319 template short const& DbStorage::getColumnByPos<>(int pos);
320 template int const& DbStorage::getColumnByPos<>(int pos);
321 template long const& DbStorage::getColumnByPos<>(int pos);
322 template long long const& DbStorage::getColumnByPos<>(int pos);
323 template float const& DbStorage::getColumnByPos<>(int pos);
324 template double const& DbStorage::getColumnByPos<>(int pos);
325 template std::string const& DbStorage::getColumnByPos<>(int pos);
326 template bool const& DbStorage::getColumnByPos<>(int pos);
327 template DateTime const& DbStorage::getColumnByPos<>(int pos);
329 
330 }}} // namespace lsst::daf::persistence
Abstract base class for FormatterStorage implementations.
void outParam(std::string const &columnName, T *location, bool isExpr=false)
Request a column in the query output and bind a destination location.
Definition: DbStorage.cc:207
virtual void executeSql(std::string const &sqlStatement)
Execute an arbitrary SQL statement.
Definition: DbStorage.cc:136
Class for handling dates/times, including MJD, UTC, and TAI.
Definition: DateTime.h:62
virtual void outColumn(std::string const &columnName, bool isExpr=false)
Request a column in the query output.
Definition: DbStorage.cc:194
Impl _impl
Interface for DbStorage class.
void setColumn(std::string const &columnName, T const &value)
Set the value to insert in a given column.
Definition: DbStorage.cc:152
Class for logical location of a persisted Persistable instance.
virtual void setQueryWhere(std::string const &whereClause)
Set the condition for the WHERE clause of the query.
Definition: DbStorage.cc:242
virtual void dropTable(std::string const &tableName)
Drop a table.
Definition: DbStorage.cc:121
bool columnIsNull(int pos)
Determine if the value of a column is NULL.
Definition: DbStorage.cc:270
void condParam(std::string const &paramName, T const &value)
Bind a value to a WHERE condition parameter.
Definition: DbStorage.cc:218
STL class.
virtual bool next(void)
Move to the next (first) row of the query result.
Definition: DbStorage.cc:255
virtual void startTransaction(void)
Start a transaction.
Definition: DbStorage.cc:95
A base class for image defects.
Definition: cameraGeom.dox:3
DbStorage(void)
Constructor.
Definition: DbStorage.cc:57
std::unique_ptr< DbStorageImpl > _impl
Implementation class for isolation.
Definition: DbStorage.h:113
virtual void groupBy(std::string const &expression)
Request that the query output be grouped by an expression.
Definition: DbStorage.cc:233
virtual void setPolicy(lsst::pex::policy::Policy::Ptr policy)
Allow a policy to be used to configure the DbStorage.
Definition: DbStorage.cc:75
virtual void orderBy(std::string const &expression)
Request that the query output be sorted by an expression.
Definition: DbStorage.cc:226
virtual void setRetrieveLocation(LogicalLocation const &location)
Set the database location to retrieve from.
Definition: DbStorage.cc:89
virtual void endTransaction(void)
End a transaction.
Definition: DbStorage.cc:101
virtual void insertRow(void)
Insert the row.
Definition: DbStorage.cc:166
Interface for DateTime class.
Class for implementation of database storage.
Definition: DbStorageImpl.h:79
virtual void setTableForQuery(std::string const &tableName, bool isExpr=false)
Set the table to query (single-table queries only).
Definition: DbStorage.cc:175
virtual void query(void)
Execute the query.
Definition: DbStorage.cc:248
T const & getColumnByPos(int pos)
Get the value of a column of the query result row by position.
Definition: DbStorage.cc:263
virtual void setTableListForQuery(std::vector< std::string > const &tableNameList)
Set a list of tables to query (multiple-table queries).
Definition: DbStorage.cc:182
~DbStorage(void)
Minimal destructor.
Definition: DbStorage.cc:69
Interface for DbStorageImpl class.
virtual void finishQuery(void)
Indicate that query processing is finished.
Definition: DbStorage.cc:278
virtual void setTableForInsert(std::string const &tableName)
Set the table to insert rows into.
Definition: DbStorage.cc:143
virtual void setPersistLocation(LogicalLocation const &location)
Set the database location to persist to.
Definition: DbStorage.cc:82
#define __attribute__(x)
Definition: DbStorage.cc:41
virtual void createTableFromTemplate(std::string const &tableName, std::string const &templateName, bool mayAlreadyExist=false)
Create a new table from an existing template table.
Definition: DbStorage.cc:112
virtual void setColumnToNull(std::string const &columnName)
Set a given column to NULL.
Definition: DbStorage.cc:159
virtual void truncateTable(std::string const &tableName)
Truncate a table.
Definition: DbStorage.cc:128