Interface_0_1.cpp (2854B)
1 // Copyright (c) Microsoft Corporation. 2 // Licensed under the MIT License. 3 #include "pch.h" 4 #include "Interface.h" 5 #include "SetInfoTable.h" 6 #include "UnitInfoTable.h" 7 8 using namespace AppInstaller::SQLite; 9 using namespace AppInstaller::Utility; 10 11 namespace winrt::Microsoft::Management::Configuration::implementation::Database::Schema::V0_1 12 { 13 static constexpr AppInstaller::SQLite::Version s_InterfaceVersion{ 0, 1 }; 14 15 Interface::Interface(std::shared_ptr<AppInstaller::SQLite::SQLiteDynamicStorage> storage) : 16 m_storage(std::move(storage)) 17 {} 18 19 const AppInstaller::SQLite::Version& Interface::GetSchemaVersion() 20 { 21 return s_InterfaceVersion; 22 } 23 24 void Interface::InitializeDatabase() 25 { 26 // Must enable WAL mode outside of a transaction 27 THROW_HR_IF(E_UNEXPECTED, !m_storage->GetConnection().SetJournalMode("WAL")); 28 29 Savepoint savepoint = Savepoint::Create(*m_storage, "InitializeDatabase_0_1"); 30 31 SetInfoTable setInfoTable(*m_storage); 32 setInfoTable.Create(); 33 34 UnitInfoTable unitInfoTable(*m_storage); 35 unitInfoTable.Create(); 36 37 savepoint.Commit(); 38 } 39 40 void Interface::AddSet(const Configuration::ConfigurationSet& configurationSet) 41 { 42 Savepoint savepoint = Savepoint::Create(*m_storage, "AddSet_0_1"); 43 44 SetInfoTable setInfoTable(*m_storage); 45 setInfoTable.Add(configurationSet); 46 47 savepoint.Commit(); 48 } 49 50 void Interface::UpdateSet(rowid_t target, const Configuration::ConfigurationSet& configurationSet) 51 { 52 Savepoint savepoint = Savepoint::Create(*m_storage, "UpdateSet_0_1"); 53 54 SetInfoTable setInfoTable(*m_storage); 55 setInfoTable.Update(target, configurationSet); 56 57 savepoint.Commit(); 58 } 59 60 void Interface::RemoveSet(rowid_t target) 61 { 62 Savepoint savepoint = Savepoint::Create(*m_storage, "RemoveSet_0_1"); 63 64 SetInfoTable setInfoTable(*m_storage); 65 setInfoTable.Remove(target); 66 67 savepoint.Commit(); 68 } 69 70 std::vector<IConfigurationDatabase::ConfigurationSetPtr> Interface::GetSets() 71 { 72 SetInfoTable setInfoTable(*m_storage); 73 return setInfoTable.GetAllSets(); 74 } 75 76 std::optional<rowid_t> Interface::GetSetRowId(const GUID& instanceIdentifier) 77 { 78 SetInfoTable setInfoTable(*m_storage); 79 return setInfoTable.GetSetRowId(instanceIdentifier); 80 } 81 82 bool Interface::MigrateFrom(IConfigurationDatabase* current) 83 { 84 return current->GetSchemaVersion() == s_InterfaceVersion; 85 } 86 87 Interface::ConfigurationSetPtr Interface::GetSet(const GUID& instanceIdentifier) 88 { 89 SetInfoTable setInfoTable(*m_storage); 90 return setInfoTable.GetSet(instanceIdentifier); 91 } 92 }