fb-cpp 0.0.2
A modern C++ wrapper for the Firebird database API
Loading...
Searching...
No Matches
DatabaseManager.h
1/*
2 * MIT License
3 *
4 * Copyright (c) 2026 Popa Adrian Marius
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in all
14 * copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 * SOFTWARE.
23 */
24
25#ifndef FBCPP_DATABASE_MANAGER_H
26#define FBCPP_DATABASE_MANAGER_H
27
28#include "ServiceManager.h"
29#include "fb-cpp-export.h"
30#include <cstdint>
31#include <optional>
32#include <string>
33
34
38namespace fbcpp
39{
43 enum class ShutdownMode
44 {
48 NORMAL,
49
53 MULTI,
54
58 SINGLE,
59
63 FULL
64 };
65
69 enum class ShutdownType
70 {
74 FORCED,
75
80
85 };
86
91 {
92 public:
96 const std::string& getDatabase() const
97 {
98 return database;
99 }
100
104 DatabasePropertiesOptions& setDatabase(const std::string& value)
105 {
106 database = value;
107 return *this;
108 }
109
113 const std::optional<ReplicaMode>& getReplicaMode() const
114 {
115 return replicaMode;
116 }
117
122 {
123 replicaMode = value;
124 return *this;
125 }
126
130 const std::optional<ShutdownMode>& getShutdownMode() const
131 {
132 return shutdownMode;
133 }
134
139 {
140 shutdownMode = value;
141 return *this;
142 }
143
147 const std::optional<ShutdownType>& getShutdownType() const
148 {
149 return shutdownType;
150 }
151
156 {
157 shutdownType = value;
158 return *this;
159 }
160
164 const std::optional<int>& getShutdownTimeout() const
165 {
166 return shutdownTimeout;
167 }
168
173 {
174 shutdownTimeout = value;
175 return *this;
176 }
177
181 const std::optional<bool>& getOnline() const
182 {
183 return online;
184 }
185
190 {
191 online = value;
192 return *this;
193 }
194
195 private:
196 std::string database;
197 std::optional<ReplicaMode> replicaMode;
198 std::optional<ShutdownMode> shutdownMode;
199 std::optional<ShutdownType> shutdownType;
200 std::optional<int> shutdownTimeout;
201 std::optional<bool> online;
202 };
203
208 {
209 public:
213 const std::string& getDatabase() const
214 {
215 return database;
216 }
217
221 DatabaseRepairOptions& setDatabase(const std::string& value)
222 {
223 database = value;
224 return *this;
225 }
226
231 {
232 return verboseOutput;
233 }
234
239 {
240 verboseOutput = std::move(value);
241 return *this;
242 }
243
247 const std::optional<std::uint32_t>& getParallelWorkers() const
248 {
249 return parallelWorkers;
250 }
251
256 {
257 parallelWorkers = value;
258 return *this;
259 }
260
264 bool getSweep() const
265 {
266 return sweep;
267 }
268
273 {
274 sweep = value;
275 return *this;
276 }
277
281 bool getValidate() const
282 {
283 return validate;
284 }
285
290 {
291 validate = value;
292 return *this;
293 }
294
298 bool getMend() const
299 {
300 return mend;
301 }
302
307 {
308 mend = value;
309 return *this;
310 }
311
315 bool getIgnoreChecksum() const
316 {
317 return ignoreChecksum;
318 }
319
324 {
325 ignoreChecksum = value;
326 return *this;
327 }
328
332 bool getKillShadows() const
333 {
334 return killShadows;
335 }
336
341 {
342 killShadows = value;
343 return *this;
344 }
345
349 bool getFull() const
350 {
351 return full;
352 }
353
358 {
359 full = value;
360 return *this;
361 }
362
366 bool getCheckDb() const
367 {
368 return checkDb;
369 }
370
375 {
376 checkDb = value;
377 return *this;
378 }
379
383 bool getIcu() const
384 {
385 return icu;
386 }
387
392 {
393 icu = value;
394 return *this;
395 }
396
400 bool getUpgradeDb() const
401 {
402 return upgradeDb;
403 }
404
409 {
410 upgradeDb = value;
411 return *this;
412 }
413
414 private:
415 std::string database;
416 ServiceManager::VerboseOutput verboseOutput;
417 std::optional<std::uint32_t> parallelWorkers;
418 bool sweep = false;
419 bool validate = false;
420 bool mend = false;
421 bool ignoreChecksum = false;
422 bool killShadows = false;
423 bool full = false;
424 bool checkDb = false;
425 bool icu = false;
426 bool upgradeDb = false;
427 };
428
432 class FB_CPP_EXPORT DatabaseManager final : public ServiceManager
433 {
434 public:
435 using ServiceManager::ServiceManager;
436
437 public:
441 void setProperties(const DatabasePropertiesOptions& options);
442
446 void repair(const DatabaseRepairOptions& options);
447 };
448} // namespace fbcpp
449
450
451#endif // FBCPP_DATABASE_MANAGER_H
Executes configuration and maintenance operations through the Firebird service manager.
Represents options used to configure database properties through the service manager.
const std::string & getDatabase() const
Returns the database path to be configured.
DatabasePropertiesOptions & setReplicaMode(ReplicaMode value)
Sets the replica mode.
const std::optional< bool > & getOnline() const
Returns whether the database should be brought online.
const std::optional< ReplicaMode > & getReplicaMode() const
Returns the replica mode.
DatabasePropertiesOptions & setShutdownMode(ShutdownMode value)
Sets the shutdown mode.
const std::optional< ShutdownMode > & getShutdownMode() const
Returns the shutdown mode.
const std::optional< ShutdownType > & getShutdownType() const
Returns the shutdown type.
const std::optional< int > & getShutdownTimeout() const
Returns the shutdown timeout in seconds.
DatabasePropertiesOptions & setShutdownType(ShutdownType value)
Sets the shutdown type.
DatabasePropertiesOptions & setShutdownTimeout(int value)
Sets the shutdown timeout in seconds.
DatabasePropertiesOptions & setOnline(bool value)
Sets whether the database should be brought online.
DatabasePropertiesOptions & setDatabase(const std::string &value)
Sets the database path to be configured.
Represents options used to run a database maintenance operation through the service manager.
DatabaseRepairOptions & setFull(bool value)
Sets whether full validation should be run.
bool getIgnoreChecksum() const
Returns whether checksum verification is configured to be ignored.
DatabaseRepairOptions & setKillShadows(bool value)
Sets whether killing database shadows should be run.
DatabaseRepairOptions & setUpgradeDb(bool value)
Sets whether database upgrade should be run.
const std::optional< std::uint32_t > & getParallelWorkers() const
Returns the requested number of parallel workers.
DatabaseRepairOptions & setSweep(bool value)
Sets whether database sweep should be run.
DatabaseRepairOptions & setVerboseOutput(ServiceManager::VerboseOutput value)
Sets the verbose output callback.
bool getUpgradeDb() const
Returns whether database upgrade is configured to be run.
DatabaseRepairOptions & setCheckDb(bool value)
Sets whether checking only metadata/structure should be run.
const ServiceManager::VerboseOutput & getVerboseOutput() const
Returns the verbose output callback.
bool getValidate() const
Returns whether database validation is configured to be run.
bool getCheckDb() const
Returns whether checking only metadata/structure is configured to be run.
bool getKillShadows() const
Returns whether killing database shadows is configured to be run.
bool getSweep() const
Returns whether database sweep is configured to be run.
const std::string & getDatabase() const
Returns the database path to be maintained.
DatabaseRepairOptions & setIcu(bool value)
Sets whether recreating ICU indexes should be run.
DatabaseRepairOptions & setIgnoreChecksum(bool value)
Sets whether checksum verification should be ignored.
bool getIcu() const
Returns whether recreating ICU indexes is configured to be run.
bool getMend() const
Returns whether database mending is configured to be run.
DatabaseRepairOptions & setParallelWorkers(std::uint32_t value)
Sets the requested number of parallel workers.
DatabaseRepairOptions & setMend(bool value)
Sets whether database mending should be run.
bool getFull() const
Returns whether full validation is configured to be run.
DatabaseRepairOptions & setDatabase(const std::string &value)
Sets the database path to be maintained.
DatabaseRepairOptions & setValidate(bool value)
Sets whether database validation should be run.
Represents a connection to the Firebird service manager.
std::function< void(std::string_view line)> VerboseOutput
Function invoked when a verbose service output line is available.
fb-cpp namespace.
Definition Attachment.h:46
ShutdownType
Shutdown type for a Firebird database.
@ DENY_TRANSACTIONS
Deny new transactions: waits for existing transactions to finish.
@ FORCED
Forced shutdown: disconnects all users immediately after the timeout.
@ DENY_ATTACHMENTS
Deny new attachments: waits for existing connections to finish.
ShutdownMode
Shutdown mode for a Firebird database.
@ SINGLE
Single-user shutdown.
@ NORMAL
Normal online state.
@ FULL
Full exclusive shutdown.
@ MULTI
Multi-user shutdown.
ReplicaMode
Replica mode.