Overpass API regression suite coverage (Saxony) / template_db/transaction.h

template_db/transaction.h

38 of 40 instrumented lines run by the suite (95.0%) at 8edf11b0419c (this file on GitHub).

runnever runcolumns: line, executions, queries (click for the queries that run the line)

1/** Copyright 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018 Roland Olbricht et al.
2 *
3 * This file is part of Overpass_API.
4 *
5 * Overpass_API is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU Affero General Public License as
7 * published by the Free Software Foundation, either version 3 of the
8 * License, or (at your option) any later version.
9 *
10 * Overpass_API 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 Affero General Public License
16 * along with Overpass_API. If not, see <http://www.gnu.org/licenses/>.
17 */
19#ifndef DE__OSM3S___TEMPLATE_DB__TRANSACTION_H
20#define DE__OSM3S___TEMPLATE_DB__TRANSACTION_H
22#include "random_file.h"
24#include <signal.h>
26#include <map>
27#include <vector>
30class Transaction
32 public:
33795673 q virtual ~Transaction() {}
34 virtual File_Blocks_Index_Base* data_index(const File_Properties*) = 0;
35 virtual Random_File_Index* random_index(const File_Properties*) = 0;
36 virtual std::string get_db_dir() const = 0;
37};
40class Nonsynced_Transaction : public Transaction
42 public:
43 Nonsynced_Transaction(
44 Access_Mode access_mode, bool use_shadow, const std::string& db_dir, const std::string& file_name_extension);
45 virtual ~Nonsynced_Transaction();
47 File_Blocks_Index_Base* data_index(const File_Properties*);
48 Random_File_Index* random_index(const File_Properties*);
50 void flush();
510 std::string get_db_dir() const { return db_dir; }
53 private:
54 std::map< const File_Properties*, File_Blocks_Index_Base* >
55 data_files;
56 std::map< const File_Properties*, Random_File_Index* >
57 random_files;
58 Access_Mode access_mode;
59 bool use_shadow;
60 std::string file_name_extension, db_dir;
61};
64inline Nonsynced_Transaction::Nonsynced_Transaction(
65 Access_Mode access_mode_, bool use_shadow_,
66 const std::string& db_dir_, const std::string& file_name_extension_)
67795673 q : access_mode(access_mode_), use_shadow(use_shadow_),
68795673 q file_name_extension(file_name_extension_), db_dir(db_dir_)
70795673 q signal(SIGTERM, sigterm);
71795673 q if (!db_dir.empty() && db_dir[db_dir.size()-1] != '/')
720 db_dir += "/";
76inline Nonsynced_Transaction::~Nonsynced_Transaction()
78795673 q flush();
82inline void Nonsynced_Transaction::flush()
84795673 q for (std::map< const File_Properties*, File_Blocks_Index_Base* >::iterator
859387673 q it = data_files.begin(); it != data_files.end(); ++it)
868592668 q delete it->second;
87795673 q data_files.clear();
88795673 q for (std::map< const File_Properties*, Random_File_Index* >::iterator
891358673 q it = random_files.begin(); it != random_files.end(); ++it)
90563228 q delete it->second;
91795673 q random_files.clear();
95inline File_Blocks_Index_Base* Nonsynced_Transaction::data_index
96 (const File_Properties* fp)
97274402668 q{
98274402668 q std::map< const File_Properties*, File_Blocks_Index_Base* >::iterator
99274402668 q it = data_files.find(fp);
100274402668 q if (it != data_files.end())
101265810539 q return it->second;
1038592668 q File_Blocks_Index_Base* data_index = fp->new_data_index(access_mode, use_shadow, db_dir, file_name_extension);
1048592668 q if (data_index != 0)
1058592668 q data_files[fp] = data_index;
1068592668 q return data_index;
107274402668 q}
110inline Random_File_Index* Nonsynced_Transaction::random_index(const File_Properties* fp)
1122607228 q std::map< const File_Properties*, Random_File_Index* >::iterator
1132607228 q it = random_files.find(fp);
1142607228 q if (it != random_files.end())
115204469 q return it->second;
117563228 q random_files[fp] = new Random_File_Index(*fp, access_mode, use_shadow, db_dir, file_name_extension);
118563228 q return random_files[fp];
122#endif