@@ -53,18 +53,18 @@ class DummyParent : public CollectionParent {
53
53
{
54
54
return m_obj;
55
55
}
56
+ uint_fast64_t root_storage_version () const noexcept final
57
+ {
58
+ return 0 ;
59
+ }
56
60
57
61
protected:
58
62
Obj m_obj;
59
63
ref_type m_ref;
60
- UpdateStatus update_if_needed_with_status () const final
64
+ UpdateStatus update_if_needed () const final
61
65
{
62
66
return UpdateStatus::Updated;
63
67
}
64
- bool update_if_needed () const final
65
- {
66
- return true ;
67
- }
68
68
ref_type get_collection_ref (Index, CollectionType) const final
69
69
{
70
70
return m_ref;
@@ -262,6 +262,7 @@ class CollectionBase : public Collection {
262
262
CollectionBase& operator =(CollectionBase&&) noexcept = default ;
263
263
264
264
void validate_index (const char * msg, size_t index, size_t size) const ;
265
+ static bool do_init_from_parent (BPlusTreeBase* tree, ref_type ref, bool allow_create);
265
266
};
266
267
267
268
inline std::string_view collection_type_name (CollectionType col_type, bool uppercase = false )
@@ -499,7 +500,7 @@ class CollectionBaseImpl : public Interface, protected ArrayParent {
499
500
if (m_parent) {
500
501
try {
501
502
// Update the parent. Will throw if parent is not existing.
502
- switch (m_parent->update_if_needed_with_status ()) {
503
+ switch (m_parent->update_if_needed ()) {
503
504
case UpdateStatus::Updated:
504
505
// Make sure to update next time around
505
506
m_content_version = 0 ;
@@ -531,7 +532,7 @@ class CollectionBaseImpl : public Interface, protected ArrayParent {
531
532
{
532
533
try {
533
534
// `has_changed()` sneakily modifies internal state.
534
- update_if_needed_with_status ();
535
+ update_if_needed ();
535
536
if (m_last_content_version != m_content_version) {
536
537
m_last_content_version = m_content_version;
537
538
return true ;
@@ -577,10 +578,10 @@ class CollectionBaseImpl : public Interface, protected ArrayParent {
577
578
using Interface::get_target_table;
578
579
579
580
protected:
580
- Obj m_obj_mem;
581
+ ObjCollectionParent m_obj_mem;
581
582
std::shared_ptr<CollectionParent> m_col_parent;
582
583
CollectionParent::Index m_index;
583
- mutable size_t m_my_version = 0 ;
584
+ mutable size_t m_storage_version = 0 ;
584
585
ColKey m_col_key;
585
586
bool m_nullable = false ;
586
587
@@ -657,13 +658,14 @@ class CollectionBaseImpl : public Interface, protected ArrayParent {
657
658
658
659
UpdateStatus get_update_status () const
659
660
{
660
- UpdateStatus status = m_parent ? m_parent->update_if_needed_with_status () : UpdateStatus::Detached;
661
+ UpdateStatus status = m_parent ? m_parent->update_if_needed () : UpdateStatus::Detached;
661
662
662
663
if (status != UpdateStatus::Detached) {
663
664
auto content_version = m_alloc->get_content_version ();
664
- if (content_version != m_content_version || m_my_version != m_parent->m_parent_version ) {
665
+ auto storage_version = m_parent->root_storage_version ();
666
+ if (content_version != m_content_version || m_storage_version != storage_version) {
665
667
m_content_version = content_version;
666
- m_my_version = m_parent-> m_parent_version ;
668
+ m_storage_version = storage_version ;
667
669
status = UpdateStatus::Updated;
668
670
}
669
671
}
@@ -674,18 +676,14 @@ class CollectionBaseImpl : public Interface, protected ArrayParent {
674
676
// / Refresh the parent object (if needed) and compare version numbers.
675
677
// / Return true if the collection should initialize from parent
676
678
// / Throws if the owning object no longer exists.
677
- bool should_update ()
679
+ bool should_update () const
678
680
{
679
681
check_parent ();
680
- bool changed = m_parent->update_if_needed (); // Throws if the object does not exist.
681
- auto content_version = m_alloc->get_content_version ();
682
-
683
- if (changed || content_version != m_content_version || m_my_version != m_parent->m_parent_version ) {
684
- m_content_version = content_version;
685
- m_my_version = m_parent->m_parent_version ;
686
- return true ;
682
+ auto status = get_update_status ();
683
+ if (status == UpdateStatus::Detached) {
684
+ throw StaleAccessor (" Parent no longer exists" );
687
685
}
688
- return false ;
686
+ return status == UpdateStatus::Updated ;
689
687
}
690
688
691
689
void bump_content_version ()
@@ -735,19 +733,19 @@ class CollectionBaseImpl : public Interface, protected ArrayParent {
735
733
void set_backlink (ColKey col_key, ObjLink new_link) const
736
734
{
737
735
check_parent ();
738
- m_parent->set_backlink (col_key, new_link);
736
+ m_parent->set_backlink (m_parent-> get_object (), col_key, new_link);
739
737
}
740
738
// Used when replacing a link, return true if CascadeState contains objects to remove
741
739
bool replace_backlink (ColKey col_key, ObjLink old_link, ObjLink new_link, CascadeState& state) const
742
740
{
743
741
check_parent ();
744
- return m_parent->replace_backlink (col_key, old_link, new_link, state);
742
+ return m_parent->replace_backlink (m_parent-> get_object (), col_key, old_link, new_link, state);
745
743
}
746
744
// Used when removing a backlink, return true if CascadeState contains objects to remove
747
745
bool remove_backlink (ColKey col_key, ObjLink old_link, CascadeState& state) const
748
746
{
749
747
check_parent ();
750
- return m_parent->remove_backlink (col_key, old_link, state);
748
+ return m_parent->remove_backlink (m_parent-> get_object (), col_key, old_link, state);
751
749
}
752
750
753
751
// / Reset the accessor's tracking of the content version. Derived classes
@@ -803,7 +801,7 @@ class CollectionBaseImpl : public Interface, protected ArrayParent {
803
801
// /
804
802
// / If no change has happened to the data, this function returns
805
803
// / `UpdateStatus::NoChange`, and the caller is allowed to not do anything.
806
- virtual UpdateStatus update_if_needed_with_status () const = 0;
804
+ virtual UpdateStatus update_if_needed () const = 0;
807
805
};
808
806
809
807
namespace _impl {
@@ -891,7 +889,7 @@ class ObjCollectionBase : public Interface, public _impl::ObjListProxy {
891
889
// / `BPlusTree<T>`.
892
890
virtual BPlusTree<ObjKey>* get_mutable_tree () const = 0;
893
891
894
- // / Implements update_if_needed() in a way that ensures the consistency of
892
+ // / Implements ` update_if_needed()` in a way that ensures the consistency of
895
893
// / the unresolved list. Derived classes should call this instead of calling
896
894
// / `update_if_needed()` on their inner accessor.
897
895
UpdateStatus update_if_needed () const
0 commit comments