LSSTApplications  11.0-24-g0a022a1,14.0+77,15.0,15.0+1
LSSTDataManagementBasePackage
DbTsvStorage.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_DBTSVSTORAGE_H
26 #define LSST_MWI_PERSISTENCE_DBTSVSTORAGE_H
27 
52 
53 #include <memory>
54 #include <fstream>
55 #include <map>
56 #include <sstream>
57 #include <string>
58 #include <vector>
59 
61 
62 namespace lsst {
63 namespace daf {
64 namespace persistence {
65 
66 class DbTsvStorage : public DbStorage {
67 public:
69 
70  DbTsvStorage(void);
71  ~DbTsvStorage(void);
72 
73  virtual void setPolicy(lsst::pex::policy::Policy::Ptr policy);
74  virtual void setPersistLocation(LogicalLocation const& location);
75  virtual void setRetrieveLocation(LogicalLocation const& location);
76 
77  virtual void startTransaction(void);
78  virtual void endTransaction(void);
79 
80  virtual void createTableFromTemplate(std::string const& tableName,
81  std::string const& templateName,
82  bool mayAlreadyExist = false);
83  virtual void dropTable(std::string const& tableName);
84  virtual void truncateTable(std::string const& tableName);
85 
86  virtual void setTableForInsert(std::string const& tableName);
87  template <typename T>
88  void setColumn(std::string const& columnName, T const& value);
89  virtual void setColumnToNull(std::string const& columnName);
90  virtual void insertRow(void);
91 
92  // Templates for forwarding to the base class.
93  template <typename T> void outParam(std::string const& columnName,
94  T* location, bool isExpr = false);
95  template <typename T> void condParam(std::string const& paramName,
96  T const& value);
97  template <typename T> T const& getColumnByPos(int pos);
98 
99 private:
101  bool _saveTemp;
103  char* _fileName;
110 
111  int _getColumnIndex(std::string const& columnName);
112 };
113 
114 }}} // namespace lsst::daf::persistence
115 
116 #endif
virtual void startTransaction(void)
Start a transaction.
int _getColumnIndex(std::string const &columnName)
Get the index of a given column.
virtual void setPersistLocation(LogicalLocation const &location)
Set the database location to persist to.
Definition: DbTsvStorage.cc:91
Interface for DbStorage class.
std::vector< std::string > _rowBuffer
Definition: DbTsvStorage.h:108
Class for logical location of a persisted Persistable instance.
virtual void setPolicy(lsst::pex::policy::Policy::Ptr policy)
Allow a policy to be used to configure the DbTsvStorage.
Definition: DbTsvStorage.cc:78
char * _fileName
Full pathname for temporary TSV file.
Definition: DbTsvStorage.h:103
virtual void setColumnToNull(std::string const &columnName)
Set a given column to NULL.
std::string _location
Database location URL.
Definition: DbTsvStorage.h:104
Class for database storage.
Definition: DbStorage.h:63
STL class.
void outParam(std::string const &columnName, T *location, bool isExpr=false)
Request a column in the query output and bind a destination location.
std::map< std::string, int > _colMap
Map from column names to positions.
Definition: DbTsvStorage.h:106
std::ostringstream _convertStream
Stream to convert to text.
Definition: DbTsvStorage.h:107
std::string _tempPath
Directory pathname for temporary TSV file.
Definition: DbTsvStorage.h:102
~DbTsvStorage(void)
Minimal destructor.
Definition: DbTsvStorage.cc:72
virtual void truncateTable(std::string const &tableName)
Truncate a table.
bool _saveTemp
Do not delete temporary TSV file if true.
Definition: DbTsvStorage.h:101
A base class for image defects.
Definition: cameraGeom.dox:3
virtual void setTableForInsert(std::string const &tableName)
Set the table to insert rows into.
Class for database storage with data loading from TSV files.
Definition: DbTsvStorage.h:66
virtual void endTransaction(void)
End a transaction.
std::shared_ptr< DbTsvStorage > Ptr
Definition: DbTsvStorage.h:68
T const & getColumnByPos(int pos)
Get the value of a column of the query result row by position.
virtual void createTableFromTemplate(std::string const &tableName, std::string const &templateName, bool mayAlreadyExist=false)
Create a new table from an existing template table.
virtual void insertRow(void)
Insert the row.
std::unique_ptr< std::ofstream > _osp
Output TSV stream.
Definition: DbTsvStorage.h:109
Interface for LogicalLocation class.
void setColumn(std::string const &columnName, T const &value)
Set the value to insert in a given column.
virtual void setRetrieveLocation(LogicalLocation const &location)
Set the database location to retrieve from.
void condParam(std::string const &paramName, T const &value)
Bind a value to a WHERE condition parameter.
virtual void dropTable(std::string const &tableName)
Drop a table.