Line | Branch | Exec | Source |
---|---|---|---|
1 | // SPDX-FileCopyrightText: 2023 Carl Zeiss Microscopy GmbH | ||
2 | // | ||
3 | // SPDX-License-Identifier: MIT | ||
4 | |||
5 | #pragma once | ||
6 | |||
7 | #include <vector> | ||
8 | #include <utility> | ||
9 | #include <string> | ||
10 | #include <memory> | ||
11 | #include "IDbConnection.h" | ||
12 | #include "database_configuration.h" | ||
13 | |||
14 | /// This class is used for discovering a database and its configuration. It is checked whether | ||
15 | /// the database is a valid "imgdoc2" database and if so, the configuration is determined. | ||
16 | class DbDiscovery | ||
17 | { | ||
18 | private: | ||
19 | std::shared_ptr<IDbConnection> db_connection_; | ||
20 | |||
21 | std::shared_ptr<DatabaseConfigurationCommon> configuration_; | ||
22 | private: | ||
23 | struct GeneralDataDiscoveryResult | ||
24 | { | ||
25 | std::string tilesdatatable_name; | ||
26 | std::string tileinfotable_name; | ||
27 | std::string blobtable_name; | ||
28 | std::string spatial_index_table_name; | ||
29 | std::string metadatatable_name; | ||
30 | |||
31 | imgdoc2::DocumentType document_type { imgdoc2::DocumentType::kInvalid }; | ||
32 | std::vector<imgdoc2::Dimension> dimensions; | ||
33 | std::vector<imgdoc2::Dimension> indexed_dimensions; | ||
34 | }; | ||
35 | |||
36 | public: | ||
37 | DbDiscovery() = delete; | ||
38 | |||
39 | /// Constructor. | ||
40 | /// | ||
41 | /// \param dbConnection The database connection. | ||
42 | 16 | explicit DbDiscovery(std::shared_ptr<IDbConnection> dbConnection) : | |
43 | 16 | db_connection_(std::move(dbConnection)) | |
44 | 16 | {} | |
45 | |||
46 | /// Executes the discovery operation. It is checked whether the database is a valid "imgdoc2" database and if so, | ||
47 | /// its type and configuration is determined. In case of an error, an exception is thrown. | ||
48 | void DoDiscovery(); | ||
49 | |||
50 | /// Gets the document type. | ||
51 | /// | ||
52 | /// \returns The document type. | ||
53 | [[nodiscard]] imgdoc2::DocumentType GetDocumentType() const; | ||
54 | |||
55 | /// Gets database configuration, i.e. the least common denominator, the base type from which all | ||
56 | /// configuration have to derive from. | ||
57 | /// \returns The base database configuration if available; otherwise, null. | ||
58 | [[nodiscard]] std::shared_ptr<DatabaseConfigurationCommon> GetDatabaseConfigurationCommon() const; | ||
59 | |||
60 | /// Gets database configuration object for an image-2D document. If the document is not an image-2D document, | ||
61 | /// an internal_error_exception is thrown. | ||
62 | /// \returns The database configuration object for an image-2D document. | ||
63 | [[nodiscard]] std::shared_ptr<DatabaseConfiguration2D> GetDatabaseConfiguration2DOrThrow() const; | ||
64 | |||
65 | /// Gets database configuration object for an image-3D document. If the document is not an image-3D document, | ||
66 | /// an internal_error_exception is thrown. | ||
67 | /// \returns The database configuration object for an image-3D document. | ||
68 | [[nodiscard]] std::shared_ptr<DatabaseConfiguration3D> GetDatabaseConfiguration3DOrThrow() const; | ||
69 | |||
70 | /// Gets database configuration object for an image-2D document. If the document is not an image-2D document, | ||
71 | /// null is returned. | ||
72 | /// \returns The database configuration object for an image-2D document if available; otherwise, null. | ||
73 | [[nodiscard]] std::shared_ptr<DatabaseConfiguration2D> GetDatabaseConfiguration2DOrNull() const; | ||
74 | |||
75 | /// Gets database configuration object for an image-3D document. If the document is not an image-3D document, | ||
76 | /// null is returned. | ||
77 | /// \returns The database configuration object for an image-3D document if available; otherwise, null. | ||
78 | [[nodiscard]] std::shared_ptr<DatabaseConfiguration3D> GetDatabaseConfiguration3DOrNull() const; | ||
79 | private: | ||
80 | GeneralDataDiscoveryResult DiscoverGeneralTable(); | ||
81 | |||
82 | /// This method tries to populate the 'general_table_discovery_result' with additional information and validates | ||
83 | /// that information. On input, it is expecting only the table-names to contain information, those names | ||
84 | /// are then here validated and the remaining fields are populated. | ||
85 | /// In case of an (unrecoverable) error, this method will throw an exception. | ||
86 | /// \param [in,out] general_table_discovery_result On input, it is expected that the table-names are filled, on exit the other fields are populated and validated. | ||
87 | void Check_Tables_And_Determine_Dimensions(GeneralDataDiscoveryResult& general_table_discovery_result); | ||
88 | |||
89 | void FillInformationForConfiguration2D(const GeneralDataDiscoveryResult& general_data_discovery_result, DatabaseConfiguration2D& configuration_2d); | ||
90 | void FillInformationForConfiguration3D(const GeneralDataDiscoveryResult& general_data_discovery_result, DatabaseConfiguration3D& configuration_3d); | ||
91 | |||
92 | struct ExpectedColumnsInfo | ||
93 | { | ||
94 |
1/2✓ Branch 1 taken 324 times.
✗ Branch 2 not taken.
|
972 | explicit ExpectedColumnsInfo(const char* sz) : column_name(sz) {} |
95 | std::string column_name; | ||
96 | }; | ||
97 | }; | ||
98 |