Interface.h (6154B)
1 // Copyright (c) Microsoft Corporation. 2 // Licensed under the MIT License. 3 #pragma once 4 #include "Microsoft/Schema/ISQLiteIndex.h" 5 #include "Microsoft/Schema/2_0/SearchResultsTable.h" 6 #include "Microsoft/Schema/2_0/OneToManyTableWithMap.h" 7 8 #include <memory> 9 #include <vector> 10 11 using namespace std::string_view_literals; 12 13 namespace AppInstaller::Repository::Microsoft::Schema::V2_0 14 { 15 // Version 2.0 16 static constexpr std::string_view s_MetadataValueName_PackageUpdateTrackingBaseTime = "updateTrackingBase"sv; 17 18 // Interface to this schema version exposed through ISQLiteIndex. 19 struct Interface : public ISQLiteIndex 20 { 21 Interface(Utility::NormalizationVersion normVersion = Utility::NormalizationVersion::Initial); 22 23 // Version 1.0 24 SQLite::Version GetVersion() const override; 25 void CreateTables(SQLite::Connection& connection, CreateOptions options) override; 26 SQLite::rowid_t AddManifest(SQLite::Connection& connection, const Manifest::Manifest& manifest, const std::optional<std::filesystem::path>& relativePath) override; 27 std::pair<bool, SQLite::rowid_t> UpdateManifest(SQLite::Connection& connection, const Manifest::Manifest& manifest, const std::optional<std::filesystem::path>& relativePath) override; 28 SQLite::rowid_t RemoveManifest(SQLite::Connection& connection, const Manifest::Manifest& manifest) override; 29 void RemoveManifestById(SQLite::Connection& connection, SQLite::rowid_t manifestId) override; 30 void PrepareForPackaging(SQLite::Connection& connection) override; 31 void PrepareForPackaging(const SQLiteIndexContext& context) override; 32 bool CheckConsistency(const SQLite::Connection& connection, bool log) const override; 33 SearchResult Search(const SQLite::Connection& connection, const SearchRequest& request) const override; 34 std::optional<std::string> GetPropertyByPrimaryId(const SQLite::Connection& connection, SQLite::rowid_t primaryId, PackageVersionProperty property) const override; 35 std::vector<std::string> GetMultiPropertyByPrimaryId(const SQLite::Connection& connection, SQLite::rowid_t primaryId, PackageVersionMultiProperty property) const override; 36 std::optional<SQLite::rowid_t> GetManifestIdByKey(const SQLite::Connection& connection, SQLite::rowid_t id, std::string_view version, std::string_view channel) const override; 37 std::optional<SQLite::rowid_t> GetManifestIdByManifest(const SQLite::Connection& connection, const Manifest::Manifest& manifest) const override; 38 std::vector<VersionKey> GetVersionKeysById(const SQLite::Connection& connection, SQLite::rowid_t id) const override; 39 40 // Version 1.1 41 MetadataResult GetMetadataByManifestId(const SQLite::Connection& connection, SQLite::rowid_t manifestId) const override; 42 void SetMetadataByManifestId(SQLite::Connection& connection, SQLite::rowid_t manifestId, PackageVersionMetadata metadata, std::string_view value) override; 43 44 // Version 1.2 45 Utility::NormalizedName NormalizeName(std::string_view name, std::string_view publisher) const override; 46 47 // Version 1.4 Get all the dependencies for a specific manifest. 48 std::set<std::pair<SQLite::rowid_t, Utility::NormalizedString>> GetDependenciesByManifestRowId(const SQLite::Connection& connection, SQLite::rowid_t manifestRowId) const override; 49 std::vector<std::pair<SQLite::rowid_t, Utility::NormalizedString>> GetDependentsById(const SQLite::Connection& connection, AppInstaller::Manifest::string_t packageId) const override; 50 51 // Version 1.7 52 void DropTables(SQLite::Connection& connection) override; 53 54 // Version 2.0 55 bool MigrateFrom(SQLite::Connection& connection, const ISQLiteIndex* current) override; 56 void SetProperty(SQLite::Connection& connection, Property property, const std::string& value) override; 57 58 protected: 59 // Creates the search results table. 60 virtual std::unique_ptr<SearchResultsTable> CreateSearchResultsTable(const SQLite::Connection& connection) const; 61 62 // Executes all relevant searches for the query. 63 virtual void PerformQuerySearch(SearchResultsTable& resultsTable, const RequestMatch& query) const; 64 65 // Gets the one to many table schema to use. 66 virtual OneToManyTableSchema GetOneToManyTableSchema() const; 67 68 // Executes search on a request that can be modified. 69 virtual SearchResult SearchInternal(const SQLite::Connection& connection, SearchRequest& request) const; 70 71 // Executes search on the given request. 72 SearchResult BasicSearchInternal(const SQLite::Connection& connection, const SearchRequest& request) const; 73 74 // Prepares for packaging, optionally vacuuming the database. 75 virtual void PrepareForPackaging(const SQLiteIndexContext& context, bool vacuum); 76 77 // Force the database to shrink the file size. 78 // This *must* be done outside of an active transaction. 79 void Vacuum(const SQLite::Connection& connection); 80 81 // If before PrepareForPackaging is called, this should find the internal interface schema version and create the object. 82 // If after PrepareForPackaging is called, this should not find the internal interface schema version and allow the code to fall through. 83 // requireInternalInterface should be set to true for modifying functions. 84 void EnsureInternalInterface(const SQLite::Connection& connection, bool requireInternalInterface = false) const; 85 86 // Allows derived types to move to a different internal schema version. 87 virtual std::unique_ptr<Schema::ISQLiteIndex> CreateInternalInterface() const; 88 89 // If EnsureInternalInterface has been called. 90 mutable bool m_internalInterfaceChecked = false; 91 92 // Interface to the data before PrepareForPackaging is called. 93 mutable std::unique_ptr<Schema::ISQLiteIndex> m_internalInterface; 94 95 // The name normalization utility 96 Utility::NameNormalizer m_normalizer; 97 }; 98 }