fb-cpp 0.0.2
A modern C++ wrapper for the Firebird database API
Loading...
Searching...
No Matches
DatabaseManager.cpp
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#include "DatabaseManager.h"
26#include "Client.h"
27#include <cassert>
28
29using namespace fbcpp;
30using namespace fbcpp::impl;
31
32
34{
35 StatusWrapper statusWrapper{getClient()};
36 auto builder =
37 fbUnique(getClient().getUtil()->getXpbBuilder(&statusWrapper, fb::IXpbBuilder::SPB_START, nullptr, 0));
38 builder->insertTag(&statusWrapper, isc_action_svc_properties);
39 builder->insertString(&statusWrapper, isc_spb_dbname, options.getDatabase().c_str());
40
41 if (const auto replicaMode = options.getReplicaMode())
42 {
43 std::uint8_t modeVal = 0;
44 switch (*replicaMode)
45 {
47 modeVal = isc_spb_prp_rm_none;
48 break;
50 modeVal = isc_spb_prp_rm_readonly;
51 break;
53 modeVal = isc_spb_prp_rm_readwrite;
54 break;
55 default:
56 assert(false);
57 break;
58 }
59 builder->insertBytes(&statusWrapper, isc_spb_prp_replica_mode, &modeVal, 1u);
60 }
61
62 const auto buffer = builder->getBuffer(&statusWrapper);
63 const auto length = builder->getBufferLength(&statusWrapper);
64
65 startAction(std::vector<std::uint8_t>(buffer, buffer + length));
66 waitForCompletion();
67}
68
69
71{
72 StatusWrapper statusWrapper{getClient()};
73 auto builder =
74 fbUnique(getClient().getUtil()->getXpbBuilder(&statusWrapper, fb::IXpbBuilder::SPB_START, nullptr, 0));
75
76 builder->insertTag(&statusWrapper, isc_action_svc_repair);
77 builder->insertString(&statusWrapper, isc_spb_dbname, options.getDatabase().c_str());
78
79 int optionsVal = 0;
80 if (options.getSweep())
81 optionsVal |= isc_spb_rpr_sweep_db;
82 if (options.getValidate())
83 optionsVal |= isc_spb_rpr_validate_db;
84 if (options.getMend())
85 optionsVal |= isc_spb_rpr_mend_db;
86 if (options.getIgnoreChecksum())
87 optionsVal |= isc_spb_rpr_ignore_checksum;
88 if (options.getKillShadows())
89 optionsVal |= isc_spb_rpr_kill_shadows;
90 if (options.getFull())
91 optionsVal |= isc_spb_rpr_full;
92 if (options.getCheckDb())
93 optionsVal |= isc_spb_rpr_check_db;
94 if (options.getIcu())
95 optionsVal |= isc_spb_rpr_icu;
96 if (options.getUpgradeDb())
97 optionsVal |= isc_spb_rpr_upgrade_db;
98
99 if (optionsVal != 0)
100 builder->insertInt(&statusWrapper, isc_spb_options, optionsVal);
101
102 if (const auto parallelWorkers = options.getParallelWorkers())
103 builder->insertInt(&statusWrapper, isc_spb_rpr_par_workers, static_cast<int>(*parallelWorkers));
104
105 const auto buffer = builder->getBuffer(&statusWrapper);
106 const auto length = builder->getBufferLength(&statusWrapper);
107
108 startAction(std::vector<std::uint8_t>(buffer, buffer + length));
109 waitForCompletion(options.getVerboseOutput());
110}
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.
const std::optional< ReplicaMode > & getReplicaMode() const
Returns the replica mode.
Represents options used to run a database maintenance operation through the service manager.
bool getIgnoreChecksum() const
Returns whether checksum verification is configured to be ignored.
const std::optional< std::uint32_t > & getParallelWorkers() const
Returns the requested number of parallel workers.
bool getUpgradeDb() const
Returns whether database upgrade is configured to 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.
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.
bool getFull() const
Returns whether full validation is configured to be run.
Client & getClient() noexcept
Returns the Client object reference used to create this ServiceManager object.
fb-cpp namespace.
Definition Attachment.h:45
FbUniquePtr< T > fbUnique(T *obj) noexcept
Creates a unique pointer for a Firebird disposable object.
Definition SmartPtrs.h:59
@ READ_ONLY
Read-only replica.
@ READ_WRITE
Read-write replica.
@ NONE
The database is not a replica (operates as primary).