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
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 
57 DbStorage::DbStorage(void) : Storage(typeid(*this)), _impl(new DbStorageImpl) {
58 }
59 
63 DbStorage::DbStorage(std::type_info const& type) :
64  Storage(type), _impl(new DbStorageImpl) {
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 
112 void DbStorage::createTableFromTemplate(std::string const& tableName,
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 
143 void DbStorage::setTableForInsert(std::string const& tableName) {
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
void outParam(std::string const &columnName, T *location, bool isExpr=false)
Definition: DbStorage.cc:207
virtual void executeSql(std::string const &sqlStatement)
Definition: DbStorage.cc:136
Class for handling dates/times, including MJD, UTC, and TAI.
Definition: DateTime.h:58
virtual void outColumn(std::string const &columnName, bool isExpr=false)
Definition: DbStorage.cc:194
Interface for DbStorage class.
void setColumn(std::string const &columnName, T const &value)
Definition: DbStorage.cc:152
boost::scoped_ptr< DbStorageImpl > _impl
Implementation class for isolation.
Definition: DbStorage.h:113
Class for logical location of a persisted Persistable instance.
virtual void setQueryWhere(std::string const &whereClause)
Definition: DbStorage.cc:242
boost::shared_ptr< Policy > Ptr
Definition: Policy.h:172
T const & getColumnByPos(int pos)
Definition: DbStorage.cc:263
virtual void dropTable(std::string const &tableName)
Definition: DbStorage.cc:121
void condParam(std::string const &paramName, T const &value)
Definition: DbStorage.cc:218
virtual void startTransaction(void)
Definition: DbStorage.cc:95
virtual void groupBy(std::string const &expression)
Definition: DbStorage.cc:233
virtual void setPolicy(lsst::pex::policy::Policy::Ptr policy)
Definition: DbStorage.cc:75
virtual void orderBy(std::string const &expression)
Definition: DbStorage.cc:226
virtual void setRetrieveLocation(LogicalLocation const &location)
Definition: DbStorage.cc:89
virtual void endTransaction(void)
Definition: DbStorage.cc:101
virtual void insertRow(void)
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)
Definition: DbStorage.cc:175
virtual void setTableListForQuery(std::vector< std::string > const &tableNameList)
Definition: DbStorage.cc:182
Interface for DbStorageImpl class.
virtual void finishQuery(void)
Definition: DbStorage.cc:278
virtual void setTableForInsert(std::string const &tableName)
Definition: DbStorage.cc:143
virtual void setPersistLocation(LogicalLocation const &location)
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)
Definition: DbStorage.cc:112
virtual void setColumnToNull(std::string const &columnName)
Definition: DbStorage.cc:159
Abstract base class for storage implementations.
Definition: Storage.h:60
virtual void truncateTable(std::string const &tableName)
Definition: DbStorage.cc:128