-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
RealmConfiguration + new constructors #929
Conversation
…ead of telescoping constructors.
I like the direction, but we're breaking the API drastically. I think we should maintain the old constructors while deprecating them until the following big release. |
Yeah that was my plan as well, this commit might have cleaned up a bit to drastically |
@alazier Would love to get your thoughts on this. See also #java on slack for additional conversation about this PR. |
Also, we might want to keep static constructor for the most common case:
|
@timanglade this is something I have proposed for the cocoa apis multiple times (and think I have mentioned it to @cmelchior). As the number of global configuration parameters grows this will likely be a necessity. My concerns with this proposal would be:
|
@alazier We don't support ReadOnly and InMemory yet, but it is coming. I don't think the configuration is a good place for adding notification setup as they are added/removed a lot more while the Realm is used. I would prefer to keep the setup methods to initialisation properties. Name is filename, on android path is split into 2 methods, one for folder and one for filename as getting a default document folder is a bit more complicated. |
…ility methods that now uses RealmConfiguration.
Conflicts: realm/src/main/java/io/realm/Realm.java
…ed my in memory realm.
I have updated the top note with current API design. Feedback welcome. We still miss support for custom schemas but that will be included ons #938 has been merged. |
.schemaVersion(42) | ||
.schema(AllTypesPrimaryKey.class) | ||
.build()); | ||
fail("A migration should be required"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems to be an inconsistency how you use try
/catch
and fail()
in this unit test and other unit tests.
Will you add an option to compact the Realm file before opening? |
I didn't consider that. It would be fairly easy adding an option like:
However I am a bit worried it would introduce a unpredictable slowdown as compaction could potentially take a lot of time + plus it require additional space on the disc ? |
Realm Core might be able to provide information about how much space is saved before actually calling compact. |
|
||
public void testWrongKeyLengthThrows() { | ||
try { | ||
new RealmConfiguration.Builder(getContext()).encryptionKey(new byte[63]).build(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about 65?
I believe it is ready to be merged (when my few last comments are addressed). |
Please make this merge-able and address @kneth 's comments. I think this is ready for prime time. |
Conflicts: changelog.txt realm/src/main/java/io/realm/Realm.java realm/src/main/java/io/realm/internal/Util.java
Any final comments @kneth @emanuelez @nhachicha @bmunkholm before I merge this? |
@@ -29,7 +32,6 @@ | |||
private JavaFileObject simpleModel = JavaFileObjects.forResource("some/test/Simple.java"); | |||
private JavaFileObject simpleProxy = JavaFileObjects.forResource("io/realm/SimpleRealmProxy.java"); | |||
private JavaFileObject allTypesModel = JavaFileObjects.forResource("some/test/AllTypes.java"); | |||
private JavaFileObject allTypesProxy = JavaFileObjects.forResource("io/realm/AllTypesRealmProxy.java"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should still check that we produce the expected model class proxy! This is a problem introduced in the Modules PR
RealmConfiguration.addModule() removed and Realm.getDefaultModule() introduced instead. |
|
RealmConfiguration + new constructors
This fixes #511
This PR is part of #880
This PR changes how Realms are created. Our current approach with telescoping constructor arguments are not scalable especially as Migrations introduce new arguments and we have in-memory/read-only realms coming as well. It also allows us to move the Android Context away from Realm.java.
API Overview
This PR replaces the current constructors with a RealmConfiguration that are constructed using the Builder pattern:
SchemaVersion and Migration
The current interaction between using
.schemaVersion()
and.migration()
is the following:If only schemaVersion is set we make a no-op migration behind the scenes that try to upgrade the version number. Schema is validated afterwards and throw an exception if there is mismatch.
If newSchemaVersion > currentSchemaVersion and a migration block is set. This migration will be called when first opening the Realm. We also have a method on the Realm for manually triggering this migration. Useful if you want to upgrade on a background thread: Realm.migrateRealm(RealmConfiguration)
Setting a migration block without a schemaVersion is a no-op, ie. migration code is never called. We might want to log a warning or throw an exception for this.
Setting a newSchemaVersion < currentSchemaVersion will throw an exception when opening the Realm.
Setting newSchemaVersion == currentSchemaVersion and a schema mismatch is detected will throw an exception when opening the Realm.
The current RealmMigration interface will be kept until we introduce the new Migration API as it will introduce breaking changes.
Discussion
Some implementation details that could be discussed:
This PR will also potentially deprecate a lot of methods (all constructors + all migrateRealmAtPath() + deleteRealmFile) , so I would rather introduce it all at once, and then having the option of extending RealmConfiguration afterwards.
Missing: