libdballe  6.8
mem/db.h
Go to the documentation of this file.
1 /*
2  * dballe/mem/db - Archive for point-based meteorological data, in-memory db
3  *
4  * Copyright (C) 2013 ARPA-SIM <urpsim@smr.arpa.emr.it>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18  *
19  * Author: Enrico Zini <enrico@enricozini.com>
20  */
21 
22 #ifndef DBA_DB_MEM_H
23 #define DBA_DB_MEM_H
24 
25 #include <dballe/db/db.h>
26 #include <dballe/db/mem/repinfo.h>
27 #include <dballe/memdb/memdb.h>
28 #include <wreport/varinfo.h>
29 #include <string>
30 #include <vector>
31 #include <memory>
32 
39 namespace dballe {
40 struct Record;
41 struct Msg;
42 struct Msgs;
43 struct MsgConsumer;
44 
45 namespace db {
46 
47 namespace mem {
48 
52 class DB : public dballe::DB
53 {
54 public:
57  Repinfo repinfo;
58 
59 protected:
60  std::string serialization_dir;
61 
62  size_t m_last_station_id;
63 
65  struct VarID
66  {
67  wreport::Varcode code;
68  // True if it is a station value
69  bool station;
70  size_t id;
71  VarID(wreport::Varcode code, bool station, size_t id) : code(code), station(station), id(id) {}
72  };
73 
75  std::vector<VarID> last_insert_varids;
76 
79 
82 
84  void raw_query_data(const Record& rec, memdb::Results<memdb::Value>& res);
85 
86 public:
87  DB();
88  DB(const std::string& arg);
89  virtual ~DB();
90 
91  db::Format format() const { return MEM; }
92 
93  void disappear();
94 
106  void reset(const char* repinfo_file = 0);
107 
125  void update_repinfo(const char* repinfo_file, int* added, int* deleted, int* updated);
126 
127  std::map<std::string, int> get_repinfo_priorities();
128 
143  void insert(const Record& rec, bool can_replace, bool station_can_add);
144 
145  int last_station_id() const;
146 
154  void remove(const Record& rec);
155 
156  void remove_all();
157 
167  void vacuum();
168 
177  std::auto_ptr<db::Cursor> query_stations(const Record& query);
178 
191  std::auto_ptr<db::Cursor> query_data(const Record& rec);
192 
193  std::auto_ptr<db::Cursor> query_summary(const Record& rec);
194 
210  unsigned query_attrs(int id_data, wreport::Varcode id_var, const db::AttrList& qcs, Record& attrs);
211 
212  void attr_insert(wreport::Varcode id_var, const Record& attrs);
213  void attr_insert(int id_data, wreport::Varcode id_var, const Record& attrs);
214 
227  void attr_remove(int id_data, wreport::Varcode id_var, const db::AttrList& qcs);
228 
243  void import_msg(const Msg& msg, const char* repmemo, int flags);
244 
254  void export_msgs(const Record& query, MsgConsumer& cons);
255 
259  void dump(FILE* out);
260 
261  friend class dballe::DB;
262 };
263 
264 } // namespace v6
265 } // namespace db
266 } // namespace dballe
267 
268 /* vim:set ts=4 sw=4: */
269 #endif
void dump(FILE *out)
Dump the entire contents of the database to an output stream.
void vacuum()
Remove orphan values from the database.
db::Format format() const
Return the format of this DB.
Definition: mem/db.h:91
void reset(const char *repinfo_file=0)
Reset the database, removing all existing DBALLE tables and re-creating them empty.
std::map< std::string, int > get_repinfo_priorities()
Get a mapping between rep_memo and their priorities.
Storage for related physical data.
Definition: msg.h:119
In-memory database backend.
Definition: memdb.h:78
void raw_query_station_data(const Record &rec, memdb::Results< memdb::StationValue > &res)
Query station data, returning a list of Value IDs.
unsigned query_attrs(int id_data, wreport::Varcode id_var, const db::AttrList &qcs, Record &attrs)
Query attributes.
std::auto_ptr< db::Cursor > query_summary(const Record &rec)
Query a summary of what the result would be for a query.
DB-All.E record.
Definition: record.h:102
Definition: cmdline.h:34
void raw_query_data(const Record &rec, memdb::Results< memdb::Value > &res)
Query data, returning a list of Value IDs.
int last_station_id() const
Return the station id for the last data that was inserted.
Functions used to connect to DB-All.e and insert, query and delete data.
void remove_all()
Remove all data from the database.
void import_msg(const Msg &msg, const char *repmemo, int flags)
Import a Msg message into the DB-All.e database.
void export_msgs(const Record &query, MsgConsumer &cons)
Perform the query in `query', and return the results as a NULL-terminated array of dba_msg...
void update_repinfo(const char *repinfo_file, int *added, int *deleted, int *updated)
Update the repinfo table in the database, with the data found in the given file.
void raw_query_stations(const Record &rec, memdb::Results< memdb::Station > &res)
Query stations, returning a list of station IDs.
std::auto_ptr< db::Cursor > query_data(const Record &rec)
Query the database.
Definition: db.h:181
void attr_remove(int id_data, wreport::Varcode id_var, const db::AttrList &qcs)
Delete QC data for the variable `var' in record `rec' (coming from a previous dba_query) ...
std::auto_ptr< db::Cursor > query_stations(const Record &query)
Start a query on the station archive.
Store information about the database ID of a variable.
Definition: mem/db.h:65
Definition: db/mem/repinfo.h:33
Consumer interface used to stream messages as they are produced.
Definition: msg.h:478
void disappear()
Remove all our traces from the database, if applicable.
Definition: levtr.h:33
std::vector< VarID > last_insert_varids
Store database variable IDs for all last inserted variables.
Definition: mem/db.h:75
Memdb memdb
In-memory database backend.
Definition: mem/db.h:56
DB-ALLe database connection.
Definition: mem/db.h:52
void attr_insert(wreport::Varcode id_var, const Record &attrs)
Insert new attributes into the database, reusing the reference IDs stored by the last insert...
void insert(const Record &rec, bool can_replace, bool station_can_add)
Insert a record into the database.