ClockWork DB CoreAPI 1.0.48
Abstract Time Series and Storage/Management Library
Loading...
Searching...
No Matches
screening-manager.hpp
1#pragma once
2
3#include "tom-tsdb/engine.hpp"
4#include "tom-tsdb/session.hpp"
5#include "tom-tsdb/connection.hpp"
6#include "tom-tsdb/datastore.hpp"
7#include "tom-tsdb/provider.hpp"
8#include "tom-tsdb/smart_pointers.hpp"
9// #include "config.h"
10#include <dbsql.h>
11#include <vector>
12#include <unordered_map>
13#include <tom-util/environment.hpp>
14#include <thread>
15#include <tuple>
16
17namespace tom {
18 namespace tsdb {
19
20 class screening_db;
21
23 public:
24 sql_query_result( screening_db & scrn_db, sqlite3 *db, const std::string &sql_statement );
26
27 bool
28 valid() const { return m_statement_valid; }
29
30 bool
31 next();
32
33 bool
34 valid_row() const { return m_valid_row; }
35
36 int
37 get_int( int col );
38
39 std::int64_t
40 get_int64( int col );
41
42 double
43 get_double( int col );
44
45 std::string
46 get_string( int col );
47
48 private:
49 sqlite3 * m_db_hndl { nullptr };
50 sqlite3_stmt * m_statement { nullptr };
51 bool m_statement_valid { false };
52 bool m_valid_row { false };
53 screening_db & m_screen_db;
54 tom::logger & m_logger;
55 };
56
58 class field {
59 public:
60 field( const tom::observation &field, const tom::observation &dim ) : m_field(field), m_dim(dim) { }
61
62 const tom::String &
63 field_name() const { return m_field; }
64
65 const tom::Int &
66 dimension() const { return m_dim; }
67 private:
68 tom::String m_field;
69 tom::Int m_dim;
70 };
71 public:
72
73 typedef std::vector<field> field_vec;
74 typedef field_vec::const_iterator const_iterator;
75 typedef field_vec::iterator iterator;
76 typedef std::vector<time_series_sptr> ts_vec;
77
78 screening_db( const tom::observation &path,
79 const tom::observation &name,
80 const tom::observation &max_days,
81 const tom::observation &max_rows,
82 const tom::observation &default_repo,
83 const tom::observation &default_db,
84 const tom::observation &discovery_id );
85
87
88 void
89 add_field( const tom::observation &field,
90 const tom::observation &dimension );
91
92 void
93 init();
94
95 bool
96 exists();
97
98 void
99 create_table();
100
101 void
102 populate_table();
103
104 void
105 update_table();
106
108 get_most_recent_date(const std::string &id );
109
110 void
111 add_ts( std::string &id, ts_vec & );
112
113 void
114 update_ts( std::string &id, ts_vec & );
115
116 const field_vec &
117 fields() const { return m_fields; }
118
119 // this can be optimized by caching query result objects, but lets keep it simple to start
120 sql_query_result_sptr
121 query( const std::string & sql_statement ) { return sql_query_result_sptr( new sql_query_result( *this, m_db_hndl, sql_statement)); }
122
123 private:
124 tom::String m_path;
125 tom::String m_name;
126 tom::Int m_max_days;
127 tom::Int m_max_rows;
128 tom::String m_default_repo;
129 tom::String m_default_db;
130 tom::String m_discovery_id;
131 sqlite3 * m_db_hndl { nullptr };
132 tom::logger & m_logger;
133
134 field_vec m_fields;
135 };
136
137 typedef std::vector<std::string> string_vec;
138 typedef std::shared_ptr<string_vec> string_vec_sptr;
139
141 public:
143
144 string_vec_sptr
145 screens() const;
146
147 screening_db_sptr
148 get_screening_db( const std::string & db_name );
149
150 // when a given engine instance is deleted
151 // this class is joined, so screening maint. can finish its work
152 // before shutting down
153 void
154 join();
155 private:
156 void run();
157
158 typedef std::unordered_map<std::string,screening_db_sptr> screen_map;
159
160 tom::logger & m_logger;
161 tom::String m_path;
162 screen_map m_screen_dbs; // use to init and create/populate/trunc/etc screening dbs
163 static thread_local screen_map s_screen_map; // use to hand out screening_db ptrs to clients
164 std::thread * m_run_thread;
165 };
166
167 } // end tsdb namespace
168} // end tom namespace
Definition string.hpp:15
Definition calendar.hpp:47
Definition logger.hpp:59
Definition observation.hpp:13
Definition screening-manager.hpp:57
Definition screening-manager.hpp:140
Definition screening-manager.hpp:22