LSSTApplications  10.0-2-g4f67435,11.0.rc2+1,11.0.rc2+12,11.0.rc2+3,11.0.rc2+4,11.0.rc2+5,11.0.rc2+6,11.0.rc2+7,11.0.rc2+8
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 <boost/scoped_ptr.hpp>
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:
68  typedef boost::shared_ptr<DbTsvStorage> Ptr;
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;
102  std::string _tempPath;
103  char* _fileName;
104  std::string _location;
105  std::string _tableName;
106  std::map<std::string, int> _colMap;
107  std::ostringstream _convertStream;
108  std::vector<std::string> _rowBuffer;
109  boost::scoped_ptr<std::ofstream> _osp;
110 
111  int _getColumnIndex(std::string const& columnName);
112 };
113 
114 }}} // namespace lsst::daf::persistence
115 
116 #endif
int _getColumnIndex(std::string const &columnName)
virtual void setPersistLocation(LogicalLocation const &location)
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.
boost::shared_ptr< DbTsvStorage > Ptr
Definition: DbTsvStorage.h:68
virtual void setPolicy(lsst::pex::policy::Policy::Ptr policy)
Definition: DbTsvStorage.cc:78
char * _fileName
Full pathname for temporary TSV file.
Definition: DbTsvStorage.h:103
virtual void setColumnToNull(std::string const &columnName)
boost::shared_ptr< Policy > Ptr
Definition: Policy.h:172
std::string _location
Database location URL.
Definition: DbTsvStorage.h:104
Class for database storage.
Definition: DbStorage.h:63
void outParam(std::string const &columnName, T *location, bool isExpr=false)
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
virtual void truncateTable(std::string const &tableName)
bool _saveTemp
Do not delete temporary TSV file if true.
Definition: DbTsvStorage.h:101
boost::scoped_ptr< std::ofstream > _osp
Output TSV stream.
Definition: DbTsvStorage.h:109
virtual void setTableForInsert(std::string const &tableName)
Class for database storage with data loading from TSV files.
Definition: DbTsvStorage.h:66
virtual void createTableFromTemplate(std::string const &tableName, std::string const &templateName, bool mayAlreadyExist=false)
Interface for LogicalLocation class.
void setColumn(std::string const &columnName, T const &value)
virtual void setRetrieveLocation(LogicalLocation const &location)
void condParam(std::string const &paramName, T const &value)
virtual void dropTable(std::string const &tableName)