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.h
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 #ifndef LSST_MWI_PERSISTENCE_DBSTORAGE_H
26 #define LSST_MWI_PERSISTENCE_DBSTORAGE_H
27 
50 
51 #include <string>
52 #include <vector>
53 #include <boost/scoped_ptr.hpp>
54 
55 namespace lsst {
56 namespace daf {
57 namespace persistence {
58 
59 // Forward declarations
60 class DbStorageImpl;
61 class DbStorageLocation;
62 
63 class DbStorage : public Storage {
64 public:
65  typedef boost::shared_ptr<DbStorage> Ptr;
66 
67  DbStorage(void);
68  ~DbStorage(void);
69 
70  virtual void setPolicy(lsst::pex::policy::Policy::Ptr policy);
71  virtual void setPersistLocation(LogicalLocation const& location);
72  virtual void setRetrieveLocation(LogicalLocation const& location);
73 
74  virtual void startTransaction(void);
75  virtual void endTransaction(void);
76 
77  virtual void createTableFromTemplate(std::string const& tableName,
78  std::string const& templateName,
79  bool mayAlreadyExist = false);
80  virtual void dropTable(std::string const& tableName);
81  virtual void truncateTable(std::string const& tableName);
82 
83  virtual void executeSql(std::string const& sqlStatement);
84 
85  virtual void setTableForInsert(std::string const& tableName);
86  template <typename T>
87  void setColumn(std::string const& columnName, T const& value);
88  virtual void setColumnToNull(std::string const& columnName);
89  virtual void insertRow(void);
90 
91  virtual void setTableForQuery(std::string const& tableName,
92  bool isExpr = false);
93  virtual void setTableListForQuery(
94  std::vector<std::string> const& tableNameList);
95  virtual void outColumn(std::string const& columnName, bool isExpr = false);
96  template <typename T> void outParam(std::string const& columnName,
97  T* location, bool isExpr = false);
98  template <typename T> void condParam(std::string const& paramName,
99  T const& value);
100  virtual void orderBy(std::string const& expression);
101  virtual void groupBy(std::string const& expression);
102  virtual void setQueryWhere(std::string const& whereClause);
103  virtual void query(void);
104  virtual bool next(void);
105  template <typename T> T const& getColumnByPos(int pos);
106  bool columnIsNull(int pos);
107  virtual void finishQuery(void);
108 
109 protected:
110  explicit DbStorage(std::type_info const& type);
111 
112 private:
113  boost::scoped_ptr<DbStorageImpl> _impl;
115 };
116 
117 }}} // namespace lsst::daf::persistence
118 
119 #endif
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
virtual void outColumn(std::string const &columnName, bool isExpr=false)
Definition: DbStorage.cc:194
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
boost::shared_ptr< DbStorage > Ptr
Definition: DbStorage.h:65
Interface for Storage abstract base class.
virtual void dropTable(std::string const &tableName)
Definition: DbStorage.cc:121
void condParam(std::string const &paramName, T const &value)
Definition: DbStorage.cc:218
Class for database storage.
Definition: DbStorage.h:63
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
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
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
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