commit
6db449ef06
|
@ -9,16 +9,12 @@
|
|||
/* Begin PBXBuildFile section */
|
||||
02258FB31BC6E2D00075F13A /* RealmRPC.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 02258FB11BC6E2D00075F13A /* RealmRPC.hpp */; settings = {ATTRIBUTES = (Public, ); }; };
|
||||
02258FB41BC6E2D00075F13A /* RealmRPC.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 02258FB21BC6E2D00075F13A /* RealmRPC.cpp */; };
|
||||
02409DC21BCF11D6005F3B3E /* RealmJSCoreTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 02409DC11BCF11D6005F3B3E /* RealmJSCoreTests.m */; settings = {ASSET_TAGS = (); }; };
|
||||
02601F031BA0F0C4007C91FF /* external_commit_helper.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 02601F011BA0F0C4007C91FF /* external_commit_helper.cpp */; };
|
||||
02601F041BA0F0C4007C91FF /* external_commit_helper.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 02601F021BA0F0C4007C91FF /* external_commit_helper.hpp */; };
|
||||
02409DC21BCF11D6005F3B3E /* RealmJSCoreTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 02409DC11BCF11D6005F3B3E /* RealmJSCoreTests.m */; };
|
||||
02601F081BA0F0CD007C91FF /* index_set.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 02601F051BA0F0CD007C91FF /* index_set.cpp */; };
|
||||
02601F091BA0F0CD007C91FF /* index_set.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 02601F061BA0F0CD007C91FF /* index_set.hpp */; };
|
||||
02601F0A1BA0F0CD007C91FF /* realm_delegate.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 02601F071BA0F0CD007C91FF /* realm_delegate.hpp */; };
|
||||
02601F0D1BA0F3A7007C91FF /* schema.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 02601F0B1BA0F3A7007C91FF /* schema.cpp */; };
|
||||
02601F0E1BA0F3A7007C91FF /* schema.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 02601F0C1BA0F3A7007C91FF /* schema.hpp */; };
|
||||
02601F111BA10228007C91FF /* transact_log_handler.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 02601F0F1BA10228007C91FF /* transact_log_handler.cpp */; };
|
||||
02601F121BA10228007C91FF /* transact_log_handler.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 02601F101BA10228007C91FF /* transact_log_handler.hpp */; };
|
||||
0270BC4C1B7CFC0D00010E03 /* RealmJS.h in Headers */ = {isa = PBXBuildFile; fileRef = 0270BC3E1B7CFC0D00010E03 /* RealmJS.h */; settings = {ATTRIBUTES = (Public, ); }; };
|
||||
0270BC4D1B7CFC0D00010E03 /* RealmJS.mm in Sources */ = {isa = PBXBuildFile; fileRef = 0270BC3F1B7CFC0D00010E03 /* RealmJS.mm */; };
|
||||
0270BC4E1B7CFC0D00010E03 /* RJSList.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 0270BC401B7CFC0D00010E03 /* RJSList.cpp */; };
|
||||
|
@ -52,20 +48,24 @@
|
|||
0270BC871B7D023200010E03 /* RealmJS.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 02B58CB11AE99CEC009B348C /* RealmJS.framework */; };
|
||||
0270BCD11B7D067300010E03 /* RealmReact.mm in Sources */ = {isa = PBXBuildFile; fileRef = 0270BCD01B7D067300010E03 /* RealmReact.mm */; };
|
||||
0291DBD21BD994F700E3852C /* JavaScriptCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 02B58CCD1AE99D4D009B348C /* JavaScriptCore.framework */; };
|
||||
029445931BDEDF40006D1617 /* transact_log_handler.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 029445911BDEDF40006D1617 /* transact_log_handler.cpp */; };
|
||||
029445941BDEDF40006D1617 /* transact_log_handler.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 029445921BDEDF40006D1617 /* transact_log_handler.hpp */; };
|
||||
029445971BDEDF46006D1617 /* external_commit_helper.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 029445951BDEDF46006D1617 /* external_commit_helper.cpp */; };
|
||||
029445981BDEDF46006D1617 /* external_commit_helper.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 029445961BDEDF46006D1617 /* external_commit_helper.hpp */; };
|
||||
02B29A311B7CF86D008A7E6B /* RealmJS.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 02B58CB11AE99CEC009B348C /* RealmJS.framework */; };
|
||||
02B58CCE1AE99D4D009B348C /* JavaScriptCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 02B58CCD1AE99D4D009B348C /* JavaScriptCore.framework */; };
|
||||
02C0864E1BCDB27000942F9C /* list.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 02C0864C1BCDB27000942F9C /* list.cpp */; settings = {ASSET_TAGS = (); }; };
|
||||
02C0864F1BCDB27000942F9C /* list.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 02C0864D1BCDB27000942F9C /* list.hpp */; settings = {ASSET_TAGS = (); }; };
|
||||
02C0864E1BCDB27000942F9C /* list.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 02C0864C1BCDB27000942F9C /* list.cpp */; };
|
||||
02C0864F1BCDB27000942F9C /* list.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 02C0864D1BCDB27000942F9C /* list.hpp */; };
|
||||
02D456DA1B7E59A500EE1299 /* ArrayTests.js in Resources */ = {isa = PBXBuildFile; fileRef = 02D456D91B7E59A500EE1299 /* ArrayTests.js */; };
|
||||
02D8D1F71B601984006DB49D /* JavaScriptCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 02B58CCD1AE99D4D009B348C /* JavaScriptCore.framework */; };
|
||||
F636F6C81BCDB3570023F35C /* RealmReact.h in Headers */ = {isa = PBXBuildFile; fileRef = 0270BCCF1B7D067300010E03 /* RealmReact.h */; settings = {ATTRIBUTES = (Public, ); }; };
|
||||
F64426C51BCDB1E200A81210 /* RealmJS.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 02B58CB11AE99CEC009B348C /* RealmJS.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
|
||||
F64E1EF11BC3510E00E0E150 /* util.js in Resources */ = {isa = PBXBuildFile; fileRef = F64E1EF01BC3510E00E0E150 /* util.js */; settings = {ASSET_TAGS = (); }; };
|
||||
F64E1EF11BC3510E00E0E150 /* util.js in Resources */ = {isa = PBXBuildFile; fileRef = F64E1EF01BC3510E00E0E150 /* util.js */; };
|
||||
F67191381BCE231100AD0939 /* GCDWebServers.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 02A3C7941BC4317A00B1A7BE /* GCDWebServers.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
|
||||
F68A278C1BC2722A0063D40A /* RJSModuleLoader.m in Sources */ = {isa = PBXBuildFile; fileRef = F68A278B1BC2722A0063D40A /* RJSModuleLoader.m */; settings = {ASSET_TAGS = (); }; };
|
||||
F68A278E1BC30F0A0063D40A /* index.js in Resources */ = {isa = PBXBuildFile; fileRef = F68A278D1BC30F0A0063D40A /* index.js */; settings = {ASSET_TAGS = (); }; };
|
||||
F68A278C1BC2722A0063D40A /* RJSModuleLoader.m in Sources */ = {isa = PBXBuildFile; fileRef = F68A278B1BC2722A0063D40A /* RJSModuleLoader.m */; };
|
||||
F68A278E1BC30F0A0063D40A /* index.js in Resources */ = {isa = PBXBuildFile; fileRef = F68A278D1BC30F0A0063D40A /* index.js */; };
|
||||
F6B3963D1BCE2430008BDC39 /* GCDWebServers.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 02A3C7941BC4317A00B1A7BE /* GCDWebServers.framework */; };
|
||||
F6F405F81BCF0C1A00A1E24F /* base-test.js in Resources */ = {isa = PBXBuildFile; fileRef = F6F405F71BCF0C1A00A1E24F /* base-test.js */; settings = {ASSET_TAGS = (); }; };
|
||||
F6F405F81BCF0C1A00A1E24F /* base-test.js in Resources */ = {isa = PBXBuildFile; fileRef = F6F405F71BCF0C1A00A1E24F /* base-test.js */; };
|
||||
/* End PBXBuildFile section */
|
||||
|
||||
/* Begin PBXContainerItemProxy section */
|
||||
|
@ -160,15 +160,11 @@
|
|||
02258FB11BC6E2D00075F13A /* RealmRPC.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = RealmRPC.hpp; path = src/RealmRPC.hpp; sourceTree = "<group>"; };
|
||||
02258FB21BC6E2D00075F13A /* RealmRPC.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = RealmRPC.cpp; path = src/RealmRPC.cpp; sourceTree = "<group>"; };
|
||||
02409DC11BCF11D6005F3B3E /* RealmJSCoreTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = RealmJSCoreTests.m; path = tests/RealmJSCoreTests.m; sourceTree = SOURCE_ROOT; };
|
||||
02601F011BA0F0C4007C91FF /* external_commit_helper.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = external_commit_helper.cpp; path = "src/object-store/apple/external_commit_helper.cpp"; sourceTree = "<group>"; };
|
||||
02601F021BA0F0C4007C91FF /* external_commit_helper.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = external_commit_helper.hpp; path = "src/object-store/apple/external_commit_helper.hpp"; sourceTree = "<group>"; };
|
||||
02601F051BA0F0CD007C91FF /* index_set.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = index_set.cpp; path = "src/object-store/index_set.cpp"; sourceTree = "<group>"; };
|
||||
02601F061BA0F0CD007C91FF /* index_set.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = index_set.hpp; path = "src/object-store/index_set.hpp"; sourceTree = "<group>"; };
|
||||
02601F071BA0F0CD007C91FF /* realm_delegate.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = realm_delegate.hpp; path = "src/object-store/realm_delegate.hpp"; sourceTree = "<group>"; };
|
||||
02601F0B1BA0F3A7007C91FF /* schema.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = schema.cpp; path = "src/object-store/schema.cpp"; sourceTree = "<group>"; };
|
||||
02601F0C1BA0F3A7007C91FF /* schema.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = schema.hpp; path = "src/object-store/schema.hpp"; sourceTree = "<group>"; };
|
||||
02601F0F1BA10228007C91FF /* transact_log_handler.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = transact_log_handler.cpp; path = "src/object-store/transact_log_handler.cpp"; sourceTree = "<group>"; };
|
||||
02601F101BA10228007C91FF /* transact_log_handler.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = transact_log_handler.hpp; path = "src/object-store/transact_log_handler.hpp"; sourceTree = "<group>"; };
|
||||
0270BC3E1B7CFC0D00010E03 /* RealmJS.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = RealmJS.h; path = src/RealmJS.h; sourceTree = "<group>"; };
|
||||
0270BC3F1B7CFC0D00010E03 /* RealmJS.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = RealmJS.mm; path = src/RealmJS.mm; sourceTree = "<group>"; };
|
||||
0270BC401B7CFC0D00010E03 /* RJSList.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = RJSList.cpp; path = src/RJSList.cpp; sourceTree = "<group>"; };
|
||||
|
@ -204,6 +200,10 @@
|
|||
0270BC7F1B7D020100010E03 /* schemas.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; name = schemas.js; path = tests/schemas.js; sourceTree = SOURCE_ROOT; };
|
||||
0270BCCF1B7D067300010E03 /* RealmReact.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = RealmReact.h; path = ReactNative/RealmReact.h; sourceTree = "<group>"; };
|
||||
0270BCD01B7D067300010E03 /* RealmReact.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = RealmReact.mm; path = ReactNative/RealmReact.mm; sourceTree = "<group>"; };
|
||||
029445911BDEDF40006D1617 /* transact_log_handler.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = transact_log_handler.cpp; path = "src/object-store/impl/transact_log_handler.cpp"; sourceTree = "<group>"; };
|
||||
029445921BDEDF40006D1617 /* transact_log_handler.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = transact_log_handler.hpp; path = "src/object-store/impl/transact_log_handler.hpp"; sourceTree = "<group>"; };
|
||||
029445951BDEDF46006D1617 /* external_commit_helper.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = external_commit_helper.cpp; path = "src/object-store/impl/apple/external_commit_helper.cpp"; sourceTree = "<group>"; };
|
||||
029445961BDEDF46006D1617 /* external_commit_helper.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = external_commit_helper.hpp; path = "src/object-store/impl/apple/external_commit_helper.hpp"; sourceTree = "<group>"; };
|
||||
02A3C7841BC4317A00B1A7BE /* GCDWebServer.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = GCDWebServer.xcodeproj; path = vendor/GCDWebServer/GCDWebServer.xcodeproj; sourceTree = "<group>"; };
|
||||
02A3C7A41BC4341500B1A7BE /* libc++.tbd */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = "libc++.tbd"; path = "usr/lib/libc++.tbd"; sourceTree = SDKROOT; };
|
||||
02B29A161B7CF7C9008A7E6B /* RealmReact.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = RealmReact.framework; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
|
@ -265,17 +265,17 @@
|
|||
0270BC641B7CFC1C00010E03 /* results.hpp */,
|
||||
0270BC651B7CFC1C00010E03 /* shared_realm.cpp */,
|
||||
0270BC661B7CFC1C00010E03 /* shared_realm.hpp */,
|
||||
02601F011BA0F0C4007C91FF /* external_commit_helper.cpp */,
|
||||
02601F021BA0F0C4007C91FF /* external_commit_helper.hpp */,
|
||||
02601F051BA0F0CD007C91FF /* index_set.cpp */,
|
||||
02601F061BA0F0CD007C91FF /* index_set.hpp */,
|
||||
02C0864C1BCDB27000942F9C /* list.cpp */,
|
||||
02C0864D1BCDB27000942F9C /* list.hpp */,
|
||||
02601F0B1BA0F3A7007C91FF /* schema.cpp */,
|
||||
02601F0C1BA0F3A7007C91FF /* schema.hpp */,
|
||||
02601F0F1BA10228007C91FF /* transact_log_handler.cpp */,
|
||||
02601F101BA10228007C91FF /* transact_log_handler.hpp */,
|
||||
02601F071BA0F0CD007C91FF /* realm_delegate.hpp */,
|
||||
029445911BDEDF40006D1617 /* transact_log_handler.cpp */,
|
||||
029445921BDEDF40006D1617 /* transact_log_handler.hpp */,
|
||||
029445951BDEDF46006D1617 /* external_commit_helper.cpp */,
|
||||
029445961BDEDF46006D1617 /* external_commit_helper.hpp */,
|
||||
0270BC3E1B7CFC0D00010E03 /* RealmJS.h */,
|
||||
0270BC3F1B7CFC0D00010E03 /* RealmJS.mm */,
|
||||
02258FB11BC6E2D00075F13A /* RealmRPC.hpp */,
|
||||
|
@ -399,11 +399,11 @@
|
|||
02601F0E1BA0F3A7007C91FF /* schema.hpp in Headers */,
|
||||
0270BC6C1B7CFC1C00010E03 /* object_store.hpp in Headers */,
|
||||
02601F0A1BA0F0CD007C91FF /* realm_delegate.hpp in Headers */,
|
||||
02601F121BA10228007C91FF /* transact_log_handler.hpp in Headers */,
|
||||
0270BC681B7CFC1C00010E03 /* object_accessor.hpp in Headers */,
|
||||
029445941BDEDF40006D1617 /* transact_log_handler.hpp in Headers */,
|
||||
0270BC711B7CFC1C00010E03 /* shared_realm.hpp in Headers */,
|
||||
029445981BDEDF46006D1617 /* external_commit_helper.hpp in Headers */,
|
||||
0270BC6A1B7CFC1C00010E03 /* object_schema.hpp in Headers */,
|
||||
02601F041BA0F0C4007C91FF /* external_commit_helper.hpp in Headers */,
|
||||
02601F091BA0F0CD007C91FF /* index_set.hpp in Headers */,
|
||||
0270BC6D1B7CFC1C00010E03 /* property.hpp in Headers */,
|
||||
02C0864F1BCDB27000942F9C /* list.hpp in Headers */,
|
||||
|
@ -643,15 +643,15 @@
|
|||
0270BC511B7CFC0D00010E03 /* RJSObject.mm in Sources */,
|
||||
0270BC4D1B7CFC0D00010E03 /* RealmJS.mm in Sources */,
|
||||
02601F081BA0F0CD007C91FF /* index_set.cpp in Sources */,
|
||||
029445931BDEDF40006D1617 /* transact_log_handler.cpp in Sources */,
|
||||
02258FB41BC6E2D00075F13A /* RealmRPC.cpp in Sources */,
|
||||
02601F111BA10228007C91FF /* transact_log_handler.cpp in Sources */,
|
||||
0270BC591B7CFC0D00010E03 /* RJSUtil.mm in Sources */,
|
||||
0270BC551B7CFC0D00010E03 /* RJSResults.mm in Sources */,
|
||||
02C0864E1BCDB27000942F9C /* list.cpp in Sources */,
|
||||
02601F031BA0F0C4007C91FF /* external_commit_helper.cpp in Sources */,
|
||||
0270BC6B1B7CFC1C00010E03 /* object_store.cpp in Sources */,
|
||||
0270BC701B7CFC1C00010E03 /* shared_realm.cpp in Sources */,
|
||||
0270BC4E1B7CFC0D00010E03 /* RJSList.cpp in Sources */,
|
||||
029445971BDEDF46006D1617 /* external_commit_helper.cpp in Sources */,
|
||||
0270BC531B7CFC0D00010E03 /* RJSRealm.mm in Sources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
|
|
|
@ -32,7 +32,7 @@ static inline List * RJSVerifiedList(JSObjectRef object) {
|
|||
|
||||
static inline List * RJSVerifiedMutableList(JSObjectRef object) {
|
||||
List *list = RJSVerifiedList(object);
|
||||
if (!list->realm->is_in_transaction()) {
|
||||
if (!list->realm()->is_in_transaction()) {
|
||||
throw std::runtime_error("Can only mutate lists within a transaction.");
|
||||
}
|
||||
return list;
|
||||
|
@ -49,7 +49,7 @@ JSValueRef ListGetProperty(JSContextRef ctx, JSObjectRef object, JSStringRef pro
|
|||
return JSValueMakeNumber(ctx, size);
|
||||
}
|
||||
|
||||
return RJSObjectCreate(ctx, Object(list->realm, list->object_schema, list->get(RJSValidatedPositiveIndex(indexStr))));
|
||||
return RJSObjectCreate(ctx, Object(list->realm(), list->object_schema, list->get(RJSValidatedPositiveIndex(indexStr))));
|
||||
}
|
||||
catch (std::out_of_range &exp) {
|
||||
// getters for nonexistent properties in JS should always return undefined
|
||||
|
@ -75,7 +75,7 @@ bool ListSetProperty(JSContextRef ctx, JSObjectRef object, JSStringRef propertyN
|
|||
throw std::runtime_error("The 'length' property is readonly.");
|
||||
}
|
||||
|
||||
list->set(RJSValidatedPositiveIndex(indexStr), RJSAccessor::to_object_index(ctx, list->realm, const_cast<JSValueRef &>(value), list->object_schema.name, false));
|
||||
list->set(RJSValidatedPositiveIndex(indexStr), RJSAccessor::to_object_index(ctx, list->realm(), const_cast<JSValueRef &>(value), list->object_schema.name, false));
|
||||
return true;
|
||||
}
|
||||
catch (std::invalid_argument &exp) {
|
||||
|
@ -108,9 +108,9 @@ JSValueRef ListPush(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObje
|
|||
List *array = RJSVerifiedMutableList(thisObject);
|
||||
RJSValidateArgumentCountIsAtLeast(argumentCount, 1);
|
||||
for (size_t i = 0; i < argumentCount; i++) {
|
||||
array->link_view->add(RJSAccessor::to_object_index(ctx, array->realm, const_cast<JSValueRef &>(arguments[i]), array->object_schema.name, false));
|
||||
array->link_view()->add(RJSAccessor::to_object_index(ctx, array->realm(), const_cast<JSValueRef &>(arguments[i]), array->object_schema.name, false));
|
||||
}
|
||||
return JSValueMakeNumber(ctx, array->link_view->size());
|
||||
return JSValueMakeNumber(ctx, array->link_view()->size());
|
||||
}
|
||||
catch (std::exception &exp) {
|
||||
if (jsException) {
|
||||
|
@ -130,8 +130,8 @@ JSValueRef ListPop(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObjec
|
|||
return JSValueMakeUndefined(ctx);
|
||||
}
|
||||
size_t index = size - 1;
|
||||
JSValueRef obj = RJSObjectCreate(ctx, Object(list->realm, list->object_schema, list->get(index)));
|
||||
list->link_view->remove(index);
|
||||
JSValueRef obj = RJSObjectCreate(ctx, Object(list->realm(), list->object_schema, list->get(index)));
|
||||
list->link_view()->remove(index);
|
||||
return obj;
|
||||
}
|
||||
catch (std::exception &exp) {
|
||||
|
@ -147,9 +147,9 @@ JSValueRef ListUnshift(JSContextRef ctx, JSObjectRef function, JSObjectRef thisO
|
|||
List *array = RJSVerifiedMutableList(thisObject);
|
||||
RJSValidateArgumentCountIsAtLeast(argumentCount, 1);
|
||||
for (size_t i = 0; i < argumentCount; i++) {
|
||||
array->link_view->insert(i, RJSAccessor::to_object_index(ctx, array->realm, const_cast<JSValueRef &>(arguments[i]), array->object_schema.name, false));
|
||||
array->link_view()->insert(i, RJSAccessor::to_object_index(ctx, array->realm(), const_cast<JSValueRef &>(arguments[i]), array->object_schema.name, false));
|
||||
}
|
||||
return JSValueMakeNumber(ctx, array->link_view->size());
|
||||
return JSValueMakeNumber(ctx, array->link_view()->size());
|
||||
}
|
||||
catch (std::exception &exp) {
|
||||
if (jsException) {
|
||||
|
@ -166,8 +166,8 @@ JSValueRef ListShift(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObj
|
|||
if (list->size() == 0) {
|
||||
return JSValueMakeUndefined(ctx);
|
||||
}
|
||||
JSValueRef obj = RJSObjectCreate(ctx, Object(list->realm, list->object_schema, list->get(0)));
|
||||
list->link_view->remove(0);
|
||||
JSValueRef obj = RJSObjectCreate(ctx, Object(list->realm(), list->object_schema, list->get(0)));
|
||||
list->link_view()->remove(0);
|
||||
return obj;
|
||||
}
|
||||
catch (std::exception &exp) {
|
||||
|
@ -194,11 +194,11 @@ JSValueRef ListSplice(JSContextRef ctx, JSObjectRef function, JSObjectRef thisOb
|
|||
|
||||
std::vector<JSObjectRef> removedObjects(remove);
|
||||
for (size_t i = 0; i < remove; i++) {
|
||||
removedObjects[i] = RJSObjectCreate(ctx, Object(list->realm, list->object_schema, list->get(index)));
|
||||
list->link_view->remove(index);
|
||||
removedObjects[i] = RJSObjectCreate(ctx, Object(list->realm(), list->object_schema, list->get(index)));
|
||||
list->link_view()->remove(index);
|
||||
}
|
||||
for (size_t i = 2; i < argumentCount; i++) {
|
||||
list->link_view->insert(index + i - 2, RJSAccessor::to_object_index(ctx, list->realm, const_cast<JSValueRef &>(arguments[i]), list->object_schema.name, false));
|
||||
list->link_view()->insert(index + i - 2, RJSAccessor::to_object_index(ctx, list->realm(), const_cast<JSValueRef &>(arguments[i]), list->object_schema.name, false));
|
||||
}
|
||||
return JSObjectMakeArray(ctx, remove, removedObjects.data(), jsException);
|
||||
}
|
||||
|
|
|
@ -64,7 +64,7 @@ JSClassRef RJSObjectClass() {
|
|||
}
|
||||
|
||||
JSObjectRef RJSObjectCreate(JSContextRef ctx, Object object) {
|
||||
JSValueRef prototype = RJSPrototypes(object.realm.get())[object.object_schema.name];
|
||||
JSValueRef prototype = RJSPrototypes(object.realm().get())[object.object_schema.name];
|
||||
JSObjectRef jsObject = RJSWrapObject(ctx, RJSObjectClass(), new Object(object), prototype);
|
||||
return jsObject;
|
||||
}
|
||||
|
@ -155,10 +155,10 @@ template<> JSValueRef RJSAccessor::from_datetime(JSContextRef ctx, DateTime dt)
|
|||
|
||||
extern JSObjectRef RJSDictForPropertyArray(JSContextRef ctx, ObjectSchema &object_schema, JSObjectRef array);
|
||||
|
||||
template<> size_t RJSAccessor::to_object_index(JSContextRef ctx, SharedRealm &realm, JSValueRef &val, std::string &type, bool try_update) {
|
||||
template<> size_t RJSAccessor::to_object_index(JSContextRef ctx, SharedRealm realm, JSValueRef &val, const std::string &type, bool try_update) {
|
||||
JSObjectRef object = RJSValidatedValueToObject(ctx, val);
|
||||
if (JSValueIsObjectOfClass(ctx, val, RJSObjectClass())) {
|
||||
return RJSGetInternal<Object *>(object)->row.get_index();
|
||||
return RJSGetInternal<Object *>(object)->row().get_index();
|
||||
}
|
||||
|
||||
auto object_schema = realm->config().schema->find(type);
|
||||
|
@ -167,7 +167,7 @@ template<> size_t RJSAccessor::to_object_index(JSContextRef ctx, SharedRealm &re
|
|||
}
|
||||
|
||||
Object child = Object::create<JSValueRef>(ctx, realm, *object_schema, (JSValueRef)object, try_update);
|
||||
return child.row.get_index();
|
||||
return child.row().get_index();
|
||||
}
|
||||
template<> JSValueRef RJSAccessor::from_object(JSContextRef ctx, Object object) {
|
||||
return RJSObjectCreate(ctx, object);
|
||||
|
|
|
@ -339,7 +339,7 @@ JSValueRef RealmDelete(JSContextRef ctx, JSObjectRef function, JSObjectRef thisO
|
|||
}
|
||||
|
||||
realm::TableRef table = ObjectStore::table_for_object_type(realm->read_group(), object->object_schema.name);
|
||||
table->move_last_over(object->row.get_index());
|
||||
table->move_last_over(object->row().get_index());
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
|
|
@ -241,7 +241,7 @@ json RPCServer::serialize_json_value(JSValueRef value) {
|
|||
return {
|
||||
{"type", RJSTypeGet(realm::PropertyTypeArray)},
|
||||
{"id", store_object(js_object)},
|
||||
{"size", list->link_view->size()},
|
||||
{"size", list->link_view()->size()},
|
||||
{"schema", serialize_object_schema(list->object_schema)}
|
||||
};
|
||||
}
|
||||
|
@ -277,7 +277,7 @@ json RPCServer::serialize_json_value(JSValueRef value) {
|
|||
assert(0);
|
||||
}
|
||||
|
||||
json RPCServer::serialize_object_schema(realm::ObjectSchema &object_schema) {
|
||||
json RPCServer::serialize_object_schema(const realm::ObjectSchema &object_schema) {
|
||||
json properties = json::array();
|
||||
for (realm::Property prop : object_schema.properties) {
|
||||
properties.push_back({
|
||||
|
|
|
@ -48,7 +48,7 @@ class RPCServer {
|
|||
json serialize_json_value(JSValueRef value);
|
||||
JSValueRef deserialize_json_value(const json dict);
|
||||
|
||||
json serialize_object_schema(realm::ObjectSchema &objectSchema);
|
||||
json serialize_object_schema(const realm::ObjectSchema &objectSchema);
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -30,6 +30,7 @@
|
|||
#include <sstream>
|
||||
|
||||
using namespace realm;
|
||||
using namespace realm::_impl;
|
||||
|
||||
namespace {
|
||||
// Write a byte to a pipe to notify anyone waiting for data on the pipe
|
|
@ -26,6 +26,7 @@
|
|||
namespace realm {
|
||||
class Realm;
|
||||
|
||||
namespace _impl {
|
||||
class ExternalCommitHelper {
|
||||
public:
|
||||
ExternalCommitHelper(Realm* realm);
|
||||
|
@ -87,6 +88,7 @@ private:
|
|||
FdHolder m_shutdown_write_fd;
|
||||
};
|
||||
|
||||
} // namespace _impl
|
||||
} // namespace realm
|
||||
|
||||
#endif /* REALM_EXTERNAL_COMMIT_HELPER_HPP */
|
|
@ -316,6 +316,7 @@ public:
|
|||
} // anonymous namespace
|
||||
|
||||
namespace realm {
|
||||
namespace _impl {
|
||||
namespace transaction {
|
||||
void advance(SharedGroup& sg, ClientHistory& history, RealmDelegate* delegate) {
|
||||
TransactLogHandler(delegate, sg, [&](auto&&... args) {
|
||||
|
@ -344,4 +345,5 @@ void cancel(SharedGroup& sg, ClientHistory& history, RealmDelegate* delegate) {
|
|||
}
|
||||
|
||||
} // namespace transaction
|
||||
} // namespace _impl
|
||||
} // namespace realm
|
|
@ -24,6 +24,7 @@ class RealmDelegate;
|
|||
class SharedGroup;
|
||||
class ClientHistory;
|
||||
|
||||
namespace _impl {
|
||||
namespace transaction {
|
||||
// Advance the read transaction version, with change notifications sent to delegate
|
||||
// Must not be called from within a write transaction.
|
||||
|
@ -41,6 +42,7 @@ void commit(SharedGroup& sg, ClientHistory& history, RealmDelegate* delegate);
|
|||
// for reverting to the old values sent to delegate
|
||||
void cancel(SharedGroup& sg, ClientHistory& history, RealmDelegate* delegate);
|
||||
} // namespace transaction
|
||||
} // namespace _impl
|
||||
} // namespace realm
|
||||
|
||||
#endif /* REALM_TRANSACT_LOG_HANDLER_HPP */
|
|
@ -22,29 +22,29 @@
|
|||
using namespace realm;
|
||||
|
||||
size_t List::size() {
|
||||
return link_view->size();
|
||||
return m_link_view->size();
|
||||
}
|
||||
|
||||
Row List::get(std::size_t row_ndx) {
|
||||
verify_valid_row(row_ndx);
|
||||
return link_view->get(row_ndx);
|
||||
return m_link_view->get(row_ndx);
|
||||
}
|
||||
|
||||
void List::set(std::size_t row_ndx, std::size_t target_row_ndx) {
|
||||
verify_valid_row(row_ndx);
|
||||
link_view->set(row_ndx, target_row_ndx);
|
||||
m_link_view->set(row_ndx, target_row_ndx);
|
||||
}
|
||||
|
||||
void List::verify_valid_row(std::size_t row_ndx) {
|
||||
size_t size = link_view->size();
|
||||
size_t size = m_link_view->size();
|
||||
if (row_ndx >= size) {
|
||||
throw std::out_of_range(std::string("Index ") + std::to_string(row_ndx) + " is outside of range 0..." + std::to_string(size) + ".");
|
||||
}
|
||||
}
|
||||
|
||||
void List::verify_attached() {
|
||||
if (!link_view->is_attached()) {
|
||||
if (!m_link_view->is_attached()) {
|
||||
throw std::runtime_error("Tableview is not attached");
|
||||
}
|
||||
link_view->sync_if_needed();
|
||||
m_link_view->sync_if_needed();
|
||||
}
|
||||
|
|
|
@ -23,18 +23,24 @@
|
|||
#import <realm/link_view.hpp>
|
||||
|
||||
namespace realm {
|
||||
struct List {
|
||||
List(SharedRealm &r, ObjectSchema &s, LinkViewRef l) : realm(r), object_schema(s), link_view(l) {}
|
||||
// FIXME - all should be const
|
||||
SharedRealm realm;
|
||||
ObjectSchema &object_schema;
|
||||
LinkViewRef link_view;
|
||||
class List {
|
||||
public:
|
||||
List(SharedRealm &r, const ObjectSchema &s, LinkViewRef l) : m_realm(r), object_schema(s), m_link_view(l) {}
|
||||
|
||||
const ObjectSchema &object_schema;
|
||||
SharedRealm realm() { return m_realm; }
|
||||
LinkViewRef link_view() { return m_link_view; }
|
||||
|
||||
size_t size();
|
||||
Row get(std::size_t row_ndx);
|
||||
void set(std::size_t row_ndx, std::size_t target_row_ndx);
|
||||
|
||||
void verify_valid_row(std::size_t row_ndx);
|
||||
void verify_attached();
|
||||
|
||||
private:
|
||||
SharedRealm m_realm;
|
||||
LinkViewRef m_link_view;
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -27,11 +27,7 @@ namespace realm {
|
|||
|
||||
class Object {
|
||||
public:
|
||||
Object(SharedRealm &r, ObjectSchema &s, Row o) : realm(r), object_schema(s), row(o) {}
|
||||
// FIXME - all should be const
|
||||
SharedRealm realm;
|
||||
ObjectSchema &object_schema;
|
||||
Row row;
|
||||
Object(SharedRealm r, const ObjectSchema &s, Row o) : m_realm(r), object_schema(s), m_row(o) {}
|
||||
|
||||
// property getter/setter
|
||||
template<typename ValueType, typename ContextType>
|
||||
|
@ -43,12 +39,19 @@ namespace realm {
|
|||
// create an Object from a native representation
|
||||
template<typename ValueType, typename ContextType>
|
||||
static inline Object create(ContextType ctx, SharedRealm realm, ObjectSchema &object_schema, ValueType value, bool try_update);
|
||||
|
||||
|
||||
const ObjectSchema &object_schema;
|
||||
SharedRealm realm() { return m_realm; }
|
||||
Row row() { return m_row; }
|
||||
|
||||
private:
|
||||
SharedRealm m_realm;
|
||||
Row m_row;
|
||||
|
||||
template<typename ValueType, typename ContextType>
|
||||
inline void set_property_value_impl(ContextType ctx, Property &property, ValueType value, bool try_update);
|
||||
inline void set_property_value_impl(ContextType ctx, const Property &property, ValueType value, bool try_update);
|
||||
template<typename ValueType, typename ContextType>
|
||||
inline ValueType get_property_value_impl(ContextType ctx, Property &property);
|
||||
inline ValueType get_property_value_impl(ContextType ctx, const Property &property);
|
||||
};
|
||||
|
||||
//
|
||||
|
@ -82,7 +85,7 @@ namespace realm {
|
|||
// convert value to persisted object
|
||||
// for existing objects return the existing row index
|
||||
// for new/updated objects return the row index
|
||||
static size_t to_object_index(ContextType ctx, SharedRealm &realm, ValueType &val, std::string &type, bool try_update);
|
||||
static size_t to_object_index(ContextType ctx, SharedRealm realm, ValueType &val, const std::string &type, bool try_update);
|
||||
static ValueType from_object(ContextType ctx, Object);
|
||||
|
||||
// list value acessors
|
||||
|
@ -102,7 +105,7 @@ namespace realm {
|
|||
template <typename ValueType, typename ContextType>
|
||||
inline void Object::set_property_value(ContextType ctx, std::string prop_name, ValueType value, bool try_update)
|
||||
{
|
||||
Property *prop = object_schema.property_for_name(prop_name);
|
||||
const Property *prop = object_schema.property_for_name(prop_name);
|
||||
if (!prop) {
|
||||
throw std::runtime_error("Setting invalid property '" + prop_name + "' on object '" + object_schema.name + "'.");
|
||||
}
|
||||
|
@ -112,7 +115,7 @@ namespace realm {
|
|||
template <typename ValueType, typename ContextType>
|
||||
inline ValueType Object::get_property_value(ContextType ctx, std::string prop_name)
|
||||
{
|
||||
Property *prop = object_schema.property_for_name(prop_name);
|
||||
const Property *prop = object_schema.property_for_name(prop_name);
|
||||
if (!prop) {
|
||||
throw std::runtime_error("Setting invalid property '" + prop_name + "' on object '" + object_schema.name + "'.");
|
||||
}
|
||||
|
@ -120,56 +123,56 @@ namespace realm {
|
|||
};
|
||||
|
||||
template <typename ValueType, typename ContextType>
|
||||
inline void Object::set_property_value_impl(ContextType ctx, Property &property, ValueType value, bool try_update)
|
||||
inline void Object::set_property_value_impl(ContextType ctx, const Property &property, ValueType value, bool try_update)
|
||||
{
|
||||
using Accessor = NativeAccessor<ValueType, ContextType>;
|
||||
|
||||
if (!realm->is_in_transaction()) {
|
||||
if (!m_realm->is_in_transaction()) {
|
||||
throw std::runtime_error("Can only set property values within a transaction.");
|
||||
}
|
||||
|
||||
size_t column = property.table_column;
|
||||
switch (property.type) {
|
||||
case PropertyTypeBool:
|
||||
row.set_bool(column, Accessor::to_bool(ctx, value));
|
||||
m_row.set_bool(column, Accessor::to_bool(ctx, value));
|
||||
break;
|
||||
case PropertyTypeInt:
|
||||
row.set_int(column, Accessor::to_long(ctx, value));
|
||||
m_row.set_int(column, Accessor::to_long(ctx, value));
|
||||
break;
|
||||
case PropertyTypeFloat:
|
||||
row.set_float(column, Accessor::to_float(ctx, value));
|
||||
m_row.set_float(column, Accessor::to_float(ctx, value));
|
||||
break;
|
||||
case PropertyTypeDouble:
|
||||
row.set_double(column, Accessor::to_double(ctx, value));
|
||||
m_row.set_double(column, Accessor::to_double(ctx, value));
|
||||
break;
|
||||
case PropertyTypeString:
|
||||
row.set_string(column, Accessor::to_string(ctx, value));
|
||||
m_row.set_string(column, Accessor::to_string(ctx, value));
|
||||
break;
|
||||
case PropertyTypeData:
|
||||
row.set_binary(column, BinaryData(Accessor::to_string(ctx, value)));
|
||||
m_row.set_binary(column, BinaryData(Accessor::to_string(ctx, value)));
|
||||
break;
|
||||
case PropertyTypeAny:
|
||||
row.set_mixed(column, Accessor::to_mixed(ctx, value));
|
||||
m_row.set_mixed(column, Accessor::to_mixed(ctx, value));
|
||||
break;
|
||||
case PropertyTypeDate:
|
||||
row.set_datetime(column, Accessor::to_datetime(ctx, value));
|
||||
m_row.set_datetime(column, Accessor::to_datetime(ctx, value));
|
||||
break;
|
||||
case PropertyTypeObject: {
|
||||
if (Accessor::is_null(ctx, value)) {
|
||||
row.nullify_link(column);
|
||||
m_row.nullify_link(column);
|
||||
}
|
||||
else {
|
||||
row.set_link(column, Accessor::to_object_index(ctx, realm, value, property.object_type, try_update));
|
||||
m_row.set_link(column, Accessor::to_object_index(ctx, m_realm, value, property.object_type, try_update));
|
||||
}
|
||||
break;
|
||||
}
|
||||
case PropertyTypeArray: {
|
||||
realm::LinkViewRef link_view = row.get_linklist(column);
|
||||
realm::LinkViewRef link_view = m_row.get_linklist(column);
|
||||
link_view->clear();
|
||||
size_t count = Accessor::list_size(ctx, value);
|
||||
for (size_t i = 0; i < count; i++) {
|
||||
ValueType element = Accessor::list_value_at_index(ctx, value, i);
|
||||
link_view->add(Accessor::to_object_index(ctx, realm, element, property.object_type, try_update));
|
||||
link_view->add(Accessor::to_object_index(ctx, m_realm, element, property.object_type, try_update));
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
@ -177,39 +180,39 @@ namespace realm {
|
|||
}
|
||||
|
||||
template <typename ValueType, typename ContextType>
|
||||
inline ValueType Object::get_property_value_impl(ContextType ctx, Property &property)
|
||||
inline ValueType Object::get_property_value_impl(ContextType ctx, const Property &property)
|
||||
{
|
||||
using Accessor = NativeAccessor<ValueType, ContextType>;
|
||||
|
||||
size_t column = property.table_column;
|
||||
switch (property.type) {
|
||||
case PropertyTypeBool:
|
||||
return Accessor::from_bool(ctx, row.get_bool(column));
|
||||
return Accessor::from_bool(ctx, m_row.get_bool(column));
|
||||
case PropertyTypeInt:
|
||||
return Accessor::from_long(ctx, row.get_int(column));
|
||||
return Accessor::from_long(ctx, m_row.get_int(column));
|
||||
case PropertyTypeFloat:
|
||||
return Accessor::from_float(ctx, row.get_float(column));
|
||||
return Accessor::from_float(ctx, m_row.get_float(column));
|
||||
case PropertyTypeDouble:
|
||||
return Accessor::from_double(ctx, row.get_double(column));
|
||||
return Accessor::from_double(ctx, m_row.get_double(column));
|
||||
case PropertyTypeString:
|
||||
return Accessor::from_string(ctx, row.get_string(column));
|
||||
return Accessor::from_string(ctx, m_row.get_string(column));
|
||||
case PropertyTypeData:
|
||||
return Accessor::from_string(ctx, (std::string)row.get_binary(column));
|
||||
return Accessor::from_string(ctx, (std::string)m_row.get_binary(column));
|
||||
case PropertyTypeAny:
|
||||
throw "Any not supported";
|
||||
case PropertyTypeDate:
|
||||
return Accessor::from_datetime(ctx, row.get_datetime(column));
|
||||
return Accessor::from_datetime(ctx, m_row.get_datetime(column));
|
||||
case PropertyTypeObject: {
|
||||
auto linkObjectSchema = realm->config().schema->find(property.object_type);
|
||||
TableRef table = ObjectStore::table_for_object_type(realm->read_group(), linkObjectSchema->name);
|
||||
if (row.is_null_link(property.table_column)) {
|
||||
auto linkObjectSchema = m_realm->config().schema->find(property.object_type);
|
||||
TableRef table = ObjectStore::table_for_object_type(m_realm->read_group(), linkObjectSchema->name);
|
||||
if (m_row.is_null_link(property.table_column)) {
|
||||
return Accessor::null_value(ctx);
|
||||
}
|
||||
return Accessor::from_object(ctx, std::move(Object(realm, *linkObjectSchema, table->get(row.get_link(column)))));
|
||||
return Accessor::from_object(ctx, std::move(Object(m_realm, *linkObjectSchema, table->get(m_row.get_link(column)))));
|
||||
}
|
||||
case PropertyTypeArray: {
|
||||
auto arrayObjectSchema = realm->config().schema->find(property.object_type);
|
||||
return Accessor::from_list(ctx, std::move(List(realm, *arrayObjectSchema, static_cast<LinkViewRef>(row.get_linklist(column)))));
|
||||
auto arrayObjectSchema = m_realm->config().schema->find(property.object_type);
|
||||
return Accessor::from_list(ctx, std::move(List(m_realm, *arrayObjectSchema, static_cast<LinkViewRef>(m_row.get_linklist(column)))));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -229,7 +232,7 @@ namespace realm {
|
|||
// try to get existing row if updating
|
||||
size_t row_index = realm::not_found;
|
||||
realm::TableRef table = ObjectStore::table_for_object_type(realm->read_group(), object_schema.name);
|
||||
Property *primary_prop = object_schema.primary_key_property();
|
||||
const Property *primary_prop = object_schema.primary_key_property();
|
||||
if (primary_prop) {
|
||||
// search for existing object based on primary key type
|
||||
ValueType primary_value = Accessor::dict_value_for_key(ctx, value, object_schema.primary_key);
|
||||
|
|
|
@ -149,6 +149,13 @@ static inline bool property_has_changed(Property const& p1, Property const& p2)
|
|||
|| p1.is_nullable != p2.is_nullable;
|
||||
}
|
||||
|
||||
static inline bool property_can_be_migrated_to_nullable(const Property& old_property, const Property& new_property) {
|
||||
return old_property.type == new_property.type
|
||||
&& !old_property.is_nullable
|
||||
&& new_property.is_nullable
|
||||
&& new_property.name == old_property.name;
|
||||
}
|
||||
|
||||
void ObjectStore::verify_schema(Schema const& actual_schema, Schema& target_schema, bool allow_missing_tables) {
|
||||
std::vector<ObjectSchemaValidationException> errors;
|
||||
for (auto &object_schema : target_schema) {
|
||||
|
@ -205,6 +212,45 @@ std::vector<ObjectSchemaValidationException> ObjectStore::verify_object_schema(O
|
|||
return exceptions;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
static void copy_property_values(const Property& old_property, const Property& new_property, Table& table,
|
||||
T (Table::*getter)(std::size_t, std::size_t) const noexcept,
|
||||
void (Table::*setter)(std::size_t, std::size_t, T)) {
|
||||
size_t old_column = old_property.table_column, new_column = new_property.table_column;
|
||||
size_t count = table.size();
|
||||
for (size_t i = 0; i < count; i++) {
|
||||
(table.*setter)(new_column, i, (table.*getter)(old_column, i));
|
||||
}
|
||||
}
|
||||
|
||||
static void copy_property_values(const Property& source, const Property& destination, Table& table) {
|
||||
switch (destination.type) {
|
||||
case PropertyTypeInt:
|
||||
copy_property_values(source, destination, table, &Table::get_int, &Table::set_int);
|
||||
break;
|
||||
case PropertyTypeBool:
|
||||
copy_property_values(source, destination, table, &Table::get_bool, &Table::set_bool);
|
||||
break;
|
||||
case PropertyTypeFloat:
|
||||
copy_property_values(source, destination, table, &Table::get_float, &Table::set_float);
|
||||
break;
|
||||
case PropertyTypeDouble:
|
||||
copy_property_values(source, destination, table, &Table::get_double, &Table::set_double);
|
||||
break;
|
||||
case PropertyTypeString:
|
||||
copy_property_values(source, destination, table, &Table::get_string, &Table::set_string);
|
||||
break;
|
||||
case PropertyTypeData:
|
||||
copy_property_values(source, destination, table, &Table::get_binary, &Table::set_binary);
|
||||
break;
|
||||
case PropertyTypeDate:
|
||||
copy_property_values(source, destination, table, &Table::get_datetime, &Table::set_datetime);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// set references to tables on targetSchema and create/update any missing or out-of-date tables
|
||||
// if update existing is true, updates existing tables, otherwise validates existing tables
|
||||
// NOTE: must be called from within write transaction
|
||||
|
@ -230,13 +276,40 @@ bool ObjectStore::create_tables(Group *group, Schema &target_schema, bool update
|
|||
ObjectSchema current_schema(group, target_object_schema->name);
|
||||
std::vector<Property> &target_props = target_object_schema->properties;
|
||||
|
||||
// handle columns changing from required to optional
|
||||
for (auto& current_prop : current_schema.properties) {
|
||||
auto target_prop = target_object_schema->property_for_name(current_prop.name);
|
||||
if (!target_prop || !property_can_be_migrated_to_nullable(current_prop, *target_prop))
|
||||
continue;
|
||||
|
||||
target_prop->table_column = current_prop.table_column;
|
||||
current_prop.table_column = current_prop.table_column + 1;
|
||||
|
||||
table->insert_column(target_prop->table_column, DataType(target_prop->type), target_prop->name, target_prop->is_nullable);
|
||||
copy_property_values(current_prop, *target_prop, *table);
|
||||
table->remove_column(current_prop.table_column);
|
||||
|
||||
current_prop.table_column = target_prop->table_column;
|
||||
changed = true;
|
||||
}
|
||||
|
||||
bool inserted_placeholder_column = false;
|
||||
|
||||
// remove extra columns
|
||||
size_t deleted = 0;
|
||||
for (auto& current_prop : current_schema.properties) {
|
||||
current_prop.table_column -= deleted;
|
||||
|
||||
auto target_prop = target_object_schema->property_for_name(current_prop.name);
|
||||
if (!target_prop || property_has_changed(current_prop, *target_prop)) {
|
||||
if (!target_prop || (property_has_changed(current_prop, *target_prop)
|
||||
&& !property_can_be_migrated_to_nullable(current_prop, *target_prop))) {
|
||||
if (deleted == current_schema.properties.size() - 1) {
|
||||
// We're about to remove the last column from the table. Insert a placeholder column to preserve
|
||||
// the number of rows in the table for the addition of new columns below.
|
||||
table->add_column(type_Bool, "placeholder");
|
||||
inserted_placeholder_column = true;
|
||||
}
|
||||
|
||||
table->remove_column(current_prop.table_column);
|
||||
++deleted;
|
||||
current_prop.table_column = npos;
|
||||
|
@ -273,6 +346,15 @@ bool ObjectStore::create_tables(Group *group, Schema &target_schema, bool update
|
|||
}
|
||||
}
|
||||
|
||||
if (inserted_placeholder_column) {
|
||||
// We inserted a placeholder due to removing all columns from the table. Remove it, and update the indices
|
||||
// of any columns that we inserted after it.
|
||||
table->remove_column(0);
|
||||
for (auto& target_prop : target_props) {
|
||||
target_prop.table_column--;
|
||||
}
|
||||
}
|
||||
|
||||
// update table metadata
|
||||
if (target_object_schema->primary_key.length()) {
|
||||
// if there is a primary key set, check if it is the same as the old key
|
||||
|
|
|
@ -29,6 +29,7 @@
|
|||
#include <mutex>
|
||||
|
||||
using namespace realm;
|
||||
using namespace realm::_impl;
|
||||
|
||||
RealmCache Realm::s_global_cache;
|
||||
|
||||
|
|
|
@ -28,13 +28,16 @@
|
|||
|
||||
namespace realm {
|
||||
class ClientHistory;
|
||||
class ExternalCommitHelper;
|
||||
class Realm;
|
||||
class RealmCache;
|
||||
class RealmDelegate;
|
||||
typedef std::shared_ptr<Realm> SharedRealm;
|
||||
typedef std::weak_ptr<Realm> WeakRealm;
|
||||
|
||||
namespace _impl {
|
||||
class ExternalCommitHelper;
|
||||
}
|
||||
|
||||
class Realm : public std::enable_shared_from_this<Realm>
|
||||
{
|
||||
public:
|
||||
|
@ -115,7 +118,7 @@ namespace realm {
|
|||
|
||||
Group *m_group = nullptr;
|
||||
|
||||
std::shared_ptr<ExternalCommitHelper> m_notifier;
|
||||
std::shared_ptr<_impl::ExternalCommitHelper> m_notifier;
|
||||
|
||||
public:
|
||||
std::unique_ptr<RealmDelegate> m_delegate;
|
||||
|
|
Loading…
Reference in New Issue