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 <cstdint>
30#include <optional>
31#include <string>
32
33
37namespace fbcpp
38{
42 enum class ShutdownMode
43 {
47 NORMAL,
48
52 MULTI,
53
57 SINGLE,
58
62 FULL
63 };
64
68 enum class ShutdownType
69 {
73 FORCED,
74
79
84 };
85
90 {
91 public:
95 const std::string& getDatabase() const
96 {
97 return database;
98 }
99
103 DatabasePropertiesOptions& setDatabase(const std::string& value)
104 {
105 database = value;
106 return *this;
107 }
108
112 const std::optional<ReplicaMode>& getReplicaMode() const
113 {
114 return replicaMode;
115 }
116
121 {
122 replicaMode = value;
123 return *this;
124 }
125
129 const std::optional<ShutdownMode>& getShutdownMode() const
130 {
131 return shutdownMode;
132 }
133
138 {
139 shutdownMode = value;
140 return *this;
141 }
142
146 const std::optional<ShutdownType>& getShutdownType() const
147 {
148 return shutdownType;
149 }
150
155 {
156 shutdownType = value;
157 return *this;
158 }
159
163 const std::optional<int>& getShutdownTimeout() const
164 {
165 return shutdownTimeout;
166 }
167
172 {
173 shutdownTimeout = value;
174 return *this;
175 }
176
180 const std::optional<bool>& getOnline() const
181 {
182 return online;
183 }
184
189 {
190 online = value;
191 return *this;
192 }
193
194 private:
195 std::string database;
196 std::optional<ReplicaMode> replicaMode;
197 std::optional<ShutdownMode> shutdownMode;
198 std::optional<ShutdownType> shutdownType;
199 std::optional<int> shutdownTimeout;
200 std::optional<bool> online;
201 };
202
207 {
208 public:
212 const std::string& getDatabase() const
213 {
214 return database;
215 }
216
220 DatabaseRepairOptions& setDatabase(const std::string& value)
221 {
222 database = value;
223 return *this;
224 }
225
230 {
231 return verboseOutput;
232 }
233
238 {
239 verboseOutput = std::move(value);
240 return *this;
241 }
242
246 const std::optional<std::uint32_t>& getParallelWorkers() const
247 {
248 return parallelWorkers;
249 }
250
255 {
256 parallelWorkers = value;
257 return *this;
258 }
259
263 bool getSweep() const
264 {
265 return sweep;
266 }
267
272 {
273 sweep = value;
274 return *this;
275 }
276
280 bool getValidate() const
281 {
282 return validate;
283 }
284
289 {
290 validate = value;
291 return *this;
292 }
293
297 bool getMend() const
298 {
299 return mend;
300 }
301
306 {
307 mend = value;
308 return *this;
309 }
310
314 bool getIgnoreChecksum() const
315 {
316 return ignoreChecksum;
317 }
318
323 {
324 ignoreChecksum = value;
325 return *this;
326 }
327
331 bool getKillShadows() const
332 {
333 return killShadows;
334 }
335
340 {
341 killShadows = value;
342 return *this;
343 }
344
348 bool getFull() const
349 {
350 return full;
351 }
352
357 {
358 full = value;
359 return *this;
360 }
361
365 bool getCheckDb() const
366 {
367 return checkDb;
368 }
369
374 {
375 checkDb = value;
376 return *this;
377 }
378
382 bool getIcu() const
383 {
384 return icu;
385 }
386
391 {
392 icu = value;
393 return *this;
394 }
395
399 bool getUpgradeDb() const
400 {
401 return upgradeDb;
402 }
403
408 {
409 upgradeDb = value;
410 return *this;
411 }
412
413 private:
414 std::string database;
415 ServiceManager::VerboseOutput verboseOutput;
416 std::optional<std::uint32_t> parallelWorkers;
417 bool sweep = false;
418 bool validate = false;
419 bool mend = false;
420 bool ignoreChecksum = false;
421 bool killShadows = false;
422 bool full = false;
423 bool checkDb = false;
424 bool icu = false;
425 bool upgradeDb = false;
426 };
427
431 class DatabaseManager final : public ServiceManager
432 {
433 public:
435
436 public:
440 void setProperties(const DatabasePropertiesOptions& options);
441
445 void repair(const DatabaseRepairOptions& options);
446 };
447} // namespace fbcpp
448
449
450#endif // FBCPP_DATABASE_MANAGER_H
Executes configuration and maintenance operations through the Firebird service manager.
void setProperties(const DatabasePropertiesOptions &options)
Configures database properties using the provided options.
void repair(const DatabaseRepairOptions &options)
Runs a repair operation using the provided options.
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.
ServiceManager(Client &client, const ServiceManagerOptions &options={})
Attaches to the service manager specified by the given options.
std::function< void(std::string_view line)> VerboseOutput
Function invoked when a verbose service output line is available.
fb-cpp namespace.
Definition Attachment.h:45
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.