From ceceeab9a54b81397d650e6e049203a956e452f3 Mon Sep 17 00:00:00 2001 From: Ari Lazier Date: Mon, 23 May 2016 11:57:07 -0700 Subject: [PATCH] object store pr feedback --- src/impl/realm_coordinator.cpp | 2 +- src/object_store.hpp | 5 ----- src/shared_realm.cpp | 19 +++++++++++++++---- src/shared_realm.hpp | 12 ++++++++---- 4 files changed, 24 insertions(+), 14 deletions(-) diff --git a/src/impl/realm_coordinator.cpp b/src/impl/realm_coordinator.cpp index df53a2ce..47033a67 100644 --- a/src/impl/realm_coordinator.cpp +++ b/src/impl/realm_coordinator.cpp @@ -105,7 +105,7 @@ std::shared_ptr RealmCoordinator::get_realm(Realm::Config config) auto realm = std::make_shared(std::move(config)); realm->init(shared_from_this()); - + if (!config.read_only && !m_notifier && config.automatic_change_notifications) { try { m_notifier = std::make_unique(*this); diff --git a/src/object_store.hpp b/src/object_store.hpp index 508b43be..0b9f05f8 100644 --- a/src/object_store.hpp +++ b/src/object_store.hpp @@ -158,11 +158,6 @@ namespace realm { std::vector m_validation_errors; }; - class SchemaUpdateValidationException : public SchemaValidationException { - public: - SchemaUpdateValidationException(std::vector const& errors); - }; - class SchemaMismatchException : public ObjectStoreException { public: SchemaMismatchException(std::vector const& errors); diff --git a/src/shared_realm.cpp b/src/shared_realm.cpp index ff731ce3..b77ec99c 100644 --- a/src/shared_realm.cpp +++ b/src/shared_realm.cpp @@ -61,7 +61,7 @@ Realm::Config& Realm::Config::operator=(realm::Realm::Config const& c) Realm::Realm(Config config) : m_config(std::move(config)) { - open_with_config(m_config, m_history, m_shared_group, m_read_only_group); + open_with_config(m_config, m_history, m_shared_group, m_read_only_group, this); if (m_read_only_group) { m_group = m_read_only_group.get(); @@ -71,7 +71,8 @@ Realm::Realm(Config config) void Realm::open_with_config(Config& config, std::unique_ptr& history, std::unique_ptr& shared_group, - std::unique_ptr& read_only_group) + std::unique_ptr& read_only_group, + Realm *realm) { try { if (config.read_only) { @@ -85,8 +86,10 @@ void Realm::open_with_config(Config& config, SharedGroup::DurabilityLevel durability = config.in_memory ? SharedGroup::durability_MemOnly : SharedGroup::durability_Full; shared_group = std::make_unique(*history, durability, config.encryption_key.data(), !config.disable_format_upgrade, [&](int from_version, int to_version) { - config.upgrade_initial_version = from_version; - config.upgrade_final_version = to_version; + if (realm) { + realm->upgrade_initial_version = from_version; + realm->upgrade_final_version = to_version; + } }); } } @@ -459,3 +462,11 @@ void Realm::close() m_binding_context = nullptr; m_coordinator = nullptr; } + +int Realm::file_format_upgraded_from_version() const +{ + if (upgrade_initial_version != upgrade_final_version) { + return upgrade_initial_version; + } + return 0; +} diff --git a/src/shared_realm.hpp b/src/shared_realm.hpp index 2526d198..d22b2c2d 100644 --- a/src/shared_realm.hpp +++ b/src/shared_realm.hpp @@ -79,9 +79,6 @@ namespace realm { // everything can be done deterministically on one thread, and // speeds up tests that don't need notifications. bool automatic_change_notifications = true; - // File format versions populated when a file format upgrade takes place - // during realm opening - int upgrade_initial_version = 0, upgrade_final_version = 0; Config(); Config(Config&&); @@ -135,6 +132,9 @@ namespace realm { // Realm after closing it will produce undefined behavior. void close(); + // returns the file format version upgraded from, or 0 if not upgraded + int file_format_upgraded_from_version() const; + ~Realm(); void init(std::shared_ptr<_impl::RealmCoordinator> coordinator); @@ -161,7 +161,8 @@ namespace realm { static void open_with_config(Config& config, std::unique_ptr& history, std::unique_ptr& shared_group, - std::unique_ptr& read_only_group); + std::unique_ptr& read_only_group, + Realm *realm = nullptr); private: Config m_config; @@ -176,6 +177,9 @@ namespace realm { std::shared_ptr<_impl::RealmCoordinator> m_coordinator; + // File format versions populated when a file format upgrade takes place during realm opening + int upgrade_initial_version = 0, upgrade_final_version = 0; + public: std::unique_ptr m_binding_context;