From 045c7b20660084f7992a7374a0bf47fa9165a8d1 Mon Sep 17 00:00:00 2001 From: Thomas Goyne Date: Thu, 27 Aug 2015 11:38:30 -0700 Subject: [PATCH] Add Realm::get_schema_version() --- shared_realm.cpp | 12 +++++++++++- shared_realm.hpp | 2 ++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/shared_realm.cpp b/shared_realm.cpp index 9d4a4a7f..c441df2d 100644 --- a/shared_realm.cpp +++ b/shared_realm.cpp @@ -133,7 +133,7 @@ SharedRealm Realm::get_shared_realm(Config config) } else if (realm->m_config.read_only) { if (old_version == ObjectStore::NotVersioned) { - throw UnitializedRealmException("Can't open an un-initizliazed Realm without a Schema"); + throw UnitializedRealmException("Can't open an un-initialized Realm without a Schema"); } ObjectStore::verify_schema(realm->read_group(), *realm->m_config.schema, true); } @@ -348,6 +348,16 @@ bool Realm::refresh() return true; } +uint64_t Realm::get_schema_version(const realm::Realm::Config &config) +{ + auto existing_realm = s_global_cache.get_any_realm(config.path); + if (existing_realm) { + return existing_realm->config().schema_version; + } + + return ObjectStore::get_schema_version(Realm(config).read_group()); +} + SharedRealm RealmCache::get_realm(const std::string &path, std::thread::id thread_id) { std::lock_guard lock(m_mutex); diff --git a/shared_realm.hpp b/shared_realm.hpp index 6f868a09..064bfff7 100644 --- a/shared_realm.hpp +++ b/shared_realm.hpp @@ -76,6 +76,8 @@ namespace realm { // returns if any changes were made bool update_schema(Schema &schema, uint64_t version); + static uint64_t get_schema_version(Config const& config); + const Config &config() const { return m_config; } void begin_transaction();