LSSTApplications  11.0-24-g0a022a1,14.0+77,15.0,15.0+1
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 <memory>
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 FormatterStorage {
64 public:
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:
115 };
116 
117 }}} // namespace lsst::daf::persistence
118 
119 #endif
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
virtual void outColumn(std::string const &columnName, bool isExpr=false)
Request a column in the query output.
Definition: DbStorage.cc:194
void setColumn(std::string const &columnName, T const &value)
Set the value to insert in a given column.
Definition: DbStorage.cc:152
Interface for FormatterStorage abstract base class.
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
Class for database storage.
Definition: DbStorage.h:63
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
std::shared_ptr< DbStorage > Ptr
Definition: DbStorage.h:65
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
STL class.
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
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
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