Overpass API regression suite coverage (Nova Scotia) / 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:
33697595 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_)
67697595 q : access_mode(access_mode_), use_shadow(use_shadow_),
68697595 q file_name_extension(file_name_extension_), db_dir(db_dir_)
70697595 q signal(SIGTERM, sigterm);
71697595 q if (!db_dir.empty() && db_dir[db_dir.size()-1] != '/')
720 db_dir += "/";
76inline Nonsynced_Transaction::~Nonsynced_Transaction()
78697595 q flush();
82inline void Nonsynced_Transaction::flush()
84697595 q for (std::map< const File_Properties*, File_Blocks_Index_Base* >::iterator
858375595 q it = data_files.begin(); it != data_files.end(); ++it)
867678590 q delete it->second;
87697595 q data_files.clear();
88697595 q for (std::map< const File_Properties*, Random_File_Index* >::iterator
891117595 q it = random_files.begin(); it != random_files.end(); ++it)
90420168 q delete it->second;
91697595 q random_files.clear();
95inline File_Blocks_Index_Base* Nonsynced_Transaction::data_index
96 (const File_Properties* fp)
9753854590 q{
9853854590 q std::map< const File_Properties*, File_Blocks_Index_Base* >::iterator
9953854590 q it = data_files.find(fp);
10053854590 q if (it != data_files.end())
10146176485 q return it->second;
1037678590 q File_Blocks_Index_Base* data_index = fp->new_data_index(access_mode, use_shadow, db_dir, file_name_extension);
1047678590 q if (data_index != 0)
1057678590 q data_files[fp] = data_index;
1067678590 q return data_index;
10753854590 q}
110inline Random_File_Index* Nonsynced_Transaction::random_index(const File_Properties* fp)
1122644168 q std::map< const File_Properties*, Random_File_Index* >::iterator
1132644168 q it = random_files.find(fp);
1142644168 q if (it != random_files.end())
115222452 q return it->second;
117420168 q random_files[fp] = new Random_File_Index(*fp, access_mode, use_shadow, db_dir, file_name_extension);
118420168 q return random_files[fp];
122#endif