forked from osm2pgsql-dev/osm2pgsql
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmiddle-pgsql.hpp
More file actions
158 lines (122 loc) · 4.8 KB
/
Copy pathmiddle-pgsql.hpp
File metadata and controls
158 lines (122 loc) · 4.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
/* Implements the mid-layer processing for osm2pgsql
* using several PostgreSQL tables
*
* This layer stores data read in from the planet.osm file
* and is then read by the backend processing code to
* emit the final geometry-enabled output formats
*/
#ifndef MIDDLE_PGSQL_H
#define MIDDLE_PGSQL_H
#include <memory>
#include "id-tracker.hpp"
#include "middle.hpp"
#include "node-persistent-cache.hpp"
#include "node-ram-cache.hpp"
#include "pgsql.hpp"
class middle_query_pgsql_t : public middle_query_t
{
public:
middle_query_pgsql_t(
char const *conninfo, std::shared_ptr<node_ram_cache> const &cache,
std::shared_ptr<node_persistent_cache> const &persistent_cache);
~middle_query_pgsql_t();
size_t nodes_get_list(osmium::WayNodeList *nodes) const override;
bool ways_get(osmid_t id, osmium::memory::Buffer &buffer) const override;
size_t rel_way_members_get(osmium::Relation const &rel, rolelist_t *roles,
osmium::memory::Buffer &buffer) const override;
idlist_t relations_using_way(osmid_t way_id) const override;
bool relations_get(osmid_t id,
osmium::memory::Buffer &buffer) const override;
void exec_sql(std::string const &sql_cmd) const;
private:
size_t local_nodes_get_list(osmium::WayNodeList *nodes) const;
pg_result_t exec_prepared(char const *stmt, char const *param) const;
pg_result_t exec_prepared(char const *stmt, osmid_t osm_id) const;
struct pg_conn *m_sql_conn;
std::shared_ptr<node_ram_cache> m_cache;
std::shared_ptr<node_persistent_cache> m_persistent_cache;
};
struct middle_pgsql_t : public slim_middle_t
{
middle_pgsql_t(options_t const *options);
void start() override;
void stop(osmium::thread::Pool &pool) override;
void analyze() override;
void commit() override;
void nodes_set(osmium::Node const &node) override;
void nodes_delete(osmid_t id) override;
void node_changed(osmid_t id) override;
void ways_set(osmium::Way const &way) override;
void ways_delete(osmid_t id) override;
void way_changed(osmid_t id) override;
void relations_set(osmium::Relation const &rel) override;
void relations_delete(osmid_t id) override;
void relation_changed(osmid_t id) override;
void flush(osmium::item_type new_type) override;
void iterate_ways(middle_t::pending_processor& pf) override;
void iterate_relations(pending_processor& pf) override;
size_t pending_count() const override;
class table_desc
{
public:
table_desc() : sql_conn(nullptr) {}
table_desc(options_t const *options, char const *name,
char const *create, char const *prepare_query,
char const *prepare = "", char const *prepare_intarray = "",
char const *array_indexes = "");
~table_desc();
char const *name() const { return m_name.c_str(); }
void clear_array_indexes() { m_array_indexes.clear(); }
int copyMode; /* True if we are in copy mode */
struct pg_conn *sql_conn;
std::string m_prepare_query;
void connect(char const *conninfo);
void begin();
void prepare_queries(bool append);
void create();
void begin_copy();
void end_copy();
pg_result_t
exec_prepared(char const *stmt, char const *param,
ExecStatusType expect = PGRES_TUPLES_OK) const;
pg_result_t
exec_prepared(char const *stmt, osmid_t osm_id,
ExecStatusType expect = PGRES_TUPLES_OK) const;
void stop(bool droptemp, bool build_indexes);
void commit();
private:
int transactionMode; /* True if we are in an extended transaction */
std::string m_name;
std::string m_create;
std::string m_prepare;
std::string m_prepare_intarray;
std::string m_array_indexes;
};
std::shared_ptr<middle_query_t>
get_query_instance(std::shared_ptr<middle_t> const &mid) const override;
private:
enum middle_tables
{
NODE_TABLE = 0,
WAY_TABLE,
REL_TABLE,
NUM_TABLES
};
/**
* Sets up sql_conn for the table
*/
void local_nodes_set(osmium::Node const &node);
void local_nodes_delete(osmid_t osm_id);
table_desc tables[NUM_TABLES];
bool append;
bool mark_pending;
options_t const *out_options;
std::shared_ptr<node_ram_cache> cache;
std::shared_ptr<node_persistent_cache> persistent_cache;
std::shared_ptr<id_tracker> ways_pending_tracker, rels_pending_tracker;
void buffer_store_string(std::string const &in, bool escape);
void buffer_store_tags(osmium::OSMObject const &obj, bool attrs, bool escape);
void buffer_correct_params(char const **param, size_t size);
std::string copy_buffer;
};
#endif