diff --git a/src/realm/db.cpp b/src/realm/db.cpp index f59caffe8e7..a2b96ab98dc 100644 --- a/src/realm/db.cpp +++ b/src/realm/db.cpp @@ -1604,7 +1604,7 @@ void DB::close_internal(std::unique_lock lock, bool allow_ope bool DB::has_changed(TransactionRef tr) { - bool changed = tr->m_read_lock_info.m_version != get_version_of_latest_snapshot(); + bool changed = tr->m_read_lock.m_version != get_version_of_latest_snapshot(); return changed; } @@ -1612,10 +1612,10 @@ bool DB::wait_for_change(TransactionRef tr) { SharedInfo* info = m_file_map.get_addr(); std::lock_guard lock(m_controlmutex); - while (tr->m_read_lock_info.m_version == info->latest_version_number && m_wait_for_change_enabled) { + while (tr->m_read_lock.m_version == info->latest_version_number && m_wait_for_change_enabled) { m_new_commit_available.wait(m_controlmutex, 0); } - return tr->m_read_lock_info.m_version != info->latest_version_number; + return tr->m_read_lock.m_version != info->latest_version_number; } @@ -1681,7 +1681,7 @@ void DB::do_async_commits() // overwritten by commits being made to memory by others. { VersionID version_id = VersionID(); // Latest available snapshot - grab_read_lock(m_read_lock_info, version_id); // Throws + grab_read_lock(m_read_lock, version_id); // Throws } // we must treat version and version_index the same way: { @@ -1701,7 +1701,7 @@ void DB::do_async_commits() } bool is_same; - Group::ReadLockInfo next_read_lock = m_read_lock_info; + Group::ReadLockInfo next_read_lock = m_read_lock; { // detect if we're the last "client", and if so, shutdown (must be under lock): std::lock_guard lock2(m_writemutex); @@ -1715,7 +1715,7 @@ void DB::do_async_commits() std::cerr << "Daemon exiting nicely" << std::endl << std::endl; #endif release_read_lock(next_read_lock); - release_read_lock(m_read_lock_info); + release_read_lock(m_read_lock); info->daemon_started = 0; info->daemon_ready = 0; return; @@ -1725,7 +1725,7 @@ void DB::do_async_commits() if (!is_same) { #ifdef REALM_ENABLE_LOGFILE - std::cerr << "Syncing from version " << m_read_lock_info.m_version << " to " << next_read_lock.m_version + std::cerr << "Syncing from version " << m_read_lock.m_version << " to " << next_read_lock.m_version << std::endl; #endif /* FIXME @@ -1739,8 +1739,8 @@ void DB::do_async_commits() // Now we can release the version that was previously commited // to disk and just keep the lock on the latest version. - release_read_lock(m_read_lock_info); - m_read_lock_info = next_read_lock; + release_read_lock(m_read_lock); + m_read_lock = next_read_lock; m_balancemutex.lock(); @@ -2119,13 +2119,13 @@ VersionID Transaction::commit_and_continue_as_read() // Grabbing the new lock before releasing the old one prevents m_transaction_count // from going shortly to zero db->grab_read_lock(new_read_lock, version_id); // Throws - db->release_read_lock(m_read_lock_info); - m_read_lock_info = new_read_lock; + db->release_read_lock(m_read_lock); + m_read_lock = new_read_lock; db->do_end_write(); // Remap file if it has grown, and update refs in underlying node structure - remap_and_update_refs(m_read_lock_info.m_top_ref, m_read_lock_info.m_file_size, false); // Throws + remap_and_update_refs(m_read_lock.m_top_ref, m_read_lock.m_file_size, false); // Throws m_history = nullptr; set_transact_stage(DB::transact_Reading); @@ -2386,7 +2386,7 @@ Transaction::Transaction(DBRef _db, SlabAlloc* alloc, Group::ReadLockInfo& rli, set_metrics(db->m_metrics); set_transact_stage(stage); m_alloc.note_reader_start(this); - attach_shared(m_read_lock_info.m_top_ref, m_read_lock_info.m_file_size, writable); + attach_shared(m_read_lock.m_top_ref, m_read_lock.m_file_size, writable); } void Transaction::close() @@ -2411,7 +2411,7 @@ void Transaction::end_read() void Transaction::do_end_read() noexcept { detach(); - db->release_read_lock(m_read_lock_info); + db->release_read_lock(m_read_lock); m_alloc.note_reader_end(this); set_transact_stage(DB::transact_Ready); // reset the std::shared_ptr to allow the DB object to release resources @@ -2423,13 +2423,13 @@ TransactionRef Transaction::freeze() { if (m_transact_stage != DB::transact_Reading) throw LogicError(LogicError::wrong_transact_state); - auto version = VersionID(m_read_lock_info.m_version, m_read_lock_info.m_reader_idx); + auto version = VersionID(m_read_lock.m_version, m_read_lock.m_reader_idx); return db->start_frozen(version); } TransactionRef Transaction::duplicate() { - auto version = VersionID(m_read_lock_info.m_version, m_read_lock_info.m_reader_idx); + auto version = VersionID(m_read_lock.m_version, m_read_lock.m_reader_idx); if (m_transact_stage == DB::transact_Reading) return db->start_read(version); if (m_transact_stage == DB::transact_Frozen) @@ -2505,7 +2505,7 @@ DB::version_type Transaction::commit() DB::version_type new_version = db->do_commit(*this); // Throws - // We need to set m_read_lock_info in order for wait_for_change to work. + // We need to set m_read_lock in order for wait_for_change to work. // To set it, we grab a readlock on the latest available snapshot // and release it again. VersionID version_id = VersionID(); // Latest available snapshot @@ -2516,7 +2516,7 @@ DB::version_type Transaction::commit() db->do_end_write(); do_end_read(); - m_read_lock_info = lock_after_commit; + m_read_lock = lock_after_commit; return new_version; } @@ -2535,24 +2535,24 @@ void Transaction::commit_and_continue_writing() db->do_commit(*this); // Throws - // We need to set m_read_lock_info in order for wait_for_change to work. + // We need to set m_read_lock in order for wait_for_change to work. // To set it, we grab a readlock on the latest available snapshot // and release it again. VersionID version_id = VersionID(); // Latest available snapshot Group::ReadLockInfo lock_after_commit; db->grab_read_lock(lock_after_commit, version_id); - db->release_read_lock(m_read_lock_info); - m_read_lock_info = lock_after_commit; + db->release_read_lock(m_read_lock); + m_read_lock = lock_after_commit; bool writable = true; - remap_and_update_refs(m_read_lock_info.m_top_ref, m_read_lock_info.m_file_size, writable); // Throws + remap_and_update_refs(m_read_lock.m_top_ref, m_read_lock.m_file_size, writable); // Throws } void Transaction::initialize_replication() { if (m_transact_stage == DB::transact_Writing) { if (Replication* repl = get_replication()) { - auto current_version = m_read_lock_info.m_version; + auto current_version = m_read_lock.m_version; bool history_updated = false; repl->initiate_transact(*this, current_version, history_updated); // Throws } @@ -2568,7 +2568,7 @@ Transaction::~Transaction() DB::VersionID Transaction::get_version_of_current_transaction() { - return VersionID(m_read_lock_info.m_version, m_read_lock_info.m_reader_idx); + return VersionID(m_read_lock.m_version, m_read_lock.m_reader_idx); } diff --git a/src/realm/db.hpp b/src/realm/db.hpp index 2a7642ff7e2..02502e2a5fc 100644 --- a/src/realm/db.hpp +++ b/src/realm/db.hpp @@ -538,7 +538,7 @@ class Transaction : public Group { DB::version_type get_version() const noexcept { - return m_read_lock_info.m_version; + return m_read_lock.m_version; } DB::version_type get_version_of_latest_snapshot() { @@ -814,22 +814,22 @@ class DB::ReadLockGuard { public: ReadLockGuard(DB& shared_group, Group::ReadLockInfo& read_lock) noexcept : m_shared_group(shared_group) - , m_read_lock_info(&read_lock) + , m_read_lock(&read_lock) { } ~ReadLockGuard() noexcept { - if (m_read_lock_info) - m_shared_group.release_read_lock(*m_read_lock_info); + if (m_read_lock) + m_shared_group.release_read_lock(*m_read_lock); } void release() noexcept { - m_read_lock_info = 0; + m_read_lock = 0; } private: DB& m_shared_group; - Group::ReadLockInfo* m_read_lock_info; + Group::ReadLockInfo* m_read_lock; }; template @@ -839,7 +839,7 @@ inline void Transaction::advance_read(O* observer, VersionID version_id) throw LogicError(LogicError::wrong_transact_state); // It is an error if the new version precedes the currently bound one. - if (version_id.version < m_read_lock_info.m_version) + if (version_id.version < m_read_lock.m_version) throw LogicError(LogicError::bad_version); auto hist = get_history(); // Throws @@ -874,7 +874,7 @@ inline bool Transaction::promote_to_write(O* observer, bool nonblocking) bool history_updated = internal_advance_read(observer, version, *m_history, true); // Throws REALM_ASSERT(repl); // Presence of `repl` follows from the presence of `hist` - DB::version_type current_version = m_read_lock_info.m_version; + DB::version_type current_version = m_read_lock.m_version; m_alloc.init_mapping_management(current_version); repl->initiate_transact(*this, current_version, history_updated); // Throws @@ -923,8 +923,8 @@ inline void Transaction::rollback_and_continue_as_read(O* observer) // Mark all managed space (beyond the attached file) as free. db->reset_free_space_tracking(); // Throws - ref_type top_ref = m_read_lock_info.m_top_ref; - size_t file_size = m_read_lock_info.m_file_size; + ref_type top_ref = m_read_lock.m_top_ref; + size_t file_size = m_read_lock.m_file_size; _impl::ReversedNoCopyInputStream reversed_in(reverser); m_alloc.update_reader_view(file_size); // Throws update_allocator_wrappers(false); @@ -943,8 +943,8 @@ inline bool Transaction::internal_advance_read(O* observer, VersionID version_id { Group::ReadLockInfo new_read_lock; db->grab_read_lock(new_read_lock, version_id); // Throws - REALM_ASSERT(new_read_lock.m_version >= m_read_lock_info.m_version); - if (new_read_lock.m_version == m_read_lock_info.m_version) { + REALM_ASSERT(new_read_lock.m_version >= m_read_lock.m_version); + if (new_read_lock.m_version == m_read_lock.m_version) { db->release_read_lock(new_read_lock); // _impl::History::update_early_from_top_ref() was not called // update allocator wrappers merely to update write protection @@ -952,7 +952,7 @@ inline bool Transaction::internal_advance_read(O* observer, VersionID version_id return false; } - DB::version_type old_version = m_read_lock_info.m_version; + DB::version_type old_version = m_read_lock.m_version; DB::ReadLockGuard g(*db, new_read_lock); DB::version_type new_version = new_read_lock.m_version; size_t new_file_size = new_read_lock.m_file_size; @@ -987,8 +987,8 @@ inline bool Transaction::internal_advance_read(O* observer, VersionID version_id _impl::ChangesetInputStream in(hist, old_version, new_version); advance_transact(new_top_ref, in, writable); // Throws g.release(); - db->release_read_lock(m_read_lock_info); - m_read_lock_info = new_read_lock; + db->release_read_lock(m_read_lock); + m_read_lock = new_read_lock; return true; // _impl::History::update_early_from_top_ref() was called } diff --git a/src/realm/group.cpp b/src/realm/group.cpp index d7f6e5074ed..f7b4d42d2fc 100644 --- a/src/realm/group.cpp +++ b/src/realm/group.cpp @@ -142,7 +142,7 @@ Group::Group(SlabAlloc* alloc) noexcept } Group::Group(SlabAlloc* alloc, ReadLockInfo read_lock_info) noexcept - : m_read_lock_info(read_lock_info) + : m_read_lock(read_lock_info) , m_alloc(*alloc) // Throws , m_top(m_alloc) , m_tables(m_alloc) diff --git a/src/realm/group.hpp b/src/realm/group.hpp index a3cfe3a5806..512a4b3e0d3 100644 --- a/src/realm/group.hpp +++ b/src/realm/group.hpp @@ -246,7 +246,7 @@ class Group : public ArrayParent { /// Returns the keys for all tables in this group. TableKeys get_table_keys() const; - // Returns a new `VersionID` using the `m_read_lock_info`. + // Returns a new `VersionID` using the `m_read_lock`. VersionID get_current_version() const; /// \defgroup group_table_access Table Accessors @@ -571,7 +571,7 @@ class Group : public ArrayParent { ref_type m_top_ref = 0; size_t m_file_size = 0; }; - ReadLockInfo m_read_lock_info; + ReadLockInfo m_read_lock; protected: virtual Replication* const* get_repl() const @@ -955,7 +955,7 @@ inline TableKeys Group::get_table_keys() const inline VersionID Group::get_current_version() const { - return VersionID(m_read_lock_info.m_version, m_read_lock_info.m_reader_idx); + return VersionID(m_read_lock.m_version, m_read_lock.m_reader_idx); } inline bool Group::is_attached() const noexcept diff --git a/src/realm/object-store/c_api/object.cpp b/src/realm/object-store/c_api/object.cpp index 6a5ab463c47..42ef7d9b3fd 100644 --- a/src/realm/object-store/c_api/object.cpp +++ b/src/realm/object-store/c_api/object.cpp @@ -9,7 +9,7 @@ RLM_API bool realm_get_num_objects(const realm_t* realm, realm_class_key_t key, { return wrap_err([&]() { auto& rlm = **realm; - auto table = rlm.get_group().get_table(TableKey(key)); + auto table = rlm.read_group().get_table(TableKey(key)); if (out_count) *out_count = table->size(); return true; @@ -21,7 +21,7 @@ RLM_API realm_object_t* realm_get_object(const realm_t* realm, realm_class_key_t return wrap_err([&]() { auto& shared_realm = *realm; auto table_key = TableKey(tbl_key); - auto table = shared_realm->get_group().get_table(table_key); + auto table = shared_realm->read_group().get_table(table_key); auto obj = table->get_object(ObjKey(obj_key)); auto object = Object{shared_realm, std::move(obj)}; return new realm_object_t{std::move(object)}; @@ -34,7 +34,7 @@ RLM_API realm_object_t* realm_object_find_with_primary_key(const realm_t* realm, return wrap_err([&]() -> realm_object_t* { auto& shared_realm = *realm; auto table_key = TableKey(class_key); - auto table = shared_realm->get_group().get_table(table_key); + auto table = shared_realm->read_group().get_table(table_key); auto pk_val = from_capi(pk); auto pk_col = table->get_primary_key_column(); @@ -69,7 +69,7 @@ RLM_API realm_results_t* realm_object_find_all(const realm_t* realm, realm_class { return wrap_err([&]() { auto& shared_realm = *realm; - auto table = shared_realm->get_group().get_table(TableKey(key)); + auto table = shared_realm->read_group().get_table(TableKey(key)); return new realm_results{Results{shared_realm, table}}; }); } @@ -79,7 +79,7 @@ RLM_API realm_object_t* realm_object_create(realm_t* realm, realm_class_key_t ta return wrap_err([&]() { auto& shared_realm = *realm; auto tblkey = TableKey(table_key); - auto table = shared_realm->get_group().get_table(tblkey); + auto table = shared_realm->read_group().get_table(tblkey); if (table->get_primary_key_column()) { auto& object_schema = schema_for_table(*realm, tblkey); @@ -98,7 +98,7 @@ RLM_API realm_object_t* realm_object_create_with_primary_key(realm_t* realm, rea return wrap_err([&]() { auto& shared_realm = *realm; auto tblkey = TableKey(table_key); - auto table = shared_realm->get_group().get_table(tblkey); + auto table = shared_realm->read_group().get_table(tblkey); // FIXME: Provide did_create? auto pkval = from_capi(pk); diff --git a/src/realm/object-store/c_api/query.cpp b/src/realm/object-store/c_api/query.cpp index 5e5509bf092..26808648a9c 100644 --- a/src/realm/object-store/c_api/query.cpp +++ b/src/realm/object-store/c_api/query.cpp @@ -193,7 +193,7 @@ RLM_API realm_query_t* realm_query_parse(const realm_t* realm, realm_class_key_t const char* query_string, size_t num_args, const realm_value_t* args) { return wrap_err([&]() { - auto table = (*realm)->get_group().get_table(TableKey(target_table_key)); + auto table = (*realm)->read_group().get_table(TableKey(target_table_key)); DescriptorOrdering ordering; Query query = parse_and_apply_query(*realm, table, ordering, query_string, num_args, args); return new realm_query_t{std::move(query), std::move(ordering), *realm}; diff --git a/src/realm/object-store/c_api/realm.cpp b/src/realm/object-store/c_api/realm.cpp index d0143969aa6..c7a6bb18f32 100644 --- a/src/realm/object-store/c_api/realm.cpp +++ b/src/realm/object-store/c_api/realm.cpp @@ -44,7 +44,7 @@ RLM_API bool realm_is_closed(realm_t* realm) RLM_API bool realm_is_writable(const realm_t* realm) { - return (*realm)->is_in_write_transaction(); + return (*realm)->is_in_transaction(); } RLM_API bool realm_close(realm_t* realm) @@ -58,7 +58,7 @@ RLM_API bool realm_close(realm_t* realm) RLM_API bool realm_begin_write(realm_t* realm) { return wrap_err([&]() { - (*realm)->begin_write_transaction(); + (*realm)->begin_transaction(); return true; }); } diff --git a/src/realm/object-store/c_api/util.hpp b/src/realm/object-store/c_api/util.hpp index 2c0b002ffda..b6836de7af4 100644 --- a/src/realm/object-store/c_api/util.hpp +++ b/src/realm/object-store/c_api/util.hpp @@ -22,7 +22,7 @@ inline auto wrap_err(F&& f) -> decltype(std::declval()()) inline const ObjectSchema& schema_for_table(const std::shared_ptr& realm, TableKey table_key) { // Validate the table key. - realm->get_group().get_table(table_key); + realm->read_group().get_table(table_key); const auto& schema = realm->schema(); auto it = schema.find(table_key); @@ -71,7 +71,7 @@ inline void check_value_assignable(const List& list, Mixed val) { auto realm = list.get_realm(); auto table_key = list.get_parent_table_key(); - auto table = realm->get_group().get_table(table_key); + auto table = realm->read_group().get_table(table_key); auto col_key = list.get_parent_column_key(); return check_value_assignable(realm, *table, col_key, val); } diff --git a/src/realm/object-store/collection.cpp b/src/realm/object-store/collection.cpp index 0cb81274a49..bf18e6fb311 100644 --- a/src/realm/object-store/collection.cpp +++ b/src/realm/object-store/collection.cpp @@ -60,8 +60,8 @@ bool Collection::is_valid() const { if (!m_realm) return false; - m_realm->verify_is_on_thread(); - if (!m_realm->is_in_any_transaction()) + m_realm->verify_thread(); + if (!m_realm->is_in_read_transaction()) return false; return m_coll_base->is_attached(); } @@ -111,7 +111,7 @@ void Collection::verify_attached() const void Collection::verify_in_transaction() const { verify_attached(); - m_realm->verify_is_in_write_transaction(); + m_realm->verify_in_write(); } size_t Collection::size() const diff --git a/src/realm/object-store/impl/collection_notifier.cpp b/src/realm/object-store/impl/collection_notifier.cpp index 9cb8d3e3bda..18f142c4f60 100644 --- a/src/realm/object-store/impl/collection_notifier.cpp +++ b/src/realm/object-store/impl/collection_notifier.cpp @@ -200,7 +200,7 @@ void CollectionNotifier::release_data() noexcept uint64_t CollectionNotifier::add_callback(CollectionChangeCallback callback) { - m_realm->verify_is_on_thread(); + m_realm->verify_thread(); util::CheckedLockGuard lock(m_callback_mutex); auto token = m_next_token++; @@ -243,8 +243,8 @@ void CollectionNotifier::suppress_next_notification(uint64_t token) { std::lock_guard lock(m_realm_mutex); REALM_ASSERT(m_realm); - m_realm->verify_is_on_thread(); - m_realm->verify_is_in_write_transaction(); + m_realm->verify_thread(); + m_realm->verify_in_write(); } util::CheckedLockGuard lock(m_callback_mutex); diff --git a/src/realm/object-store/impl/realm_coordinator.cpp b/src/realm/object-store/impl/realm_coordinator.cpp index 8228f052ebf..8165229d437 100644 --- a/src/realm/object-store/impl/realm_coordinator.cpp +++ b/src/realm/object-store/impl/realm_coordinator.cpp @@ -149,7 +149,7 @@ void RealmCoordinator::set_config(const Realm::Config& config) throw std::logic_error("Realms opened in read-only mode do not use an initialization function"); if (config.schema && config.schema_version == ObjectStore::NotVersioned) throw std::logic_error("A schema version must be specified when the schema is specified"); - if (!config.realm_data.is_null() && (!config.is_immutable() || !config.is_in_memory)) + if (!config.realm_data.is_null() && (!config.immutable() || !config.in_memory)) throw std::logic_error( "In-memory realms initialized from memory buffers can only be opened in read-only mode"); if (!config.realm_data.is_null() && !config.path.empty()) @@ -168,11 +168,11 @@ void RealmCoordinator::set_config(const Realm::Config& config) m_config.scheduler = nullptr; } else { - if (m_config.is_immutable() != config.is_immutable()) { + if (m_config.immutable() != config.immutable()) { throw MismatchedConfigException("Realm at path '%1' already opened with different read permissions.", config.path); } - if (m_config.is_in_memory != config.is_in_memory) { + if (m_config.in_memory != config.in_memory) { throw MismatchedConfigException("Realm at path '%1' already opened with different inMemory settings.", config.path); } @@ -281,7 +281,7 @@ std::shared_ptr RealmCoordinator::get_realm(Realm::Config config, util::O set_config(config); if ((realm = do_get_cached_realm(config))) { if (version) { - REALM_ASSERT(realm->get_version_of_current_transaction() == version.value()); + REALM_ASSERT(realm->read_transaction_version() == version.value()); } return realm; } @@ -322,7 +322,7 @@ void RealmCoordinator::do_get_realm(Realm::Config config, std::shared_ptr config.schema = {}; realm = Realm::make_shared_realm(std::move(config), version, shared_from_this()); - if (!m_notifier && !m_config.is_immutable() && m_config.automatic_change_notifications) { + if (!m_notifier && !m_config.immutable() && m_config.automatic_change_notifications) { try { m_notifier = std::make_unique(*this); } @@ -454,7 +454,7 @@ void RealmCoordinator::open_db() bool server_synchronization_mode = m_config.sync_config || m_config.force_sync_history; try { - if (m_config.is_immutable()) { + if (m_config.immutable()) { if (m_config.realm_data.is_null()) { m_read_only_group = std::make_shared(m_config.path, m_config.encryption_key.data(), Group::mode_ReadOnly); @@ -478,7 +478,7 @@ void RealmCoordinator::open_db() } DBOptions options; - options.durability = m_config.is_in_memory ? DBOptions::Durability::MemOnly : DBOptions::Durability::Full; + options.durability = m_config.in_memory ? DBOptions::Durability::MemOnly : DBOptions::Durability::Full; if (!m_config.fifo_files_fallback_path.empty()) { options.temp_dir = util::normalize_dir(m_config.fifo_files_fallback_path); @@ -490,25 +490,25 @@ void RealmCoordinator::open_db() } catch (realm::FileFormatUpgradeRequired const&) { if (m_config.schema_mode != SchemaMode::ResetFile) { - translate_file_exception(m_config.path, m_config.is_immutable()); + translate_file_exception(m_config.path, m_config.immutable()); } util::File::remove(m_config.path); return open_db(); } catch (UnsupportedFileFormatVersion const&) { if (m_config.schema_mode != SchemaMode::ResetFile) { - translate_file_exception(m_config.path, m_config.is_immutable()); + translate_file_exception(m_config.path, m_config.immutable()); } util::File::remove(m_config.path); return open_db(); } #if REALM_ENABLE_SYNC catch (IncompatibleHistories const&) { - translate_file_exception(m_config.path, m_config.is_immutable()); // Throws + translate_file_exception(m_config.path, m_config.immutable()); // Throws } #endif // REALM_ENABLE_SYNC catch (...) { - translate_file_exception(m_config.path, m_config.is_immutable()); + translate_file_exception(m_config.path, m_config.immutable()); } if (!m_config.should_compact_on_launch_function) @@ -707,8 +707,8 @@ void RealmCoordinator::wake_up_notifier_worker() void RealmCoordinator::commit_write(Realm& realm) { - REALM_ASSERT(!m_config.is_immutable()); - REALM_ASSERT(realm.is_in_write_transaction()); + REALM_ASSERT(!m_config.immutable()); + REALM_ASSERT(realm.is_in_transaction()); Transaction& tr = Realm::Internal::get_transaction(realm); VersionID new_version; @@ -722,7 +722,7 @@ void RealmCoordinator::commit_write(Realm& realm) // The skip version must always be the notifier transaction's current // version plus one, as we can only skip a prefix and not intermediate // transactions. If we have a notifier for the current Realm, then we - // waited until it finished running in begin_write_transaction() and this + // waited until it finished running in begin_transaction() and this // invarient holds. If we don't have any notifiers then we don't need // to set the skip version, but more importantly *can't* because we // didn't block when starting the write and the notifier transaction @@ -1087,7 +1087,7 @@ void RealmCoordinator::advance_to_ready(Realm& realm) notifiers.package_and_wait(util::none); // FIXME: we probably won't actually want a strong pointer here - auto sg = Realm::Internal::get_transaction_reference(realm); + auto sg = Realm::Internal::get_transaction_ref(realm); if (notifiers) { auto version = notifiers.version(); if (version) { @@ -1131,7 +1131,7 @@ bool RealmCoordinator::advance_to_latest(Realm& realm) { // FIXME: we probably won't actually want a strong pointer here auto self = shared_from_this(); - auto sg = Realm::Internal::get_transaction_reference(realm); + auto sg = Realm::Internal::get_transaction_ref(realm); util::CheckedUniqueLock lock(m_notifier_mutex); _impl::NotifierPackage notifiers(m_async_error, notifiers_for_realm(realm), this); lock.unlock(); @@ -1149,20 +1149,20 @@ bool RealmCoordinator::advance_to_latest(Realm& realm) void RealmCoordinator::promote_to_write(Realm& realm) { - REALM_ASSERT(!realm.is_in_write_transaction()); + REALM_ASSERT(!realm.is_in_transaction()); util::CheckedUniqueLock lock(m_notifier_mutex); _impl::NotifierPackage notifiers(m_async_error, notifiers_for_realm(realm), this); lock.unlock(); // FIXME: we probably won't actually want a strong pointer here - auto tr = Realm::Internal::get_transaction_reference(realm); + auto tr = Realm::Internal::get_transaction_ref(realm); transaction::begin(tr, realm.m_binding_context.get(), notifiers); } void RealmCoordinator::process_available_async(Realm& realm) { - REALM_ASSERT(!realm.is_in_write_transaction()); + REALM_ASSERT(!realm.is_in_transaction()); util::CheckedUniqueLock lock(m_notifier_mutex); auto notifiers = notifiers_for_realm(realm); @@ -1180,7 +1180,7 @@ void RealmCoordinator::process_available_async(Realm& realm) return; } - bool in_read = realm.is_in_any_transaction(); + bool in_read = realm.is_in_read_transaction(); auto& sg = Realm::Internal::get_transaction(realm); auto version = sg.get_version_of_current_transaction(); auto package = [&](auto& notifier) { diff --git a/src/realm/object-store/impl/realm_coordinator.hpp b/src/realm/object-store/impl/realm_coordinator.hpp index fdbf65b5abd..354a245edf5 100644 --- a/src/realm/object-store/impl/realm_coordinator.hpp +++ b/src/realm/object-store/impl/realm_coordinator.hpp @@ -103,7 +103,7 @@ class RealmCoordinator : public std::enable_shared_from_this { } bool is_in_memory() const noexcept { - return m_config.is_in_memory; + return m_config.in_memory; } // Returns the number of versions in the Realm file. uint_fast64_t get_number_of_versions() const diff --git a/src/realm/object-store/impl/results_notifier.cpp b/src/realm/object-store/impl/results_notifier.cpp index e14fb4f122a..08c57e45267 100644 --- a/src/realm/object-store/impl/results_notifier.cpp +++ b/src/realm/object-store/impl/results_notifier.cpp @@ -207,8 +207,8 @@ bool ResultsNotifier::prepare_to_deliver() if (!m_handover_tv) { bool transaction_is_stale = m_delivered_transaction && - (!realm->is_in_any_transaction() || realm->get_version_of_current_transaction() > - m_delivered_transaction->get_version_of_current_transaction()); + (!realm->is_in_read_transaction() || + realm->read_transaction_version() > m_delivered_transaction->get_version_of_current_transaction()); if (transaction_is_stale) { m_delivered_tv.reset(); m_delivered_transaction.reset(); diff --git a/src/realm/object-store/impl/transact_log_handler.cpp b/src/realm/object-store/impl/transact_log_handler.cpp index 484e308a7a6..05a0557df83 100644 --- a/src/realm/object-store/impl/transact_log_handler.cpp +++ b/src/realm/object-store/impl/transact_log_handler.cpp @@ -69,7 +69,7 @@ KVOAdapter::KVOAdapter(std::vector& observers, Bi tables_needed.erase(std::unique(begin(tables_needed), end(tables_needed)), end(tables_needed)); auto realm = context->realm.lock(); - auto& group = realm->get_group(); + auto& group = realm->read_group(); for (auto& observer : observers) { auto table = group.get_table(TableKey(observer.table_key)); for (auto key : table->get_column_keys()) { diff --git a/src/realm/object-store/keypath_helpers.hpp b/src/realm/object-store/keypath_helpers.hpp index b2c4ef09176..b800094e65a 100644 --- a/src/realm/object-store/keypath_helpers.hpp +++ b/src/realm/object-store/keypath_helpers.hpp @@ -32,7 +32,7 @@ inline void populate_keypath_mapping(query_parser::KeyPathMapping& mapping, Real TableRef table; auto get_table = [&] { if (!table) - table = realm.get_group().get_table(object_schema.table_key); + table = realm.read_group().get_table(object_schema.table_key); return table; }; diff --git a/src/realm/object-store/object.cpp b/src/realm/object-store/object.cpp index 2cd2c2ec3bf..714f0274678 100644 --- a/src/realm/object-store/object.cpp +++ b/src/realm/object-store/object.cpp @@ -98,30 +98,30 @@ Object::Object(SharedRealm r, Obj const& o) , m_obj(o) { REALM_ASSERT(!m_obj.get_table() || - (&m_realm->get_group() == _impl::TableFriend::get_parent_group(*m_obj.get_table()))); + (&m_realm->read_group() == _impl::TableFriend::get_parent_group(*m_obj.get_table()))); } Object::Object(SharedRealm r, StringData object_type, ObjKey key) : m_realm(std::move(r)) , m_object_schema(&*m_realm->schema().find(object_type)) - , m_obj(m_realm->get_group().get_table(m_object_schema->table_key)->get_object(key)) + , m_obj(m_realm->read_group().get_table(m_object_schema->table_key)->get_object(key)) { REALM_ASSERT(!m_obj.get_table() || - (&m_realm->get_group() == _impl::TableFriend::get_parent_group(*m_obj.get_table()))); + (&m_realm->read_group() == _impl::TableFriend::get_parent_group(*m_obj.get_table()))); } Object::Object(SharedRealm r, StringData object_type, size_t index) : m_realm(std::move(r)) , m_object_schema(&*m_realm->schema().find(object_type)) - , m_obj(m_realm->get_group().get_table(m_object_schema->table_key)->get_object(index)) + , m_obj(m_realm->read_group().get_table(m_object_schema->table_key)->get_object(index)) { REALM_ASSERT(!m_obj.get_table() || - (&m_realm->get_group() == _impl::TableFriend::get_parent_group(*m_obj.get_table()))); + (&m_realm->read_group() == _impl::TableFriend::get_parent_group(*m_obj.get_table()))); } Object::Object(std::shared_ptr r, ObjLink link) : m_realm(std::move(r)) - , m_obj(m_realm->get_group().get_object(link)) + , m_obj(m_realm->read_group().get_object(link)) { m_object_schema = &*m_realm->schema().find(ObjectStore::object_type_for_table_name(m_obj.get_table()->get_name())); @@ -147,7 +147,7 @@ NotificationToken Object::add_notification_callback(CollectionChangeCallback cal void Object::verify_attached() const { - m_realm->verify_is_on_thread(); + m_realm->verify_thread(); if (!m_obj.is_valid()) { throw InvalidatedObjectException(m_object_schema->name); } @@ -165,7 +165,7 @@ Property const& Object::property_for_name(StringData prop_name) const void Object::validate_property_for_setter(Property const& property) const { verify_attached(); - m_realm->verify_is_in_write_transaction(); + m_realm->verify_in_write(); // Modifying primary keys is allowed in migrations to make it possible to // add a new primary key to a type (or change the property type), but it diff --git a/src/realm/object-store/object_accessor.hpp b/src/realm/object-store/object_accessor.hpp index c541163afbb..bd1887bfc8e 100644 --- a/src/realm/object-store/object_accessor.hpp +++ b/src/realm/object-store/object_accessor.hpp @@ -215,7 +215,7 @@ ValueType Object::get_property_value_impl(ContextType& ctx, const Property& prop case PropertyType::LinkingObjects: { auto target_object_schema = m_realm->schema().find(property.object_type); auto link_property = target_object_schema->property_for_name(property.link_origin_property_name); - auto table = m_realm->get_group().get_table(target_object_schema->table_key); + auto table = m_realm->read_group().get_table(target_object_schema->table_key); auto tv = const_cast(m_obj).get_backlink_view(table, ColKey(link_property->column_key)); return ctx.box(Results(m_realm, std::move(tv))); } @@ -247,7 +247,7 @@ template Object Object::create(ContextType& ctx, std::shared_ptr const& realm, ObjectSchema const& object_schema, ValueType value, CreatePolicy policy, ObjKey current_obj, Obj* out_row) { - realm->verify_is_in_write_transaction(); + realm->verify_in_write(); // When setting each property, we normally want to skip over the primary key // as that's set as part of object creation. However, during migrations the @@ -260,7 +260,7 @@ Object Object::create(ContextType& ctx, std::shared_ptr const& realm, Obj bool created = false; Obj obj; - auto table = realm->get_group().get_table(object_schema.table_key); + auto table = realm->read_group().get_table(object_schema.table_key); // If there's a primary key, we need to first check if an object with the // same primary key already exists. If it does, we either update that object @@ -369,7 +369,7 @@ Object Object::get_for_primary_key(ContextType& ctx, std::shared_ptr cons TableRef table; if (object_schema.table_key) - table = realm->get_group().get_table(object_schema.table_key); + table = realm->read_group().get_table(object_schema.table_key); if (!table) return Object(realm, object_schema, Obj()); if (ctx.is_null(primary_value) && !is_nullable(primary_prop->type)) diff --git a/src/realm/object-store/results.cpp b/src/realm/object-store/results.cpp index e17f5ebcb38..4a442b778ce 100644 --- a/src/realm/object-store/results.cpp +++ b/src/realm/object-store/results.cpp @@ -121,7 +121,7 @@ Results::Mode Results::get_mode() const noexcept bool Results::is_valid() const { if (m_realm) { - m_realm->verify_is_on_thread(); + m_realm->verify_thread(); } // Here we cannot just use if (m_table) as it combines a check if the @@ -146,7 +146,7 @@ void Results::validate_read() const void Results::validate_write() const { validate_read(); - if (!m_realm || !m_realm->is_in_write_transaction()) + if (!m_realm || !m_realm->is_in_transaction()) throw InvalidTransactionException("Must be in a write transaction"); } @@ -214,7 +214,7 @@ void Results::evaluate_sort_and_distinct_on_collection() // We can't use the sorted list from the notifier if we're in a write // transaction as we only check the transaction version to see if the data matches - if (m_notifier && m_notifier->get_list_indices(m_list_indices) && !m_realm->is_in_write_transaction()) + if (m_notifier && m_notifier->get_list_indices(m_list_indices) && !m_realm->is_in_transaction()) return; bool needs_update = m_collection->has_changed(); @@ -474,7 +474,7 @@ void Results::do_evaluate_query_if_needed(bool wants_notifications) if (m_update_policy == UpdatePolicy::Auto) m_table_view.sync_if_needed(); if (auto audit = m_realm->audit_context()) - audit->record_query(m_realm->get_version_of_current_transaction(), m_table_view); + audit->record_query(m_realm->read_transaction_version(), m_table_view); break; } } diff --git a/src/realm/object-store/shared_realm.cpp b/src/realm/object-store/shared_realm.cpp index 2b94989e099..55a49714209 100644 --- a/src/realm/object-store/shared_realm.cpp +++ b/src/realm/object-store/shared_realm.cpp @@ -73,29 +73,29 @@ Realm::~Realm() } } -Group& Realm::get_group() +Group& Realm::read_group() { - verify_is_open(); + verify_open(); if (!m_group) begin_read(m_frozen_version.value_or(VersionID{})); return *m_group; } -Transaction& Realm::get_transaction() +Transaction& Realm::transaction() { - REALM_ASSERT(!m_config.is_immutable()); - return static_cast(get_group()); + REALM_ASSERT(!m_config.immutable()); + return static_cast(read_group()); } -Transaction& Realm::get_transaction() const +Transaction& Realm::transaction() const { - REALM_ASSERT(!m_config.is_immutable()); - // FIXME: get_group() is not even remotly const - return static_cast(const_cast(this)->get_group()); + REALM_ASSERT(!m_config.immutable()); + // FIXME: read_group() is not even remotly const + return static_cast(const_cast(this)->read_group()); } -std::shared_ptr Realm::get_transaction_reference() +std::shared_ptr Realm::transaction_ref() { return std::static_pointer_cast(m_group); } @@ -103,11 +103,11 @@ std::shared_ptr Realm::get_transaction_reference() std::shared_ptr Realm::duplicate() const { VersionID version; - if (m_config.is_immutable()) { + if (m_config.immutable()) { version = get_current_version(); } else { - version = get_version_of_current_transaction(); + version = read_transaction_version(); } std::shared_ptr group = m_coordinator->begin_read(version, is_frozen()); std::shared_ptr transaction = std::static_pointer_cast(group); @@ -171,7 +171,7 @@ std::shared_ptr Realm::get_synchronized_realm(Config config) void Realm::set_schema(Schema const& reference, Schema schema) { - m_has_dynamic_schema = false; + m_dynamic_schema = false; schema.copy_keys_from(reference); m_schema = std::move(schema); notify_schema_changed(); @@ -179,7 +179,7 @@ void Realm::set_schema(Schema const& reference, Schema schema) void Realm::read_schema_from_group_if_needed() { - if (m_config.is_immutable()) { + if (m_config.immutable()) { REALM_ASSERT(m_group); if (m_schema.empty()) { m_schema_version = ObjectStore::get_schema_version(*m_group); @@ -188,8 +188,8 @@ void Realm::read_schema_from_group_if_needed() return; } - Group& group = get_group(); - auto current_version = get_transaction().get_version_of_current_transaction().version; + Group& group = read_group(); + auto current_version = transaction().get_version_of_current_transaction().version; if (m_schema_transaction_version == current_version) return; @@ -199,7 +199,7 @@ void Realm::read_schema_from_group_if_needed() if (m_coordinator) m_coordinator->cache_schema(schema, m_schema_version, m_schema_transaction_version); - if (m_has_dynamic_schema) { + if (m_dynamic_schema) { if (m_schema == schema) { // The structure of the schema hasn't changed. Bring the table column indices up to date. m_schema.copy_keys_from(schema); @@ -226,8 +226,8 @@ bool Realm::reset_file(Schema& schema, std::vector& required_chang m_coordinator->close(); util::File::remove(m_config.path); - m_schema = ObjectStore::schema_from_group(get_group()); - m_schema_version = ObjectStore::get_schema_version(get_group()); + m_schema = ObjectStore::schema_from_group(read_group()); + m_schema_version = ObjectStore::get_schema_version(read_group()); required_changes = m_schema.compare(schema); m_coordinator->clear_schema_cache_and_set_schema_version(m_schema_version); return false; @@ -283,31 +283,31 @@ bool Realm::schema_change_needs_write_transaction(Schema& schema, std::vectorget_cached_schema(actual_schema, actual_version, version); - if (!got_cached || version != get_transaction().get_version_of_current_transaction().version) - return ObjectStore::schema_from_group(get_group()); + if (!got_cached || version != transaction().get_version_of_current_transaction().version) + return ObjectStore::schema_from_group(read_group()); return actual_schema; } void Realm::set_schema_subset(Schema schema) { - REALM_ASSERT(m_has_dynamic_schema); + REALM_ASSERT(m_dynamic_schema); REALM_ASSERT(m_schema_version != ObjectStore::NotVersioned); std::vector changes = m_schema.compare(schema); @@ -348,7 +348,7 @@ void Realm::update_schema(Schema schema, uint64_t version, MigrationFunction mig schema.validate(validation_mode); - bool was_in_read_transaction = is_in_any_transaction(); + bool was_in_read_transaction = is_in_read_transaction(); Schema actual_schema = get_full_schema(); std::vector required_changes = actual_schema.compare(schema); @@ -363,14 +363,14 @@ void Realm::update_schema(Schema schema, uint64_t version, MigrationFunction mig // Cancel the write transaction if we exit this function before committing it auto cleanup = util::make_scope_exit([&]() noexcept { // When in_transaction is true, caller is responsible to cancel the transaction. - if (!in_transaction && is_in_write_transaction()) + if (!in_transaction && is_in_transaction()) cancel_transaction(); if (!was_in_read_transaction) m_group = nullptr; }); if (!in_transaction) { - get_transaction().promote_to_write(); + transaction().promote_to_write(); // Beginning the write transaction may have advanced the version and left // us with nothing to do if someone else initialized the schema on disk @@ -404,26 +404,26 @@ void Realm::update_schema(Schema schema, uint64_t version, MigrationFunction mig // migration function needs to see the target schema on the "new" Realm std::swap(m_schema, schema); std::swap(m_schema_version, version); - m_is_in_migration = true; + m_in_migration = true; auto restore = util::make_scope_exit([&]() noexcept { std::swap(m_schema, schema); std::swap(m_schema_version, version); - m_is_in_migration = false; + m_in_migration = false; }); - ObjectStore::apply_schema_changes(get_transaction(), version, m_schema, m_schema_version, - m_config.schema_mode, required_changes, wrapper); + ObjectStore::apply_schema_changes(transaction(), version, m_schema, m_schema_version, m_config.schema_mode, + required_changes, wrapper); } else { - ObjectStore::apply_schema_changes(get_transaction(), m_schema_version, schema, version, m_config.schema_mode, + ObjectStore::apply_schema_changes(transaction(), m_schema_version, schema, version, m_config.schema_mode, required_changes); REALM_ASSERT_DEBUG(additive || - (required_changes = ObjectStore::schema_from_group(get_group()).compare(schema)).empty()); + (required_changes = ObjectStore::schema_from_group(read_group()).compare(schema)).empty()); } if (initialization_function && old_schema_version == ObjectStore::NotVersioned) { // Initialization function needs to see the latest schema - uint64_t temp_version = ObjectStore::get_schema_version(get_group()); + uint64_t temp_version = ObjectStore::get_schema_version(read_group()); std::swap(m_schema, schema); std::swap(m_schema_version, temp_version); auto restore = util::make_scope_exit([&]() noexcept { @@ -434,9 +434,9 @@ void Realm::update_schema(Schema schema, uint64_t version, MigrationFunction mig } m_schema = std::move(schema); - m_new_schema = ObjectStore::schema_from_group(get_group()); - m_schema_version = ObjectStore::get_schema_version(get_group()); - m_has_dynamic_schema = false; + m_new_schema = ObjectStore::schema_from_group(read_group()); + m_schema_version = ObjectStore::get_schema_version(read_group()); + m_dynamic_schema = false; m_coordinator->clear_schema_cache_and_set_schema_version(version); if (!in_transaction) { @@ -449,12 +449,12 @@ void Realm::update_schema(Schema schema, uint64_t version, MigrationFunction mig void Realm::add_schema_change_handler() { - if (m_config.is_immutable()) + if (m_config.immutable()) return; m_group->set_schema_change_notification_handler([&] { - m_new_schema = ObjectStore::schema_from_group(get_group()); - m_schema_version = ObjectStore::get_schema_version(get_group()); - if (m_has_dynamic_schema) { + m_new_schema = ObjectStore::schema_from_group(read_group()); + m_schema_version = ObjectStore::get_schema_version(read_group()); + if (m_dynamic_schema) { m_schema = *m_new_schema; } else @@ -467,7 +467,7 @@ void Realm::add_schema_change_handler() void Realm::cache_new_schema() { if (!is_closed()) { - auto new_version = get_transaction().get_version_of_current_transaction().version; + auto new_version = transaction().get_version_of_current_transaction().version; if (m_new_schema) m_coordinator->cache_schema(std::move(*m_new_schema), m_schema_version, new_version); else @@ -496,20 +496,20 @@ void Realm::notify_schema_changed() } } -static void verify_can_create_any_transaction(const Realm* realm) +static void check_can_create_any_transaction(const Realm* realm) { - if (realm->config().is_immutable()) { - throw InvalidTransactionException("Can't perform any transactions on read-only Realms."); + if (realm->config().immutable()) { + throw InvalidTransactionException("Can't perform transactions on read-only Realms."); } } -static void verify_can_create_write_transaction(const Realm* realm) +static void check_can_create_write_transaction(const Realm* realm) { - if (realm->config().is_immutable() || realm->config().is_read_only_alternative()) { - throw InvalidTransactionException("Can't perform write transactions on read-only Realms."); + if (realm->config().immutable() || realm->config().read_only_alternative()) { + throw InvalidTransactionException("Can't perform transactions on read-only Realms."); } if (realm->is_frozen()) { - throw InvalidTransactionException("Can't perform write transactions on a frozen Realm."); + throw InvalidTransactionException("Can't perform transactions on a frozen Realm"); } if (!realm->is_closed() && realm->get_number_of_versions() > realm->config().max_number_of_active_versions) { throw InvalidTransactionException( @@ -518,20 +518,20 @@ static void verify_can_create_write_transaction(const Realm* realm) } } -void Realm::verify_is_on_thread() const +void Realm::verify_thread() const { if (m_scheduler && !m_scheduler->is_on_thread()) throw IncorrectThreadException(); } -void Realm::verify_is_in_write_transaction() const +void Realm::verify_in_write() const { - if (!is_in_write_transaction()) { + if (!is_in_transaction()) { throw InvalidTransactionException("Cannot modify managed objects outside of a write transaction."); } } -void Realm::verify_is_open() const +void Realm::verify_open() const { if (is_closed()) { throw ClosedRealmException(); @@ -546,12 +546,12 @@ bool Realm::verify_notifications_available(bool throw_on_error) const "Notifications are not available on frozen lists since they do not change."); return false; } - if (config().is_immutable()) { + if (config().immutable()) { if (throw_on_error) throw InvalidTransactionException("Cannot create asynchronous query for immutable Realms"); return false; } - if (is_in_write_transaction()) { + if (is_in_transaction()) { if (throw_on_error) throw InvalidTransactionException("Cannot create asynchronous query while in a write transaction"); return false; @@ -562,29 +562,29 @@ bool Realm::verify_notifications_available(bool throw_on_error) const VersionID Realm::get_current_version() const { - verify_is_on_thread(); - verify_is_open(); + verify_thread(); + verify_open(); if (!m_group) { throw InvalidTransactionException("Cannot retrieve a version without a group."); } return m_group->get_current_version(); } -VersionID Realm::get_version_of_current_transaction() const +VersionID Realm::read_transaction_version() const { - verify_is_on_thread(); - verify_is_open(); - if (!is_in_any_transaction()) { + verify_thread(); + verify_open(); + if (!is_in_read_transaction()) { throw InvalidTransactionException("Cannot retrieve a transaction version without a transaction."); } return static_cast(*m_group).get_version_of_current_transaction(); } -util::Optional Realm::get_version_of_current_or_frozen_transaction() const +util::Optional Realm::current_transaction_version() const { util::Optional current_transaction_version; if (m_group) { - current_transaction_version = get_version_of_current_transaction(); + current_transaction_version = read_transaction_version(); } else if (m_frozen_version) { current_transaction_version = m_frozen_version; @@ -594,19 +594,19 @@ util::Optional Realm::get_version_of_current_or_frozen_transaction() uint_fast64_t Realm::get_number_of_versions() const { - verify_is_open(); - verify_can_create_any_transaction(this); + verify_open(); + check_can_create_any_transaction(this); return m_coordinator->get_number_of_versions(); } -bool Realm::is_in_any_transaction() const noexcept +bool Realm::is_in_read_transaction() const noexcept { - return !m_config.is_immutable() && !is_closed() && m_group; + return !m_config.immutable() && !is_closed() && m_group; } -bool Realm::is_in_write_transaction() const noexcept +bool Realm::is_in_transaction() const noexcept { - return is_in_any_transaction() && get_transaction().get_transact_stage() == DB::transact_Writing; + return is_in_read_transaction() && transaction().get_transact_stage() == DB::transact_Writing; } bool Realm::has_group() const noexcept @@ -619,12 +619,12 @@ void Realm::enable_wait_for_change() m_coordinator->enable_wait_for_change(); } -bool Realm::should_wait_for_change() +bool Realm::wait_for_change() { if (m_frozen_version) { return false; } - return m_group ? m_coordinator->wait_for_change(get_transaction_reference()) : false; + return m_group ? m_coordinator->wait_for_change(transaction_ref()) : false; } void Realm::wait_for_change_release() @@ -632,12 +632,12 @@ void Realm::wait_for_change_release() m_coordinator->wait_for_change_release(); } -void Realm::begin_write_transaction() +void Realm::begin_transaction() { - verify_is_on_thread(); - verify_can_create_write_transaction(this); + verify_thread(); + check_can_create_write_transaction(this); - if (is_in_write_transaction()) { + if (is_in_transaction()) { throw InvalidTransactionException("The Realm is already in a write transaction"); } @@ -651,12 +651,12 @@ void Realm::begin_write_transaction() // state, but that's unavoidable. if (m_is_sending_notifications) { _impl::NotifierPackage notifiers; - transaction::begin(get_transaction_reference(), m_binding_context.get(), notifiers); + transaction::begin(transaction_ref(), m_binding_context.get(), notifiers); return; } // make sure we have a read transaction - get_group(); + read_group(); m_is_sending_notifications = true; auto cleanup = util::make_scope_exit([this]() noexcept { @@ -674,17 +674,17 @@ void Realm::begin_write_transaction() void Realm::commit_transaction() { - verify_can_create_write_transaction(this); - verify_is_on_thread(); + check_can_create_write_transaction(this); + verify_thread(); - if (!is_in_write_transaction()) { + if (!is_in_transaction()) { throw InvalidTransactionException("Can't commit a non-existing write transaction"); } if (auto audit = audit_context()) { - auto prev_version = get_transaction().get_version_of_current_transaction(); + auto prev_version = transaction().get_version_of_current_transaction(); m_coordinator->commit_write(*this); - audit->record_write(prev_version, get_transaction().get_version_of_current_transaction()); + audit->record_write(prev_version, transaction().get_version_of_current_transaction()); // m_shared_group->unpin_version(prev_version); } else { @@ -695,27 +695,27 @@ void Realm::commit_transaction() void Realm::cancel_transaction() { - verify_can_create_write_transaction(this); - verify_is_on_thread(); + check_can_create_write_transaction(this); + verify_thread(); - if (!is_in_write_transaction()) { + if (!is_in_transaction()) { throw InvalidTransactionException("Can't cancel a non-existing write transaction"); } - transaction::cancel(get_transaction(), m_binding_context.get()); + transaction::cancel(transaction(), m_binding_context.get()); } void Realm::invalidate() { - verify_is_open(); - verify_is_on_thread(); - verify_can_create_any_transaction(this); + verify_open(); + verify_thread(); + check_can_create_any_transaction(this); if (m_is_sending_notifications) { return; } - if (is_in_write_transaction()) { + if (is_in_transaction()) { cancel_transaction(); } @@ -724,17 +724,17 @@ void Realm::invalidate() bool Realm::compact() { - verify_is_on_thread(); - verify_is_open(); + verify_thread(); + verify_open(); - if (m_config.is_immutable() || m_config.is_read_only_alternative()) { + if (m_config.immutable() || m_config.read_only_alternative()) { throw InvalidTransactionException("Can't compact a read-only Realm"); } - if (is_in_write_transaction()) { + if (is_in_transaction()) { throw InvalidTransactionException("Can't compact a Realm within a write transaction"); } - verify_is_open(); + verify_open(); m_group = nullptr; return m_coordinator->compact(); } @@ -744,9 +744,9 @@ void Realm::write_copy(StringData path, BinaryData key) if (key.data() && key.size() != 64) { throw InvalidEncryptionKeyException(); } - verify_is_on_thread(); + verify_thread(); try { - get_group().write(path, key.data()); + read_group().write(path, key.data()); } catch (...) { _impl::translate_file_exception(path); @@ -755,8 +755,8 @@ void Realm::write_copy(StringData path, BinaryData key) OwnedBinaryData Realm::write_copy() { - verify_is_on_thread(); - BinaryData buffer = get_group().write_to_mem(); + verify_thread(); + BinaryData buffer = read_group().write_to_mem(); // Since OwnedBinaryData does not have a constructor directly taking // ownership of BinaryData, we have to do this to avoid copying the buffer @@ -765,11 +765,11 @@ OwnedBinaryData Realm::write_copy() void Realm::notify() { - if (is_closed() || is_in_write_transaction() || is_frozen()) { + if (is_closed() || is_in_transaction() || is_frozen()) { return; } - verify_is_on_thread(); + verify_thread(); // Any of the callbacks to user code below could drop the last remaining // strong reference to `this` @@ -777,7 +777,7 @@ void Realm::notify() if (m_binding_context) { m_binding_context->before_notify(); - if (is_closed() || is_in_write_transaction()) { + if (is_closed() || is_in_transaction()) { return; } } @@ -825,8 +825,8 @@ void Realm::notify() bool Realm::refresh() { - verify_is_on_thread(); - verify_can_create_any_transaction(this); + verify_thread(); + check_can_create_any_transaction(this); return do_refresh(); } @@ -838,7 +838,7 @@ bool Realm::do_refresh() } // can't be any new changes if we're in a write transaction - if (is_in_write_transaction()) { + if (is_in_transaction()) { return false; } // don't advance if we're already in the process of advancing as that just @@ -873,7 +873,7 @@ bool Realm::do_refresh() } // No current read transaction, so just create a new one - get_group(); + read_group(); m_coordinator->process_available_async(*this); return true; } @@ -889,7 +889,7 @@ void Realm::set_auto_refresh(bool auto_refresh) bool Realm::can_deliver_notifications() const noexcept { - if (m_config.is_immutable() || !m_config.automatic_change_notifications) { + if (m_config.immutable() || !m_config.automatic_change_notifications) { return false; } @@ -905,7 +905,7 @@ uint64_t Realm::get_schema_version(const Realm::Config& config) auto coordinator = RealmCoordinator::get_coordinator(config.path); auto version = coordinator->get_schema_version(); if (version == ObjectStore::NotVersioned) - version = ObjectStore::get_schema_version(coordinator->get_realm(config, util::none)->get_group()); + version = ObjectStore::get_schema_version(coordinator->get_realm(config, util::none)->read_group()); return version; } @@ -920,7 +920,7 @@ bool Realm::is_frozen() const SharedRealm Realm::freeze() { auto config = m_config; - auto version = get_version_of_current_transaction(); + auto version = read_transaction_version(); config.scheduler = util::Scheduler::get_frozen(version); return Realm::get_frozen_realm(std::move(config), version); } @@ -930,8 +930,8 @@ void Realm::close() if (m_coordinator) { m_coordinator->unregister_realm(this); } - if (!m_config.is_immutable() && m_group) { - get_transaction().close(); + if (!m_config.immutable() && m_group) { + transaction().close(); } m_group = nullptr; diff --git a/src/realm/object-store/shared_realm.hpp b/src/realm/object-store/shared_realm.hpp index b3984b3b80f..f2b1edd0138 100644 --- a/src/realm/object-store/shared_realm.hpp +++ b/src/realm/object-store/shared_realm.hpp @@ -179,7 +179,7 @@ class Realm : public std::enable_shared_from_this { // In order to work around this, a separate path can be specified for these files. std::string fifo_files_fallback_path; - bool is_in_memory = false; + bool in_memory = false; SchemaMode schema_mode = SchemaMode::Automatic; // Optional schema for the file. @@ -204,12 +204,12 @@ class Realm : public std::enable_shared_from_this { ShouldCompactOnLaunchFunction should_compact_on_launch_function; // WARNING: The original read_only() has been renamed to immutable(). - bool is_immutable() const + bool immutable() const { return schema_mode == SchemaMode::Immutable; } // FIXME: Rename this to read_only(). - bool is_read_only_alternative() const + bool read_only_alternative() const { return schema_mode == SchemaMode::ReadOnlyAlternative; } @@ -298,13 +298,13 @@ class Realm : public std::enable_shared_from_this { return m_schema_version; } - void begin_write_transaction(); + void begin_transaction(); void commit_transaction(); void cancel_transaction(); // Returns `true`, if `m_group` is set and mutable (which means it is actually a transaction). - bool is_in_any_transaction() const noexcept; + bool is_in_read_transaction() const noexcept; // Returns `true` if `m_group` is set, mutable and in the `DB::transact_Writing` stage. - bool is_in_write_transaction() const noexcept; + bool is_in_transaction() const noexcept; // Returns a frozen copy for the current version of this Realm SharedRealm freeze(); @@ -321,30 +321,30 @@ class Realm : public std::enable_shared_from_this { uint_fast64_t get_number_of_versions() const; // Returns the current version for `m_group`. - // This is only relevant for read-only realms since they cannot `use get_version_of_current_transaction()` + // This is only relevant for read-only realms since they cannot `use read_transaction_version()` // or `get_version_of_current_or_frozen_transaction()` for which a transaction is required. VersionID get_current_version() const; // Returns the current version of `m_group` (if it is a transaction). // Caution: crashes for read-only realms since they don't have a transaction. - VersionID get_version_of_current_transaction() const; + VersionID read_transaction_version() const; // Returns the version of the current read or frozen transaction, `null` otherwise. // This is only used in tests. - util::Optional get_version_of_current_or_frozen_transaction() const; + util::Optional current_transaction_version() const; // Returns `m_group`. - Group& get_group(); + Group& read_group(); // Returns `true` if `m_group` is set, `false` otherwise. bool has_group() const noexcept; TransactionRef duplicate() const; void enable_wait_for_change(); - bool should_wait_for_change(); + bool wait_for_change(); void wait_for_change_release(); bool is_in_migration() const noexcept { - return m_is_in_migration; + return m_in_migration; } bool refresh(); @@ -363,9 +363,9 @@ class Realm : public std::enable_shared_from_this { void write_copy(StringData path, BinaryData encryption_key); OwnedBinaryData write_copy(); - void verify_is_on_thread() const; - void verify_is_in_write_transaction() const; - void verify_is_open() const; + void verify_thread() const; + void verify_in_write() const; + void verify_open() const; bool verify_notifications_available(bool throw_on_error = true) const; bool can_deliver_notifications() const noexcept; @@ -397,14 +397,14 @@ class Realm : public std::enable_shared_from_this { { // Read-only realms only have a group but no transaction. The group still supports `import_copy_of(..)` // though. - if (m_config.is_immutable()) { - Transaction& transaction = static_cast(const_cast(this)->get_group()); + if (m_config.immutable()) { + Transaction& transaction = static_cast(const_cast(this)->read_group()); auto copy = transaction.import_copy_of(std::forward(args)...); return copy; } else { - Transaction& transaction = get_transaction(); - auto copy = transaction.import_copy_of(std::forward(args)...); + Transaction& transactionRef = transaction(); + auto copy = transactionRef.import_copy_of(std::forward(args)...); return copy; } } @@ -426,11 +426,11 @@ class Realm : public std::enable_shared_from_this { static Transaction& get_transaction(Realm& realm) { - return realm.get_transaction(); + return realm.transaction(); } - static std::shared_ptr get_transaction_reference(Realm& realm) + static std::shared_ptr get_transaction_ref(Realm& realm) { - return realm.get_transaction_reference(); + return realm.transaction_ref(); } // CollectionNotifier needs to be able to access the owning @@ -465,7 +465,7 @@ class Realm : public std::enable_shared_from_this { // FIXME: this should be a Dynamic schema mode instead, but only once // that's actually fully working - bool m_has_dynamic_schema = true; + bool m_dynamic_schema = true; // True while sending the notifications caused by advancing the read // transaction version, to avoid recursive notifications where possible @@ -474,7 +474,7 @@ class Realm : public std::enable_shared_from_this { // True while we're performing a schema migration via this Realm instance // to allow for different behavior (such as allowing modifications to // primary key values) - bool m_is_in_migration = false; + bool m_in_migration = false; void begin_read(VersionID); bool do_refresh(); @@ -493,9 +493,9 @@ class Realm : public std::enable_shared_from_this { void translate_schema_error(); void notify_schema_changed(); - Transaction& get_transaction(); - Transaction& get_transaction() const; - std::shared_ptr get_transaction_reference(); + Transaction& transaction(); + Transaction& transaction() const; + std::shared_ptr transaction_ref(); public: std::unique_ptr m_binding_context; diff --git a/src/realm/object-store/sync/impl/sync_metadata.cpp b/src/realm/object-store/sync/impl/sync_metadata.cpp index 15e9e2c94a0..e8b8a5d84eb 100644 --- a/src/realm/object-store/sync/impl/sync_metadata.cpp +++ b/src/realm/object-store/sync/impl/sync_metadata.cpp @@ -199,9 +199,9 @@ SyncMetadataManager::SyncMetadataManager(std::string path, bool should_encrypt, m_metadata_config = std::move(config); m_client_uuid = [&]() -> std::string { - TableRef table = ObjectStore::table_for_object_type(realm->get_group(), c_sync_clientMetadata); + TableRef table = ObjectStore::table_for_object_type(realm->read_group(), c_sync_clientMetadata); if (table->is_empty()) { - realm->begin_write_transaction(); + realm->begin_transaction(); if (table->is_empty()) { auto uuid = util::uuid_string(); table->create_object().set(m_client_schema.idx_uuid, uuid); @@ -227,7 +227,7 @@ SyncUserMetadataResults SyncMetadataManager::all_users_marked_for_removal() cons SyncUserMetadataResults SyncMetadataManager::get_users(bool marked) const { auto realm = get_realm(); - TableRef table = ObjectStore::table_for_object_type(realm->get_group(), c_sync_userMetadata); + TableRef table = ObjectStore::table_for_object_type(realm->read_group(), c_sync_userMetadata); Query query = table->where().equal(m_user_schema.idx_marked_for_removal, marked); Results results(realm, std::move(query)); @@ -237,7 +237,7 @@ SyncUserMetadataResults SyncMetadataManager::get_users(bool marked) const util::Optional SyncMetadataManager::get_current_user_identity() const { auto realm = get_realm(); - TableRef table = ObjectStore::table_for_object_type(realm->get_group(), c_sync_current_user_identity); + TableRef table = ObjectStore::table_for_object_type(realm->read_group(), c_sync_current_user_identity); if (!table->is_empty()) { auto first = table->begin(); @@ -250,7 +250,7 @@ util::Optional SyncMetadataManager::get_current_user_identity() con SyncFileActionMetadataResults SyncMetadataManager::all_pending_actions() const { auto realm = get_realm(); - TableRef table = ObjectStore::table_for_object_type(realm->get_group(), c_sync_fileActionMetadata); + TableRef table = ObjectStore::table_for_object_type(realm->read_group(), c_sync_fileActionMetadata); Results results(realm, table->where()); return SyncFileActionMetadataResults(std::move(results), std::move(realm), m_file_action_schema); } @@ -259,10 +259,10 @@ void SyncMetadataManager::set_current_user_identity(const std::string& identity) { auto realm = get_realm(); - realm->begin_write_transaction(); + realm->begin_transaction(); TableRef currentUserIdentityTable = - ObjectStore::table_for_object_type(realm->get_group(), c_sync_current_user_identity); + ObjectStore::table_for_object_type(realm->read_group(), c_sync_current_user_identity); Obj currentUserIdentityObj; if (currentUserIdentityTable->is_empty()) @@ -283,7 +283,7 @@ util::Optional SyncMetadataManager::get_or_make_user_metadata( auto& schema = m_user_schema; // Retrieve or create the row for this object. - TableRef table = ObjectStore::table_for_object_type(realm->get_group(), c_sync_userMetadata); + TableRef table = ObjectStore::table_for_object_type(realm->read_group(), c_sync_userMetadata); Query query = table->where() .equal(schema.idx_identity, StringData(identity)) .equal(schema.idx_provider_type, StringData(provider_type)); @@ -295,13 +295,13 @@ util::Optional SyncMetadataManager::get_or_make_user_metadata( if (!make_if_absent) return none; - realm->begin_write_transaction(); + realm->begin_transaction(); // Check the results again. row = results.first(); if (!row) { // Because "making this user" is our last action, set this new user as the current user TableRef currentUserIdentityTable = - ObjectStore::table_for_object_type(realm->get_group(), c_sync_current_user_identity); + ObjectStore::table_for_object_type(realm->read_group(), c_sync_current_user_identity); Obj currentUserIdentityObj; if (currentUserIdentityTable->is_empty()) @@ -347,7 +347,7 @@ util::Optional SyncMetadataManager::get_or_make_user_metadata( if (row->get(schema.idx_marked_for_removal)) { // User is dead. Revive or return none. if (make_if_absent) { - realm->begin_write_transaction(); + realm->begin_transaction(); row->set(schema.idx_marked_for_removal, false); realm->commit_transaction(); } @@ -390,7 +390,7 @@ util::Optional SyncMetadataManager::get_file_action_meta { auto realm = get_realm(); auto& schema = m_file_action_schema; - TableRef table = ObjectStore::table_for_object_type(realm->get_group(), c_sync_fileActionMetadata); + TableRef table = ObjectStore::table_for_object_type(realm->read_group(), c_sync_fileActionMetadata); auto row_idx = table->find_first_string(schema.idx_original_name, original_name); if (!row_idx) return none; @@ -418,9 +418,9 @@ void SyncMetadataManager::set_app_metadata(const std::string& deployment_model, auto realm = get_realm(); auto& schema = m_app_metadata_schema; - realm->begin_write_transaction(); + realm->begin_transaction(); - auto table = ObjectStore::table_for_object_type(realm->get_group(), c_sync_app_metadata); + auto table = ObjectStore::table_for_object_type(realm->read_group(), c_sync_app_metadata); auto obj = table->create_object_with_primary_key(app_metadata_pk); obj.set(schema.idx_deployment_model, deployment_model); obj.set(schema.idx_location, location); @@ -434,7 +434,7 @@ util::Optional SyncMetadataManager::get_app_metadata() { if (!m_app_metadata) { auto realm = get_realm(); - auto table = ObjectStore::table_for_object_type(realm->get_group(), c_sync_app_metadata); + auto table = ObjectStore::table_for_object_type(realm->read_group(), c_sync_app_metadata); if (!table->size()) return util::none; @@ -460,7 +460,7 @@ SyncUserMetadata::SyncUserMetadata(Schema schema, SharedRealm realm, const Obj& std::string SyncUserMetadata::identity() const { REALM_ASSERT(m_realm); - m_realm->verify_is_on_thread(); + m_realm->verify_thread(); m_realm->refresh(); return m_obj.get(m_schema.idx_identity); } @@ -468,7 +468,7 @@ std::string SyncUserMetadata::identity() const SyncUser::State SyncUserMetadata::state() const { REALM_ASSERT(m_realm); - m_realm->verify_is_on_thread(); + m_realm->verify_thread(); m_realm->refresh(); return SyncUser::State(m_obj.get(m_schema.idx_state)); } @@ -476,7 +476,7 @@ SyncUser::State SyncUserMetadata::state() const std::string SyncUserMetadata::local_uuid() const { REALM_ASSERT(m_realm); - m_realm->verify_is_on_thread(); + m_realm->verify_thread(); m_realm->refresh(); return m_obj.get(m_schema.idx_local_uuid); } @@ -484,7 +484,7 @@ std::string SyncUserMetadata::local_uuid() const std::string SyncUserMetadata::refresh_token() const { REALM_ASSERT(m_realm); - m_realm->verify_is_on_thread(); + m_realm->verify_thread(); m_realm->refresh(); StringData result = m_obj.get(m_schema.idx_refresh_token); return result.is_null() ? "" : std::string(result); @@ -493,7 +493,7 @@ std::string SyncUserMetadata::refresh_token() const std::string SyncUserMetadata::access_token() const { REALM_ASSERT(m_realm); - m_realm->verify_is_on_thread(); + m_realm->verify_thread(); StringData result = m_obj.get(m_schema.idx_access_token); return result.is_null() ? "" : std::string(result); } @@ -501,7 +501,7 @@ std::string SyncUserMetadata::access_token() const std::string SyncUserMetadata::device_id() const { REALM_ASSERT(m_realm); - m_realm->verify_is_on_thread(); + m_realm->verify_thread(); StringData result = m_obj.get(m_schema.idx_device_id); return result.is_null() ? "" : std::string(result); } @@ -514,7 +514,7 @@ inline SyncUserIdentity user_identity_from_obj(const Obj& obj) std::vector SyncUserMetadata::identities() const { REALM_ASSERT(m_realm); - m_realm->verify_is_on_thread(); + m_realm->verify_thread(); m_realm->refresh(); auto linklist = m_obj.get_linklist(m_schema.idx_identities); @@ -531,7 +531,7 @@ std::vector SyncUserMetadata::identities() const std::string SyncUserMetadata::provider_type() const { REALM_ASSERT(m_realm); - m_realm->verify_is_on_thread(); + m_realm->verify_thread(); m_realm->refresh(); return m_obj.get(m_schema.idx_provider_type); } @@ -542,8 +542,8 @@ void SyncUserMetadata::set_refresh_token(const std::string& refresh_token) return; REALM_ASSERT_DEBUG(m_realm); - m_realm->verify_is_on_thread(); - m_realm->begin_write_transaction(); + m_realm->verify_thread(); + m_realm->begin_transaction(); m_obj.set(m_schema.idx_refresh_token, refresh_token); m_realm->commit_transaction(); } @@ -554,8 +554,8 @@ void SyncUserMetadata::set_state(SyncUser::State state) return; REALM_ASSERT_DEBUG(m_realm); - m_realm->verify_is_on_thread(); - m_realm->begin_write_transaction(); + m_realm->verify_thread(); + m_realm->begin_transaction(); m_obj.set(m_schema.idx_state, (int64_t)state); m_realm->commit_transaction(); } @@ -566,8 +566,8 @@ void SyncUserMetadata::set_identities(std::vector identities) return; REALM_ASSERT_DEBUG(m_realm); - m_realm->verify_is_on_thread(); - m_realm->begin_write_transaction(); + m_realm->verify_thread(); + m_realm->begin_transaction(); auto link_list = m_obj.get_linklist(m_schema.idx_identities); @@ -589,8 +589,8 @@ void SyncUserMetadata::set_access_token(const std::string& user_token) return; REALM_ASSERT_DEBUG(m_realm); - m_realm->verify_is_on_thread(); - m_realm->begin_write_transaction(); + m_realm->verify_thread(); + m_realm->begin_transaction(); m_obj.set(m_schema.idx_access_token, user_token); m_realm->commit_transaction(); } @@ -601,8 +601,8 @@ void SyncUserMetadata::set_device_id(const std::string& device_id) return; REALM_ASSERT_DEBUG(m_realm); - m_realm->verify_is_on_thread(); - m_realm->begin_write_transaction(); + m_realm->verify_thread(); + m_realm->begin_transaction(); m_obj.set(m_schema.idx_device_id, device_id); m_realm->commit_transaction(); } @@ -613,8 +613,8 @@ void SyncUserMetadata::set_user_profile(const SyncUserProfile& profile) return; REALM_ASSERT_DEBUG(m_realm); - m_realm->verify_is_on_thread(); - m_realm->begin_write_transaction(); + m_realm->verify_thread(); + m_realm->begin_transaction(); Obj obj; if (m_obj.is_null(m_schema.idx_profile)) { @@ -651,8 +651,8 @@ void SyncUserMetadata::mark_for_removal() if (m_invalid) return; - m_realm->verify_is_on_thread(); - m_realm->begin_write_transaction(); + m_realm->verify_thread(); + m_realm->begin_transaction(); m_obj.set(m_schema.idx_marked_for_removal, true); m_realm->commit_transaction(); } @@ -660,7 +660,7 @@ void SyncUserMetadata::mark_for_removal() void SyncUserMetadata::remove() { m_invalid = true; - m_realm->begin_write_transaction(); + m_realm->begin_transaction(); m_obj.remove(); m_realm->commit_transaction(); m_realm = nullptr; @@ -678,7 +678,7 @@ SyncFileActionMetadata::SyncFileActionMetadata(Schema schema, SharedRealm realm, std::string SyncFileActionMetadata::original_name() const { REALM_ASSERT(m_realm); - m_realm->verify_is_on_thread(); + m_realm->verify_thread(); m_realm->refresh(); return m_obj.get(m_schema.idx_original_name); } @@ -686,7 +686,7 @@ std::string SyncFileActionMetadata::original_name() const util::Optional SyncFileActionMetadata::new_name() const { REALM_ASSERT(m_realm); - m_realm->verify_is_on_thread(); + m_realm->verify_thread(); m_realm->refresh(); StringData result = m_obj.get(m_schema.idx_new_name); return result.is_null() ? util::none : util::make_optional(std::string(result)); @@ -695,7 +695,7 @@ util::Optional SyncFileActionMetadata::new_name() const std::string SyncFileActionMetadata::user_local_uuid() const { REALM_ASSERT(m_realm); - m_realm->verify_is_on_thread(); + m_realm->verify_thread(); m_realm->refresh(); return m_obj.get(m_schema.idx_user_identity); } @@ -703,7 +703,7 @@ std::string SyncFileActionMetadata::user_local_uuid() const SyncFileActionMetadata::Action SyncFileActionMetadata::action() const { REALM_ASSERT(m_realm); - m_realm->verify_is_on_thread(); + m_realm->verify_thread(); m_realm->refresh(); return static_cast(m_obj.get(m_schema.idx_action)); } @@ -711,7 +711,7 @@ SyncFileActionMetadata::Action SyncFileActionMetadata::action() const std::string SyncFileActionMetadata::url() const { REALM_ASSERT(m_realm); - m_realm->verify_is_on_thread(); + m_realm->verify_thread(); m_realm->refresh(); return m_obj.get(m_schema.idx_url); } @@ -719,8 +719,8 @@ std::string SyncFileActionMetadata::url() const void SyncFileActionMetadata::remove() { REALM_ASSERT(m_realm); - m_realm->verify_is_on_thread(); - m_realm->begin_write_transaction(); + m_realm->verify_thread(); + m_realm->begin_transaction(); m_obj.remove(); m_realm->commit_transaction(); m_realm = nullptr; diff --git a/src/realm/object-store/thread_safe_reference.cpp b/src/realm/object-store/thread_safe_reference.cpp index ae65f9cede8..8e46e06524e 100644 --- a/src/realm/object-store/thread_safe_reference.cpp +++ b/src/realm/object-store/thread_safe_reference.cpp @@ -39,14 +39,14 @@ class ThreadSafeReference::Payload { public: virtual ~Payload() = default; Payload(Realm& realm) - // A read-only realm (which means that the configuration's schema mode `is_immutable()`) does not have a + // A read-only realm (which means that the configuration's schema mode `immutable()`) does not have a // transaction. For this special case we instead need to check if a group was created, which is sufficient to // create a duplicate of the realm. - : m_transaction(realm.is_in_any_transaction() || (realm.config().is_immutable() && realm.has_group()) + : m_transaction(realm.is_in_read_transaction() || (realm.config().immutable() && realm.has_group()) ? realm.duplicate() : nullptr) , m_coordinator(Realm::Internal::get_coordinator(realm).shared_from_this()) - , m_created_in_write_transaction(realm.is_in_write_transaction()) + , m_created_in_write_transaction(realm.is_in_transaction()) { } @@ -62,14 +62,14 @@ class ThreadSafeReference::Payload { void ThreadSafeReference::Payload::refresh_target_realm(Realm& realm) { - if (!realm.is_in_any_transaction()) { + if (!realm.is_in_read_transaction()) { if (m_created_in_write_transaction) - realm.get_group(); + realm.read_group(); else Realm::Internal::begin_read(realm, m_transaction->get_version_of_current_transaction()); } else { - auto version = realm.get_version_of_current_transaction(); + auto version = realm.read_transaction_version(); auto target_version = m_transaction->get_version_of_current_transaction(); if (version < target_version || (version == target_version && m_created_in_write_transaction)) realm.refresh(); @@ -89,7 +89,7 @@ class ThreadSafeReference::PayloadImpl : public ThreadSafeReference::Paylo List import_into(std::shared_ptr const& r) { - Obj obj = r->get_group().get_table(m_table_key)->get_object(m_key); + Obj obj = r->read_group().get_table(m_table_key)->get_object(m_key); return List(r, obj, m_col_key); } @@ -112,7 +112,7 @@ class ThreadSafeReference::PayloadImpl : public ThreadSafeRef object_store::Set import_into(std::shared_ptr const& r) { - Obj obj = r->get_group().get_table(m_table_key)->get_object(m_key); + Obj obj = r->read_group().get_table(m_table_key)->get_object(m_key); return object_store::Set(r, obj, m_col_key); } @@ -135,7 +135,7 @@ class ThreadSafeReference::PayloadImpl : public ThreadSafeReference::Pay OsDict import_into(const std::shared_ptr& r) { - Obj obj = r->get_group().get_table(m_table_key)->get_object(m_key); + Obj obj = r->read_group().get_table(m_table_key)->get_object(m_key); return OsDict(r, obj, m_col_key); } @@ -179,7 +179,7 @@ class ThreadSafeReference::PayloadImpl : public ThreadSafeReference::Pa } else { Query q(r.get_query()); - if (!q.produces_results_in_table_order() && r.get_realm()->is_in_write_transaction()) { + if (!q.produces_results_in_table_order() && r.get_realm()->is_in_transaction()) { // FIXME: This is overly restrictive. It's only a problem if // the parent of the List or LinkingObjects was created in this // write transaction, but Query doesn't expose a way to check @@ -195,7 +195,7 @@ class ThreadSafeReference::PayloadImpl : public ThreadSafeReference::Pa { if (m_key) { CollectionBasePtr collection; - auto table = r->get_group().get_table(m_table_key); + auto table = r->read_group().get_table(m_table_key); try { collection = table->get_object(m_key).get_collection_ptr(m_col_key); } @@ -259,7 +259,7 @@ template ThreadSafeReference::ThreadSafeReference(T const& value) { auto realm = value.get_realm(); - realm->verify_is_on_thread(); + realm->verify_thread(); m_payload.reset(new PayloadImpl(value)); } @@ -279,7 +279,7 @@ template T ThreadSafeReference::resolve(std::shared_ptr const& realm) { REALM_ASSERT(realm); - realm->verify_is_on_thread(); + realm->verify_thread(); REALM_ASSERT(m_payload); auto& payload = static_cast&>(*m_payload); diff --git a/test/object-store/benchmarks/object.cpp b/test/object-store/benchmarks/object.cpp index 33d637ce26d..b8e8f8c51c5 100644 --- a/test/object-store/benchmarks/object.cpp +++ b/test/object-store/benchmarks/object.cpp @@ -201,7 +201,7 @@ TEST_CASE("Benchmark object", "[benchmark]") { TestContext d(r); SECTION("create object") { - r->begin_write_transaction(); + r->begin_transaction(); ObjectSchema all_types = *r->schema().find("all types"); int64_t benchmark_pk = 0; @@ -234,8 +234,8 @@ TEST_CASE("Benchmark object", "[benchmark]") { } SECTION("update object") { - auto table = r->get_group().get_table("class_all types"); - r->begin_write_transaction(); + auto table = r->read_group().get_table("class_all types"); + r->begin_transaction(); ObjectSchema all_types = *r->schema().find("all types"); auto obj = Object::create(d, r, all_types, util::Any(AnyDict{ @@ -273,7 +273,7 @@ TEST_CASE("Benchmark object", "[benchmark]") { REQUIRE(col_int); BENCHMARK_ADVANCED("update object")(Catch::Benchmark::Chronometer meter) { - r->begin_write_transaction(); + r->begin_transaction(); meter.measure([&d, &all_types, &update_int, &r] { auto shadow = Object::create(d, r, all_types, util::Any(AnyDict{ @@ -291,7 +291,7 @@ TEST_CASE("Benchmark object", "[benchmark]") { } SECTION("change notifications reporting") { - auto table = r->get_group().get_table("class_person"); + auto table = r->read_group().get_table("class_person"); Results result(r, table); size_t num_calls = 0; size_t num_insertions = 0; @@ -310,7 +310,7 @@ TEST_CASE("Benchmark object", "[benchmark]") { BENCHMARK_ADVANCED("create notifications")(Catch::Benchmark::Chronometer meter) { - r->begin_write_transaction(); + r->begin_transaction(); result.clear(); r->commit_transaction(); advance_and_notify(*r); @@ -318,7 +318,7 @@ TEST_CASE("Benchmark object", "[benchmark]") { num_modifications = 0; num_deletions = 0; - r->begin_write_transaction(); + r->begin_transaction(); for (size_t i = 0; i < num_objects; ++i) { std::stringstream name; name << "person_" << i; @@ -339,7 +339,7 @@ TEST_CASE("Benchmark object", "[benchmark]") { REQUIRE(result.size() == num_objects); }; - r->begin_write_transaction(); + r->begin_transaction(); result.clear(); r->commit_transaction(); advance_and_notify(*r); @@ -347,7 +347,7 @@ TEST_CASE("Benchmark object", "[benchmark]") { BENCHMARK_ADVANCED("delete notifications")(Catch::Benchmark::Chronometer meter) { - r->begin_write_transaction(); + r->begin_transaction(); result.clear(); r->commit_transaction(); advance_and_notify(*r); @@ -355,7 +355,7 @@ TEST_CASE("Benchmark object", "[benchmark]") { num_modifications = 0; num_deletions = 0; - r->begin_write_transaction(); + r->begin_transaction(); for (size_t i = 0; i < num_objects; ++i) { std::stringstream name; name << "person_" << i; @@ -372,7 +372,7 @@ TEST_CASE("Benchmark object", "[benchmark]") { REQUIRE(num_deletions == 0); REQUIRE(result.size() == num_objects); - r->begin_write_transaction(); + r->begin_transaction(); result.clear(); r->commit_transaction(); @@ -388,7 +388,7 @@ TEST_CASE("Benchmark object", "[benchmark]") { BENCHMARK_ADVANCED("modify notifications")(Catch::Benchmark::Chronometer meter) { - r->begin_write_transaction(); + r->begin_transaction(); result.clear(); r->commit_transaction(); advance_and_notify(*r); @@ -396,7 +396,7 @@ TEST_CASE("Benchmark object", "[benchmark]") { num_modifications = 0; num_deletions = 0; - r->begin_write_transaction(); + r->begin_transaction(); for (size_t i = 0; i < num_objects; ++i) { std::stringstream name; name << "person_" << i; @@ -416,7 +416,7 @@ TEST_CASE("Benchmark object", "[benchmark]") { num_modifications = 0; num_deletions = 0; - r->begin_write_transaction(); + r->begin_transaction(); for (size_t i = 0; i < num_objects; ++i) { std::stringstream name; name << "person_" << i; @@ -442,7 +442,7 @@ TEST_CASE("Benchmark object", "[benchmark]") { advance_and_notify(*r); ObjectSchema schema = *r->schema().find("all types"); - r->begin_write_transaction(); + r->begin_transaction(); AnyDict values{ {"pk", INT64_C(0)}, {"bool", true}, @@ -480,11 +480,11 @@ TEST_CASE("Benchmark object", "[benchmark]") { std::vector notifiers; auto get_object = [&] { auto r = Realm::get_shared_realm(config); - auto obj = r->get_group().get_table("class_all types")->get_object(0); + auto obj = r->read_group().get_table("class_all types")->get_object(0); return Object(r, obj); }; auto change_object = [&] { - r->begin_write_transaction(); + r->begin_transaction(); int64_t int_value = obj.get_column_value("int"); obj.set_column_value("int", int_value + 1); obj.set_column_value("bool", !obj.get_column_value("bool")); @@ -538,7 +538,7 @@ TEST_CASE("Benchmark object", "[benchmark]") { } SECTION("change notifications sorted") { - auto table = r->get_group().get_table("class_person"); + auto table = r->read_group().get_table("class_person"); auto age_col = table->get_column_key("age"); Results result = Results(r, table).sort({{"age", true}}); size_t num_insertions = 0; @@ -553,7 +553,7 @@ TEST_CASE("Benchmark object", "[benchmark]") { advance_and_notify(*r); ObjectSchema person_schema = *r->schema().find("person"); auto add_objects = [&](size_t num_objects, size_t start_index = 0) { - r->begin_write_transaction(); + r->begin_transaction(); for (size_t i = 0; i < num_objects; ++i) { size_t index = i + start_index; std::stringstream name; @@ -571,7 +571,7 @@ TEST_CASE("Benchmark object", "[benchmark]") { { constexpr size_t num_initial_objects = 1000; constexpr size_t num_prepend_objects = 1000; - r->begin_write_transaction(); + r->begin_transaction(); result.clear(); r->commit_transaction(); advance_and_notify(*r); @@ -600,7 +600,7 @@ TEST_CASE("Benchmark object", "[benchmark]") { BENCHMARK_ADVANCED("insert, delete odds")(Catch::Benchmark::Chronometer meter) { constexpr size_t num_objects = 800; - r->begin_write_transaction(); + r->begin_transaction(); result.clear(); r->commit_transaction(); advance_and_notify(*r); @@ -610,7 +610,7 @@ TEST_CASE("Benchmark object", "[benchmark]") { advance_and_notify(*r); // remove odds - r->begin_write_transaction(); + r->begin_transaction(); for (size_t i = result.size() - 1; i > 0; --i) { if (i % 2 == 1) { Obj odd = result.get(i); @@ -636,7 +636,7 @@ TEST_CASE("Benchmark object", "[benchmark]") { }; constexpr size_t num_objects = 1000; - r->begin_write_transaction(); + r->begin_transaction(); result.clear(); r->commit_transaction(); advance_and_notify(*r); @@ -645,7 +645,7 @@ TEST_CASE("Benchmark object", "[benchmark]") { BENCHMARK_ADVANCED("modify all")(Catch::Benchmark::Chronometer meter) { - r->begin_write_transaction(); + r->begin_transaction(); for (size_t i = 0; i < table->size(); ++i) { Obj obj = table->get_object(i); obj.set(age_col, obj.get(age_col) + 1); @@ -668,12 +668,12 @@ TEST_CASE("Benchmark object", "[benchmark]") { BENCHMARK_ADVANCED("modify odds")(Catch::Benchmark::Chronometer meter) { - r->begin_write_transaction(); + r->begin_transaction(); result.clear(); r->commit_transaction(); advance_and_notify(*r); - r->begin_write_transaction(); + r->begin_transaction(); for (size_t i = 0; i < num_objects; ++i) { std::stringstream name; name << "person_" << i; @@ -687,7 +687,7 @@ TEST_CASE("Benchmark object", "[benchmark]") { advance_and_notify(*r); - r->begin_write_transaction(); + r->begin_transaction(); for (size_t i = 0; i < table->size(); ++i) { Obj obj = table->get_object(i); int64_t age = obj.get(age_col); diff --git a/test/object-store/benchmarks/results.cpp b/test/object-store/benchmarks/results.cpp index 930ed74e393..863dc06b794 100644 --- a/test/object-store/benchmarks/results.cpp +++ b/test/object-store/benchmarks/results.cpp @@ -52,11 +52,11 @@ TEST_CASE("Benchmark results", "[benchmark]") { }; auto realm = Realm::get_shared_realm(config); - auto table = realm->get_group().get_table("class_object"); - auto table2 = realm->get_group().get_table("class_object 2"); + auto table = realm->read_group().get_table("class_object"); + auto table2 = realm->read_group().get_table("class_object 2"); Results r(realm, table); - realm->begin_write_transaction(); + realm->begin_transaction(); ObjKeys table_keys; ObjKeys table2_keys; table->create_objects(4, table_keys); @@ -133,7 +133,7 @@ TEST_CASE("Benchmark results", "[benchmark]") { SECTION("iteration") { const int additional_row_count = 10000; - realm->begin_write_transaction(); + realm->begin_transaction(); table->create_objects(additional_row_count, table_keys); for (int i = 0; i < additional_row_count; ++i) table->get_object(table_keys[i]).set_all((i + 2) % 4, bool(i % 2)); diff --git a/test/object-store/dictionary.cpp b/test/object-store/dictionary.cpp index e514b199dd3..60e6945fcbc 100644 --- a/test/object-store/dictionary.cpp +++ b/test/object-store/dictionary.cpp @@ -65,9 +65,9 @@ TEST_CASE("dictionary") { auto r = Realm::get_shared_realm(config); auto r2 = Realm::get_shared_realm(config); - auto table = r->get_group().get_table("class_object"); - auto table2 = r2->get_group().get_table("class_object"); - r->begin_write_transaction(); + auto table = r->read_group().get_table("class_object"); + auto table2 = r2->read_group().get_table("class_object"); + r->begin_transaction(); Obj obj = table->create_object(); ColKey col = table->get_column_key("value"); @@ -137,7 +137,7 @@ TEST_CASE("dictionary") { for (size_t i = 0; i < values.size(); ++i) { REQUIRE(results2.get(i) == values[i]); } - r->begin_write_transaction(); + r->begin_transaction(); obj.remove(); r->commit_transaction(); results2 = ref.resolve(r); @@ -168,12 +168,12 @@ TEST_CASE("dictionary") { // Remove the existing copy of this value so that the sorted list // doesn't have dupes resulting in an unstable order advance_and_notify(*r); - r->begin_write_transaction(); + r->begin_transaction(); dict.erase("b"); r->commit_transaction(); advance_and_notify(*r); - r->begin_write_transaction(); + r->begin_transaction(); dict.insert("d", "dade"); r->commit_transaction(); @@ -187,7 +187,7 @@ TEST_CASE("dictionary") { SECTION("replace value in dictionary") { advance_and_notify(*r); - r->begin_write_transaction(); + r->begin_transaction(); dict.insert("b", "blueberry"); r->commit_transaction(); @@ -201,7 +201,7 @@ TEST_CASE("dictionary") { SECTION("remove value from list") { advance_and_notify(*r); auto ndx = results.index_of(StringData("apple")); - r->begin_write_transaction(); + r->begin_transaction(); dict.erase("a"); r->commit_transaction(); @@ -215,7 +215,7 @@ TEST_CASE("dictionary") { SECTION("clear list") { advance_and_notify(*r); - r->begin_write_transaction(); + r->begin_transaction(); dict.remove_all(); r->commit_transaction(); advance_and_notify(*r); @@ -229,7 +229,7 @@ TEST_CASE("dictionary") { REQUIRE(calls == 3); REQUIRE(!change.collection_root_was_deleted); - r->begin_write_transaction(); + r->begin_transaction(); obj.remove(); r->commit_transaction(); advance_and_notify(*r); @@ -239,7 +239,7 @@ TEST_CASE("dictionary") { REQUIRE(srchange.deletions.count() == values.size()); REQUIRE(change.collection_root_was_deleted); - r->begin_write_transaction(); + r->begin_transaction(); table->create_object(); r->commit_transaction(); advance_and_notify(*r); @@ -247,7 +247,7 @@ TEST_CASE("dictionary") { } SECTION("deleting containing row before first run of notifier") { - r2->begin_write_transaction(); + r2->begin_transaction(); table2->begin()->remove(); r2->commit_transaction(); advance_and_notify(*r); @@ -258,7 +258,7 @@ TEST_CASE("dictionary") { SECTION("deleting a row with an empty dictionary triggers notifications") { advance_and_notify(*r); REQUIRE(calls == 3); - r->begin_write_transaction(); + r->begin_transaction(); REQUIRE(dict.size() == values.size()); results.clear(); REQUIRE(dict.size() == 0); @@ -269,7 +269,7 @@ TEST_CASE("dictionary") { REQUIRE(!change.collection_root_was_deleted); REQUIRE(calls == 6); - r->begin_write_transaction(); + r->begin_transaction(); obj.remove(); r->commit_transaction(); advance_and_notify(*r); diff --git a/test/object-store/frozen_objects.cpp b/test/object-store/frozen_objects.cpp index 047d447b443..f4aab387f21 100644 --- a/test/object-store/frozen_objects.cpp +++ b/test/object-store/frozen_objects.cpp @@ -70,11 +70,10 @@ TEST_CASE("Construct frozen Realm") { SECTION("Create frozen Realm directly") { auto realm = Realm::get_shared_realm(config); - realm->get_group(); - auto frozen_realm = Realm::get_frozen_realm(config, realm->get_version_of_current_transaction()); + realm->read_group(); + auto frozen_realm = Realm::get_frozen_realm(config, realm->read_transaction_version()); REQUIRE(frozen_realm->is_frozen()); - REQUIRE(realm->get_version_of_current_transaction() == - *frozen_realm->get_version_of_current_or_frozen_transaction()); + REQUIRE(realm->read_transaction_version() == *frozen_realm->current_transaction_version()); } } @@ -86,8 +85,8 @@ TEST_CASE("Freeze Realm", "[freeze_realm]") { }; auto realm = Realm::get_shared_realm(config); - realm->get_group(); - auto frozen_realm = Realm::get_frozen_realm(config, realm->get_version_of_current_transaction()); + realm->read_group(); + auto frozen_realm = Realm::get_frozen_realm(config, realm->read_transaction_version()); SECTION("is_frozen") { REQUIRE(frozen_realm->is_frozen()); @@ -97,8 +96,8 @@ TEST_CASE("Freeze Realm", "[freeze_realm]") { REQUIRE(!frozen_realm->refresh()); } - SECTION("should_wait_for_change() returns false") { - REQUIRE(!frozen_realm->should_wait_for_change()); + SECTION("wait_for_change() returns false") { + REQUIRE(!frozen_realm->wait_for_change()); } SECTION("auto_refresh") { @@ -107,15 +106,15 @@ TEST_CASE("Freeze Realm", "[freeze_realm]") { REQUIRE(!frozen_realm->auto_refresh()); } - SECTION("begin_write_transaction() throws") { - REQUIRE_THROWS(frozen_realm->begin_write_transaction()); + SECTION("begin_transaction() throws") { + REQUIRE_THROWS(frozen_realm->begin_transaction()); } SECTION("can call methods on another thread") { JoiningThread thread([&] { // Smoke-test REQUIRE_NOTHROW(frozen_realm->write_copy()); - REQUIRE_NOTHROW(frozen_realm->get_version_of_current_transaction()); + REQUIRE_NOTHROW(frozen_realm->read_transaction_version()); }); } @@ -139,15 +138,15 @@ TEST_CASE("Freeze Results", "[freeze_results]") { }; auto realm = Realm::get_shared_realm(config); - auto table = realm->get_group().get_table("class_object"); - auto linked_table = realm->get_group().get_table("class_linked to object"); + auto table = realm->read_group().get_table("class_object"); + auto linked_table = realm->read_group().get_table("class_linked to object"); auto value_col = table->get_column_key("value"); auto object_link_col = table->get_column_key("object_array"); auto int_list_col = table->get_column_key("int_array"); auto int_dict_col = table->get_column_key("int_dict"); auto linked_object_value_col = linked_table->get_column_key("value"); - realm->begin_write_transaction(); + realm->begin_transaction(); for (int i = 0; i < 8; ++i) { Obj obj = table->create_object(); obj.set(value_col, (i + 2)); @@ -166,7 +165,7 @@ TEST_CASE("Freeze Results", "[freeze_results]") { realm->commit_transaction(); Results results(realm, table); - auto frozen_realm = Realm::get_frozen_realm(config, realm->get_version_of_current_transaction()); + auto frozen_realm = Realm::get_frozen_realm(config, realm->read_transaction_version()); Results frozen_results = results.freeze(frozen_realm); SECTION("is_frozen") { @@ -195,7 +194,7 @@ TEST_CASE("Freeze Results", "[freeze_results]") { } SECTION("Result constructor - Table") { - Results res = Results(frozen_realm, frozen_realm->get_group().get_table("class_object")); + Results res = Results(frozen_realm, frozen_realm->read_group().get_table("class_object")); Results frozen_res = results.freeze(frozen_realm); JoiningThread thread([&] { auto obj = frozen_res.get(0); @@ -311,14 +310,14 @@ TEST_CASE("Freeze List", "[freeze_list]") { }; auto realm = Realm::get_shared_realm(config); - auto table = realm->get_group().get_table("class_object"); - auto linked_table = realm->get_group().get_table("class_linked to object"); + auto table = realm->read_group().get_table("class_object"); + auto linked_table = realm->read_group().get_table("class_linked to object"); auto value_col = table->get_column_key("value"); auto object_link_col = table->get_column_key("object_array"); auto int_link_col = table->get_column_key("int_array"); auto linked_object_value_col = linked_table->get_column_key("value"); - realm->begin_write_transaction(); + realm->begin_transaction(); Obj obj = table->create_object(); obj.set(value_col, 100); std::shared_ptr object_link_view = obj.get_linklist_ptr(object_link_col); @@ -332,7 +331,7 @@ TEST_CASE("Freeze List", "[freeze_list]") { realm->commit_transaction(); Results results(realm, table); - auto frozen_realm = Realm::get_frozen_realm(config, realm->get_version_of_current_transaction()); + auto frozen_realm = Realm::get_frozen_realm(config, realm->read_transaction_version()); std::shared_ptr link_list = results.get(0).get_linklist_ptr(object_link_col); List frozen_link_list = List(realm, *link_list).freeze(frozen_realm); @@ -384,14 +383,14 @@ TEST_CASE("Freeze Object", "[freeze_object]") { }; auto realm = Realm::get_shared_realm(config); - auto table = realm->get_group().get_table("class_object"); - auto linked_table = realm->get_group().get_table("class_linked to object"); + auto table = realm->read_group().get_table("class_object"); + auto linked_table = realm->read_group().get_table("class_linked to object"); auto value_col = table->get_column_key("value"); auto object_link_col = table->get_column_key("object_array"); auto int_link_col = table->get_column_key("int_array"); auto linked_object_value_col = linked_table->get_column_key("value"); - realm->begin_write_transaction(); + realm->begin_transaction(); Obj obj = table->create_object(); obj.set(value_col, 100); std::shared_ptr object_link_view = obj.get_linklist_ptr(object_link_col); @@ -405,7 +404,7 @@ TEST_CASE("Freeze Object", "[freeze_object]") { realm->commit_transaction(); Results results(realm, table); - auto frozen_realm = Realm::get_frozen_realm(config, realm->get_version_of_current_transaction()); + auto frozen_realm = Realm::get_frozen_realm(config, realm->read_transaction_version()); Object frozen_obj = Object(realm, table->get_object(0)).freeze(frozen_realm); CppContext ctx(frozen_realm); diff --git a/test/object-store/list.cpp b/test/object-store/list.cpp index 6949626b79a..8276733bf43 100644 --- a/test/object-store/list.cpp +++ b/test/object-store/list.cpp @@ -54,16 +54,16 @@ TEST_CASE("list") { auto& coordinator = *_impl::RealmCoordinator::get_coordinator(config.path); - auto origin = r->get_group().get_table("class_origin"); - auto target = r->get_group().get_table("class_target"); - auto other_origin = r->get_group().get_table("class_other_origin"); - auto other_target = r->get_group().get_table("class_other_target"); + auto origin = r->read_group().get_table("class_origin"); + auto target = r->read_group().get_table("class_target"); + auto other_origin = r->read_group().get_table("class_other_origin"); + auto other_target = r->read_group().get_table("class_other_target"); ColKey col_link = origin->get_column_key("array"); ColKey col_value = target->get_column_key("value"); ColKey other_col_link = other_origin->get_column_key("array"); ColKey other_col_value = other_target->get_column_key("value"); - r->begin_write_transaction(); + r->begin_transaction(); std::vector target_keys; target->create_objects(10, target_keys); @@ -91,14 +91,14 @@ TEST_CASE("list") { r->commit_transaction(); auto r2 = coordinator.get_realm(); - auto r2_lv = r2->get_group().get_table("class_origin")->get_object(0).get_linklist_ptr(col_link); + auto r2_lv = r2->read_group().get_table("class_origin")->get_object(0).get_linklist_ptr(col_link); SECTION("add_notification_block()") { CollectionChangeSet change; List lst(r, obj, col_link); auto write = [&](auto&& f) { - r->begin_write_transaction(); + r->begin_transaction(); f(); r->commit_transaction(); @@ -237,7 +237,7 @@ TEST_CASE("list") { } SECTION("modifying a row which appears multiple times in a list marks them all as modified") { - r->begin_write_transaction(); + r->begin_transaction(); lst.add(target_keys[5]); r->commit_transaction(); @@ -249,7 +249,7 @@ TEST_CASE("list") { } SECTION("deleting a row which appears multiple times in a list marks them all as modified") { - r->begin_write_transaction(); + r->begin_transaction(); lst.add(target_keys[5]); r->commit_transaction(); @@ -270,7 +270,7 @@ TEST_CASE("list") { SECTION("moving a target row does not send a change notification") { // Remove a row from the LV so that we have one to delete that's not in the list - r->begin_write_transaction(); + r->begin_transaction(); if (lv->size() > 2) lv->remove(2); r->commit_transaction(); @@ -282,7 +282,7 @@ TEST_CASE("list") { } SECTION("multiple LinkViews for the same LinkList can get notifications") { - r->begin_write_transaction(); + r->begin_transaction(); target->clear(); std::vector keys; target->create_objects(5, keys); @@ -290,11 +290,11 @@ TEST_CASE("list") { auto get_list = [&] { auto r = Realm::get_shared_realm(config); - auto obj = r->get_group().get_table("class_origin")->get_object(0); + auto obj = r->read_group().get_table("class_origin")->get_object(0); return List(r, obj, col_link); }; auto change_list = [&] { - r->begin_write_transaction(); + r->begin_transaction(); if (lv->size()) { target->get_object(lv->size() - 1).set(col_value, int64_t(lv->size())); } @@ -345,7 +345,7 @@ TEST_CASE("list") { auto token = require_no_change(); auto token2 = require_change(); - r->begin_write_transaction(); + r->begin_transaction(); lv->add(target_keys[0]); token.suppress_next(); r->commit_transaction(); @@ -363,7 +363,7 @@ TEST_CASE("list") { }); advance_and_notify(*r); - r->begin_write_transaction(); + r->begin_transaction(); lv->add(target_keys[0]); token.suppress_next(); r->commit_transaction(); @@ -376,14 +376,14 @@ TEST_CASE("list") { auto token = require_change(); // would not produce a notification even if it wasn't skipped because no changes were made - r->begin_write_transaction(); + r->begin_transaction(); token.suppress_next(); r->commit_transaction(); advance_and_notify(*r); REQUIRE(change.empty()); // should now produce a notification - r->begin_write_transaction(); + r->begin_transaction(); lv->add(target_keys[0]); r->commit_transaction(); advance_and_notify(*r); @@ -442,23 +442,23 @@ TEST_CASE("list") { changes1 = std::move(c); }); - r2->begin_write_transaction(); - r2->get_group().get_table("class_target")->get_object(target_keys[0]).set(col_value, 10); - r2->get_group() + r2->begin_transaction(); + r2->read_group().get_table("class_target")->get_object(target_keys[0]).set(col_value, 10); + r2->read_group() .get_table("class_other_target") ->get_object(other_target_keys[1]) .set(other_col_value, 10); r2->commit_transaction(); - List list2(r2, r2->get_group().get_table("class_other_origin")->get_object(0), other_col_link); + List list2(r2, r2->read_group().get_table("class_other_origin")->get_object(0), other_col_link); auto token2 = list2.add_notification_callback([&](CollectionChangeSet c, std::exception_ptr) { changes2 = std::move(c); }); auto r3 = coordinator.get_realm(); - r3->begin_write_transaction(); - r3->get_group().get_table("class_target")->get_object(target_keys[2]).set(col_value, 10); - r3->get_group() + r3->begin_transaction(); + r3->read_group().get_table("class_target")->get_object(target_keys[2]).set(col_value, 10); + r3->read_group() .get_table("class_other_target") ->get_object(other_target_keys[3]) .set(other_col_value, 10); @@ -474,7 +474,7 @@ TEST_CASE("list") { SECTION("modifications are reported for rows that are moved and then moved back in a second transaction") { auto token = require_change(); - r2->begin_write_transaction(); + r2->begin_transaction(); r2_lv->get_object(5).set(col_value, 10); r2_lv->get_object(1).set(col_value, 10); r2_lv->move(5, 8); @@ -483,7 +483,7 @@ TEST_CASE("list") { coordinator.on_change(); - r2->begin_write_transaction(); + r2->begin_transaction(); if (r2_lv->size() > 8) r2_lv->move(8, 5); r2->commit_transaction(); @@ -499,7 +499,7 @@ TEST_CASE("list") { auto token = lst.add_notification_callback([&](CollectionChangeSet c, std::exception_ptr) { change = c; }); - r2->begin_write_transaction(); + r2->begin_transaction(); r2_lv->remove(5); r2->commit_transaction(); advance_and_notify(*r); @@ -513,7 +513,7 @@ TEST_CASE("list") { token = {}; auto write = [&] { - r2->begin_write_transaction(); + r2->begin_transaction(); r2_lv->remove(5); r2->commit_transaction(); }; @@ -569,7 +569,7 @@ TEST_CASE("list") { advance_and_notify(*r); auto write = [&](auto&& f) { - r->begin_write_transaction(); + r->begin_transaction(); f(); r->commit_transaction(); @@ -624,7 +624,7 @@ TEST_CASE("list") { advance_and_notify(*r); auto write = [&](auto&& f) { - r->begin_write_transaction(); + r->begin_transaction(); f(); r->commit_transaction(); @@ -725,7 +725,7 @@ TEST_CASE("list") { REQUIRE(snapshot.get_mode() == Results::Mode::TableView); REQUIRE(snapshot.size() == 10); - r->begin_write_transaction(); + r->begin_transaction(); for (size_t i = 0; i < 5; ++i) { list.remove(0); } @@ -753,7 +753,7 @@ TEST_CASE("list") { auto snapshot = list.snapshot(); for (size_t i = 0; i < snapshot.size(); ++i) { - r->begin_write_transaction(); + r->begin_transaction(); Obj obj = snapshot.get(i); obj.remove(); r->commit_transaction(); @@ -772,7 +772,7 @@ TEST_CASE("list") { SECTION("delete_at()") { List list(r, *lv); - r->begin_write_transaction(); + r->begin_transaction(); auto initial_view_size = lv->size(); auto initial_target_size = target->size(); list.delete_at(1); @@ -783,7 +783,7 @@ TEST_CASE("list") { SECTION("delete_all()") { List list(r, *lv); - r->begin_write_transaction(); + r->begin_transaction(); list.delete_all(); REQUIRE(lv->size() == 0); REQUIRE(target->size() == 0); @@ -792,7 +792,7 @@ TEST_CASE("list") { SECTION("as_results().clear()") { List list(r, *lv); - r->begin_write_transaction(); + r->begin_transaction(); list.as_results().clear(); REQUIRE(lv->size() == 0); REQUIRE(target->size() == 0); @@ -801,7 +801,7 @@ TEST_CASE("list") { SECTION("snapshot().clear()") { List list(r, *lv); - r->begin_write_transaction(); + r->begin_transaction(); auto snapshot = list.snapshot(); snapshot.clear(); REQUIRE(snapshot.size() == 10); @@ -813,7 +813,7 @@ TEST_CASE("list") { SECTION("add(RowExpr)") { List list(r, *lv); - r->begin_write_transaction(); + r->begin_transaction(); SECTION("adds rows from the correct table") { list.add(target_keys[5]); REQUIRE(list.size() == 11); @@ -828,7 +828,7 @@ TEST_CASE("list") { SECTION("insert(RowExpr)") { List list(r, *lv); - r->begin_write_transaction(); + r->begin_transaction(); SECTION("insert rows from the correct table") { list.insert(0, target_keys[5]); @@ -849,7 +849,7 @@ TEST_CASE("list") { SECTION("set(RowExpr)") { List list(r, *lv); - r->begin_write_transaction(); + r->begin_transaction(); SECTION("assigns for rows from the correct table") { list.set(0, target_keys[5]); @@ -877,7 +877,7 @@ TEST_CASE("list") { } SECTION("returns index in list and not index in table") { - r->begin_write_transaction(); + r->begin_transaction(); list.remove(1); REQUIRE(list.find(obj5) == 4); REQUIRE(list.as_results().index_of(obj5) == 4); @@ -885,7 +885,7 @@ TEST_CASE("list") { } SECTION("returns npos for values not in the list") { - r->begin_write_transaction(); + r->begin_transaction(); list.remove(1); REQUIRE(list.find(obj1) == npos); REQUIRE(list.as_results().index_of(obj1) == npos); @@ -906,7 +906,7 @@ TEST_CASE("list") { } SECTION("returns index in list and not index in table") { - r->begin_write_transaction(); + r->begin_transaction(); list.remove(1); REQUIRE(list.find(std::move(target->where().equal(col_value, 5))) == 4); r->cancel_transaction(); @@ -920,7 +920,7 @@ TEST_CASE("list") { SECTION("add(Context)") { List list(r, *lv); CppContext ctx(r, &list.get_object_schema()); - r->begin_write_transaction(); + r->begin_transaction(); SECTION("adds boxed RowExpr") { list.add(ctx, util::Any(target->get_object(target_keys[5]))); @@ -1000,14 +1000,14 @@ TEST_CASE("embedded List") { auto& coordinator = *_impl::RealmCoordinator::get_coordinator(config.path); - auto origin = r->get_group().get_table("class_origin"); - auto target = r->get_group().get_table("class_target"); - auto other_origin = r->get_group().get_table("class_other_origin"); + auto origin = r->read_group().get_table("class_origin"); + auto target = r->read_group().get_table("class_target"); + auto other_origin = r->read_group().get_table("class_other_origin"); ColKey col_link = origin->get_column_key("array"); ColKey col_value = target->get_column_key("value"); ColKey other_col_link = other_origin->get_column_key("array"); - r->begin_write_transaction(); + r->begin_transaction(); Obj obj = origin->create_object_with_primary_key(0); auto lv = obj.get_linklist_ptr(col_link); @@ -1029,14 +1029,14 @@ TEST_CASE("embedded List") { other_lv->size(); auto r2 = coordinator.get_realm(); - auto r2_lv = r2->get_group().get_table("class_origin")->get_object(0).get_linklist_ptr(col_link); + auto r2_lv = r2->read_group().get_table("class_origin")->get_object(0).get_linklist_ptr(col_link); SECTION("add_notification_block()") { CollectionChangeSet change; List lst(r, obj, col_link); auto write = [&](auto&& f) { - r->begin_write_transaction(); + r->begin_transaction(); f(); r->commit_transaction(); @@ -1155,7 +1155,7 @@ TEST_CASE("embedded List") { advance_and_notify(*r); auto write = [&](auto&& f) { - r->begin_write_transaction(); + r->begin_transaction(); f(); r->commit_transaction(); @@ -1201,7 +1201,7 @@ TEST_CASE("embedded List") { advance_and_notify(*r); auto write = [&](auto&& f) { - r->begin_write_transaction(); + r->begin_transaction(); f(); r->commit_transaction(); @@ -1245,7 +1245,7 @@ TEST_CASE("embedded List") { auto initial_target_size = target->size(); SECTION("delete_at()") { List list(r, *lv); - r->begin_write_transaction(); + r->begin_transaction(); list.delete_at(1); REQUIRE(lv->size() == initial_view_size - 1); REQUIRE(target->size() == initial_target_size - 1); @@ -1254,7 +1254,7 @@ TEST_CASE("embedded List") { SECTION("delete_all()") { List list(r, *lv); - r->begin_write_transaction(); + r->begin_transaction(); list.delete_all(); REQUIRE(lv->size() == 0); REQUIRE(target->size() == initial_target_size - 10); @@ -1263,7 +1263,7 @@ TEST_CASE("embedded List") { SECTION("as_results().clear()") { List list(r, *lv); - r->begin_write_transaction(); + r->begin_transaction(); list.as_results().clear(); REQUIRE(lv->size() == 0); REQUIRE(target->size() == initial_target_size - 10); @@ -1272,7 +1272,7 @@ TEST_CASE("embedded List") { SECTION("snapshot().clear()") { List list(r, *lv); - r->begin_write_transaction(); + r->begin_transaction(); auto snapshot = list.snapshot(); snapshot.clear(); REQUIRE(snapshot.size() == 10); @@ -1284,7 +1284,7 @@ TEST_CASE("embedded List") { SECTION("add(), insert(), and set() to existing object is not allowed") { List list(r, *lv); - r->begin_write_transaction(); + r->begin_transaction(); REQUIRE_THROWS_AS(list.add(target->get_object(0)), List::InvalidEmbeddedOperationException); REQUIRE_THROWS_AS(list.insert(0, target->get_object(0)), List::InvalidEmbeddedOperationException); REQUIRE_THROWS_AS(list.set(0, target->get_object(0)), List::InvalidEmbeddedOperationException); @@ -1301,7 +1301,7 @@ TEST_CASE("embedded List") { } SECTION("returns index in list and not index in table") { - r->begin_write_transaction(); + r->begin_transaction(); list.remove(1); REQUIRE(list.find(obj5) == 4); REQUIRE(list.as_results().index_of(obj5) == 4); @@ -1309,7 +1309,7 @@ TEST_CASE("embedded List") { } SECTION("returns npos for values not in the list") { - r->begin_write_transaction(); + r->begin_transaction(); list.remove(1); REQUIRE(list.find(obj1) == npos); REQUIRE_THROWS_AS(list.as_results().index_of(obj1), Results::DetatchedAccessorException); @@ -1330,7 +1330,7 @@ TEST_CASE("embedded List") { } SECTION("returns index in list and not index in table") { - r->begin_write_transaction(); + r->begin_transaction(); list.remove(1); REQUIRE(list.find(std::move(target->where().equal(col_value, 5))) == 4); r->cancel_transaction(); @@ -1344,7 +1344,7 @@ TEST_CASE("embedded List") { SECTION("add(Context)") { List list(r, *lv); CppContext ctx(r, &list.get_object_schema()); - r->begin_write_transaction(); + r->begin_transaction(); auto initial_target_size = target->size(); SECTION("rejects boxed Obj and Object") { @@ -1367,7 +1367,7 @@ TEST_CASE("embedded List") { SECTION("set(Context)") { List list(r, *lv); CppContext ctx(r, &list.get_object_schema()); - r->begin_write_transaction(); + r->begin_transaction(); auto initial_target_size = target->size(); SECTION("rejects boxed Obj and Object") { @@ -1453,11 +1453,11 @@ TEST_CASE("list of embedded objects") { config.schema_mode = SchemaMode::Automatic; config.schema = schema; auto realm = Realm::get_shared_realm(config); - auto parent_table = realm->get_group().get_table("class_parent"); + auto parent_table = realm->read_group().get_table("class_parent"); ColKey col_array = parent_table->get_column_key("array"); - auto embedded_table = realm->get_group().get_table("class_embedded"); + auto embedded_table = realm->read_group().get_table("class_embedded"); ColKey col_value = embedded_table->get_column_key("value"); - realm->begin_write_transaction(); + realm->begin_transaction(); auto parent = parent_table->create_object(); realm->commit_transaction(); @@ -1486,7 +1486,7 @@ TEST_CASE("list of embedded objects") { }; SECTION("add to list") { - realm->begin_write_transaction(); + realm->begin_transaction(); add_two_elements(); realm->commit_transaction(); @@ -1496,7 +1496,7 @@ TEST_CASE("list of embedded objects") { } SECTION("insert in list") { - realm->begin_write_transaction(); + realm->begin_transaction(); add_two_elements(); insert_three_elements(); realm->commit_transaction(); @@ -1510,7 +1510,7 @@ TEST_CASE("list of embedded objects") { } SECTION("set in list") { - realm->begin_write_transaction(); + realm->begin_transaction(); add_two_elements(); insert_three_elements(); diff --git a/test/object-store/migrations.cpp b/test/object-store/migrations.cpp index 87297de350c..f5f3db2fae9 100644 --- a/test/object-store/migrations.cpp +++ b/test/object-store/migrations.cpp @@ -67,7 +67,7 @@ void verify_schema(Realm& r, int line, bool in_migration) { CAPTURE(line); for (auto&& object_schema : r.schema()) { - auto table = r.get_group().get_table(object_schema.table_key); + auto table = r.read_group().get_table(object_schema.table_key); REQUIRE(table); REQUIRE(std::string(table->get_name()) == ObjectStore::table_name_for_object_type(object_schema.name)); CAPTURE(object_schema.name); @@ -94,7 +94,7 @@ void verify_schema(Realm& r, int line, bool in_migration) TableRef get_table(std::shared_ptr const& realm, StringData object_type) { - return ObjectStore::table_for_object_type(realm->get_group(), object_type); + return ObjectStore::table_for_object_type(realm->read_group(), object_type); } // Helper functions for modifying Schema objects, mostly for the sake of making @@ -529,7 +529,7 @@ TEST_CASE("migration: Automatic") { auto realm = Realm::get_shared_realm(config); realm->update_schema(schema, 1); REQUIRE_THROWS(realm->update_schema(schema, 2, [](SharedRealm, SharedRealm realm, Schema&) { - auto table = ObjectStore::table_for_object_type(realm->get_group(), "object"); + auto table = ObjectStore::table_for_object_type(realm->read_group(), "object"); table->create_object_with_primary_key(1); table->create_object_with_primary_key(2).set("value", 1); })); @@ -545,8 +545,8 @@ TEST_CASE("migration: Automatic") { auto realm = Realm::get_shared_realm(config); realm->update_schema(schema, 1); - realm->begin_write_transaction(); - auto table = ObjectStore::table_for_object_type(realm->get_group(), "object"); + realm->begin_transaction(); + auto table = ObjectStore::table_for_object_type(realm->read_group(), "object"); create_objects(*table, 2); realm->commit_transaction(); @@ -566,12 +566,12 @@ TEST_CASE("migration: Automatic") { realm->update_schema(schema1, 1); REQUIRE_THROWS(realm->update_schema(schema2, 2, [](SharedRealm, SharedRealm realm, Schema&) { - auto table = ObjectStore::table_for_object_type(realm->get_group(), "object"); + auto table = ObjectStore::table_for_object_type(realm->read_group(), "object"); table->create_object(); throw 5; })); - auto table = ObjectStore::table_for_object_type(realm->get_group(), "object"); + auto table = ObjectStore::table_for_object_type(realm->read_group(), "object"); REQUIRE(table->size() == 0); REQUIRE(realm->schema_version() == 1); REQUIRE(realm->schema() == schema1); @@ -590,7 +590,7 @@ TEST_CASE("migration: Automatic") { }; auto realm = Realm::get_shared_realm(config); realm->update_schema(schema, 1); - auto child_table = ObjectStore::table_for_object_type(realm->get_group(), "child_table"); + auto child_table = ObjectStore::table_for_object_type(realm->read_group(), "child_table"); REQUIRE_FALSE(child_table->is_embedded()); REQUIRE_THROWS(realm->update_schema(set_embedded(schema, "child_table", true), 2, nullptr)); @@ -605,7 +605,7 @@ TEST_CASE("migration: Automatic") { }; auto realm = Realm::get_shared_realm(config); realm->update_schema(schema, 1); - auto child_table = ObjectStore::table_for_object_type(realm->get_group(), "object"); + auto child_table = ObjectStore::table_for_object_type(realm->read_group(), "object"); REQUIRE_FALSE(child_table->is_embedded()); REQUIRE_THROWS(realm->update_schema(set_embedded(schema, "object", true), 2, nullptr)); @@ -620,7 +620,7 @@ TEST_CASE("migration: Automatic") { }; auto realm = Realm::get_shared_realm(config); realm->update_schema(schema, 1); - auto child_table = ObjectStore::table_for_object_type(realm->get_group(), "object"); + auto child_table = ObjectStore::table_for_object_type(realm->read_group(), "object"); REQUIRE_FALSE(child_table->is_embedded()); REQUIRE_THROWS(realm->update_schema(set_embedded(schema, "object", true), 2, [](auto, auto, auto&) {})); @@ -639,11 +639,11 @@ TEST_CASE("migration: Automatic") { }; auto realm = Realm::get_shared_realm(config); realm->update_schema(schema, 1); - realm->begin_write_transaction(); - auto child_table = ObjectStore::table_for_object_type(realm->get_group(), "child_table"); + realm->begin_transaction(); + auto child_table = ObjectStore::table_for_object_type(realm->read_group(), "child_table"); Obj child_object = child_table->create_object(); child_object.set("value", 42); - auto parent_table = ObjectStore::table_for_object_type(realm->get_group(), "parent_table"); + auto parent_table = ObjectStore::table_for_object_type(realm->read_group(), "parent_table"); auto child_object_key = child_object.get_key(); parent_table->create_object().set_all(child_object_key); parent_table->create_object().set_all(child_object_key); @@ -668,10 +668,10 @@ TEST_CASE("migration: Automatic") { }; auto realm = Realm::get_shared_realm(config); realm->update_schema(schema, 1); - realm->begin_write_transaction(); - auto child_table = ObjectStore::table_for_object_type(realm->get_group(), "child_table"); + realm->begin_transaction(); + auto child_table = ObjectStore::table_for_object_type(realm->read_group(), "child_table"); Obj child_object = child_table->create_object(); - auto parent_table = ObjectStore::table_for_object_type(realm->get_group(), "parent_table"); + auto parent_table = ObjectStore::table_for_object_type(realm->read_group(), "parent_table"); auto child_object_key = child_object.get_key(); parent_table->create_object().set_all(child_object_key); realm->commit_transaction(); @@ -682,7 +682,7 @@ TEST_CASE("migration: Automatic") { REQUIRE_THROWS( realm->update_schema(set_embedded(schema, "child_table", true), 2, [](auto, auto new_realm, auto&) { Object child_object(new_realm, "child_table", 0); - auto parent_table = ObjectStore::table_for_object_type(new_realm->get_group(), "parent_table"); + auto parent_table = ObjectStore::table_for_object_type(new_realm->read_group(), "parent_table"); Obj parent_obj = parent_table->create_object(); Object parent_object(new_realm, parent_obj); CppContext context(new_realm); @@ -702,8 +702,8 @@ TEST_CASE("migration: Automatic") { auto realm = Realm::get_shared_realm(config); realm->update_schema(schema, 1); - realm->begin_write_transaction(); - auto table = ObjectStore::table_for_object_type(realm->get_group(), "object"); + realm->begin_transaction(); + auto table = ObjectStore::table_for_object_type(realm->read_group(), "object"); create_objects(*table, 10); realm->commit_transaction(); @@ -722,8 +722,8 @@ TEST_CASE("migration: Automatic") { auto realm = Realm::get_shared_realm(config); realm->update_schema(schema, 1); - realm->begin_write_transaction(); - auto table = ObjectStore::table_for_object_type(realm->get_group(), "object"); + realm->begin_transaction(); + auto table = ObjectStore::table_for_object_type(realm->read_group(), "object"); auto key = table->get_column_key("value"); create_objects(*table, 10); for (int i = 0; i < 10; ++i) @@ -746,8 +746,8 @@ TEST_CASE("migration: Automatic") { auto realm = Realm::get_shared_realm(config); realm->update_schema(schema, 1); - realm->begin_write_transaction(); - auto table = ObjectStore::table_for_object_type(realm->get_group(), "object"); + realm->begin_transaction(); + auto table = ObjectStore::table_for_object_type(realm->read_group(), "object"); auto key = table->get_column_key("value"); create_objects(*table, 10); for (int i = 0; i < 10; ++i) @@ -771,9 +771,9 @@ TEST_CASE("migration: Automatic") { realm->update_schema(schema, 1); realm->update_schema({}, 2, [](SharedRealm, SharedRealm realm, Schema&) { - ObjectStore::delete_data_for_object(realm->get_group(), "object"); + ObjectStore::delete_data_for_object(realm->read_group(), "object"); }); - REQUIRE_FALSE(ObjectStore::table_for_object_type(realm->get_group(), "object")); + REQUIRE_FALSE(ObjectStore::table_for_object_type(realm->read_group(), "object")); } SECTION("deleting table still in the schema recreates it with no rows") { @@ -786,14 +786,14 @@ TEST_CASE("migration: Automatic") { auto realm = Realm::get_shared_realm(config); realm->update_schema(schema, 1); - realm->begin_write_transaction(); - ObjectStore::table_for_object_type(realm->get_group(), "object")->create_object(); + realm->begin_transaction(); + ObjectStore::table_for_object_type(realm->read_group(), "object")->create_object(); realm->commit_transaction(); realm->update_schema(schema, 2, [](SharedRealm, SharedRealm realm, Schema&) { - ObjectStore::delete_data_for_object(realm->get_group(), "object"); + ObjectStore::delete_data_for_object(realm->read_group(), "object"); }); - auto table = ObjectStore::table_for_object_type(realm->get_group(), "object"); + auto table = ObjectStore::table_for_object_type(realm->read_group(), "object"); REQUIRE(table); REQUIRE(table->size() == 0); } @@ -809,7 +809,7 @@ TEST_CASE("migration: Automatic") { realm->update_schema(schema, 1); REQUIRE_NOTHROW(realm->update_schema({}, 2, [](SharedRealm, SharedRealm realm, Schema&) { - ObjectStore::delete_data_for_object(realm->get_group(), "foo"); + ObjectStore::delete_data_for_object(realm->read_group(), "foo"); })); } @@ -826,7 +826,7 @@ TEST_CASE("migration: Automatic") { }; auto realm = Realm::get_shared_realm(config); realm->update_schema(schema, 1); - auto child_table = ObjectStore::table_for_object_type(realm->get_group(), "child_table"); + auto child_table = ObjectStore::table_for_object_type(realm->read_group(), "child_table"); REQUIRE_FALSE(child_table->is_embedded()); REQUIRE_NOTHROW(realm->update_schema(set_embedded(schema, "child_table", true), 2, nullptr)); @@ -849,7 +849,7 @@ TEST_CASE("migration: Automatic") { }; auto realm = Realm::get_shared_realm(config); realm->update_schema(schema, 1); - auto child_table = ObjectStore::table_for_object_type(realm->get_group(), "child_table"); + auto child_table = ObjectStore::table_for_object_type(realm->read_group(), "child_table"); REQUIRE(child_table->is_embedded()); REQUIRE_NOTHROW(realm->update_schema(set_embedded(schema, "child_table", false), 2, nullptr)); @@ -872,7 +872,7 @@ TEST_CASE("migration: Automatic") { }; auto realm = Realm::get_shared_realm(config); realm->update_schema(schema, 1); - auto child_table = ObjectStore::table_for_object_type(realm->get_group(), "child_table"); + auto child_table = ObjectStore::table_for_object_type(realm->read_group(), "child_table"); REQUIRE(child_table->is_embedded()); REQUIRE_NOTHROW(realm->update_schema(set_embedded(schema, "child_table", true), 2, nullptr)); @@ -894,13 +894,13 @@ TEST_CASE("migration: Automatic") { }; auto realm = Realm::get_shared_realm(config); realm->update_schema(schema, 1); - realm->begin_write_transaction(); - auto child_table = ObjectStore::table_for_object_type(realm->get_group(), "child_table"); + realm->begin_transaction(); + auto child_table = ObjectStore::table_for_object_type(realm->read_group(), "child_table"); Obj child_object1 = child_table->create_object(); child_object1.set("value", 42); Obj child_object2 = child_table->create_object(); child_object2.set("value", 43); - auto parent_table = ObjectStore::table_for_object_type(realm->get_group(), "parent_table"); + auto parent_table = ObjectStore::table_for_object_type(realm->read_group(), "parent_table"); auto child_object_key1 = child_object1.get_key(); auto child_object_key2 = child_object2.get_key(); parent_table->create_object().set_all(child_object_key1); @@ -939,11 +939,11 @@ TEST_CASE("migration: Automatic") { }; auto realm = Realm::get_shared_realm(config); realm->update_schema(schema, 1); - realm->begin_write_transaction(); - auto child_table = ObjectStore::table_for_object_type(realm->get_group(), "child_table"); + realm->begin_transaction(); + auto child_table = ObjectStore::table_for_object_type(realm->read_group(), "child_table"); Obj child_object = child_table->create_object(); child_object.set("value", 42); - auto parent_table = ObjectStore::table_for_object_type(realm->get_group(), "parent_table"); + auto parent_table = ObjectStore::table_for_object_type(realm->read_group(), "parent_table"); auto child_object_key = child_object.get_key(); parent_table->create_object().set_all(child_object_key); parent_table->create_object().set_all(child_object_key); @@ -960,7 +960,7 @@ TEST_CASE("migration: Automatic") { any_cast(parent_object1.get_property_value(context, "child_property")); Int value = any_cast(child_object1.get_property_value(context, "value")); - auto child_table = ObjectStore::table_for_object_type(new_realm->get_group(), "child_table"); + auto child_table = ObjectStore::table_for_object_type(new_realm->read_group(), "child_table"); Obj child_object2 = child_table->create_object(); child_object2.set("value", value); @@ -1126,12 +1126,12 @@ TEST_CASE("migration: Automatic") { {"EmployeeId", "XHGR"s}, {"Name", "John Doe"s}, }; - realm->begin_write_transaction(); + realm->begin_transaction(); Object::create(ctx, realm, *realm->schema().find("EmpDetails"), values); realm->commit_transaction(); realm->update_schema(schema2, 2, [](auto old_realm, auto new_realm, auto&) { - // ObjectStore::delete_data_for_object(realm->get_group(), "DetailStudentStatus"); + // ObjectStore::delete_data_for_object(realm->read_group(), "DetailStudentStatus"); Object old_obj(old_realm, "EmpDetails", 0); Object new_obj(new_realm, "EmpDetails", 0); @@ -1204,7 +1204,7 @@ TEST_CASE("migration: Automatic") { {"object", AnyDict{{"value", INT64_C(10)}}}, {"array", AnyVector{AnyDict{{"value", INT64_C(20)}}}}, }; - realm->begin_write_transaction(); + realm->begin_transaction(); Object::create(ctx, realm, *realm->schema().find("all types"), values); realm->commit_transaction(); @@ -1257,7 +1257,7 @@ TEST_CASE("migration: Automatic") { Object obj = Object::get_for_primary_key(ctx, old_realm, "all types", util::Any(INT64_C(1))); REQUIRE(obj.is_valid()); REQUIRE_THROWS(obj.set_property_value(ctx, "bool", util::Any(false))); - REQUIRE_THROWS(old_realm->begin_write_transaction()); + REQUIRE_THROWS(old_realm->begin_transaction()); }); } @@ -1363,7 +1363,7 @@ TEST_CASE("migration: Automatic") { SECTION("create object in new realm") { realm->update_schema(schema, 2, [&values](auto, auto new_realm, Schema&) { - REQUIRE(new_realm->is_in_write_transaction()); + REQUIRE(new_realm->is_in_transaction()); CppContext ctx(new_realm); any_cast(values)["pk"] = INT64_C(2); @@ -1378,7 +1378,7 @@ TEST_CASE("migration: Automatic") { SECTION("upsert in new realm") { realm->update_schema(schema, 2, [&values](auto, auto new_realm, Schema&) { - REQUIRE(new_realm->is_in_write_transaction()); + REQUIRE(new_realm->is_in_transaction()); CppContext ctx(new_realm); any_cast(values)["bool"] = false; Object obj = Object::create(ctx, new_realm, "all types", values, CreatePolicy::UpdateAll); @@ -1392,7 +1392,7 @@ TEST_CASE("migration: Automatic") { SECTION("upsert in new realm after modifying primary key") { realm->update_schema(schema, 2, [&values](auto, auto new_realm, Schema&) { get_table(new_realm, "all types")->set_primary_key_column(ColKey()); - REQUIRE(new_realm->is_in_write_transaction()); + REQUIRE(new_realm->is_in_transaction()); CppContext ctx(new_realm); any_cast(values)["bool"] = false; Object obj = Object::create(ctx, new_realm, "all types", values, CreatePolicy::UpdateAll); @@ -1438,7 +1438,7 @@ TEST_CASE("migration: Automatic") { // actually breaking if we're doing invalid things CppContext ctx(realm); auto object_schema = realm->schema().find("all types"); - realm->begin_write_transaction(); + realm->begin_transaction(); for (int i = 1; i < 10; ++i) { any_cast(values)["pk"] = INT64_C(1) + i; any_cast(values)["int"] = INT64_C(5) + i; @@ -1458,7 +1458,7 @@ TEST_CASE("migration: Automatic") { }); // Create a new object with the no-longer-used pk of 1 - realm->begin_write_transaction(); + realm->begin_transaction(); any_cast(values)["pk"] = INT64_C(1); any_cast(values)["int"] = INT64_C(4); object_schema = realm->schema().find("all types"); @@ -1481,7 +1481,7 @@ TEST_CASE("migration: Automatic") { // actually breaking if we're doing invalid things CppContext ctx(realm); auto object_schema = realm->schema().find("string pk"); - realm->begin_write_transaction(); + realm->begin_transaction(); for (int64_t i = 0; i < 10; ++i) { util::Any values = AnyDict{ {"pk", util::to_string(i)}, @@ -1503,7 +1503,7 @@ TEST_CASE("migration: Automatic") { }); // Create a new object with the no-longer-used pk of 0 - realm->begin_write_transaction(); + realm->begin_transaction(); util::Any values = AnyDict{ {"pk", "0"s}, {"value", INT64_C(0)}, @@ -1523,7 +1523,7 @@ TEST_CASE("migration: Automatic") { SECTION("create and modify int primary key inside migration") { SECTION("with index") { - realm->begin_write_transaction(); + realm->begin_transaction(); auto table = get_table(realm, "int pk"); table->add_search_index(table->get_column_key("pk")); realm->commit_transaction(); @@ -1552,7 +1552,7 @@ TEST_CASE("migration: Automatic") { SECTION("create and modify string primary key inside migration") { SECTION("with index") { - realm->begin_write_transaction(); + realm->begin_transaction(); auto table = get_table(realm, "string pk"); table->add_search_index(table->get_column_key("pk")); realm->commit_transaction(); @@ -1602,7 +1602,7 @@ TEST_CASE("migration: Automatic") { auto apply_renames = [&](std::initializer_list renames) -> Realm::MigrationFunction { return [=](SharedRealm, SharedRealm realm, Schema& schema) { for (auto rename : renames) { - ObjectStore::rename_property(realm->get_group(), schema, rename.object_type, rename.old_name, + ObjectStore::rename_property(realm->read_group(), schema, rename.object_type, rename.old_name, rename.new_name); } }; @@ -1735,8 +1735,8 @@ TEST_CASE("migration: Automatic") { auto init = [&](Schema const& old_schema) { realm->update_schema(old_schema, 1); - realm->begin_write_transaction(); - auto table = ObjectStore::table_for_object_type(realm->get_group(), "object"); + realm->begin_transaction(); + auto table = ObjectStore::table_for_object_type(realm->read_group(), "object"); auto col = table->get_primary_key_column(); if (col) table->create_object_with_primary_key(10); @@ -1752,7 +1752,7 @@ TEST_CASE("migration: Automatic") { REQUIRE_NOTHROW(realm->update_schema(new_schema, 2, apply_renames({__VA_ARGS__}))); \ REQUIRE(realm->schema() == new_schema); \ VERIFY_SCHEMA(*realm, false); \ - auto table = ObjectStore::table_for_object_type(realm->get_group(), "object"); \ + auto table = ObjectStore::table_for_object_type(realm->read_group(), "object"); \ auto key = table->get_column_keys()[0]; \ if (table->get_column_attr(key).test(col_attr_Nullable)) \ REQUIRE(table->begin()->get>(key) == 10); \ @@ -1809,7 +1809,7 @@ TEST_CASE("migration: Automatic") { auto new_schema = set_primary_key(rename_value(schema), "object", "new"); init(schema); REQUIRE_NOTHROW(realm->update_schema(new_schema, 2, [](auto, auto realm, Schema& schema) { - ObjectStore::rename_property(realm->get_group(), schema, "object", "value", "new"); + ObjectStore::rename_property(realm->read_group(), schema, "object", "value", "new"); CppContext ctx(realm); util::Any values = AnyDict{{"new", INT64_C(11)}}; @@ -1817,7 +1817,7 @@ TEST_CASE("migration: Automatic") { })); REQUIRE(realm->schema() == new_schema); VERIFY_SCHEMA(*realm, false); - auto table = ObjectStore::table_for_object_type(realm->get_group(), "object"); + auto table = ObjectStore::table_for_object_type(realm->read_group(), "object"); auto key = table->get_column_keys()[0]; auto it = table->begin(); REQUIRE(it->get(key) == 10); @@ -2149,8 +2149,8 @@ TEST_CASE("migration: ResetFile") { auto ino = get_fileid(); realm->update_schema(schema); REQUIRE(ino == get_fileid()); - realm->begin_write_transaction(); - ObjectStore::table_for_object_type(realm->get_group(), "object")->create_object(); + realm->begin_transaction(); + ObjectStore::table_for_object_type(realm->read_group(), "object")->create_object(); realm->commit_transaction(); } auto realm = Realm::get_shared_realm(config); @@ -2158,13 +2158,13 @@ TEST_CASE("migration: ResetFile") { SECTION("file is reset when schema version increases") { realm->update_schema(schema, 1); - REQUIRE(ObjectStore::table_for_object_type(realm->get_group(), "object")->size() == 0); + REQUIRE(ObjectStore::table_for_object_type(realm->read_group(), "object")->size() == 0); REQUIRE(ino != get_fileid()); } SECTION("file is reset when an existing table is modified") { realm->update_schema(add_property(schema, "object", {"value 2", PropertyType::Int})); - REQUIRE(ObjectStore::table_for_object_type(realm->get_group(), "object")->size() == 0); + REQUIRE(ObjectStore::table_for_object_type(realm->read_group(), "object")->size() == 0); REQUIRE(ino != get_fileid()); } @@ -2173,29 +2173,29 @@ TEST_CASE("migration: ResetFile") { { {"value", PropertyType::Int}, }})); - REQUIRE(ObjectStore::table_for_object_type(realm->get_group(), "object")->size() == 1); + REQUIRE(ObjectStore::table_for_object_type(realm->read_group(), "object")->size() == 1); REQUIRE(realm->schema().size() == 3); REQUIRE(ino == get_fileid()); } SECTION("file is not reset when removing a table") { realm->update_schema(remove_table(schema, "object 2")); - REQUIRE(ObjectStore::table_for_object_type(realm->get_group(), "object")->size() == 1); - REQUIRE(ObjectStore::table_for_object_type(realm->get_group(), "object 2")); + REQUIRE(ObjectStore::table_for_object_type(realm->read_group(), "object")->size() == 1); + REQUIRE(ObjectStore::table_for_object_type(realm->read_group(), "object 2")); REQUIRE(realm->schema().size() == 1); REQUIRE(ino == get_fileid()); } SECTION("file is not reset when adding an index") { realm->update_schema(set_indexed(schema, "object", "value", true)); - REQUIRE(ObjectStore::table_for_object_type(realm->get_group(), "object")->size() == 1); + REQUIRE(ObjectStore::table_for_object_type(realm->read_group(), "object")->size() == 1); REQUIRE(ino == get_fileid()); } SECTION("file is not reset when removing an index") { realm->update_schema(set_indexed(schema, "object", "value", true)); realm->update_schema(schema); - REQUIRE(ObjectStore::table_for_object_type(realm->get_group(), "object")->size() == 1); + REQUIRE(ObjectStore::table_for_object_type(realm->read_group(), "object")->size() == 1); REQUIRE(ino == get_fileid()); } } @@ -2224,7 +2224,7 @@ TEST_CASE("migration: AdditiveDiscovered") { DYNAMIC_SECTION("can add new properties to existing tables" << mode_string) { REQUIRE_NOTHROW(realm->update_schema(add_property(schema, "object", {"value 3", PropertyType::Int}))); - REQUIRE(ObjectStore::table_for_object_type(realm->get_group(), "object")->get_column_count() == 3); + REQUIRE(ObjectStore::table_for_object_type(realm->read_group(), "object")->get_column_count() == 3); } DYNAMIC_SECTION("can add new tables" << mode_string) { @@ -2232,8 +2232,8 @@ TEST_CASE("migration: AdditiveDiscovered") { { {"value", PropertyType::Int}, }}))); - REQUIRE(ObjectStore::table_for_object_type(realm->get_group(), "object")); - REQUIRE(ObjectStore::table_for_object_type(realm->get_group(), "object 2")); + REQUIRE(ObjectStore::table_for_object_type(realm->read_group(), "object")); + REQUIRE(ObjectStore::table_for_object_type(realm->read_group(), "object 2")); } DYNAMIC_SECTION("embedded orphan types" << mode_string) { @@ -2243,8 +2243,8 @@ TEST_CASE("migration: AdditiveDiscovered") { add_table(schema, {"origin", ObjectSchema::IsEmbedded{true}, {{"link", PropertyType::Object | PropertyType::Nullable, "object"}}}))); - REQUIRE(ObjectStore::table_for_object_type(realm->get_group(), "object")); - REQUIRE(!ObjectStore::table_for_object_type(realm->get_group(), "origin")); + REQUIRE(ObjectStore::table_for_object_type(realm->read_group(), "object")); + REQUIRE(!ObjectStore::table_for_object_type(realm->read_group(), "origin")); } else { // explicitly included embedded orphan types is an error @@ -2260,7 +2260,7 @@ TEST_CASE("migration: AdditiveDiscovered") { } DYNAMIC_SECTION("indexes are updated when schema version is bumped" << mode_string) { - auto table = ObjectStore::table_for_object_type(realm->get_group(), "object"); + auto table = ObjectStore::table_for_object_type(realm->read_group(), "object"); auto col_keys = table->get_column_keys(); REQUIRE(table->has_search_index(col_keys[0])); REQUIRE(!table->has_search_index(col_keys[1])); @@ -2273,7 +2273,7 @@ TEST_CASE("migration: AdditiveDiscovered") { } DYNAMIC_SECTION("indexes are not updated when schema version is not bumped" << mode_string) { - auto table = ObjectStore::table_for_object_type(realm->get_group(), "object"); + auto table = ObjectStore::table_for_object_type(realm->read_group(), "object"); auto col_keys = table->get_column_keys(); REQUIRE(table->has_search_index(col_keys[0])); REQUIRE(!table->has_search_index(col_keys[1])); @@ -2286,9 +2286,9 @@ TEST_CASE("migration: AdditiveDiscovered") { } DYNAMIC_SECTION("can remove properties from existing tables, but column is not removed" << mode_string) { - auto table = ObjectStore::table_for_object_type(realm->get_group(), "object"); + auto table = ObjectStore::table_for_object_type(realm->read_group(), "object"); REQUIRE_NOTHROW(realm->update_schema(remove_property(schema, "object", "value"))); - REQUIRE(ObjectStore::table_for_object_type(realm->get_group(), "object")->get_column_count() == 2); + REQUIRE(ObjectStore::table_for_object_type(realm->read_group(), "object")->get_column_count() == 2); auto const& properties = realm->schema().find("object")->persisted_properties; REQUIRE(properties.size() == 1); auto col_keys = table->get_column_keys(); @@ -2341,8 +2341,8 @@ TEST_CASE("migration: AdditiveDiscovered") { DYNAMIC_SECTION("add new columns from different SG" << mode_string) { auto realm2 = Realm::get_shared_realm(config); - auto& group = realm2->get_group(); - realm2->begin_write_transaction(); + auto& group = realm2->read_group(); + realm2->begin_transaction(); auto table = ObjectStore::table_for_object_type(group, "object"); auto col_keys = table->get_column_keys(); table->add_column(type_Int, "new column"); @@ -2356,8 +2356,8 @@ TEST_CASE("migration: AdditiveDiscovered") { DYNAMIC_SECTION("opening new Realms uses the correct schema after an external change" << mode_string) { auto realm2 = Realm::get_shared_realm(config); - auto& group = realm2->get_group(); - realm2->begin_write_transaction(); + auto& group = realm2->read_group(); + realm2->begin_transaction(); auto table = ObjectStore::table_for_object_type(group, "object"); auto col_keys = table->get_column_keys(); table->add_column(type_Double, "newcol"); @@ -2452,7 +2452,7 @@ TEST_CASE("migration: AdditiveDiscovered") { DYNAMIC_SECTION("update_schema() does not begin a write transaction when extra columns are present" << mode_string) { - realm->begin_write_transaction(); + realm->begin_transaction(); auto realm2 = Realm::get_shared_realm(config); // will deadlock if it tries to start a write transaction @@ -2463,7 +2463,7 @@ TEST_CASE("migration: AdditiveDiscovered") { "update_schema() does not begin a write transaction when indexes are changed without bumping schema " "version" << mode_string) { - realm->begin_write_transaction(); + realm->begin_transaction(); auto realm2 = Realm::get_shared_realm(config); // will deadlock if it tries to start a write transaction @@ -2472,7 +2472,7 @@ TEST_CASE("migration: AdditiveDiscovered") { DYNAMIC_SECTION("update_schema() does not begin a write transaction for invalid schema changes" << mode_string) { - realm->begin_write_transaction(); + realm->begin_transaction(); auto realm2 = Realm::get_shared_realm(config); auto new_schema = @@ -2502,7 +2502,7 @@ TEST_CASE("migration: Manual") { {"array", PropertyType::Array | PropertyType::Object, "object"}, }}}; realm->update_schema(schema); - auto col_keys = realm->get_group().get_table("class_object")->get_column_keys(); + auto col_keys = realm->read_group().get_table("class_object")->get_column_keys(); #define REQUIRE_MIGRATION(schema, migration) \ do { \ @@ -2521,7 +2521,7 @@ TEST_CASE("migration: Manual") { {"value", PropertyType::Int}, }}), [](SharedRealm, SharedRealm realm, Schema&) { - realm->get_group().add_table("class_new table")->add_column(type_Int, "value"); + realm->read_group().add_table("class_new table")->add_column(type_Int, "value"); }); } SECTION("add property to table") { @@ -2621,7 +2621,7 @@ TEST_CASE("migration: Manual") { } SECTION("update_schema() does not begin a write transaction when schema version is unchanged") { - realm->begin_write_transaction(); + realm->begin_transaction(); auto realm2 = Realm::get_shared_realm(config); // will deadlock if it tries to start a write transaction diff --git a/test/object-store/notifications-fuzzer/command_file.cpp b/test/object-store/notifications-fuzzer/command_file.cpp index f23c0fa7de2..cf5ed816032 100644 --- a/test/object-store/notifications-fuzzer/command_file.cpp +++ b/test/object-store/notifications-fuzzer/command_file.cpp @@ -81,7 +81,7 @@ static void run_commit(RealmState& state) log("commit\n"); state.realm.commit_transaction(); state.coordinator.on_change(); - state.realm.begin_write_transaction(); + state.realm.begin_transaction(); } static void run_lv_insert(RealmState& state, size_t pos, size_t target) @@ -224,7 +224,7 @@ void CommandFile::import(RealmState& state) { auto& table = state.table; - state.realm.begin_write_transaction(); + state.realm.begin_transaction(); table.clear(); size_t ndx = table.add_empty_row(initial_values.size()); @@ -244,7 +244,7 @@ void CommandFile::import(RealmState& state) void CommandFile::run(RealmState& state) { - state.realm.begin_write_transaction(); + state.realm.begin_transaction(); for (auto& command : commands) { command(state); } diff --git a/test/object-store/notifications-fuzzer/fuzzer.cpp b/test/object-store/notifications-fuzzer/fuzzer.cpp index a9d947aeb11..90f2e4f907b 100644 --- a/test/object-store/notifications-fuzzer/fuzzer.cpp +++ b/test/object-store/notifications-fuzzer/fuzzer.cpp @@ -170,8 +170,8 @@ static void test(Realm::Config const& config, SharedRealm& r, SharedRealm& r2, s { fuzzer::RealmState state = {*r, *_impl::RealmCoordinator::get_existing_coordinator(r->config().path), - *r->get_group()->get_table("class_object"), - r->get_group()->get_table("class_linklist")->get_linklist(0, 0), + *r->read_group()->get_table("class_object"), + r->read_group()->get_table("class_linklist")->get_linklist(0, 0), 0, {}}; @@ -184,9 +184,9 @@ static void test(Realm::Config const& config, SharedRealm& r, SharedRealm& r2, s fuzzer::RealmState state2 = { *r2, state.coordinator, - *r2->get_group()->get_table("class_object"), + *r2->read_group()->get_table("class_object"), #if FUZZ_LINKVIEW - r2->get_group()->get_table("class_linklist")->get_linklist(0, 0), + r2->read_group()->get_table("class_linklist")->get_linklist(0, 0), #else {}, #endif @@ -258,14 +258,14 @@ int main(int argc, char** argv) auto r2 = Realm::get_shared_realm(config); auto& coordinator = *_impl::RealmCoordinator::get_existing_coordinator(config.path); - r->begin_write_transaction(); - r->get_group()->get_table("class_linklist")->add_empty_row(); + r->begin_transaction(); + r->read_group()->get_table("class_linklist")->add_empty_row(); r->commit_transaction(); auto test_on = [&](auto& buffer) { std::istringstream ss(buffer); test(config, r, r2, ss); - if (r->is_in_write_transaction()) + if (r->is_in_transaction()) r->cancel_transaction(); r2->invalidate(); coordinator.on_change(); diff --git a/test/object-store/object.cpp b/test/object-store/object.cpp index d656b644b34..164b32bb9e1 100644 --- a/test/object-store/object.cpp +++ b/test/object-store/object.cpp @@ -204,10 +204,10 @@ TEST_CASE("object") { auto& coordinator = *_impl::RealmCoordinator::get_coordinator(config.path); SECTION("add_notification_callback()") { - auto table = r->get_group().get_table("class_table"); + auto table = r->read_group().get_table("class_table"); auto col_keys = table->get_column_keys(); std::vector pks = {3, 4, 7, 9, 10, 21, 24, 34, 42, 50}; - r->begin_write_transaction(); + r->begin_transaction(); for (int i = 0; i < 10; ++i) table->create_object_with_primary_key(pks[i]).set("value 1", i).set("value 2", i); r->commit_transaction(); @@ -219,7 +219,7 @@ TEST_CASE("object") { Object object(r, obj); auto write = [&](auto&& f) { - r->begin_write_transaction(); + r->begin_transaction(); f(); r->commit_transaction(); @@ -299,11 +299,11 @@ TEST_CASE("object") { SECTION("multiple write transactions") { auto token = require_change(); - auto r2row = r2->get_group().get_table("class_table")->get_object(0); - r2->begin_write_transaction(); + auto r2row = r2->read_group().get_table("class_table")->get_object(0); + r2->begin_transaction(); r2row.set(col_keys[0], 1); r2->commit_transaction(); - r2->begin_write_transaction(); + r2->begin_transaction(); r2row.set(col_keys[1], 2); r2->commit_transaction(); @@ -360,19 +360,19 @@ TEST_CASE("object") { TestContext d(r); auto create = [&](util::Any&& value, CreatePolicy policy = CreatePolicy::ForceCreate) { - r->begin_write_transaction(); + r->begin_transaction(); auto obj = Object::create(d, r, *r->schema().find("all types"), value, policy); r->commit_transaction(); return obj; }; auto create_sub = [&](util::Any&& value, CreatePolicy policy = CreatePolicy::ForceCreate) { - r->begin_write_transaction(); + r->begin_transaction(); auto obj = Object::create(d, r, *r->schema().find("link target"), value, policy); r->commit_transaction(); return obj; }; auto create_company = [&](util::Any&& value, CreatePolicy policy = CreatePolicy::ForceCreate) { - r->begin_write_transaction(); + r->begin_transaction(); Object obj = Object::create(d, r, *r->schema().find("person"), value, policy); r->commit_transaction(); return obj; @@ -412,10 +412,10 @@ TEST_CASE("object") { }); Obj row = obj.obj(); - auto link_target = *r->get_group().get_table("class_link target")->begin(); + auto link_target = *r->read_group().get_table("class_link target")->begin(); TableRef table = row.get_table(); auto target_table = link_target.get_table(); - auto array_target_table = r->get_group().get_table("class_array target"); + auto array_target_table = r->read_group().get_table("class_array target"); REQUIRE(row.get(table->get_column_key("_id")) == 1); REQUIRE(row.get(table->get_column_key("bool")) == true); REQUIRE(row.get(table->get_column_key("int")) == 5); @@ -561,7 +561,7 @@ TEST_CASE("object") { } SECTION("create does not complain about missing values for nullable fields") { - r->begin_write_transaction(); + r->begin_transaction(); realm::Object obj; REQUIRE_NOTHROW(obj = Object::create(d, r, *r->schema().find("all optional types"), util::Any(AnyDict{}))); r->commit_transaction(); @@ -604,7 +604,7 @@ TEST_CASE("object") { {"_id", INT64_C(7)}, }; // Core will throw if the list is populated before the PK is set - r->begin_write_transaction(); + r->begin_transaction(); REQUIRE_NOTHROW(Object::create(d, r, *r->schema().find("pk after list"), util::Any(value))); } @@ -699,7 +699,7 @@ TEST_CASE("object") { {"team", AnyVec{donald, charley}}}; Object obj = create_company(eddie, CreatePolicy::UpdateAll); - auto table = r->get_group().get_table("class_person"); + auto table = r->read_group().get_table("class_person"); REQUIRE(table->size() == 5); Results result(r, table); result = result.sort({{"_id", false}}); @@ -767,7 +767,7 @@ TEST_CASE("object") { {"dictionary", AnyDict{{"key", "value"s}}}, }); - auto obj_table = r->get_group().get_table("class_all types"); + auto obj_table = r->read_group().get_table("class_all types"); Results result(r, obj_table); bool callback_called; bool results_callback_called; @@ -783,7 +783,7 @@ TEST_CASE("object") { }); advance_and_notify(*r); - auto table = r->get_group().get_table("class_link target"); + auto table = r->read_group().get_table("class_link target"); REQUIRE(table->size() == 1); create( @@ -859,7 +859,7 @@ TEST_CASE("object") { }; Object obj = create(dict); - auto obj_table = r->get_group().get_table("class_all types"); + auto obj_table = r->read_group().get_table("class_all types"); Results result(r, obj_table); auto token1 = result.add_notification_callback([&](CollectionChangeSet, std::exception_ptr) { callback_called = true; @@ -908,7 +908,7 @@ TEST_CASE("object") { {"decimal array", AnyVec{Decimal128("1.23e45")}}, {"uuid array", AnyVec{UUID("3b241101-1111-bbbb-cccc-4136c566a962")}}, }; - r->begin_write_transaction(); + r->begin_transaction(); auto obj = Object::create(d, r, *r->schema().find("all optional types"), util::Any(initial_values)); // Missing fields in dictionary do not update anything @@ -1091,15 +1091,15 @@ TEST_CASE("object") { {"_id", "value"s}, }; auto create = [&](util::Any&& value, StringData type) { - r->begin_write_transaction(); + r->begin_transaction(); auto obj = Object::create(d, r, *r->schema().find(type), value); r->commit_transaction(); return obj; }; auto obj = create(AnyDict{{"_id", d.null_value()}}, "nullable int pk"); - auto col_pk_int = r->get_group().get_table("class_nullable int pk")->get_column_key("_id"); - auto col_pk_str = r->get_group().get_table("class_nullable string pk")->get_column_key("_id"); + auto col_pk_int = r->read_group().get_table("class_nullable int pk")->get_column_key("_id"); + auto col_pk_str = r->read_group().get_table("class_nullable string pk")->get_column_key("_id"); REQUIRE(obj.obj().is_null(col_pk_int)); obj = create(AnyDict{{"_id", d.null_value()}}, "nullable string pk"); REQUIRE(obj.obj().is_null(col_pk_str)); @@ -1112,36 +1112,36 @@ TEST_CASE("object") { SECTION("create null and 0 primary keys for Int types") { auto create = [&](util::Any&& value, StringData type) { - r->begin_write_transaction(); + r->begin_transaction(); auto obj = Object::create(d, r, *r->schema().find(type), value); r->commit_transaction(); return obj; }; create(AnyDict{{"_id", util::Any()}}, "all optional types"); create(AnyDict{{"_id", INT64_C(0)}}, "all optional types"); - REQUIRE(Results(r, r->get_group().get_table("class_all optional types")).size() == 2); + REQUIRE(Results(r, r->read_group().get_table("class_all optional types")).size() == 2); } SECTION("create null and default primary keys for ObjectId types") { auto create = [&](util::Any&& value, StringData type) { - r->begin_write_transaction(); + r->begin_transaction(); auto obj = Object::create(d, r, *r->schema().find(type), value); r->commit_transaction(); return obj; }; create(AnyDict{{"_id", util::Any()}}, "nullable object id pk"); create(AnyDict{{"_id", ObjectId::gen()}}, "nullable object id pk"); - REQUIRE(Results(r, r->get_group().get_table("class_nullable object id pk")).size() == 2); + REQUIRE(Results(r, r->read_group().get_table("class_nullable object id pk")).size() == 2); } SECTION("getters and setters") { - r->begin_write_transaction(); + r->begin_transaction(); - auto table = r->get_group().get_table("class_all types"); + auto table = r->read_group().get_table("class_all types"); table->create_object_with_primary_key(1); Object obj(r, *r->schema().find("all types"), *table->begin()); - auto link_table = r->get_group().get_table("class_link target"); + auto link_table = r->read_group().get_table("class_link target"); link_table->create_object_with_primary_key(0); Object linkobj(r, *r->schema().find("link target"), *link_table->begin()); @@ -1240,7 +1240,7 @@ TEST_CASE("object") { REQUIRE(any_cast(obj.get_property_value(d, "bool array")).size() == 2); REQUIRE(any_cast(obj.get_property_value(d, "object array")).size() == 1); - r->begin_write_transaction(); + r->begin_transaction(); obj.set_property_value(d, "bool array", obj.get_property_value(d, "bool array")); obj.set_property_value(d, "object array", obj.get_property_value(d, "object array")); r->commit_transaction(); @@ -1283,8 +1283,8 @@ TEST_CASE("object") { }; c2.defaults = c1.defaults; - r1->begin_write_transaction(); - r2->begin_write_transaction(); + r1->begin_transaction(); + r2->begin_transaction(); auto object1 = Object::create(c1, r1, *r1->schema().find("pk after list"), util::Any(v1)); auto object2 = Object::create(c2, r2, *r2->schema().find("pk after list"), util::Any(v2)); r2->commit_transaction(); @@ -1292,7 +1292,7 @@ TEST_CASE("object") { server.start(); util::EventLoop::main().run_until([&] { - return r1->get_group().get_table("class_array target")->size() == 4; + return r1->read_group().get_table("class_array target")->size() == 4; }); Obj obj = object1.obj(); @@ -1339,7 +1339,7 @@ TEST_CASE("Embedded Object") { CppContext ctx(realm); auto create = [&](util::Any&& value, CreatePolicy policy = CreatePolicy::UpdateAll) { - realm->begin_write_transaction(); + realm->begin_transaction(); auto obj = Object::create(ctx, realm, *realm->schema().find("all types"), value, policy); realm->commit_transaction(); return obj; @@ -1370,7 +1370,7 @@ TEST_CASE("Embedded Object") { }); SECTION("throws when given a managed object") { - realm->begin_write_transaction(); + realm->begin_transaction(); REQUIRE_THROWS_WITH( obj.set_property_value(ctx, "object", obj.get_property_value(ctx, "object")), "Cannot set a link to an existing managed embedded object"); @@ -1378,7 +1378,7 @@ TEST_CASE("Embedded Object") { } SECTION("replaces object when given a dictionary and CreatePolicy::UpdateAll") { - realm->begin_write_transaction(); + realm->begin_transaction(); auto old_linked = any_cast(obj.get_property_value(ctx, "object")); obj.set_property_value(ctx, "object", util::Any(AnyDict{{"value", INT64_C(40)}})); auto new_linked = any_cast(obj.get_property_value(ctx, "object")); @@ -1388,7 +1388,7 @@ TEST_CASE("Embedded Object") { } SECTION("mutates existing object when given a dictionary and CreatePolicy::UpdateModified") { - realm->begin_write_transaction(); + realm->begin_transaction(); auto old_linked = any_cast(obj.get_property_value(ctx, "object")); obj.set_property_value(ctx, "object", util::Any(AnyDict{{"value", INT64_C(40)}}), CreatePolicy::UpdateModified); @@ -1400,7 +1400,7 @@ TEST_CASE("Embedded Object") { } SECTION("can set embedded link to null") { - realm->begin_write_transaction(); + realm->begin_transaction(); auto old_linked = any_cast(obj.get_property_value(ctx, "object")); obj.set_property_value(ctx, "object", util::Any()); auto new_linked = obj.get_property_value(ctx, "object"); @@ -1423,14 +1423,14 @@ TEST_CASE("Embedded Object") { List list2(realm, obj2.obj().get_linklist("array")); SECTION("throws when given a managed object") { - realm->begin_write_transaction(); + realm->begin_transaction(); REQUIRE_THROWS_WITH(obj.set_property_value(ctx, "array", util::Any{AnyVector{list2.get(0)}}), "Cannot add an existing managed embedded object to a List."); realm->cancel_transaction(); } SECTION("replaces objects when given a dictionary and CreatePolicy::UpdateAll") { - realm->begin_write_transaction(); + realm->begin_transaction(); auto old_obj_1 = list.get(0); auto old_obj_2 = list.get(1); obj.set_property_value(ctx, "array", @@ -1447,7 +1447,7 @@ TEST_CASE("Embedded Object") { } SECTION("mutates existing objects when given a dictionary and CreatePolicy::UpdateModified") { - realm->begin_write_transaction(); + realm->begin_transaction(); auto old_obj_1 = list.get(0); auto old_obj_2 = list.get(1); obj.set_property_value(ctx, "array", @@ -1464,7 +1464,7 @@ TEST_CASE("Embedded Object") { } SECTION("clears list when given null") { - realm->begin_write_transaction(); + realm->begin_transaction(); obj.set_property_value(ctx, "array", util::Any()); REQUIRE(list.size() == 0); realm->cancel_transaction(); @@ -1478,7 +1478,7 @@ TEST_CASE("Embedded Object") { {"array", AnyVector{AnyDict{{"value", INT64_C(20)}}, AnyDict{{"value", INT64_C(30)}}}}, }); - auto array_table = realm->get_group().get_table("class_array target"); + auto array_table = realm->read_group().get_table("class_array target"); Results result(realm, array_table); bool obj_callback_called = false; @@ -1539,7 +1539,7 @@ TEST_CASE("Embedded Object") { advance_and_notify(*realm); REQUIRE(calls == 1); - realm->begin_write_transaction(); + realm->begin_transaction(); parent.obj().remove(); realm->commit_transaction(); advance_and_notify(*realm); diff --git a/test/object-store/primitive_list.cpp b/test/object-store/primitive_list.cpp index b709a9168c0..31a79531e1c 100644 --- a/test/object-store/primitive_list.cpp +++ b/test/object-store/primitive_list.cpp @@ -509,9 +509,9 @@ TEMPLATE_TEST_CASE("primitive list", "[primitives]", ::Int, ::Bool, ::Float, ::D auto r = Realm::get_shared_realm(config); auto r2 = Realm::get_shared_realm(config); - auto table = r->get_group().get_table("class_object"); - auto table2 = r2->get_group().get_table("class_object"); - r->begin_write_transaction(); + auto table = r->read_group().get_table("class_object"); + auto table2 = r2->read_group().get_table("class_object"); + r->begin_transaction(); Obj obj = table->create_object(); ColKey col = table->get_column_key("value"); @@ -624,7 +624,7 @@ TEMPLATE_TEST_CASE("primitive list", "[primitives]", ::Int, ::Bool, ::Float, ::D } } - if (!list.is_valid() || !r->is_in_write_transaction()) + if (!list.is_valid() || !r->is_in_transaction()) return; for (T value : values) @@ -960,12 +960,12 @@ TEMPLATE_TEST_CASE("primitive list", "[primitives]", ::Int, ::Bool, ::Float, ::D // Remove the existing copy of this value so that the sorted list // doesn't have dupes resulting in an unstable order advance_and_notify(*r); - r->begin_write_transaction(); + r->begin_transaction(); list.remove(0); r->commit_transaction(); advance_and_notify(*r); - r->begin_write_transaction(); + r->begin_transaction(); list.insert(0, static_cast(values[0])); r->commit_transaction(); @@ -978,7 +978,7 @@ TEMPLATE_TEST_CASE("primitive list", "[primitives]", ::Int, ::Bool, ::Float, ::D SECTION("remove value from list") { advance_and_notify(*r); - r->begin_write_transaction(); + r->begin_transaction(); list.remove(1); r->commit_transaction(); @@ -993,7 +993,7 @@ TEMPLATE_TEST_CASE("primitive list", "[primitives]", ::Int, ::Bool, ::Float, ::D SECTION("clear list") { advance_and_notify(*r); - r->begin_write_transaction(); + r->begin_transaction(); list.remove_all(); r->commit_transaction(); advance_and_notify(*r); @@ -1006,7 +1006,7 @@ TEMPLATE_TEST_CASE("primitive list", "[primitives]", ::Int, ::Bool, ::Float, ::D advance_and_notify(*r); REQUIRE(calls == 3); - r->begin_write_transaction(); + r->begin_transaction(); obj.remove(); r->commit_transaction(); advance_and_notify(*r); @@ -1015,7 +1015,7 @@ TEMPLATE_TEST_CASE("primitive list", "[primitives]", ::Int, ::Bool, ::Float, ::D REQUIRE(rchange.deletions.count() == values.size()); REQUIRE(srchange.deletions.count() == values.size()); - r->begin_write_transaction(); + r->begin_transaction(); table->create_object(); r->commit_transaction(); advance_and_notify(*r); @@ -1023,7 +1023,7 @@ TEMPLATE_TEST_CASE("primitive list", "[primitives]", ::Int, ::Bool, ::Float, ::D } SECTION("deleting containing row before first run of notifier") { - r2->begin_write_transaction(); + r2->begin_transaction(); table2->begin()->remove(); r2->commit_transaction(); advance_and_notify(*r); @@ -1043,7 +1043,7 @@ TEMPLATE_TEST_CASE("primitive list", "[primitives]", ::Int, ::Bool, ::Float, ::D { auto r = Realm::get_shared_realm(sync_config); - r->begin_write_transaction(); + r->begin_transaction(); CppContext ctx(r); auto obj = Object::create(ctx, r, *r->schema().find("object"), util::Any(AnyDict{})); @@ -1058,7 +1058,7 @@ TEMPLATE_TEST_CASE("primitive list", "[primitives]", ::Int, ::Bool, ::Float, ::D { auto r = Realm::get_shared_realm(sync_config); - auto table = r->get_group().get_table("class_object"); + auto table = r->read_group().get_table("class_object"); util::EventLoop::main().run_until([&] { return table->size() == 1; diff --git a/test/object-store/realm.cpp b/test/object-store/realm.cpp index d6ffca03593..b54e8b80152 100644 --- a/test/object-store/realm.cpp +++ b/test/object-store/realm.cpp @@ -153,7 +153,7 @@ TEST_CASE("SharedRealm: get_shared_realm()") { SECTION("durability") { auto realm = Realm::get_shared_realm(config); - config.is_in_memory = true; + config.in_memory = true; REQUIRE_THROWS(Realm::get_shared_realm(config)); } @@ -235,8 +235,8 @@ TEST_CASE("SharedRealm: get_shared_realm()") { bool migration_called = false; config.migration_function = [&](SharedRealm old_realm, SharedRealm new_realm, Schema&) { migration_called = true; - REQUIRE(ObjectStore::table_for_object_type(old_realm->get_group(), "object")->get_column_count() == 1); - REQUIRE(ObjectStore::table_for_object_type(new_realm->get_group(), "object")->get_column_count() == 2); + REQUIRE(ObjectStore::table_for_object_type(old_realm->read_group(), "object")->get_column_count() == 1); + REQUIRE(ObjectStore::table_for_object_type(new_realm->read_group(), "object")->get_column_count() == 2); }; Realm::get_shared_realm(config); REQUIRE(migration_called); @@ -251,8 +251,8 @@ TEST_CASE("SharedRealm: get_shared_realm()") { }; bool migration_called = false; config.migration_function = [&](SharedRealm old_realm, SharedRealm new_realm, Schema&) { - REQUIRE(ObjectStore::table_for_object_type(old_realm->get_group(), "object")->get_column_count() == 1); - REQUIRE(ObjectStore::table_for_object_type(new_realm->get_group(), "object")->get_column_count() == 2); + REQUIRE(ObjectStore::table_for_object_type(old_realm->read_group(), "object")->get_column_count() == 1); + REQUIRE(ObjectStore::table_for_object_type(new_realm->read_group(), "object")->get_column_count() == 2); if (!migration_called) { migration_called = true; throw "error"; @@ -270,7 +270,7 @@ TEST_CASE("SharedRealm: get_shared_realm()") { auto realm = Realm::get_shared_realm(config); REQUIRE(realm->schema().size() == 1); auto it = realm->schema().find("object"); - auto table = realm->get_group().get_table("class_object"); + auto table = realm->read_group().get_table("class_object"); REQUIRE(it != realm->schema().end()); REQUIRE(it->table_key == table->get_key()); REQUIRE(it->persisted_properties.size() == 1); @@ -341,7 +341,7 @@ TEST_CASE("SharedRealm: get_shared_realm()") { config.schema_mode = SchemaMode::Immutable; auto realm = Realm::get_shared_realm(config); auto it = realm->schema().find("object"); - auto table = realm->get_group().get_table("class_object"); + auto table = realm->read_group().get_table("class_object"); REQUIRE(it != realm->schema().end()); REQUIRE(it->table_key == table->get_key()); REQUIRE(it->persisted_properties.size() == 1); @@ -405,7 +405,7 @@ TEST_CASE("SharedRealm: get_shared_realm()") { SECTION("should detect use of Realm on incorrect thread") { auto realm = Realm::get_shared_realm(config); std::thread([&] { - REQUIRE_THROWS_AS(realm->verify_is_on_thread(), IncorrectThreadException); + REQUIRE_THROWS_AS(realm->verify_thread(), IncorrectThreadException); }).join(); } @@ -455,7 +455,7 @@ TEST_CASE("SharedRealm: get_shared_realm()") { config.scheduler = std::make_shared(1); auto realm = Realm::get_shared_realm(config); std::thread([&] { - REQUIRE_NOTHROW(realm->verify_is_on_thread()); + REQUIRE_NOTHROW(realm->verify_thread()); }).join(); } @@ -477,27 +477,27 @@ TEST_CASE("SharedRealm: get_shared_realm()") { SECTION("should not use cached frozen Realm if versions don't match") { auto realm = Realm::get_shared_realm(config); - realm->get_group(); + realm->read_group(); auto frozen1 = realm->freeze(); - frozen1->get_group(); + frozen1->read_group(); REQUIRE(frozen1 != realm); - REQUIRE(realm->get_version_of_current_transaction() == frozen1->get_version_of_current_transaction()); + REQUIRE(realm->read_transaction_version() == frozen1->read_transaction_version()); - auto table = realm->get_group().get_table("class_object"); - realm->begin_write_transaction(); + auto table = realm->read_group().get_table("class_object"); + realm->begin_transaction(); Obj obj = table->create_object(); realm->commit_transaction(); - REQUIRE(realm->get_version_of_current_transaction() > frozen1->get_version_of_current_transaction()); + REQUIRE(realm->read_transaction_version() > frozen1->read_transaction_version()); auto frozen2 = realm->freeze(); - frozen2->get_group(); + frozen2->read_group(); REQUIRE(frozen2 != frozen1); REQUIRE(frozen2 != realm); - REQUIRE(realm->get_version_of_current_transaction() == frozen2->get_version_of_current_transaction()); - REQUIRE(frozen2->get_version_of_current_transaction() > frozen1->get_version_of_current_transaction()); + REQUIRE(realm->read_transaction_version() == frozen2->read_transaction_version()); + REQUIRE(frozen2->read_transaction_version() > frozen1->read_transaction_version()); } } @@ -539,7 +539,7 @@ TEST_CASE("Get Realm using Async Open", "[asyncOpen]") { REQUIRE(!error); called = true; - REQUIRE(Realm::get_shared_realm(std::move(ref))->get_group().get_table("class_object")); + REQUIRE(Realm::get_shared_realm(std::move(ref))->read_group().get_table("class_object")); }); util::EventLoop::main().run_until([&] { return called.load(); @@ -551,8 +551,8 @@ TEST_CASE("Get Realm using Async Open", "[asyncOpen]") { SECTION("downloads Realms which exist on the server") { { auto realm = Realm::get_shared_realm(config2); - realm->begin_write_transaction(); - realm->get_group().get_table("class_object")->create_object_with_primary_key(0); + realm->begin_transaction(); + realm->read_group().get_table("class_object")->create_object_with_primary_key(0); realm->commit_transaction(); wait_for_upload(*realm); } @@ -564,7 +564,7 @@ TEST_CASE("Get Realm using Async Open", "[asyncOpen]") { REQUIRE(!error); called = true; - REQUIRE(Realm::get_shared_realm(std::move(ref))->get_group().get_table("class_object")); + REQUIRE(Realm::get_shared_realm(std::move(ref))->read_group().get_table("class_object")); }); util::EventLoop::main().run_until([&] { return called.load(); @@ -578,8 +578,8 @@ TEST_CASE("Get Realm using Async Open", "[asyncOpen]") { { auto realm = Realm::get_shared_realm(config2); - realm->begin_write_transaction(); - realm->get_group().get_table("class_object")->create_object_with_primary_key(0); + realm->begin_transaction(); + realm->read_group().get_table("class_object")->create_object_with_primary_key(0); realm->commit_transaction(); wait_for_upload(*realm); } @@ -591,7 +591,7 @@ TEST_CASE("Get Realm using Async Open", "[asyncOpen]") { REQUIRE(!error); called = true; - REQUIRE(Realm::get_shared_realm(std::move(ref))->get_group().get_table("class_object")->size() == 1); + REQUIRE(Realm::get_shared_realm(std::move(ref))->read_group().get_table("class_object")->size() == 1); }); util::EventLoop::main().run_until([&] { return called.load(); @@ -652,12 +652,12 @@ TEST_CASE("SharedRealm: notifications") { size_t change_count = 0; auto realm = Realm::get_shared_realm(config); - realm->get_group(); + realm->read_group(); realm->m_binding_context.reset(new Context{&change_count}); realm->m_binding_context->realm = realm; SECTION("local notifications are sent synchronously") { - realm->begin_write_transaction(); + realm->begin_transaction(); REQUIRE(change_count == 0); realm->commit_transaction(); REQUIRE(change_count == 1); @@ -665,7 +665,7 @@ TEST_CASE("SharedRealm: notifications") { SECTION("remote notifications are sent asynchronously") { auto r2 = Realm::get_shared_realm(config); - r2->begin_write_transaction(); + r2->begin_transaction(); r2->commit_transaction(); REQUIRE(change_count == 0); util::EventLoop::main().run_until([&] { @@ -691,7 +691,7 @@ TEST_CASE("SharedRealm: notifications") { realm->set_auto_refresh(false); auto r2 = Realm::get_shared_realm(config); - r2->begin_write_transaction(); + r2->begin_transaction(); r2->commit_transaction(); realm->notify(); // Should return false as the realm was already advanced @@ -710,7 +710,7 @@ TEST_CASE("SharedRealm: notifications") { { // Create another version so that refresh() could do something auto r2 = Realm::get_shared_realm(realm.config()); - r2->begin_write_transaction(); + r2->begin_transaction(); r2->commit_transaction(); // Should be a no-op @@ -720,15 +720,15 @@ TEST_CASE("SharedRealm: notifications") { realm->m_binding_context.reset(new Context{*realm}); auto r2 = Realm::get_shared_realm(config); - r2->begin_write_transaction(); + r2->begin_transaction(); r2->commit_transaction(); REQUIRE(realm->refresh()); - auto ver = realm->get_version_of_current_or_frozen_transaction(); + auto ver = realm->current_transaction_version(); realm->m_binding_context.reset(); // Should advance to the version created in the previous did_change() REQUIRE(realm->refresh()); - auto new_ver = realm->get_version_of_current_or_frozen_transaction(); + auto new_ver = realm->current_transaction_version(); REQUIRE(*new_ver > *ver); // No more versions, so returns false REQUIRE_FALSE(realm->refresh()); @@ -746,15 +746,15 @@ TEST_CASE("SharedRealm: notifications") { void did_change(std::vector const&, std::vector const&, bool) override { ++calls; - if (realm.is_in_write_transaction()) + if (realm.is_in_transaction()) return; // Create another version so that begin_write() advances the version auto r2 = Realm::get_shared_realm(realm.config()); - r2->begin_write_transaction(); + r2->begin_transaction(); r2->commit_transaction(); - realm.begin_write_transaction(); + realm.begin_transaction(); realm.cancel_transaction(); } }; @@ -762,7 +762,7 @@ TEST_CASE("SharedRealm: notifications") { realm->m_binding_context.reset(context); auto r2 = Realm::get_shared_realm(config); - r2->begin_write_transaction(); + r2->begin_transaction(); r2->commit_transaction(); REQUIRE(realm->refresh()); REQUIRE(context->calls == 2); @@ -790,8 +790,8 @@ TEST_CASE("SharedRealm: schema updating from external changes") { auto r1 = Realm::get_shared_realm(config); auto r2 = Realm::get_shared_realm(config); auto test = [&] { - r2->begin_write_transaction(); - r2->get_group().get_table("class_object")->add_column(type_String, "new col"); + r2->begin_transaction(); + r2->read_group().get_table("class_object")->add_column(type_String, "new col"); r2->commit_transaction(); auto& object_schema = *r1->schema().find("object"); @@ -801,7 +801,7 @@ TEST_CASE("SharedRealm: schema updating from external changes") { REQUIRE(object_schema.persisted_properties[0].column_key == col); }; SECTION("with an active read transaction") { - r1->get_group(); + r1->read_group(); test(); } SECTION("without an active read transaction") { @@ -871,9 +871,9 @@ TEST_CASE("SharedRealm: close()") { REQUIRE(realm->is_closed()); - REQUIRE_THROWS_AS(realm->get_group(), ClosedRealmException); - REQUIRE_THROWS_AS(realm->begin_write_transaction(), ClosedRealmException); - REQUIRE(!realm->is_in_write_transaction()); + REQUIRE_THROWS_AS(realm->read_group(), ClosedRealmException); + REQUIRE_THROWS_AS(realm->begin_transaction(), ClosedRealmException); + REQUIRE(!realm->is_in_transaction()); REQUIRE_THROWS_AS(realm->commit_transaction(), InvalidTransactionException); REQUIRE_THROWS_AS(realm->cancel_transaction(), InvalidTransactionException); @@ -883,8 +883,8 @@ TEST_CASE("SharedRealm: close()") { } SECTION("fully closes database file even with live notifiers") { - auto& group = realm->get_group(); - realm->begin_write_transaction(); + auto& group = realm->read_group(); + realm->begin_transaction(); auto obj = ObjectStore::table_for_object_type(group, "list")->create_object(); realm->commit_transaction(); @@ -898,7 +898,7 @@ TEST_CASE("SharedRealm: close()") { // Perform a dummy transaction to ensure the notifiers actually acquire // resources that need to be closed - realm->begin_write_transaction(); + realm->begin_transaction(); realm->commit_transaction(); realm->close(); @@ -922,7 +922,7 @@ TEST_CASE("ShareRealm: in-memory mode from buffer") { // Open the buffer as a new (immutable in-memory) Realm realm::Realm::Config config2; - config2.is_in_memory = true; + config2.in_memory = true; config2.schema_mode = SchemaMode::Immutable; config2.realm_data = realm_buffer.get(); @@ -931,7 +931,7 @@ TEST_CASE("ShareRealm: in-memory mode from buffer") { // Verify that it can read the schema and that it is the same REQUIRE(realm->schema().size() == 1); auto it = realm->schema().find("object"); - auto table = realm->get_group().get_table("class_object"); + auto table = realm->read_group().get_table("class_object"); REQUIRE(it != realm->schema().end()); REQUIRE(it->table_key == table->get_key()); REQUIRE(it->persisted_properties.size() == 1); @@ -943,7 +943,7 @@ TEST_CASE("ShareRealm: in-memory mode from buffer") { config3.realm_data = realm_buffer.get(); REQUIRE_THROWS(Realm::get_shared_realm(config3)); // missing in_memory and immutable - config3.is_in_memory = true; + config3.in_memory = true; config3.schema_mode = SchemaMode::Immutable; config3.path = "path"; REQUIRE_THROWS(Realm::get_shared_realm(config3)); // both buffer and path @@ -964,8 +964,8 @@ TEST_CASE("ShareRealm: realm closed in did_change callback") { config.automatic_change_notifications = false; auto r1 = Realm::get_shared_realm(config); - r1->begin_write_transaction(); - auto table = r1->get_group().get_table("class_object"); + r1->begin_transaction(); + auto table = r1->read_group().get_table("class_object"); table->create_object(); r1->commit_transaction(); @@ -985,8 +985,8 @@ TEST_CASE("ShareRealm: realm closed in did_change callback") { r1->invalidate(); auto r2 = Realm::get_shared_realm(config); - r2->begin_write_transaction(); - r2->get_group().get_table("class_object")->create_object(); + r2->begin_transaction(); + r2->read_group().get_table("class_object")->create_object(); r2->commit_transaction(); r2.reset(); @@ -1002,8 +1002,8 @@ TEST_CASE("ShareRealm: realm closed in did_change callback") { }); auto r2 = Realm::get_shared_realm(config); - r2->begin_write_transaction(); - r2->get_group().get_table("class_object")->create_object(); + r2->begin_transaction(); + r2->read_group().get_table("class_object")->create_object(); r2->commit_transaction(); r2.reset(); @@ -1017,8 +1017,8 @@ TEST_CASE("ShareRealm: realm closed in did_change callback") { r1->m_binding_context.reset(new Context()); auto r2 = Realm::get_shared_realm(config); - r2->begin_write_transaction(); - r2->get_group().get_table("class_object")->create_object(); + r2->begin_transaction(); + r2->read_group().get_table("class_object")->create_object(); r2->commit_transaction(); r2.reset(); @@ -1198,7 +1198,7 @@ TEST_CASE("SharedRealm: coordinator schema cache") { SECTION("transaction version is bumped after a local write") { auto tv = cache_tv; - r->begin_write_transaction(); + r->begin_transaction(); r->commit_transaction(); REQUIRE(coordinator->get_cached_schema(cache_schema, cache_sv, cache_tv)); REQUIRE(cache_tv == tv + 1); @@ -1225,7 +1225,7 @@ TEST_CASE("SharedRealm: coordinator schema cache") { } SECTION("notify() with a read transaction bumps transaction version") { - r->get_group(); + r->read_group(); external_write(config, [](auto& wt) { wt.get_table("class_object")->create_object(); }); @@ -1237,7 +1237,7 @@ TEST_CASE("SharedRealm: coordinator schema cache") { } SECTION("notify() with a read transaction updates schema folloing external schema change") { - r->get_group(); + r->read_group(); external_write(config, [](auto& wt) { wt.add_table("class_object 2"); }); @@ -1275,7 +1275,7 @@ TEST_CASE("SharedRealm: coordinator schema cache") { } SECTION("update_schema() to version already on disk updates cache") { - r->get_group(); + r->read_group(); external_write(config, [](auto& wt) { auto table = wt.add_table("class_object 2"); table->add_column(type_Int, "value"); @@ -1291,7 +1291,7 @@ TEST_CASE("SharedRealm: coordinator schema cache") { } SECTION("update_schema() to version already on disk updates cache") { - r->get_group(); + r->read_group(); external_write(config, [](auto& wt) { auto table = wt.add_table("class_object 2"); table->add_column(type_Int, "value"); @@ -1307,7 +1307,7 @@ TEST_CASE("SharedRealm: coordinator schema cache") { } SECTION("update_schema() to version populated on disk while waiting for the write lock updates cache") { - r->get_group(); + r->read_group(); // We want to commit the write while we're waiting on the write lock on // this thread, which can't really be done in a properly synchronized manner @@ -1369,11 +1369,11 @@ TEST_CASE("SharedRealm: dynamic schema mode doesn't invalidate object schema poi auto* object_schema = &*r2->schema().find("object"); // Perform an empty write to create a new version, resulting in the other Realm needing to re-read the schema. - r1->begin_write_transaction(); + r1->begin_transaction(); r1->commit_transaction(); // Advance to the latest version, and verify the object schema is at the same location in memory. - r2->get_group(); + r2->read_group(); REQUIRE(object_schema == &*r2->schema().find("object")); } @@ -1392,7 +1392,7 @@ TEST_CASE("SharedRealm: declaring an object as embedded results in creating an e }}}; auto r1 = Realm::get_shared_realm(config); - Group& g = r1->get_group(); + Group& g = r1->read_group(); auto t = g.get_table("class_object1"); REQUIRE(t->is_embedded()); } @@ -1430,7 +1430,7 @@ TEST_CASE("SharedRealm: SchemaChangedFunction") { }}}; config.schema_version = 1; auto r1 = Realm::get_shared_realm(config); - r1->get_group(); + r1->read_group(); r1->m_binding_context.reset(new Context(&schema_changed_called, &changed_fixed_schema)); SECTION("Fixed schema") { @@ -1451,7 +1451,7 @@ TEST_CASE("SharedRealm: SchemaChangedFunction") { SECTION("Non schema related transaction doesn't trigger") { auto r2 = Realm::get_shared_realm(config); - r2->begin_write_transaction(); + r2->begin_transaction(); r2->commit_transaction(); r1->refresh(); REQUIRE(schema_changed_called == 0); @@ -1459,8 +1459,8 @@ TEST_CASE("SharedRealm: SchemaChangedFunction") { SECTION("Schema is changed by another Realm") { auto r2 = Realm::get_shared_realm(config); - r2->begin_write_transaction(); - r2->get_group().get_table("class_object1")->add_column(type_String, "new col"); + r2->begin_transaction(); + r2->read_group().get_table("class_object1")->add_column(type_String, "new col"); r2->commit_transaction(); r1->refresh(); REQUIRE(schema_changed_called == 1); @@ -1469,8 +1469,8 @@ TEST_CASE("SharedRealm: SchemaChangedFunction") { // This is not a valid use case. m_schema won't be refreshed. SECTION("Schema is changed by this Realm won't trigger") { - r1->begin_write_transaction(); - r1->get_group().get_table("class_object1")->add_column(type_String, "new col"); + r1->begin_transaction(); + r1->read_group().get_table("class_object1")->add_column(type_String, "new col"); r1->commit_transaction(); REQUIRE(schema_changed_called == 0); } @@ -1496,7 +1496,7 @@ TEST_CASE("SharedRealm: SchemaChangedFunction") { SECTION("Non schema related transaction will always trigger in dynamic mode") { auto r1 = Realm::get_shared_realm(config); // An empty transaction will trigger the schema changes always in dynamic mode. - r1->begin_write_transaction(); + r1->begin_transaction(); r1->commit_transaction(); r2->refresh(); REQUIRE(dynamic_schema_changed_called == 1); @@ -1504,8 +1504,8 @@ TEST_CASE("SharedRealm: SchemaChangedFunction") { } SECTION("Schema is changed by another Realm") { - r1->begin_write_transaction(); - r1->get_group().get_table("class_object1")->add_column(type_String, "new col"); + r1->begin_transaction(); + r1->read_group().get_table("class_object1")->add_column(type_String, "new col"); r1->commit_transaction(); r2->refresh(); REQUIRE(dynamic_schema_changed_called == 1); @@ -1531,8 +1531,8 @@ TEST_CASE("SharedRealm: compact on launch") { REQUIRE(num_opens == 0); auto r = Realm::get_shared_realm(config); REQUIRE(num_opens == 1); - r->begin_write_transaction(); - auto table = r->get_group().get_table("class_object"); + r->begin_transaction(); + auto table = r->read_group().get_table("class_object"); size_t count = 1000; for (size_t i = 0; i < count; ++i) table->create_object().set_all(util::format("Foo_%1", i % 10).c_str()); @@ -1552,10 +1552,10 @@ TEST_CASE("SharedRealm: compact on launch") { REQUIRE(size_t(util::File(config.path).get_size()) < size_before); // File size after returning true // Validate that the file still contains what it should - REQUIRE(r->get_group().get_table("class_object")->size() == count); + REQUIRE(r->read_group().get_table("class_object")->size() == count); // Registering for a collection notification shouldn't crash when compact on launch is used. - Results results(r, r->get_group().get_table("class_object")); + Results results(r, r->read_group().get_table("class_object")); results.add_notification_callback([](CollectionChangeSet const&, std::exception_ptr) {}); r->close(); } @@ -1628,7 +1628,7 @@ TEMPLATE_TEST_CASE("SharedRealm: update_schema with initialization_function", "[ Schema schema_in_callback; auto initialization_function = [&initialization_function_called, &schema_version_in_callback, &schema_in_callback](auto shared_realm) { - REQUIRE(shared_realm->is_in_write_transaction()); + REQUIRE(shared_realm->is_in_transaction()); initialization_function_called = true; schema_version_in_callback = shared_realm->schema_version(); schema_in_callback = shared_realm->schema(); @@ -1687,7 +1687,7 @@ TEST_CASE("BindingContext is notified about delivery of change notifications") { }); auto coordinator = _impl::RealmCoordinator::get_coordinator(config.path); - auto table = r->get_group().get_table("class_object"); + auto table = r->read_group().get_table("class_object"); SECTION("BindingContext notified even if no callbacks are registered") { static int binding_context_start_notify_calls = 0; @@ -1709,7 +1709,7 @@ TEST_CASE("BindingContext is notified about delivery of change notifications") { binding_context_start_notify_calls = 0; binding_context_end_notify_calls = 0; coordinator->on_change(); - r->begin_write_transaction(); + r->begin_transaction(); REQUIRE(binding_context_start_notify_calls == 1); REQUIRE(binding_context_end_notify_calls == 1); r->cancel_transaction(); @@ -1720,8 +1720,8 @@ TEST_CASE("BindingContext is notified about delivery of change notifications") { binding_context_end_notify_calls = 0; JoiningThread([&] { auto r2 = coordinator->get_realm(util::Scheduler::get_frozen(VersionID())); - r2->begin_write_transaction(); - auto table2 = r2->get_group().get_table("class_object"); + r2->begin_transaction(); + auto table2 = r2->read_group().get_table("class_object"); table2->create_object(); r2->commit_transaction(); }); @@ -1772,7 +1772,7 @@ TEST_CASE("BindingContext is notified about delivery of change notifications") { binding_context_end_notify_calls = 0; notification_calls = 0; coordinator->on_change(); - r->begin_write_transaction(); + r->begin_transaction(); table->create_object(); r->commit_transaction(); REQUIRE(binding_context_start_notify_calls == 1); @@ -1785,8 +1785,8 @@ TEST_CASE("BindingContext is notified about delivery of change notifications") { notification_calls = 0; JoiningThread([&] { auto r2 = coordinator->get_realm(util::Scheduler::get_frozen(VersionID())); - r2->begin_write_transaction(); - auto table2 = r2->get_group().get_table("class_object"); + r2->begin_transaction(); + auto table2 = r2->read_group().get_table("class_object"); table2->create_object(); r2->commit_transaction(); }); @@ -1837,8 +1837,8 @@ TEST_CASE("BindingContext is notified about delivery of change notifications") { JoiningThread([&] { auto r = coordinator->get_realm(util::Scheduler::get_frozen(VersionID())); - r->begin_write_transaction(); - r->get_group().get_table("class_object")->create_object(); + r->begin_transaction(); + r->read_group().get_table("class_object")->create_object(); r->commit_transaction(); }); @@ -1861,8 +1861,8 @@ TEST_CASE("BindingContext is notified about delivery of change notifications") { JoiningThread([&] { auto r = coordinator->get_realm(util::Scheduler::get_frozen(VersionID())); - r->begin_write_transaction(); - r->get_group().get_table("class_object")->create_object(); + r->begin_transaction(); + r->read_group().get_table("class_object")->create_object(); r->commit_transaction(); }); @@ -1886,7 +1886,7 @@ TEST_CASE("Statistics on Realms") { }); SECTION("compute_size") { - auto s = r->get_group().compute_aggregated_byte_size(); + auto s = r->read_group().compute_aggregated_byte_size(); REQUIRE(s > 0); } } @@ -1924,8 +1924,8 @@ TEST_CASE("BindingContext is notified in case of notifier errors") { }); auto coordinator = _impl::RealmCoordinator::get_coordinator(config.path); - auto table = r->get_group().get_table("class_object"); - Results results(r, *r->get_group().get_table("class_object")); + auto table = r->read_group().get_table("class_object"); + Results results(r, *r->read_group().get_table("class_object")); static int binding_context_start_notify_calls = 0; static int binding_context_end_notify_calls = 0; static bool error_called = false; @@ -1974,9 +1974,9 @@ TEST_CASE("RealmCoordinator: get_unbound_realm()") { SECTION("checks thread after being resolved") { auto realm = Realm::get_shared_realm(std::move(ref)); - REQUIRE_NOTHROW(realm->verify_is_on_thread()); + REQUIRE_NOTHROW(realm->verify_thread()); std::thread([&] { - REQUIRE_THROWS(realm->verify_is_on_thread()); + REQUIRE_THROWS(realm->verify_thread()); }).join(); } @@ -1984,7 +1984,7 @@ TEST_CASE("RealmCoordinator: get_unbound_realm()") { if (!util::EventLoop::has_implementation()) return; auto realm = Realm::get_shared_realm(std::move(ref)); - Results results(realm, ObjectStore::table_for_object_type(realm->get_group(), "object")->where()); + Results results(realm, ObjectStore::table_for_object_type(realm->read_group(), "object")->where()); bool called = false; auto token = results.add_notification_callback([&](CollectionChangeSet, std::exception_ptr) { called = true; diff --git a/test/object-store/results.cpp b/test/object-store/results.cpp index 06514736636..58d653e9c30 100644 --- a/test/object-store/results.cpp +++ b/test/object-store/results.cpp @@ -114,10 +114,10 @@ TEST_CASE("notifications: async delivery") { }); auto coordinator = _impl::RealmCoordinator::get_coordinator(config.path); - auto table = r->get_group().get_table("class_object"); + auto table = r->read_group().get_table("class_object"); auto col = table->get_column_key("value"); - r->begin_write_transaction(); + r->begin_transaction(); for (int i = 0; i < 10; ++i) table->create_object().set_all(i * 2); r->commit_transaction(); @@ -131,15 +131,15 @@ TEST_CASE("notifications: async delivery") { }); auto make_local_change = [&] { - r->begin_write_transaction(); + r->begin_transaction(); table->begin()->set(col, 4); r->commit_transaction(); }; auto make_remote_change = [&] { auto r2 = coordinator->get_realm(util::Scheduler::get_frozen(VersionID())); - r2->begin_write_transaction(); - r2->get_group().get_table("class_object")->begin()->set(col, 5); + r2->begin_transaction(); + r2->read_group().get_table("class_object")->begin()->set(col, 5); r2->commit_transaction(); }; @@ -157,10 +157,10 @@ TEST_CASE("notifications: async delivery") { REQUIRE(notification_calls == 1); } - SECTION("is delivered on begin_write_transaction()") { + SECTION("is delivered on begin_transaction()") { coordinator->on_change(); REQUIRE(notification_calls == 0); - r->begin_write_transaction(); + r->begin_transaction(); REQUIRE(notification_calls == 1); r->cancel_transaction(); } @@ -182,13 +182,13 @@ TEST_CASE("notifications: async delivery") { REQUIRE(notification_calls == 1); } - SECTION("begin_write_transaction() blocks due to initial results not being ready") { + SECTION("begin_transaction() blocks due to initial results not being ready") { REQUIRE(notification_calls == 0); JoiningThread thread([&] { std::this_thread::sleep_for(std::chrono::microseconds(5000)); coordinator->on_change(); }); - r->begin_write_transaction(); + r->begin_transaction(); REQUIRE(notification_calls == 1); r->cancel_transaction(); } @@ -204,7 +204,7 @@ TEST_CASE("notifications: async delivery") { SECTION("notify()") { coordinator->on_change(); - REQUIRE_FALSE(r->is_in_any_transaction()); + REQUIRE_FALSE(r->is_in_read_transaction()); r->notify(); REQUIRE(notification_calls == 1); } @@ -212,22 +212,22 @@ TEST_CASE("notifications: async delivery") { SECTION("notify() without autorefresh") { r->set_auto_refresh(false); coordinator->on_change(); - REQUIRE_FALSE(r->is_in_any_transaction()); + REQUIRE_FALSE(r->is_in_read_transaction()); r->notify(); REQUIRE(notification_calls == 1); } SECTION("refresh()") { coordinator->on_change(); - REQUIRE_FALSE(r->is_in_any_transaction()); + REQUIRE_FALSE(r->is_in_read_transaction()); r->refresh(); REQUIRE(notification_calls == 1); } - SECTION("begin_write_transaction()") { + SECTION("begin_transaction()") { coordinator->on_change(); - REQUIRE_FALSE(r->is_in_any_transaction()); - r->begin_write_transaction(); + REQUIRE_FALSE(r->is_in_read_transaction()); + r->begin_transaction(); REQUIRE(notification_calls == 1); r->cancel_transaction(); } @@ -265,8 +265,8 @@ TEST_CASE("notifications: async delivery") { REQUIRE(notification_calls == 2); } - SECTION("begin_write_transaction()") { - r->begin_write_transaction(); + SECTION("begin_transaction()") { + r->begin_transaction(); REQUIRE(notification_calls == 2); r->cancel_transaction(); } @@ -295,8 +295,8 @@ TEST_CASE("notifications: async delivery") { REQUIRE(notification_calls == 2); } - SECTION("begin_write_transaction()") { - r->begin_write_transaction(); + SECTION("begin_transaction()") { + r->begin_transaction(); REQUIRE(notification_calls == 2); r->cancel_transaction(); } @@ -438,7 +438,7 @@ TEST_CASE("notifications: async delivery") { } SECTION("the first call of a notification can include changes if it previously ran for a different callback") { - r->begin_write_transaction(); + r->begin_transaction(); auto token2 = results.add_notification_callback([&](CollectionChangeSet c, std::exception_ptr) { REQUIRE(!c.empty()); }); @@ -491,13 +491,13 @@ TEST_CASE("notifications: async delivery") { REQUIRE(notification_calls == 3); } - SECTION("begin_write_transaction() blocks") { + SECTION("begin_transaction() blocks") { REQUIRE(notification_calls == 1); JoiningThread thread([&] { std::this_thread::sleep_for(std::chrono::microseconds(5000)); coordinator->on_change(); }); - r->begin_write_transaction(); + r->begin_transaction(); REQUIRE(notification_calls == 2); r->cancel_transaction(); } @@ -508,14 +508,14 @@ TEST_CASE("notifications: async delivery") { r->refresh(); } - SECTION("begin_write_transaction() does not block for results without callbacks") { + SECTION("begin_transaction() does not block for results without callbacks") { token = {}; // this would deadlock if it waits for the notifier to be ready - r->begin_write_transaction(); + r->begin_transaction(); r->cancel_transaction(); } - SECTION("begin_write_transaction() does not block for Results for different Realms") { + SECTION("begin_transaction() does not block for Results for different Realms") { // this would deadlock if beginning the write on the secondary Realm // waited for the primary Realm to be ready make_remote_change(); @@ -551,13 +551,13 @@ TEST_CASE("notifications: async delivery") { REQUIRE(notification_calls == 2); } - SECTION("begin_write_transaction() blocks") { + SECTION("begin_transaction() blocks") { REQUIRE(notification_calls == 1); JoiningThread thread([&] { std::this_thread::sleep_for(std::chrono::microseconds(5000)); coordinator->on_change(); }); - r->begin_write_transaction(); + r->begin_transaction(); REQUIRE(notification_calls == 2); r->cancel_transaction(); } @@ -569,7 +569,7 @@ TEST_CASE("notifications: async delivery") { SECTION("notify()") { coordinator->on_change(); - REQUIRE_FALSE(r->is_in_any_transaction()); + REQUIRE_FALSE(r->is_in_read_transaction()); r->notify(); REQUIRE(notification_calls == 2); } @@ -577,7 +577,7 @@ TEST_CASE("notifications: async delivery") { SECTION("notify() without autorefresh") { r->set_auto_refresh(false); coordinator->on_change(); - REQUIRE_FALSE(r->is_in_any_transaction()); + REQUIRE_FALSE(r->is_in_read_transaction()); r->notify(); REQUIRE(notification_calls == 1); r->refresh(); @@ -586,15 +586,15 @@ TEST_CASE("notifications: async delivery") { SECTION("refresh()") { coordinator->on_change(); - REQUIRE_FALSE(r->is_in_any_transaction()); + REQUIRE_FALSE(r->is_in_read_transaction()); r->refresh(); REQUIRE(notification_calls == 2); } - SECTION("begin_write_transaction()") { + SECTION("begin_transaction()") { coordinator->on_change(); - REQUIRE_FALSE(r->is_in_any_transaction()); - r->begin_write_transaction(); + REQUIRE_FALSE(r->is_in_read_transaction()); + r->begin_transaction(); REQUIRE(notification_calls == 2); r->cancel_transaction(); } @@ -643,7 +643,7 @@ TEST_CASE("notifications: async delivery") { REQUIRE_FALSE(r->refresh()); // does not advance since it's now up-to-date } - SECTION("begin_write_transaction() from within a notification does not send notifications immediately") { + SECTION("begin_transaction() from within a notification does not send notifications immediately") { bool first = true; auto token2 = results.add_notification_callback([&](CollectionChangeSet, std::exception_ptr err) { REQUIRE_FALSE(err); @@ -651,7 +651,7 @@ TEST_CASE("notifications: async delivery") { first = false; else { // would deadlock if it tried to send notifications as they aren't ready yet - r->begin_write_transaction(); + r->begin_transaction(); r->cancel_transaction(); } }); @@ -667,8 +667,7 @@ TEST_CASE("notifications: async delivery") { REQUIRE(notification_calls == 3); } - SECTION( - "begin_write_transaction() from within a notification does not break delivering additional notifications") { + SECTION("begin_transaction() from within a notification does not break delivering additional notifications") { size_t calls = 0; token = results.add_notification_callback([&](CollectionChangeSet, std::exception_ptr err) { REQUIRE_FALSE(err); @@ -676,7 +675,7 @@ TEST_CASE("notifications: async delivery") { return; // force the read version to advance by beginning a transaction - r->begin_write_transaction(); + r->begin_transaction(); r->cancel_transaction(); }); @@ -701,7 +700,7 @@ TEST_CASE("notifications: async delivery") { REQUIRE(calls2 == 2); } - SECTION("begin_write_transaction() from within did_change() does not break delivering collection notification") { + SECTION("begin_transaction() from within did_change() does not break delivering collection notification") { struct Context : BindingContext { Realm& realm; Context(Realm& realm) @@ -711,9 +710,9 @@ TEST_CASE("notifications: async delivery") { void did_change(std::vector const&, std::vector const&, bool) override { - if (!realm.is_in_write_transaction()) { + if (!realm.is_in_transaction()) { // advances to version from 2 (and recursively calls this, hence the check above) - realm.begin_write_transaction(); + realm.begin_transaction(); realm.cancel_transaction(); } } @@ -726,25 +725,24 @@ TEST_CASE("notifications: async delivery") { r->notify(); // advances to version from 1 } - SECTION("is_in_write_transaction() is reported correctly within a notification from begin_write_transaction() " - "and changes " + SECTION("is_in_transaction() is reported correctly within a notification from begin_transaction() and changes " "can be made") { bool first = true; token = results.add_notification_callback([&](CollectionChangeSet, std::exception_ptr err) { REQUIRE_FALSE(err); if (first) { - REQUIRE_FALSE(r->is_in_write_transaction()); + REQUIRE_FALSE(r->is_in_transaction()); first = false; } else { - REQUIRE(r->is_in_write_transaction()); + REQUIRE(r->is_in_transaction()); table->begin()->set(col, 100); } }); advance_and_notify(*r); make_remote_change(); coordinator->on_change(); - r->begin_write_transaction(); + r->begin_transaction(); REQUIRE(table->begin()->get(col) == 100); r->cancel_transaction(); REQUIRE(table->begin()->get(col) != 100); @@ -754,29 +752,29 @@ TEST_CASE("notifications: async delivery") { token = results.add_notification_callback([&](CollectionChangeSet, std::exception_ptr err) { REQUIRE_FALSE(err); r->invalidate(); - REQUIRE(r->is_in_any_transaction()); + REQUIRE(r->is_in_read_transaction()); }); advance_and_notify(*r); - REQUIRE(r->is_in_any_transaction()); + REQUIRE(r->is_in_read_transaction()); make_remote_change(); coordinator->on_change(); - r->begin_write_transaction(); - REQUIRE(r->is_in_write_transaction()); + r->begin_transaction(); + REQUIRE(r->is_in_transaction()); r->cancel_transaction(); } - SECTION("cancel_transaction() from within notification ends the write transaction started by " - "begin_write_transaction()") { + SECTION( + "cancel_transaction() from within notification ends the write transaction started by begin_transaction()") { token = results.add_notification_callback([&](CollectionChangeSet, std::exception_ptr err) { REQUIRE_FALSE(err); - if (r->is_in_write_transaction()) + if (r->is_in_transaction()) r->cancel_transaction(); }); advance_and_notify(*r); make_remote_change(); coordinator->on_change(); - r->begin_write_transaction(); - REQUIRE_FALSE(r->is_in_write_transaction()); + r->begin_transaction(); + REQUIRE_FALSE(r->is_in_transaction()); } } @@ -793,10 +791,10 @@ TEST_CASE("notifications: skip") { }); auto coordinator = _impl::RealmCoordinator::get_coordinator(config.path); - auto table = r->get_group().get_table("class_object"); + auto table = r->read_group().get_table("class_object"); auto col = table->get_column_key("value"); - r->begin_write_transaction(); + r->begin_transaction(); for (int i = 0; i < 10; ++i) table->create_object().set(col, i * 2); r->commit_transaction(); @@ -812,7 +810,7 @@ TEST_CASE("notifications: skip") { }; auto make_local_change = [&](auto& token) { - r->begin_write_transaction(); + r->begin_transaction(); table->create_object(); token.suppress_next(); r->commit_transaction(); @@ -820,8 +818,8 @@ TEST_CASE("notifications: skip") { auto make_remote_change = [&] { auto r2 = coordinator->get_realm(util::Scheduler::get_frozen(VersionID())); - r2->begin_write_transaction(); - r2->get_group().get_table("class_object")->create_object(); + r2->begin_transaction(); + r2->read_group().get_table("class_object")->create_object(); r2->commit_transaction(); }; @@ -922,7 +920,7 @@ TEST_CASE("notifications: skip") { SECTION("skipping must be done from the Realm's thread") { advance_and_notify(*r); - r->begin_write_transaction(); + r->begin_transaction(); std::thread([&] { REQUIRE_THROWS(token1.suppress_next()); }).join(); @@ -937,7 +935,7 @@ TEST_CASE("notifications: skip") { // new notifier at a version before the skipped one auto r2 = coordinator->get_realm(); - Results results2(r2, r2->get_group().get_table("class_object")->where()); + Results results2(r2, r2->read_group().get_table("class_object")->where()); int calls2 = 0; auto token2 = add_callback(results2, calls2, changes); @@ -945,7 +943,7 @@ TEST_CASE("notifications: skip") { // new notifier at the skipped version auto r3 = coordinator->get_realm(); - Results results3(r3, r3->get_group().get_table("class_object")->where()); + Results results3(r3, r3->read_group().get_table("class_object")->where()); int calls3 = 0; auto token3 = add_callback(results3, calls3, changes); @@ -953,7 +951,7 @@ TEST_CASE("notifications: skip") { // new notifier at version after the skipped one auto r4 = coordinator->get_realm(); - Results results4(r4, r4->get_group().get_table("class_object")->where()); + Results results4(r4, r4->read_group().get_table("class_object")->where()); int calls4 = 0; auto token4 = add_callback(results4, calls4, changes); @@ -974,14 +972,14 @@ TEST_CASE("notifications: skip") { REQUIRE(calls1 == 1); // would not produce a notification even if it wasn't skipped because no changes were made - r->begin_write_transaction(); + r->begin_transaction(); token1.suppress_next(); r->commit_transaction(); advance_and_notify(*r); REQUIRE(calls1 == 1); // should now produce a notification - r->begin_write_transaction(); + r->begin_transaction(); table->create_object(); r->commit_transaction(); advance_and_notify(*r); @@ -1020,7 +1018,7 @@ TEST_CASE("notifications: skip") { }); for (int i = 0; i < 10; ++i) { - r->begin_write_transaction(); + r->begin_transaction(); table->create_object(); token1.suppress_next(); r->commit_transaction(); @@ -1044,10 +1042,10 @@ TEST_CASE("notifications: TableView delivery") { }); auto coordinator = _impl::RealmCoordinator::get_coordinator(config.path); - auto table = r->get_group().get_table("class_object"); + auto table = r->read_group().get_table("class_object"); auto col = table->get_column_key("value"); - r->begin_write_transaction(); + r->begin_transaction(); for (int i = 0; i < 10; ++i) table->create_object().set(col, i * 2); r->commit_transaction(); @@ -1068,15 +1066,15 @@ TEST_CASE("notifications: TableView delivery") { REQUIRE(results.size() == 0); auto make_local_change = [&] { - r->begin_write_transaction(); + r->begin_transaction(); table->create_object(); r->commit_transaction(); }; auto make_remote_change = [&] { auto r2 = coordinator->get_realm(util::Scheduler::get_frozen(VersionID())); - r2->begin_write_transaction(); - r2->get_group().get_table("class_object")->create_object(); + r2->begin_transaction(); + r2->read_group().get_table("class_object")->create_object(); r2->commit_transaction(); }; @@ -1144,7 +1142,7 @@ TEST_CASE("notifications: TableView delivery") { SECTION("no changes") { make_remote_change(); advance_and_notify(*r); - r->begin_write_transaction(); + r->begin_transaction(); REQUIRE(results.size() == 0); r->cancel_transaction(); } @@ -1155,8 +1153,8 @@ TEST_CASE("notifications: TableView delivery") { make_remote_change(); advance_and_notify(*r); - r->begin_write_transaction(); - r->get_group().get_table("class_object")->create_object(); + r->begin_transaction(); + r->read_group().get_table("class_object")->create_object(); REQUIRE(results.size() == 10); r->cancel_transaction(); } @@ -1172,8 +1170,8 @@ TEST_CASE("notifications: TableView delivery") { make_remote_change(); advance_and_notify(*r); - r->begin_write_transaction(); - r->get_group().get_table("class_object")->create_object(); + r->begin_transaction(); + r->read_group().get_table("class_object")->create_object(); REQUIRE(results.size() == 12); r->cancel_transaction(); } @@ -1207,7 +1205,7 @@ TEST_CASE("notifications: async error handling") { }); auto coordinator = _impl::RealmCoordinator::get_coordinator(config.path); - Results results(r, *r->get_group().get_table("class_object")); + Results results(r, *r->read_group().get_table("class_object")); auto r2 = Realm::get_shared_realm(config); @@ -1250,7 +1248,7 @@ TEST_CASE("notifications: async error handling") { } SECTION("error is delivered on notify() with changes") { - r2->begin_write_transaction(); + r2->begin_transaction(); r2->commit_transaction(); REQUIRE(!called); coordinator->on_change(); @@ -1267,7 +1265,7 @@ TEST_CASE("notifications: async error handling") { } SECTION("error is delivered on refresh() with changes") { - r2->begin_write_transaction(); + r2->begin_transaction(); r2->commit_transaction(); REQUIRE(!called); coordinator->on_change(); @@ -1276,21 +1274,21 @@ TEST_CASE("notifications: async error handling") { REQUIRE(called); } - SECTION("error is delivered on begin_write_transaction() without changes") { + SECTION("error is delivered on begin_transaction() without changes") { coordinator->on_change(); REQUIRE(!called); - r->begin_write_transaction(); + r->begin_transaction(); REQUIRE(called); r->cancel_transaction(); } - SECTION("error is delivered on begin_write_transaction() with changes") { - r2->begin_write_transaction(); + SECTION("error is delivered on begin_transaction() with changes") { + r2->begin_transaction(); r2->commit_transaction(); REQUIRE(!called); coordinator->on_change(); REQUIRE(!called); - r->begin_write_transaction(); + r->begin_transaction(); REQUIRE(called); r->cancel_transaction(); } @@ -1420,16 +1418,16 @@ TEST_CASE("notifications: sync") { auto r = Realm::get_shared_realm(config); auto wait_realm = Realm::get_shared_realm(config); - Results results(r, r->get_group().get_table("class_object")); - Results wait_results(wait_realm, wait_realm->get_group().get_table("class_object")); + Results results(r, r->read_group().get_table("class_object")); + Results wait_results(wait_realm, wait_realm->read_group().get_table("class_object")); auto token1 = results.add_notification_callback([&](CollectionChangeSet, std::exception_ptr) {}); auto token2 = wait_results.add_notification_callback([&](CollectionChangeSet, std::exception_ptr) {}); // Add an object to the Realm so that notifications are needed { auto write_realm = Realm::get_shared_realm(config); - write_realm->begin_write_transaction(); - write_realm->get_group().get_table("class_object")->create_object_with_primary_key(0); + write_realm->begin_transaction(); + write_realm->read_group().get_table("class_object")->create_object_with_primary_key(0); write_realm->commit_transaction(); } @@ -1467,14 +1465,14 @@ TEST_CASE("notifications: results") { {"second linked to object", {{"value", PropertyType::Int}}}}); auto coordinator = _impl::RealmCoordinator::get_coordinator(config.path); - auto table = r->get_group().get_table("class_object"); - auto other_table = r->get_group().get_table("class_other object"); - auto linked_to_table = r->get_group().get_table("class_linked to object"); - auto second_linked_to_table = r->get_group().get_table("class_second linked to object"); + auto table = r->read_group().get_table("class_object"); + auto other_table = r->read_group().get_table("class_other object"); + auto linked_to_table = r->read_group().get_table("class_linked to object"); + auto second_linked_to_table = r->read_group().get_table("class_second linked to object"); auto col_value = table->get_column_key("value"); auto col_link = table->get_column_key("link"); - r->begin_write_transaction(); + r->begin_transaction(); std::vector target_keys; linked_to_table->create_objects(10, target_keys); std::vector second_target_keys; @@ -1487,12 +1485,12 @@ TEST_CASE("notifications: results") { r->commit_transaction(); auto r2 = coordinator->get_realm(); - auto r2_table = r2->get_group().get_table("class_object"); + auto r2_table = r2->read_group().get_table("class_object"); Results results(r, table->where().greater(col_value, 0).less(col_value, 10)); auto write = [&](auto&& f) { - r->begin_write_transaction(); + r->begin_transaction(); f(); r->commit_transaction(); advance_and_notify(*r); @@ -1525,7 +1523,7 @@ TEST_CASE("notifications: results") { SECTION("irrelevant modifications to linking tables do not send notifications") { write([&] { - r->get_group().get_table("class_linking object")->create_object(); + r->read_group().get_table("class_linking object")->create_object(); }); REQUIRE(notification_calls == 1); } @@ -1581,13 +1579,13 @@ TEST_CASE("notifications: results") { } SECTION("modifications from multiple transactions are collapsed") { - r2->begin_write_transaction(); + r2->begin_transaction(); r2_table->get_object(object_keys[0]).set(col_value, 6); r2->commit_transaction(); coordinator->on_change(); - r2->begin_write_transaction(); + r2->begin_transaction(); r2_table->get_object(object_keys[1]).set(col_value, 03); r2->commit_transaction(); @@ -1598,13 +1596,13 @@ TEST_CASE("notifications: results") { } SECTION("inserting a row then modifying it in a second transaction does not report it as modified") { - r2->begin_write_transaction(); + r2->begin_transaction(); ObjKey k = r2_table->create_object(ObjKey(53)).set(col_value, 6).get_key(); r2->commit_transaction(); coordinator->on_change(); - r2->begin_write_transaction(); + r2->begin_transaction(); r2_table->get_object(k).set(col_value, 7); r2->commit_transaction(); @@ -1617,7 +1615,7 @@ TEST_CASE("notifications: results") { } SECTION("modification indices are pre-insert/delete") { - r->begin_write_transaction(); + r->begin_transaction(); table->get_object(object_keys[2]).set(col_value, 0); table->get_object(object_keys[3]).set(col_value, 6); r->commit_transaction(); @@ -1630,13 +1628,13 @@ TEST_CASE("notifications: results") { } SECTION("notifications are not delivered when collapsing transactions results in no net change") { - r2->begin_write_transaction(); + r2->begin_transaction(); ObjKey k = r2_table->create_object().set(col_value, 5).get_key(); r2->commit_transaction(); coordinator->on_change(); - r2->begin_write_transaction(); + r2->begin_transaction(); r2_table->remove_object(k); r2->commit_transaction(); @@ -1708,7 +1706,7 @@ TEST_CASE("notifications: results") { } auto write_r2 = [&](auto&& func) { - r2->begin_write_transaction(); + r2->begin_transaction(); func(*r2_table); r2->commit_transaction(); advance_and_notify(*r); @@ -1881,11 +1879,11 @@ TEST_CASE("notifications: results") { } SECTION("modifications from multiple transactions are collapsed") { - r2->begin_write_transaction(); + r2->begin_transaction(); r2_table->get_object(object_keys[0]).set(col_value, 5); r2->commit_transaction(); - r2->begin_write_transaction(); + r2->begin_transaction(); r2_table->get_object(object_keys[1]).set(col_value, 0); r2->commit_transaction(); @@ -1895,7 +1893,7 @@ TEST_CASE("notifications: results") { } SECTION("moving a matching row by deleting all other rows") { - r->begin_write_transaction(); + r->begin_transaction(); table->clear(); ObjKey k0 = table->create_object().set(col_value, 15).get_key(); table->create_object().set(col_value, 5); @@ -1996,7 +1994,7 @@ TEST_CASE("notifications: results") { SECTION("insert table before observed table") { write([&] { table->create_object(ObjKey(53)).set(col_value, 5); - r->get_group().add_table("new table"); + r->read_group().add_table("new table"); table->create_object(ObjKey(0)).set(col_value, 5); }); REQUIRE_INDICES(change.insertions, 0, 5); @@ -2016,7 +2014,7 @@ TEST_CASE("notifications: results") { SECTION("insert table before link target") { write([&] { linked_table->get_object(target_keys[1]).set(col, 5); - r->get_group().add_table("new table"); + r->read_group().add_table("new table"); linked_table->get_object(target_keys[2]).set(col, 5); }); REQUIRE_INDICES(change.modifications, 0, 1); @@ -2104,7 +2102,7 @@ TEST_CASE("results: notifications after move") { }}, }); - auto table = r->get_group().get_table("class_object"); + auto table = r->read_group().get_table("class_object"); auto results = std::make_unique(r, table); int notification_calls = 0; @@ -2116,7 +2114,7 @@ TEST_CASE("results: notifications after move") { advance_and_notify(*r); auto write = [&](auto&& f) { - r->begin_write_transaction(); + r->begin_transaction(); f(); r->commit_transaction(); advance_and_notify(*r); @@ -2160,7 +2158,7 @@ TEST_CASE("results: notifier with no callbacks") { }}, }); - auto table = r->get_group().get_table("class_object"); + auto table = r->read_group().get_table("class_object"); Results results(r, table->where()); results.last(); // force evaluation and creation of TableView @@ -2171,8 +2169,8 @@ TEST_CASE("results: notifier with no callbacks") { results.add_notification_callback([](CollectionChangeSet const&, std::exception_ptr) {}); auto r2 = coordinator->get_realm(util::Scheduler::get_frozen(VersionID())); - r2->begin_write_transaction(); - r2->get_group().get_table("class_object")->create_object(); + r2->begin_transaction(); + r2->read_group().get_table("class_object")->create_object(); r2->commit_transaction(); r->refresh(); // would deadlock if there was a callback @@ -2182,11 +2180,11 @@ TEST_CASE("results: notifier with no callbacks") { results.add_notification_callback([](CollectionChangeSet const&, std::exception_ptr) {}); // Create version 1 - r->begin_write_transaction(); + r->begin_transaction(); table->create_object(); r->commit_transaction(); - r->begin_write_transaction(); + r->begin_transaction(); // Run async query for version 1 coordinator->on_change(); // Create version 2 without ever letting 1 be delivered @@ -2208,12 +2206,12 @@ TEST_CASE("results: notifier with no callbacks") { // isn't clean up until the *next* commit REQUIRE(shared_group->get_number_of_versions() == 2); - auto table = r2->get_group().get_table("class_object"); + auto table = r2->read_group().get_table("class_object"); - r2->begin_write_transaction(); + r2->begin_transaction(); table->create_object(); r2->commit_transaction(); - r2->begin_write_transaction(); + r2->begin_transaction(); table->create_object(); r2->commit_transaction(); @@ -2232,10 +2230,10 @@ TEST_CASE("results: error messages") { }; auto r = Realm::get_shared_realm(config); - auto table = r->get_group().get_table("class_object"); + auto table = r->read_group().get_table("class_object"); Results results(r, table); - r->begin_write_transaction(); + r->begin_transaction(); table->create_object(); r->commit_transaction(); @@ -2267,14 +2265,14 @@ TEST_CASE("results: snapshots") { } auto write = [&](auto&& f) { - r->begin_write_transaction(); + r->begin_transaction(); f(); r->commit_transaction(); advance_and_notify(*r); }; SECTION("snapshot of Results based on Table") { - auto table = r->get_group().get_table("class_object"); + auto table = r->read_group().get_table("class_object"); Results results(r, table); { @@ -2313,9 +2311,9 @@ TEST_CASE("results: snapshots") { } SECTION("snapshot of Results based on LinkView") { - auto object = r->get_group().get_table("class_object"); + auto object = r->read_group().get_table("class_object"); auto col_link = object->get_column_key("array"); - auto linked_to = r->get_group().get_table("class_linked to object"); + auto linked_to = r->read_group().get_table("class_linked to object"); write([=] { object->create_object(); @@ -2366,7 +2364,7 @@ TEST_CASE("results: snapshots") { } SECTION("snapshot of Results based on Query") { - auto table = r->get_group().get_table("class_object"); + auto table = r->read_group().get_table("class_object"); auto col_value = table->get_column_key("value"); Query q = table->column(col_value) > 0; Results results(r, std::move(q)); @@ -2413,7 +2411,7 @@ TEST_CASE("results: snapshots") { } SECTION("snapshot of Results based on TableView from query") { - auto table = r->get_group().get_table("class_object"); + auto table = r->read_group().get_table("class_object"); auto col_value = table->get_column_key("value"); Query q = table->column(col_value) > 0; Results results(r, q.find_all()); @@ -2460,9 +2458,9 @@ TEST_CASE("results: snapshots") { } SECTION("snapshot of Results based on TableView from backlinks") { - auto object = r->get_group().get_table("class_object"); + auto object = r->read_group().get_table("class_object"); auto col_link = object->get_column_key("array"); - auto linked_to = r->get_group().get_table("class_linked to object"); + auto linked_to = r->read_group().get_table("class_linked to object"); write([=] { linked_to->create_object(); @@ -2518,7 +2516,7 @@ TEST_CASE("results: snapshots") { } SECTION("snapshot of Results with notification callback registered") { - auto table = r->get_group().get_table("class_object"); + auto table = r->read_group().get_table("class_object"); auto col_value = table->get_column_key("value"); Query q = table->column(col_value) > 0; Results results(r, q.find_all()); @@ -2546,7 +2544,7 @@ TEST_CASE("results: snapshots") { } SECTION("adding notification callback to snapshot throws") { - auto table = r->get_group().get_table("class_object"); + auto table = r->read_group().get_table("class_object"); auto col_value = table->get_column_key("value"); Query q = table->column(col_value) > 0; Results results(r, q.find_all()); @@ -2555,7 +2553,7 @@ TEST_CASE("results: snapshots") { } SECTION("accessors should return none for detached row") { - auto table = r->get_group().get_table("class_object"); + auto table = r->read_group().get_table("class_object"); write([=] { table->create_object(); }); @@ -2587,9 +2585,9 @@ TEST_CASE("results: distinct") { {"num3", PropertyType::Int}}}, }); - auto table = r->get_group().get_table("class_object"); + auto table = r->read_group().get_table("class_object"); - r->begin_write_transaction(); + r->begin_transaction(); for (int i = 0; i < N; ++i) { table->create_object().set_all(i % 3, util::format("Foo_%1", i % 3).c_str(), N - i, i % 2); } @@ -2804,8 +2802,8 @@ TEST_CASE("results: sort") { }; auto realm = Realm::get_shared_realm(config); - auto table = realm->get_group().get_table("class_object"); - auto table2 = realm->get_group().get_table("class_object 2"); + auto table = realm->read_group().get_table("class_object"); + auto table2 = realm->read_group().get_table("class_object 2"); Results r(realm, table); SECTION("invalid keypaths") { @@ -2855,7 +2853,7 @@ TEST_CASE("results: sort") { } } - realm->begin_write_transaction(); + realm->begin_transaction(); ObjKeys table_keys; ObjKeys table2_keys; table->create_objects(4, table_keys); @@ -2927,8 +2925,8 @@ struct ResultsFromTableView { struct ResultsFromLinkView { static Results call(std::shared_ptr r, ConstTableRef table) { - r->begin_write_transaction(); - auto link_table = r->get_group().get_table("class_linking_object"); + r->begin_transaction(); + auto link_table = r->read_group().get_table("class_linking_object"); std::shared_ptr link_view = link_table->create_object().get_linklist_ptr(link_table->get_column_key("link")); for (auto& o : *table) @@ -2941,8 +2939,8 @@ struct ResultsFromLinkView { struct ResultsFromLinkSet { static Results call(std::shared_ptr r, ConstTableRef table) { - r->begin_write_transaction(); - auto link_table = r->get_group().get_table("class_linking_object"); + r->begin_transaction(); + auto link_table = r->read_group().get_table("class_linking_object"); std::shared_ptr link_set = link_table->create_object().get_linkset_ptr(link_table->get_column_key("linkset")); for (auto& o : *table) { @@ -2972,10 +2970,10 @@ TEMPLATE_TEST_CASE("results: get()", "", ResultsFromTable, ResultsFromQuery }}, }); - auto table = r->get_group().get_table("class_object"); + auto table = r->read_group().get_table("class_object"); ColKey col_value = table->get_column_key("value"); - r->begin_write_transaction(); + r->begin_transaction(); for (int i = 0; i < 10; ++i) table->create_object().set_all(i); r->commit_transaction(); @@ -3020,11 +3018,11 @@ TEMPLATE_TEST_CASE("results: get() intermixed with writes", "", ResultsFrom }}, }); - auto table = r->get_group().get_table("class_object"); + auto table = r->read_group().get_table("class_object"); ColKey col_value = table->get_column_key("pk"); Results results = TestType::call(r, table); - r->begin_write_transaction(); + r->begin_transaction(); SECTION("front insertion") { for (int i = 0; i < 1000; ++i) { @@ -3091,7 +3089,7 @@ TEMPLATE_TEST_CASE("results: accessor interface", "", ResultsFromTable, ResultsF }}, }); - auto table = r->get_group().get_table("class_object"); + auto table = r->read_group().get_table("class_object"); Results empty_results = TestType::call(r, table); CppContext ctx(r, &empty_results.get_object_schema()); @@ -3108,8 +3106,8 @@ TEMPLATE_TEST_CASE("results: accessor interface", "", ResultsFromTable, ResultsF } } - r->begin_write_transaction(); - auto other_obj = r->get_group().get_table("class_different type")->create_object(); + r->begin_transaction(); + auto other_obj = r->read_group().get_table("class_different type")->create_object(); for (int i = 0; i < 10; ++i) table->create_object().set_all(i); r->commit_transaction(); @@ -3141,7 +3139,7 @@ TEMPLATE_TEST_CASE("results: accessor interface", "", ResultsFromTable, ResultsF "Object of type 'different type' does not match Results type 'object'"); } SECTION("wrong realm") { - auto obj = r2->get_group().get_table("class_object")->get_object(0); + auto obj = r2->read_group().get_table("class_object")->get_object(0); CHECK_THROWS_WITH(results.index_of(ctx, util::Any(obj)), "Object of type 'object' does not match Results type 'object'"); } @@ -3175,14 +3173,14 @@ TEMPLATE_TEST_CASE("results: aggregate", "[query][aggregate]", ResultsFromTable, }}, }); - auto table = r->get_group().get_table("class_object"); + auto table = r->read_group().get_table("class_object"); ColKey col_int = table->get_column_key("int"); ColKey col_float = table->get_column_key("float"); ColKey col_double = table->get_column_key("double"); ColKey col_date = table->get_column_key("date"); SECTION("one row with null values") { - r->begin_write_transaction(); + r->begin_transaction(); table->create_object(); table->create_object().set_all(0, 0.f, 0.0, Timestamp(0, 0)); table->create_object().set_all(2, 2.f, 2.0, Timestamp(2, 0)); @@ -3224,7 +3222,7 @@ TEMPLATE_TEST_CASE("results: aggregate", "[query][aggregate]", ResultsFromTable, } SECTION("rows with all null values") { - r->begin_write_transaction(); + r->begin_transaction(); table->create_object(); table->create_object(); table->create_object(); @@ -3334,8 +3332,8 @@ TEST_CASE("results: set property value on all objects", "[batch_updates]") { }}}; config.schema_version = 0; auto realm = Realm::get_shared_realm(config); - auto table = realm->get_group().get_table("class_AllTypes"); - realm->begin_write_transaction(); + auto table = realm->read_group().get_table("class_AllTypes"); + realm->begin_transaction(); table->create_object_with_primary_key(1); table->create_object_with_primary_key(2); realm->commit_transaction(); @@ -3344,26 +3342,26 @@ TEST_CASE("results: set property value on all objects", "[batch_updates]") { TestContext ctx(realm); SECTION("non-existing property name") { - realm->begin_write_transaction(); + realm->begin_transaction(); REQUIRE_THROWS_AS(r.set_property_value(ctx, "i dont exist", util::Any(false)), Results::InvalidPropertyException); realm->cancel_transaction(); } SECTION("readonly property") { - realm->begin_write_transaction(); + realm->begin_transaction(); REQUIRE_THROWS_AS(r.set_property_value(ctx, "parents", util::Any(false)), ReadOnlyPropertyException); realm->cancel_transaction(); } SECTION("primarykey property") { - realm->begin_write_transaction(); + realm->begin_transaction(); REQUIRE_THROWS_AS(r.set_property_value(ctx, "pk", util::Any(1)), std::logic_error); realm->cancel_transaction(); } SECTION("set property values removes object from Results") { - realm->begin_write_transaction(); + realm->begin_transaction(); Results results(realm, table->where().equal(table->get_column_key("int"), 0)); CHECK(results.size() == 2); r.set_property_value(ctx, "int", util::Any(INT64_C(42))); @@ -3372,7 +3370,7 @@ TEST_CASE("results: set property value on all objects", "[batch_updates]") { } SECTION("set property value") { - realm->begin_write_transaction(); + realm->begin_transaction(); r.set_property_value(ctx, "bool", util::Any(true)); for (size_t i = 0; i < r.size(); i++) { @@ -3516,12 +3514,12 @@ TEST_CASE("results: nullable list of primitives") { }}}; config.schema_version = 0; auto realm = Realm::get_shared_realm(config); - auto table = realm->get_group().get_table("class_ListTypes"); + auto table = realm->read_group().get_table("class_ListTypes"); auto nullable_decimal_col = table->get_column_key("nullable decimal list"); auto non_nullable_decimal_col = table->get_column_key("non nullable decimal list"); auto nullable_oid_col = table->get_column_key("nullable objectid list"); auto non_nullable_oid_col = table->get_column_key("non nullable objectid list"); - realm->begin_write_transaction(); + realm->begin_transaction(); auto obj = table->create_object_with_primary_key(1); List nullable_decimal_list(realm, obj, nullable_decimal_col); List non_nullable_decimal_list(realm, obj, non_nullable_decimal_col); @@ -3565,10 +3563,10 @@ TEST_CASE("results: limit", "[limit]") { }; auto realm = Realm::get_shared_realm(config); - auto table = realm->get_group().get_table("class_object"); + auto table = realm->read_group().get_table("class_object"); auto col = table->get_column_key("value"); - realm->begin_write_transaction(); + realm->begin_transaction(); for (int i = 0; i < 8; ++i) { table->create_object().set(col, (i + 2) % 4); } @@ -3639,7 +3637,7 @@ TEST_CASE("results: limit", "[limit]") { }); advance_and_notify(*realm); REQUIRE(notification_calls == 1); - realm->begin_write_transaction(); + realm->begin_transaction(); table->create_object().set(col, 5); realm->commit_transaction(); advance_and_notify(*realm); @@ -3667,7 +3665,7 @@ TEST_CASE("results: limit", "[limit]") { }); advance_and_notify(*realm); REQUIRE(notification_calls == 1); - realm->begin_write_transaction(); + realm->begin_transaction(); table->get_object(1).set(col, 5); realm->commit_transaction(); advance_and_notify(*realm); @@ -3715,16 +3713,16 @@ TEST_CASE("notifications: objects with PK recreated") { }; auto coordinator = _impl::RealmCoordinator::get_existing_coordinator(config.path); - auto table1 = r->get_group().get_table("class_no_pk"); - auto table2 = r->get_group().get_table("class_int_pk"); - auto table3 = r->get_group().get_table("class_string_pk"); + auto table1 = r->read_group().get_table("class_no_pk"); + auto table2 = r->read_group().get_table("class_int_pk"); + auto table3 = r->read_group().get_table("class_string_pk"); TestContext d(r); auto create = [&](StringData type, util::Any&& value) { return Object::create(d, r, *r->schema().find(type), value); }; - r->begin_write_transaction(); + r->begin_transaction(); auto k1 = create("no_pk", AnyDict{{"id", INT64_C(123)}, {"value", INT64_C(100)}}).obj().get_key(); auto k2 = create("int_pk", AnyDict{{"id", INT64_C(456)}, {"value", INT64_C(100)}}).obj().get_key(); auto k3 = create("string_pk", AnyDict{{"id", std::string("hello")}, {"value", INT64_C(100)}}).obj().get_key(); @@ -3751,10 +3749,10 @@ TEST_CASE("notifications: objects with PK recreated") { REQUIRE(calls3 == 1); SECTION("objects removed") { - r->begin_write_transaction(); - r->get_group().get_table("class_no_pk")->remove_object(k1); - r->get_group().get_table("class_int_pk")->remove_object(k2); - r->get_group().get_table("class_string_pk")->remove_object(k3); + r->begin_transaction(); + r->read_group().get_table("class_no_pk")->remove_object(k1); + r->read_group().get_table("class_int_pk")->remove_object(k2); + r->read_group().get_table("class_string_pk")->remove_object(k3); create("no_pk", AnyDict{{"id", INT64_C(123)}, {"value", INT64_C(200)}}); create("int_pk", AnyDict{{"id", INT64_C(456)}, {"value", INT64_C(200)}}); create("string_pk", AnyDict{{"id", std::string("hello")}, {"value", INT64_C(200)}}); @@ -3773,10 +3771,10 @@ TEST_CASE("notifications: objects with PK recreated") { } SECTION("table cleared") { - r->begin_write_transaction(); - r->get_group().get_table("class_no_pk")->clear(); - r->get_group().get_table("class_int_pk")->clear(); - r->get_group().get_table("class_string_pk")->clear(); + r->begin_transaction(); + r->read_group().get_table("class_no_pk")->clear(); + r->read_group().get_table("class_int_pk")->clear(); + r->read_group().get_table("class_string_pk")->clear(); create("no_pk", AnyDict{{"id", INT64_C(123)}, {"value", INT64_C(200)}}); create("int_pk", AnyDict{{"id", INT64_C(456)}, {"value", INT64_C(200)}}); create("string_pk", AnyDict{{"id", std::string("hello")}, {"value", INT64_C(200)}}); diff --git a/test/object-store/set.cpp b/test/object-store/set.cpp index 75aaecf343c..8d3a718afc0 100644 --- a/test/object-store/set.cpp +++ b/test/object-store/set.cpp @@ -39,10 +39,10 @@ TEST_CASE("set") { auto& coordinator = *_impl::RealmCoordinator::get_coordinator(config.path); static_cast(coordinator); - auto table = r->get_group().get_table("class_table"); - auto table2 = r->get_group().get_table("class_table2"); - auto other_table = r->get_group().get_table("class_table"); - auto other_table2 = r->get_group().get_table("class_table2"); + auto table = r->read_group().get_table("class_table"); + auto table2 = r->read_group().get_table("class_table2"); + auto other_table = r->read_group().get_table("class_table"); + auto other_table2 = r->read_group().get_table("class_table2"); ColKey col_int_set = table->get_column_key("int_set"); ColKey col_decimal_set = table->get_column_key("decimal_set"); @@ -52,7 +52,7 @@ TEST_CASE("set") { ColKey other_col_link_set = table->get_column_key("link_set"); auto write = [&](auto&& f) { - r->begin_write_transaction(); + r->begin_transaction(); if constexpr (std::is_void_v) { f(); r->commit_transaction(); diff --git a/test/object-store/sync/app.cpp b/test/object-store/sync/app.cpp index 5c54280d7f6..df7d6c0938c 100644 --- a/test/object-store/sync/app.cpp +++ b/test/object-store/sync/app.cpp @@ -1926,7 +1926,7 @@ TEST_CASE("app: sync integration", "[sync][app]") { util::EventLoop::main().run_until([&] { return called.load(); }); - return realm::Results(r, r->get_group().get_table("class_Dog")); + return realm::Results(r, r->read_group().get_table("class_Dog")); }; // MARK: Add Objects - @@ -1941,13 +1941,13 @@ TEST_CASE("app: sync integration", "[sync][app]") { // clear state from previous runs { Results dogs = get_dogs(r, session); - r->begin_write_transaction(); + r->begin_transaction(); dogs.clear(); r->commit_transaction(); } REQUIRE(get_dogs(r, session).size() == 0); - r->begin_write_transaction(); + r->begin_transaction(); CppContext c; Object::create(c, r, "Dog", util::Any(realm::AnyDict{{valid_pk_name, util::Any(ObjectId::gen())}, @@ -1990,13 +1990,13 @@ TEST_CASE("app: sync integration", "[sync][app]") { // clear state from previous runs { Results dogs = get_dogs(r, session); - r->begin_write_transaction(); + r->begin_transaction(); dogs.clear(); r->commit_transaction(); } REQUIRE(get_dogs(r, session).size() == 0); - r->begin_write_transaction(); + r->begin_transaction(); CppContext c; Object::create(c, r, "Dog", util::Any(realm::AnyDict{{valid_pk_name, util::Any(ObjectId::gen())}, @@ -2098,7 +2098,7 @@ TEST_CASE("app: sync integration", "[sync][app]") { // Create 26 MB worth of dogs in a single transaction - this should all get put into one changeset // and get uploaded at once, which for now is an error on the server. - r->begin_write_transaction(); + r->begin_transaction(); CppContext c; for (auto i = 'a'; i < 'z'; ++i) { Object::create(c, r, "Dog", diff --git a/test/object-store/sync/session/session.cpp b/test/object-store/sync/session/session.cpp index 2fcf9b4996e..504500a6e6d 100644 --- a/test/object-store/sync/session/session.cpp +++ b/test/object-store/sync/session/session.cpp @@ -440,8 +440,8 @@ TEMPLATE_TEST_CASE("sync: stop policy behavior", "[sync]", RegularUser) // Add an object so there's something to upload auto r = Realm::get_shared_realm(config); - TableRef table = ObjectStore::table_for_object_type(r->get_group(), "object"); - r->begin_write_transaction(); + TableRef table = ObjectStore::table_for_object_type(r->read_group(), "object"); + r->begin_transaction(); table->create_object_with_primary_key(0); r->commit_transaction(); @@ -636,7 +636,7 @@ TEST_CASE("sync: stable IDs", "[sync]") { auto realm = Realm::get_shared_realm(config); - ObjectSchema object_schema(realm->get_group(), "object", TableKey()); + ObjectSchema object_schema(realm->read_group(), "object", TableKey()); REQUIRE(object_schema == *config.schema->find("object")); } } @@ -675,7 +675,7 @@ TEST_CASE("sync: Migration from Sync 1.x to Sync 2.x", "[sync]") { config.schema_mode = SchemaMode::Immutable; auto recovered_realm = Realm::get_shared_realm(config); - TableRef table = ObjectStore::table_for_object_type(recovered_realm->get_group(), "object"); + TableRef table = ObjectStore::table_for_object_type(recovered_realm->read_group(), "object"); REQUIRE(table); REQUIRE(table->size() == 2); } @@ -746,7 +746,7 @@ TEST_CASE("sync: client resync") { SyncTestFile config2(init_sync_manager.app(), "default"); auto get_table = [](Realm& realm, StringData object_type) { - return ObjectStore::table_for_object_type(realm.get_group(), object_type); + return ObjectStore::table_for_object_type(realm.read_group(), object_type); }; auto create_object = [&](Realm& realm, StringData object_type) -> Obj { auto table = get_table(realm, object_type); @@ -757,7 +757,7 @@ TEST_CASE("sync: client resync") { auto setup = [&](auto fn) { auto realm = Realm::get_shared_realm(config); - realm->begin_write_transaction(); + realm->begin_transaction(); fn(*realm); realm->commit_transaction(); wait_for_upload(*realm); @@ -767,7 +767,7 @@ TEST_CASE("sync: client resync") { auto realm = Realm::get_shared_realm(config); auto session = sync_manager->get_session(realm->config().path, *realm->config().sync_config); { - realm->begin_write_transaction(); + realm->begin_transaction(); auto obj = create_object(*realm, "object"); auto col = obj.get_table()->get_column_key("value"); @@ -781,7 +781,7 @@ TEST_CASE("sync: client resync") { // Make a change while offline so that log compaction will cause a // client reset - realm->begin_write_transaction(); + realm->begin_transaction(); obj.set(col, 4); local(*realm); realm->commit_transaction(); @@ -794,7 +794,7 @@ TEST_CASE("sync: client resync") { for (int i = 0; i < 2; ++i) { wait_for_download(*realm2); - realm2->begin_write_transaction(); + realm2->begin_transaction(); auto table = get_table(*realm2, "object"); auto col = table->get_column_key("value"); table->begin()->set(col, i + 5); @@ -803,7 +803,7 @@ TEST_CASE("sync: client resync") { server.advance_clock(10s); } - realm2->begin_write_transaction(); + realm2->begin_transaction(); remote(*realm2); realm2->commit_transaction(); wait_for_upload(*realm2); @@ -844,7 +844,7 @@ TEST_CASE("sync: client resync") { wait_for_download(*realm); realm->refresh(); // FIXME: sync needs to notify - CHECK(ObjectStore::table_for_object_type(realm->get_group(), "object")->begin()->get("value") == 6); + CHECK(ObjectStore::table_for_object_type(realm->read_group(), "object")->begin()->get("value") == 6); } SECTION("should recover local changeset when mode is recover") @@ -858,7 +858,7 @@ TEST_CASE("sync: client resync") { wait_for_download(*realm); realm->refresh(); - CHECK(ObjectStore::table_for_object_type(realm->get_group(), "object")->begin()->get("value") == 4); + CHECK(ObjectStore::table_for_object_type(realm->read_group(), "object")->begin()->get("value") == 4); } */ @@ -879,7 +879,7 @@ TEST_CASE("sync: client resync") { SECTION("add table in discarded transaction") { setup([&](auto& realm) { - auto table = ObjectStore::table_for_object_type(realm.get_group(), "object2"); + auto table = ObjectStore::table_for_object_type(realm.read_group(), "object2"); REQUIRE(!table); }); @@ -900,12 +900,12 @@ TEST_CASE("sync: client resync") { wait_for_download(*realm); // test local realm that changes were persisted REQUIRE_THROWS(realm->refresh()); - auto table = ObjectStore::table_for_object_type(realm->get_group(), "object2"); + auto table = ObjectStore::table_for_object_type(realm->read_group(), "object2"); REQUIRE(table); REQUIRE(table->size() == 1); // test resync'd realm that changes were overwritten realm = Realm::get_shared_realm(config); - table = ObjectStore::table_for_object_type(realm->get_group(), "object2"); + table = ObjectStore::table_for_object_type(realm->read_group(), "object2"); REQUIRE(!table); } @@ -921,19 +921,19 @@ TEST_CASE("sync: client resync") { }}, }, 0, nullptr, nullptr, true); - ObjectStore::table_for_object_type(realm.get_group(), "object")->begin()->set("value2", 123); + ObjectStore::table_for_object_type(realm.read_group(), "object")->begin()->set("value2", 123); }, [](auto&) {}); wait_for_download(*realm); // test local realm that changes were persisted REQUIRE_THROWS(realm->refresh()); - auto table = ObjectStore::table_for_object_type(realm->get_group(), "object"); + auto table = ObjectStore::table_for_object_type(realm->read_group(), "object"); REQUIRE(table->get_column_count() == 3); REQUIRE(table->begin()->get("value2") == 123); REQUIRE_THROWS(realm->refresh()); // test resync'd realm that changes were overwritten realm = Realm::get_shared_realm(config); - table = ObjectStore::table_for_object_type(realm->get_group(), "object"); + table = ObjectStore::table_for_object_type(realm->read_group(), "object"); REQUIRE(table); REQUIRE(table->get_column_count() == 2); REQUIRE(!bool(table->get_column_key("value2"))); @@ -952,14 +952,14 @@ TEST_CASE("sync: client resync") { }}, }, 0, nullptr, nullptr, true); - auto table = ObjectStore::table_for_object_type(realm.get_group(), "object2"); + auto table = ObjectStore::table_for_object_type(realm.read_group(), "object2"); table->create_object_with_primary_key(Mixed()); table->create_object_with_primary_key(Mixed(1)); }, [](auto&) {}); wait_for_download(*realm); REQUIRE_NOTHROW(realm->refresh()); - auto table = ObjectStore::table_for_object_type(realm->get_group(), "object2"); + auto table = ObjectStore::table_for_object_type(realm->read_group(), "object2"); REQUIRE(table); ColKey pk_col_key = table->get_column_key("_id"); REQUIRE(bool(pk_col_key)); @@ -982,13 +982,13 @@ TEST_CASE("sync: client resync") { }}, }, 0, nullptr, nullptr, true); - auto table = ObjectStore::table_for_object_type(realm.get_group(), "object"); + auto table = ObjectStore::table_for_object_type(realm.read_group(), "object"); table->begin()->set(table->get_column_key("value2"), 123); }, [](auto&) {}); wait_for_download(*realm); REQUIRE_NOTHROW(realm->refresh()); - auto table = ObjectStore::table_for_object_type(realm->get_group(), "object"); + auto table = ObjectStore::table_for_object_type(realm->read_group(), "object"); REQUIRE(table->get_column_count() == 5); REQUIRE(bool(table->get_column_key("value2"))); // FIXME: sync has object recovery disabled currently @@ -1056,7 +1056,7 @@ TEST_CASE("sync: client resync") { SECTION("add object in recovered transaction") { Obj obj; auto realm = trigger_client_reset([&](auto& realm) { - auto table = ObjectStore::table_for_object_type(realm.get_group(), "object"); + auto table = ObjectStore::table_for_object_type(realm.read_group(), "object"); obj = table->create_object(); realm.update_schema({ @@ -1068,18 +1068,18 @@ TEST_CASE("sync: client resync") { }, [](auto&){}); wait_for_download(*realm); REQUIRE_NOTHROW(realm->refresh()); - auto table = ObjectStore::table_for_object_type(realm->get_group(), "object"); + auto table = ObjectStore::table_for_object_type(realm->read_group(), "object"); REQUIRE(table->get_column_count() == 2); REQUIRE(table->begin()->get("value2") == 123); } SECTION("delete object in recovered transaction") { auto realm = trigger_client_reset([&](auto& realm) { - ObjectStore::table_for_object_type(realm.get_group(), "object")->clear(); + ObjectStore::table_for_object_type(realm.read_group(), "object")->clear(); }, [](auto&){}); wait_for_download(*realm); REQUIRE_NOTHROW(realm->refresh()); - auto table = ObjectStore::table_for_object_type(realm->get_group(), "object"); + auto table = ObjectStore::table_for_object_type(realm->read_group(), "object"); REQUIRE(table->size() == 0); } diff --git a/test/object-store/thread_safe_reference.cpp b/test/object-store/thread_safe_reference.cpp index c458c8dc38e..d85dbe485aa 100644 --- a/test/object-store/thread_safe_reference.cpp +++ b/test/object-store/thread_safe_reference.cpp @@ -42,7 +42,7 @@ using namespace realm; static TableRef get_table(Realm& realm, StringData object_name) { - return ObjectStore::table_for_object_type(realm.get_group(), object_name); + return ObjectStore::table_for_object_type(realm.read_group(), object_name); } static Object create_object(SharedRealm const& realm, StringData object_type, AnyDict value) @@ -74,25 +74,25 @@ TEST_CASE("thread safe reference") { InMemoryTestFile config; config.automatic_change_notifications = false; config.cache = false; - SharedRealm realm = Realm::get_shared_realm(config); - realm->update_schema(schema); + SharedRealm r = Realm::get_shared_realm(config); + r->update_schema(schema); // Convenience object - realm->begin_write_transaction(); - auto foo = create_object(realm, "foo object", {{"ignore me", INT64_C(0)}}); - realm->commit_transaction(); + r->begin_transaction(); + auto foo = create_object(r, "foo object", {{"ignore me", INT64_C(0)}}); + r->commit_transaction(); - const auto int_column_key = realm->schema().find("int object")->persisted_properties[0].column_key; + const auto int_obj_col = r->schema().find("int object")->persisted_properties[0].column_key; SECTION("allowed during write transactions") { SECTION("obtain") { - realm->begin_write_transaction(); + r->begin_transaction(); REQUIRE_NOTHROW(ThreadSafeReference(foo)); } SECTION("resolve") { auto ref = ThreadSafeReference(foo); - realm->begin_write_transaction(); - REQUIRE_NOTHROW(ref.resolve(realm)); + r->begin_transaction(); + REQUIRE_NOTHROW(ref.resolve(r)); } } @@ -108,23 +108,23 @@ TEST_CASE("thread safe reference") { auto reference_version = get_current_version(); auto ref = util::make_optional(ThreadSafeReference(foo)); - realm->begin_write_transaction(); - realm->commit_transaction(); // Advance version + r->begin_transaction(); + r->commit_transaction(); // Advance version REQUIRE(get_current_version() != reference_version); // Ensure advanced REQUIRE_NOTHROW(shared_group->start_read(reference_version)); // Ensure pinned ref = {}; // Destroy thread safe reference, unpinning version - realm->begin_write_transaction(); - realm->commit_transaction(); // Clean up old versions + r->begin_transaction(); + r->commit_transaction(); // Clean up old versions REQUIRE_THROWS(shared_group->start_read(reference_version)); // Verify unpinned } SECTION("version mismatch") { SECTION("resolves at older version") { - realm->begin_write_transaction(); - Object num = create_object(realm, "int object", {{"value", INT64_C(7)}}); - realm->commit_transaction(); + r->begin_transaction(); + Object num = create_object(r, "int object", {{"value", INT64_C(7)}}); + r->commit_transaction(); ColKey col = num.get_object_schema().property_for_name("value")->column_key; ObjKey k = num.obj().get_key(); @@ -136,7 +136,7 @@ TEST_CASE("thread safe reference") { Object num = Object(r2, "int object", k); REQUIRE(num.obj().get(col) == 7); - r2->begin_write_transaction(); + r2->begin_transaction(); num.obj().set(col, 9); r2->commit_transaction(); @@ -144,22 +144,22 @@ TEST_CASE("thread safe reference") { }; REQUIRE(num.obj().get(col) == 7); - Object num_prime = ref.resolve(realm); + Object num_prime = ref.resolve(r); REQUIRE(num_prime.obj().get(col) == 9); REQUIRE(num.obj().get(col) == 9); - realm->begin_write_transaction(); + r->begin_transaction(); num.obj().set(col, 11); - realm->commit_transaction(); + r->commit_transaction(); REQUIRE(num_prime.obj().get(col) == 11); REQUIRE(num.obj().get(col) == 11); } SECTION("resolve at newer version") { - realm->begin_write_transaction(); - Object num = create_object(realm, "int object", {{"value", INT64_C(7)}}); - realm->commit_transaction(); + r->begin_transaction(); + Object num = create_object(r, "int object", {{"value", INT64_C(7)}}); + r->commit_transaction(); ColKey col = num.get_object_schema().property_for_name("value")->column_key; ObjKey k = num.obj().get_key(); @@ -170,7 +170,7 @@ TEST_CASE("thread safe reference") { SharedRealm r2 = Realm::get_shared_realm(config); Object num = Object(r2, "int object", k); - r2->begin_write_transaction(); + r2->begin_transaction(); num.obj().set(col, 9); r2->commit_transaction(); REQUIRE(num.obj().get(col) == 9); @@ -178,7 +178,7 @@ TEST_CASE("thread safe reference") { Object num_prime = ref.resolve(r2); REQUIRE(num_prime.obj().get(col) == 9); - r2->begin_write_transaction(); + r2->begin_transaction(); num_prime.obj().set(col, 11); r2->commit_transaction(); @@ -187,22 +187,22 @@ TEST_CASE("thread safe reference") { } REQUIRE(num.obj().get(col) == 7); - realm->refresh(); + r->refresh(); REQUIRE(num.obj().get(col) == 11); } SECTION("resolve at newer version when schema is specified") { - realm->close(); + r->close(); config.schema = schema; SharedRealm r = Realm::get_shared_realm(config); - r->begin_write_transaction(); + r->begin_transaction(); Object num = create_object(r, "int object", {{"value", INT64_C(7)}}); r->commit_transaction(); ColKey col = num.get_object_schema().property_for_name("value")->column_key; auto ref = ThreadSafeReference(num); - r->begin_write_transaction(); + r->begin_transaction(); num.obj().set(col, 9); r->commit_transaction(); @@ -211,9 +211,9 @@ TEST_CASE("thread safe reference") { SECTION("resolve references at multiple versions") { auto commit_new_num = [&](int64_t value) -> Object { - realm->begin_write_transaction(); - Object num = create_object(realm, "int object", {{"value", value}}); - realm->commit_transaction(); + r->begin_transaction(); + Object num = create_object(r, "int object", {{"value", value}}); + r->commit_transaction(); return num; }; @@ -232,9 +232,9 @@ TEST_CASE("thread safe reference") { } SECTION("same thread") { - realm->begin_write_transaction(); - Object num = create_object(realm, "int object", {{"value", INT64_C(7)}}); - realm->commit_transaction(); + r->begin_transaction(); + Object num = create_object(r, "int object", {{"value", INT64_C(7)}}); + r->commit_transaction(); ColKey col = num.get_object_schema().property_for_name("value")->column_key; REQUIRE(num.obj().get(col) == 7); @@ -244,11 +244,11 @@ TEST_CASE("thread safe reference") { SECTION("same realm") { did_run_section = true; { - Object num = ref.resolve(realm); + Object num = ref.resolve(r); REQUIRE(num.obj().get(col) == 7); - realm->begin_write_transaction(); + r->begin_transaction(); num.obj().set(col, 9); - realm->commit_transaction(); + r->commit_transaction(); REQUIRE(num.obj().get(col) == 9); } REQUIRE(num.obj().get(col) == 9); @@ -259,7 +259,7 @@ TEST_CASE("thread safe reference") { SharedRealm r = Realm::get_shared_realm(config); Object num = ref.resolve(r); REQUIRE(num.obj().get(col) == 7); - r->begin_write_transaction(); + r->begin_transaction(); num.obj().set(col, 9); r->commit_transaction(); REQUIRE(num.obj().get(col) == 9); @@ -267,9 +267,9 @@ TEST_CASE("thread safe reference") { REQUIRE(num.obj().get(col) == 7); } catch2_ensure_section_run_workaround(did_run_section, "same thread", [&]() { - realm->begin_write_transaction(); // advance to latest version by starting a write + r->begin_transaction(); // advance to latest version by starting a write REQUIRE(num.obj().get(col) == 9); - realm->cancel_transaction(); + r->cancel_transaction(); }); } @@ -281,25 +281,25 @@ TEST_CASE("thread safe reference") { TestFile configuration; SharedRealm realm = Realm::get_shared_realm(configuration); realm->update_schema(schema); - realm->begin_write_transaction(); + realm->begin_transaction(); create_object(realm, "int object", {{"value", INT64_C(42)}}); realm->commit_transaction(); realm->close(); configuration.schema_mode = SchemaMode::Immutable; SharedRealm read_only_realm = Realm::get_shared_realm(configuration); - auto table = read_only_realm->get_group().get_table("class_int object"); + auto table = read_only_realm->read_group().get_table("class_int object"); Results results(read_only_realm, table); REQUIRE(results.size() == 1); - REQUIRE(results.get(0).get(int_column_key) == 42); + REQUIRE(results.get(0).get(int_obj_col) == 42); SECTION("read-only `ThreadSafeReference` to `Results`") { auto thread_safe_results = ThreadSafeReference(results); std::thread([thread_safe_results = std::move(thread_safe_results), configuration, - int_column_key]() mutable { + int_obj_col]() mutable { SharedRealm realm_in_thread = Realm::get_shared_realm(configuration); Results resolved_results = thread_safe_results.resolve(realm_in_thread); REQUIRE(resolved_results.size() == 1); - REQUIRE(resolved_results.get(0).get(int_column_key) == 42); + REQUIRE(resolved_results.get(0).get(int_obj_col) == 42); }).join(); } @@ -307,20 +307,20 @@ TEST_CASE("thread safe reference") { Object object(read_only_realm, results.get(0)); auto thread_safe_object = ThreadSafeReference(object); std::thread([thread_safe_object = std::move(thread_safe_object), configuration, - int_column_key]() mutable { + int_obj_col]() mutable { SharedRealm realm_in_thread = Realm::get_shared_realm(configuration); auto resolved_object = thread_safe_object.resolve(realm_in_thread); REQUIRE(resolved_object.is_valid()); - REQUIRE(resolved_object.obj().get(int_column_key) == 42); + REQUIRE(resolved_object.obj().get(int_obj_col) == 42); }).join(); } } SECTION("objects") { - realm->begin_write_transaction(); - auto str = create_object(realm, "string object", {}); - auto num = create_object(realm, "int object", {{"value", INT64_C(0)}}); - realm->commit_transaction(); + r->begin_transaction(); + auto str = create_object(r, "string object", {}); + auto num = create_object(r, "int object", {{"value", INT64_C(0)}}); + r->commit_transaction(); ColKey col_num = num.get_object_schema().property_for_name("value")->column_key; ColKey col_str = str.get_object_schema().property_for_name("value")->column_key; @@ -334,7 +334,7 @@ TEST_CASE("thread safe reference") { REQUIRE(str.obj().get(col_str).is_null()); REQUIRE(num.obj().get(col_num) == 0); - r2->begin_write_transaction(); + r2->begin_transaction(); str.obj().set(col_str, "the meaning of life"); num.obj().set(col_num, 42); r2->commit_transaction(); @@ -343,30 +343,30 @@ TEST_CASE("thread safe reference") { REQUIRE(str.obj().get(col_str).is_null()); REQUIRE(num.obj().get(col_num) == 0); - realm->refresh(); + r->refresh(); REQUIRE(str.obj().get(col_str) == "the meaning of life"); REQUIRE(num.obj().get(col_num) == 42); } SECTION("object list") { - realm->begin_write_transaction(); - auto zero = create_object(realm, "int object", {{"value", INT64_C(0)}}); - auto obj = create_object(realm, "int array object", {{"value", AnyVector{zero}}}); - auto col = get_table(*realm, "int array object")->get_column_key("value"); - List list(realm, obj.obj(), col); - realm->commit_transaction(); + r->begin_transaction(); + auto zero = create_object(r, "int object", {{"value", INT64_C(0)}}); + auto obj = create_object(r, "int array object", {{"value", AnyVector{zero}}}); + auto col = get_table(*r, "int array object")->get_column_key("value"); + List list(r, obj.obj(), col); + r->commit_transaction(); REQUIRE(list.size() == 1); - REQUIRE(list.get(0).get(int_column_key) == 0); + REQUIRE(list.get(0).get(int_obj_col) == 0); auto ref = ThreadSafeReference(list); { SharedRealm r2 = Realm::get_shared_realm(config); List list = ref.resolve(r2); REQUIRE(list.size() == 1); - REQUIRE(list.get(0).get(int_column_key) == 0); + REQUIRE(list.get(0).get(int_obj_col) == 0); - r2->begin_write_transaction(); + r2->begin_transaction(); list.remove_all(); auto one = create_object(r2, "int object", {{"value", INT64_C(1)}}); auto two = create_object(r2, "int object", {{"value", INT64_C(2)}}); @@ -375,31 +375,31 @@ TEST_CASE("thread safe reference") { r2->commit_transaction(); REQUIRE(list.size() == 2); - REQUIRE(list.get(0).get(int_column_key) == 1); - REQUIRE(list.get(1).get(int_column_key) == 2); + REQUIRE(list.get(0).get(int_obj_col) == 1); + REQUIRE(list.get(1).get(int_obj_col) == 2); } REQUIRE(list.size() == 1); - REQUIRE(list.get(0).get(int_column_key) == 0); + REQUIRE(list.get(0).get(int_obj_col) == 0); - realm->refresh(); + r->refresh(); REQUIRE(list.size() == 2); - REQUIRE(list.get(0).get(int_column_key) == 1); - REQUIRE(list.get(1).get(int_column_key) == 2); + REQUIRE(list.get(0).get(int_obj_col) == 1); + REQUIRE(list.get(1).get(int_obj_col) == 2); } SECTION("sorted object results") { - auto& table = *get_table(*realm, "string object"); + auto& table = *get_table(*r, "string object"); auto col = table.get_column_key("value"); - auto results = Results(realm, table.where().not_equal(col, "C")).sort({{{col}}, {false}}); + auto results = Results(r, table.where().not_equal(col, "C")).sort({{{col}}, {false}}); - realm->begin_write_transaction(); - create_object(realm, "string object", {{"value", "A"s}}); - create_object(realm, "string object", {{"value", "B"s}}); - create_object(realm, "string object", {{"value", "C"s}}); - create_object(realm, "string object", {{"value", "D"s}}); - realm->commit_transaction(); + r->begin_transaction(); + create_object(r, "string object", {{"value", "A"s}}); + create_object(r, "string object", {{"value", "B"s}}); + create_object(r, "string object", {{"value", "C"s}}); + create_object(r, "string object", {{"value", "D"s}}); + r->commit_transaction(); REQUIRE(results.size() == 3); REQUIRE(results.get(0).get(col) == "D"); @@ -415,7 +415,7 @@ TEST_CASE("thread safe reference") { REQUIRE(results.get(1).get(col) == "B"); REQUIRE(results.get(2).get(col) == "A"); - r2->begin_write_transaction(); + r2->begin_transaction(); results.get(2).remove(); results.get(0).remove(); create_object(r2, "string object", {{"value", "E"s}}); @@ -431,7 +431,7 @@ TEST_CASE("thread safe reference") { REQUIRE(results.get(1).get(col) == "B"); REQUIRE(results.get(2).get(col) == "A"); - realm->refresh(); + r->refresh(); REQUIRE(results.size() == 2); REQUIRE(results.get(0).get(col) == "E"); @@ -439,15 +439,15 @@ TEST_CASE("thread safe reference") { } SECTION("distinct object results") { - auto& table = *get_table(*realm, "string object"); + auto& table = *get_table(*r, "string object"); auto col = table.get_column_key("value"); - auto results = Results(realm, table.where()).distinct({{{col}}}).sort({{"value", true}}); + auto results = Results(r, table.where()).distinct({{{col}}}).sort({{"value", true}}); - realm->begin_write_transaction(); - create_object(realm, "string object", {{"value", "A"s}}); - create_object(realm, "string object", {{"value", "A"s}}); - create_object(realm, "string object", {{"value", "B"s}}); - realm->commit_transaction(); + r->begin_transaction(); + create_object(r, "string object", {{"value", "A"s}}); + create_object(r, "string object", {{"value", "A"s}}); + create_object(r, "string object", {{"value", "B"s}}); + r->commit_transaction(); REQUIRE(results.size() == 2); REQUIRE(results.get(0).get(col) == "A"); @@ -461,7 +461,7 @@ TEST_CASE("thread safe reference") { REQUIRE(results.get(0).get(col) == "A"); REQUIRE(results.get(1).get(col) == "B"); - r2->begin_write_transaction(); + r2->begin_transaction(); results.get(0).remove(); create_object(r2, "string object", {{"value", "C"s}}); r2->commit_transaction(); @@ -476,7 +476,7 @@ TEST_CASE("thread safe reference") { REQUIRE(results.get(0).get(col) == "A"); REQUIRE(results.get(1).get(col) == "B"); - realm->refresh(); + r->refresh(); REQUIRE(results.size() == 3); REQUIRE(results.get(0).get(col) == "A"); @@ -485,11 +485,11 @@ TEST_CASE("thread safe reference") { } SECTION("int list") { - realm->begin_write_transaction(); - auto obj = create_object(realm, "int array", {{"value", AnyVector{INT64_C(0)}}}); - auto col = get_table(*realm, "int array")->get_column_key("value"); - List list(realm, obj.obj(), col); - realm->commit_transaction(); + r->begin_transaction(); + auto obj = create_object(r, "int array", {{"value", AnyVector{INT64_C(0)}}}); + auto col = get_table(*r, "int array")->get_column_key("value"); + List list(r, obj.obj(), col); + r->commit_transaction(); auto ref = ThreadSafeReference(list); { @@ -498,7 +498,7 @@ TEST_CASE("thread safe reference") { REQUIRE(list.size() == 1); REQUIRE(list.get(0) == 0); - r2->begin_write_transaction(); + r2->begin_transaction(); list.remove_all(); list.add(int64_t(1)); list.add(int64_t(2)); @@ -512,7 +512,7 @@ TEST_CASE("thread safe reference") { REQUIRE(list.size() == 1); REQUIRE(list.get(0) == 0); - realm->refresh(); + r->refresh(); REQUIRE(list.size() == 2); REQUIRE(list.get(0) == 1); @@ -520,11 +520,11 @@ TEST_CASE("thread safe reference") { } SECTION("sorted int results") { - realm->begin_write_transaction(); - auto obj = create_object(realm, "int array", {{"value", AnyVector{INT64_C(0), INT64_C(2), INT64_C(1)}}}); - auto col = get_table(*realm, "int array")->get_column_key("value"); - List list(realm, obj.obj(), col); - realm->commit_transaction(); + r->begin_transaction(); + auto obj = create_object(r, "int array", {{"value", AnyVector{INT64_C(0), INT64_C(2), INT64_C(1)}}}); + auto col = get_table(*r, "int array")->get_column_key("value"); + List list(r, obj.obj(), col); + r->commit_transaction(); auto results = list.sort({{"self", true}}); @@ -543,7 +543,7 @@ TEST_CASE("thread safe reference") { REQUIRE(results.get(1) == 1); REQUIRE(results.get(2) == 2); - r->begin_write_transaction(); + r->begin_transaction(); auto table = get_table(*r, "int array"); List list(r, *table->begin(), table->get_column_key("value")); list.remove(1); @@ -561,7 +561,7 @@ TEST_CASE("thread safe reference") { REQUIRE(results.get(1) == 1); REQUIRE(results.get(2) == 2); - realm->refresh(); + r->refresh(); REQUIRE(results.size() == 3); REQUIRE(results.get(0) == -1); @@ -570,13 +570,12 @@ TEST_CASE("thread safe reference") { } SECTION("distinct int results") { - realm->begin_write_transaction(); - auto obj = - create_object(realm, "int array", - {{"value", AnyVector{INT64_C(3), INT64_C(2), INT64_C(1), INT64_C(1), INT64_C(2)}}}); - auto col = get_table(*realm, "int array")->get_column_key("value"); - List list(realm, obj.obj(), col); - realm->commit_transaction(); + r->begin_transaction(); + auto obj = create_object( + r, "int array", {{"value", AnyVector{INT64_C(3), INT64_C(2), INT64_C(1), INT64_C(1), INT64_C(2)}}}); + auto col = get_table(*r, "int array")->get_column_key("value"); + List list(r, obj.obj(), col); + r->commit_transaction(); auto results = list.as_results().distinct({"self"}).sort({{"self", true}}); @@ -596,7 +595,7 @@ TEST_CASE("thread safe reference") { REQUIRE(results.get(1) == 2); REQUIRE(results.get(2) == 3); - r->begin_write_transaction(); + r->begin_transaction(); auto table = get_table(*r, "int array"); List list(r, *table->begin(), table->get_column_key("value")); list.remove(1); @@ -613,7 +612,7 @@ TEST_CASE("thread safe reference") { REQUIRE(results.get(1) == 2); REQUIRE(results.get(2) == 3); - realm->refresh(); + r->refresh(); REQUIRE(results.size() == 2); REQUIRE(results.get(0) == 1); @@ -621,18 +620,18 @@ TEST_CASE("thread safe reference") { } SECTION("multiple types") { - auto results = Results(realm, get_table(*realm, "int object")->where().equal(int_column_key, 5)); + auto results = Results(r, get_table(*r, "int object")->where().equal(int_obj_col, 5)); - realm->begin_write_transaction(); - auto num = create_object(realm, "int object", {{"value", INT64_C(5)}}); - auto obj = create_object(realm, "int array object", {{"value", AnyVector{}}}); - auto col = get_table(*realm, "int array object")->get_column_key("value"); - List list(realm, obj.obj(), col); - realm->commit_transaction(); + r->begin_transaction(); + auto num = create_object(r, "int object", {{"value", INT64_C(5)}}); + auto obj = create_object(r, "int array object", {{"value", AnyVector{}}}); + auto col = get_table(*r, "int array object")->get_column_key("value"); + List list(r, obj.obj(), col); + r->commit_transaction(); REQUIRE(list.size() == 0); REQUIRE(results.size() == 1); - REQUIRE(results.get(0).get(int_column_key) == 5); + REQUIRE(results.get(0).get(int_obj_col) == 5); auto ref_num = ThreadSafeReference(num); auto ref_list = ThreadSafeReference(list); auto ref_results = ThreadSafeReference(results); @@ -644,26 +643,26 @@ TEST_CASE("thread safe reference") { REQUIRE(list.size() == 0); REQUIRE(results.size() == 1); - REQUIRE(results.get(0).get(int_column_key) == 5); + REQUIRE(results.get(0).get(int_obj_col) == 5); - r2->begin_write_transaction(); + r2->begin_transaction(); num.obj().set_all(6); list.add(num.obj().get_key()); r2->commit_transaction(); REQUIRE(list.size() == 1); - REQUIRE(list.get(0).get(int_column_key) == 6); + REQUIRE(list.get(0).get(int_obj_col) == 6); REQUIRE(results.size() == 0); } REQUIRE(list.size() == 0); REQUIRE(results.size() == 1); - REQUIRE(results.get(0).get(int_column_key) == 5); + REQUIRE(results.get(0).get(int_obj_col) == 5); - realm->refresh(); + r->refresh(); REQUIRE(list.size() == 1); - REQUIRE(list.get(0).get(int_column_key) == 6); + REQUIRE(list.get(0).get(int_obj_col) == 6); REQUIRE(results.size() == 0); } } @@ -673,47 +672,47 @@ TEST_CASE("thread safe reference") { auto delete_and_resolve = [&](auto&& list) { auto ref = ThreadSafeReference(list); - realm->begin_write_transaction(); + r->begin_transaction(); obj.obj().remove(); - realm->commit_transaction(); + r->commit_transaction(); - return ref.resolve::type>(realm); + return ref.resolve::type>(r); }; SECTION("object") { - realm->begin_write_transaction(); - obj = create_object(realm, "int object", {{"value", INT64_C(7)}}); - realm->commit_transaction(); + r->begin_transaction(); + obj = create_object(r, "int object", {{"value", INT64_C(7)}}); + r->commit_transaction(); REQUIRE(!delete_and_resolve(obj).is_valid()); } SECTION("object list") { - realm->begin_write_transaction(); - obj = create_object(realm, "int array object", {{"value", AnyVector{AnyDict{{"value", INT64_C(0)}}}}}); - auto col = get_table(*realm, "int array object")->get_column_key("value"); - List list(realm, obj.obj(), col); - realm->commit_transaction(); + r->begin_transaction(); + obj = create_object(r, "int array object", {{"value", AnyVector{AnyDict{{"value", INT64_C(0)}}}}}); + auto col = get_table(*r, "int array object")->get_column_key("value"); + List list(r, obj.obj(), col); + r->commit_transaction(); REQUIRE(!delete_and_resolve(list).is_valid()); } SECTION("int list") { - realm->begin_write_transaction(); - obj = create_object(realm, "int array", {{"value", AnyVector{{INT64_C(1)}}}}); - auto col = get_table(*realm, "int array")->get_column_key("value"); - List list(realm, obj.obj(), col); - realm->commit_transaction(); + r->begin_transaction(); + obj = create_object(r, "int array", {{"value", AnyVector{{INT64_C(1)}}}}); + auto col = get_table(*r, "int array")->get_column_key("value"); + List list(r, obj.obj(), col); + r->commit_transaction(); REQUIRE(!delete_and_resolve(list).is_valid()); } SECTION("object results") { - realm->begin_write_transaction(); - obj = create_object(realm, "int array object", {{"value", AnyVector{AnyDict{{"value", INT64_C(0)}}}}}); - auto col = get_table(*realm, "int array object")->get_column_key("value"); - List list(realm, obj.obj(), col); - realm->commit_transaction(); + r->begin_transaction(); + obj = create_object(r, "int array object", {{"value", AnyVector{AnyDict{{"value", INT64_C(0)}}}}}); + auto col = get_table(*r, "int array object")->get_column_key("value"); + List list(r, obj.obj(), col); + r->commit_transaction(); auto results = delete_and_resolve(list.sort({{"value", true}})); REQUIRE(results.is_valid()); @@ -721,10 +720,10 @@ TEST_CASE("thread safe reference") { } SECTION("int results") { - realm->begin_write_transaction(); - obj = create_object(realm, "int array", {{"value", AnyVector{{INT64_C(1)}}}}); - List list(realm, obj.obj(), get_table(*realm, "int array")->get_column_key("value")); - realm->commit_transaction(); + r->begin_transaction(); + obj = create_object(r, "int array", {{"value", AnyVector{{INT64_C(1)}}}}); + List list(r, obj.obj(), get_table(*r, "int array")->get_column_key("value")); + r->commit_transaction(); REQUIRE(!delete_and_resolve(list).is_valid()); } @@ -735,7 +734,7 @@ TEST_CASE("thread safe reference") { ThreadSafeReference ref; { SharedRealm r2 = Realm::get_shared_realm(config); - r2->begin_write_transaction(); + r2->begin_transaction(); auto obj = fn(r2); r2->commit_transaction(); ref = obj; @@ -746,7 +745,7 @@ TEST_CASE("thread safe reference") { SECTION("object") { auto obj = create_ref([](auto& r) { return create_object(r, "int object", {{"value", INT64_C(7)}}); - }).resolve(realm); + }).resolve(r); REQUIRE(obj.is_valid()); REQUIRE(obj.get_column_value("value") == 7); } @@ -756,7 +755,7 @@ TEST_CASE("thread safe reference") { auto obj = create_object(r, "int array object", {{"value", AnyVector{AnyDict{{"value", INT64_C(0)}}}}}); return List(r, obj.obj(), get_table(*r, "int array object")->get_column_key("value")); - }).resolve(realm); + }).resolve(r); REQUIRE(list.is_valid()); REQUIRE(list.size() == 1); } @@ -765,7 +764,7 @@ TEST_CASE("thread safe reference") { auto list = create_ref([](auto& r) { auto obj = create_object(r, "int array", {{"value", AnyVector{{INT64_C(1)}}}}); return List(r, obj.obj(), get_table(*r, "int array")->get_column_key("value")); - }).resolve(realm); + }).resolve(r); REQUIRE(list.is_valid()); REQUIRE(list.size() == 1); } @@ -779,7 +778,7 @@ TEST_CASE("thread safe reference") { .sort({{"value", true}}); REQUIRE(results.size() == 1); return results; - }).resolve(realm); + }).resolve(r); REQUIRE(results.is_valid()); REQUIRE(results.size() == 1); } @@ -789,7 +788,7 @@ TEST_CASE("thread safe reference") { auto obj = create_object(r, "int array", {{"value", AnyVector{{INT64_C(1)}}}}); return List(r, obj.obj(), get_table(*r, "int array")->get_column_key("value")) .sort({{"self", true}}); - }).resolve(realm); + }).resolve(r); REQUIRE(results.is_valid()); REQUIRE(results.size() == 1); } @@ -800,7 +799,7 @@ TEST_CASE("thread safe reference") { ThreadSafeReference ref; { SharedRealm r2 = Realm::get_shared_realm(config); - r2->begin_write_transaction(); + r2->begin_transaction(); ref = fn(r2); r2->commit_transaction(); }; @@ -810,7 +809,7 @@ TEST_CASE("thread safe reference") { SECTION("object") { auto obj = create_ref([](auto& r) { return create_object(r, "int object", {{"value", INT64_C(7)}}); - }).resolve(realm); + }).resolve(r); REQUIRE(obj.is_valid()); REQUIRE(obj.get_column_value("value") == 7); } @@ -820,7 +819,7 @@ TEST_CASE("thread safe reference") { auto obj = create_object(r, "int array object", {{"value", AnyVector{AnyDict{{"value", INT64_C(0)}}}}}); return List(r, obj.obj(), get_table(*r, "int array object")->get_column_key("value")); - }).resolve(realm); + }).resolve(r); REQUIRE(list.is_valid()); REQUIRE(list.size() == 1); } @@ -829,7 +828,7 @@ TEST_CASE("thread safe reference") { auto list = create_ref([](auto& r) { auto obj = create_object(r, "int array", {{"value", AnyVector{{INT64_C(1)}}}}); return List(r, obj.obj(), get_table(*r, "int array")->get_column_key("value")); - }).resolve(realm); + }).resolve(r); REQUIRE(list.is_valid()); REQUIRE(list.size() == 1); } @@ -850,7 +849,7 @@ TEST_CASE("thread safe reference") { auto obj = create_object(r, "int array", {{"value", AnyVector{{INT64_C(1)}}}}); return List(r, obj.obj(), get_table(*r, "int array")->get_column_key("value")) .sort({{"self", true}}); - }).resolve(realm); + }).resolve(r); REQUIRE(results.is_valid()); REQUIRE(results.size() == 1); } @@ -861,7 +860,7 @@ TEST_CASE("thread safe reference") { ThreadSafeReference ref; { SharedRealm r2 = Realm::get_shared_realm(config); - r2->begin_write_transaction(); + r2->begin_transaction(); ref = fn(r2); r2->cancel_transaction(); }; @@ -871,7 +870,7 @@ TEST_CASE("thread safe reference") { SECTION("object") { auto obj = create_ref([](auto& r) { return create_object(r, "int object", {{"value", INT64_C(7)}}); - }).resolve(realm); + }).resolve(r); REQUIRE_FALSE(obj.is_valid()); } @@ -880,7 +879,7 @@ TEST_CASE("thread safe reference") { auto obj = create_object(r, "int array object", {{"value", AnyVector{AnyDict{{"value", INT64_C(0)}}}}}); return List(r, obj.obj(), get_table(*r, "int array object")->get_column_key("value")); - }).resolve(realm); + }).resolve(r); REQUIRE_FALSE(list.is_valid()); } @@ -888,7 +887,7 @@ TEST_CASE("thread safe reference") { auto list = create_ref([](auto& r) { auto obj = create_object(r, "int array", {{"value", AnyVector{{INT64_C(1)}}}}); return List(r, obj.obj(), get_table(*r, "int array")->get_column_key("value")); - }).resolve(realm); + }).resolve(r); REQUIRE_FALSE(list.is_valid()); } @@ -908,7 +907,7 @@ TEST_CASE("thread safe reference") { auto obj = create_object(r, "int array", {{"value", AnyVector{{INT64_C(1)}}}}); return List(r, obj.obj(), get_table(*r, "int array")->get_column_key("value")) .sort({{"self", true}}); - }).resolve(realm); + }).resolve(r); REQUIRE_FALSE(results.is_valid()); } } @@ -917,24 +916,24 @@ TEST_CASE("thread safe reference") { SECTION("retains source realm") { // else version will become unpinned auto ref = ThreadSafeReference(foo); foo = {}; - realm = nullptr; - realm = Realm::get_shared_realm(config); - REQUIRE_NOTHROW(ref.resolve(realm)); + r = nullptr; + r = Realm::get_shared_realm(config); + REQUIRE_NOTHROW(ref.resolve(r)); } SECTION("retains source RealmCoordinator") { auto ref = ThreadSafeReference(foo); auto coordinator = _impl::RealmCoordinator::get_existing_coordinator(config.path).get(); foo = {}; - realm = nullptr; + r = nullptr; REQUIRE(coordinator == _impl::RealmCoordinator::get_existing_coordinator(config.path).get()); } } SECTION("metadata") { - realm->begin_write_transaction(); - auto num = create_object(realm, "int object", {{"value", INT64_C(5)}}); - realm->commit_transaction(); + r->begin_transaction(); + auto num = create_object(r, "int object", {{"value", INT64_C(5)}}); + r->commit_transaction(); REQUIRE(num.get_object_schema().name == "int object"); auto ref = ThreadSafeReference(num); @@ -947,7 +946,7 @@ TEST_CASE("thread safe reference") { SECTION("allow multiple resolves") { auto ref = ThreadSafeReference(foo); - ref.resolve(realm); - REQUIRE_NOTHROW(ref.resolve(realm)); + ref.resolve(r); + REQUIRE_NOTHROW(ref.resolve(r)); } } diff --git a/test/object-store/transaction_log_parsing.cpp b/test/object-store/transaction_log_parsing.cpp index b2bcfe346aa..e3b05cdd391 100644 --- a/test/object-store/transaction_log_parsing.cpp +++ b/test/object-store/transaction_log_parsing.cpp @@ -43,7 +43,7 @@ class CaptureHelper { , m_list(lv) , m_table_key(table_key) { - m_realm->begin_write_transaction(); + m_realm->begin_transaction(); m_initial.reserve(lv.size()); for (size_t i = 0; i < lv.size(); ++i) @@ -71,7 +71,7 @@ class CaptureHelper { explicit operator bool() const { - return m_realm->is_in_write_transaction(); + return m_realm->is_in_transaction(); } private: @@ -234,7 +234,7 @@ TEST_CASE("Transaction log parsing: schema change validation") { {{"unindexed", PropertyType::Int}, {"indexed", PropertyType::Int, Property::IsPrimary{false}, Property::IsIndexed{true}}}}, }); - r->get_group(); + r->read_group(); auto history = make_in_realm_history(config.path); auto db = DB::create(*history, config.options()); @@ -285,11 +285,11 @@ TEST_CASE("Transaction log parsing: changeset calcuation") { {"table", {{"pk", PropertyType::Int}, {"value", PropertyType::Int}}}, }); - auto& table = *r->get_group().get_table("class_table"); + auto& table = *r->read_group().get_table("class_table"); auto table_key = table.get_key().value; auto cols = table.get_column_keys(); - r->begin_write_transaction(); + r->begin_transaction(); std::vector objects; table.create_objects(10, objects); for (int i = 0; i < 10; ++i) @@ -301,7 +301,7 @@ TEST_CASE("Transaction log parsing: changeset calcuation") { auto track_changes = [&](std::vector tables_needed, auto&& f) { auto sg = coordinator->begin_read(); - r->begin_write_transaction(); + r->begin_transaction(); f(); r->commit_transaction(); @@ -391,10 +391,10 @@ TEST_CASE("Transaction log parsing: changeset calcuation") { {"target", {{"value", PropertyType::Int}}}, }); - auto origin = r->get_group().get_table("class_origin"); - auto target = r->get_group().get_table("class_target"); + auto origin = r->read_group().get_table("class_origin"); + auto target = r->read_group().get_table("class_target"); - r->begin_write_transaction(); + r->begin_transaction(); LnkLst lv = origin->create_object().get_linklist("array"); std::vector target_keys; @@ -929,7 +929,7 @@ TEST_CASE("Transaction log parsing: changeset calcuation") { } SECTION("delete a different lv") { - r->begin_write_transaction(); + r->begin_transaction(); auto new_obj = origin->create_object(); r->commit_transaction(); @@ -944,7 +944,7 @@ TEST_CASE("Transaction log parsing: changeset calcuation") { } SECTION("modifying a different linkview should not produce notifications") { - r->begin_write_transaction(); + r->begin_transaction(); auto lv2 = origin->create_object().get_linklist("array"); lv2.add(target_keys[5]); r->commit_transaction(); @@ -990,12 +990,12 @@ TEST_CASE("Transaction log parsing: changeset calcuation") { }}, }); - auto origin = realm->get_group().get_table("class_origin"); - auto target = realm->get_group().get_table("class_target"); + auto origin = realm->read_group().get_table("class_origin"); + auto target = realm->read_group().get_table("class_target"); auto origin_cols = origin->get_column_keys(); auto target_cols = target->get_column_keys(); - realm->begin_write_transaction(); + realm->begin_transaction(); std::vector target_keys; target->create_objects(10, target_keys); @@ -1019,19 +1019,19 @@ TEST_CASE("Transaction log parsing: changeset calcuation") { for (int i = 0; i < 10; ++i) tr2.add(0); - realm->get_group().get_table("class_origin 2")->create_object_with_primary_key(48); + realm->read_group().get_table("class_origin 2")->create_object_with_primary_key(48); realm->commit_transaction(); auto observe = [&](std::initializer_list rows, auto&& fn) { auto realm2 = Realm::get_shared_realm(config); - auto& group = realm2->get_group(); + auto& group = realm2->read_group(); static_cast(group); // silence unused warning KVOContext observer(rows); observer.realm = realm2; realm2->m_binding_context.reset(&observer); - realm->begin_write_transaction(); + realm->begin_transaction(); lv.size(); lv2.size(); tr.size(); @@ -1054,7 +1054,7 @@ TEST_CASE("Transaction log parsing: changeset calcuation") { observer.realm = realm; realm->m_binding_context.reset(&observer); - realm->begin_write_transaction(); + realm->begin_transaction(); lv.size(); lv2.size(); tr.size(); @@ -1384,7 +1384,7 @@ TEST_CASE("Transaction log parsing: changeset calcuation") { SECTION("array: modifying different table does not produce changes") { auto changes = observe({o}, [&] { - realm->get_group().get_table("class_origin 2")->begin()->get_linklist("array").add(target_keys[0]); + realm->read_group().get_table("class_origin 2")->begin()->get_linklist("array").add(target_keys[0]); }); REQUIRE_FALSE(changes.modified(0, target_cols[2])); } @@ -1586,10 +1586,10 @@ TEST_CASE("DeepChangeChecker") { {"link2", PropertyType::Object | PropertyType::Nullable, "table"}, {"array", PropertyType::Array | PropertyType::Object, "table"}}}, }); - auto table = r->get_group().get_table("class_table"); + auto table = r->read_group().get_table("class_table"); std::vector objects; - r->begin_write_transaction(); + r->begin_transaction(); for (int i = 0; i < 10; ++i) objects.push_back(table->create_object().set_all(i)); r->commit_transaction(); @@ -1599,7 +1599,7 @@ TEST_CASE("DeepChangeChecker") { auto db = DB::create(*history, config.options()); auto rt = db->start_read(); - r->begin_write_transaction(); + r->begin_transaction(); f(); r->commit_transaction(); @@ -1628,7 +1628,7 @@ TEST_CASE("DeepChangeChecker") { bool did_run_section = false; SECTION("first link set") { did_run_section = true; - r->begin_write_transaction(); + r->begin_transaction(); objects[0].set(cols[1], objects[1].get_key()); objects[1].set(cols[1], objects[2].get_key()); objects[2].set(cols[1], objects[4].get_key()); @@ -1636,7 +1636,7 @@ TEST_CASE("DeepChangeChecker") { } SECTION("second link set") { did_run_section = true; - r->begin_write_transaction(); + r->begin_transaction(); objects[0].set(cols[2], objects[1].get_key()); objects[1].set(cols[2], objects[2].get_key()); objects[2].set(cols[2], objects[4].get_key()); @@ -1644,7 +1644,7 @@ TEST_CASE("DeepChangeChecker") { } SECTION("both set") { did_run_section = true; - r->begin_write_transaction(); + r->begin_transaction(); objects[0].set(cols[1], objects[1].get_key()); objects[1].set(cols[1], objects[2].get_key()); objects[2].set(cols[1], objects[4].get_key()); @@ -1656,7 +1656,7 @@ TEST_CASE("DeepChangeChecker") { } SECTION("circular link") { did_run_section = true; - r->begin_write_transaction(); + r->begin_transaction(); objects[0].set(cols[1], objects[0].get_key()); objects[1].set(cols[1], objects[1].get_key()); objects[2].set(cols[1], objects[2].get_key()); @@ -1683,7 +1683,7 @@ TEST_CASE("DeepChangeChecker") { } SECTION("changes over linklists are tracked") { - r->begin_write_transaction(); + r->begin_transaction(); for (int i = 0; i < 3; ++i) { objects[i].get_linklist(cols[3]).add(objects[i].get_key()); objects[i].get_linklist(cols[3]).add(objects[i].get_key()); @@ -1700,7 +1700,7 @@ TEST_CASE("DeepChangeChecker") { } SECTION("changes from an invalidated object") { - r->begin_write_transaction(); + r->begin_transaction(); size_t obj_ndx_to_invalidate = 6; for (int i = 0; i < 3; ++i) { objects[i].get_linklist(cols[3]).add(objects[i].get_key()); @@ -1726,7 +1726,7 @@ TEST_CASE("DeepChangeChecker") { } SECTION("cycles over links do not loop forever") { - r->begin_write_transaction(); + r->begin_transaction(); objects[0].set(cols[1], objects[0].get_key()); r->commit_transaction(); @@ -1737,7 +1737,7 @@ TEST_CASE("DeepChangeChecker") { } SECTION("cycles over linklists do not loop forever") { - r->begin_write_transaction(); + r->begin_transaction(); objects[0].get_linklist(cols[3]).add(objects[0].get_key()); r->commit_transaction(); @@ -1748,7 +1748,7 @@ TEST_CASE("DeepChangeChecker") { } SECTION("link chains are tracked up to 4 levels deep") { - r->begin_write_transaction(); + r->begin_transaction(); for (int i = 0; i < 10; ++i) objects.push_back(table->create_object()); for (int i = 0; i < 19; ++i) @@ -1781,7 +1781,7 @@ TEST_CASE("DeepChangeChecker") { } SECTION("changes made in the 3rd elements in the link list") { - r->begin_write_transaction(); + r->begin_transaction(); objects[0].get_linklist(cols[3]).add(objects[1].get_key()); objects[0].get_linklist(cols[3]).add(objects[2].get_key()); objects[0].get_linklist(cols[3]).add(objects[3].get_key()); diff --git a/test/object-store/util/test_file.cpp b/test/object-store/util/test_file.cpp index 263db42fcaa..ca1fe83c0c6 100644 --- a/test/object-store/util/test_file.cpp +++ b/test/object-store/util/test_file.cpp @@ -91,13 +91,13 @@ TestFile::~TestFile() DBOptions TestFile::options() const { DBOptions options; - options.durability = is_in_memory ? DBOptions::Durability::MemOnly : DBOptions::Durability::Full; + options.durability = in_memory ? DBOptions::Durability::MemOnly : DBOptions::Durability::Full; return options; } InMemoryTestFile::InMemoryTestFile() { - is_in_memory = true; + in_memory = true; } #if REALM_ENABLE_SYNC