Skip to content

Commit ec38176

Browse files
committed
Merge branch 'master' into merge-b59c82-to-master
Conflicts: realm/realm-library/src/main/java/io/realm/internal/android/AndroidCapabilities.java
2 parents b59c827 + 8902700 commit ec38176

171 files changed

Lines changed: 5981 additions & 3431 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

CHANGELOG.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,35 @@
1+
## 3.6.0 (YYYY-MM-DD)
2+
3+
### Breaking Changes
4+
5+
* [ObjectServer] `SyncUser.logout()` no longer throws an exception when associated Realms instances are not closed (#4962).
6+
7+
### Deprecated
8+
9+
* [ObjectServer] `SyncUser#retrieveUser` and `SyncUser#retrieveUserAsync` replaced by `SyncUser#retrieveInfoForUser`
10+
and `SyncUser#retrieveInfoForUserAsync` which returns a `SyncUserInfo` with mode information (#5008).
11+
* [ObjectServer] `SyncUser#Callback` replaced by the generic version `SyncUser#RequestCallback<T>`.
12+
13+
### Enhancements
14+
15+
* [ObjectServer] Added `SyncSession.uploadAllLocalChanges()`.
16+
* [ObjectServer] APIs of `UserStore` have been changed to support same user identity but different authentication server scenario.
17+
* [ObjectServer] Added `SyncUser.allSessions` to retrieve the all valid sessions belonging to the user (#4783).
18+
* Added `Nullable` annotation to methods that may return `null` in order to improve Kotlin usability. This also introduced a dependency to `com.google.code.findbugs:jsr305`.
19+
* Added support for new data type `MutableRealmIntegers`. The new type behaves almost exactly as a reference to a Long (mutable nullable, etc) but supports `increment` and `decrement` methods, which implement a Conflict Free Replicated Data Type, whose value will converge even when changed across distributed devices with poor connections (#4266).
20+
* Added more detailed exception message for `RealmMigrationNeeded`.
21+
* Bumping schema version only without any actual schema changes will just succeed even when the migration block is not supplied. It threw an `RealmMigrationNeededException` before in the same case.
22+
* Throw `IllegalStateException` when schema validation fails because of wrong declaration of `@LinkingObjects`.
23+
24+
### Bug Fixes
25+
26+
### Internal
27+
28+
* [ObjectServer] removed `ObjectServerUser` and its inner classes, in a step to reduce `SyncUser` complexity (#3741).
29+
* [ObjectServer] changed the `SyncSessionStopPolicy` to `AfterChangesUploaded` to align with other binding and to prevent use cases where the Realm might be deleted before the last changes get synchronized (#5028).
30+
* Upgraded Realm Sync to 1.10.8
31+
* Let Object Store handle migration.
32+
133
## 3.5.1 (YYYY-MM-DD)
234

335
### Bug Fixes

CONTRIBUTING.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,16 @@ While we havn't described our code style yet, please just follow the existing st
3333

3434
For source code written in C++, we format it using `clang-format`. You can use the [plugin](https://plugins.jetbrains.com/plugin/8396-clangformatij): mark the entire file and right-click to execute `clang-format` before committing any changes. Of course, if you don't use Android Studio to edit C++ code, run `clang-format` on the command-line.
3535

36+
### Nullability by Annotataion
37+
38+
To improve code quality and usability in Kotlin, nullability of parameters and return types must be annotated with JSR305 annotations.
39+
40+
If a parameter is nullable, you must add `@Nullable` annotation to the parameter. On the other hand, if a parameter is non-null, you don't need to add `@Nonnull` annotation since all parameters are treated as `@Nonnull` by default.
41+
42+
For return types, there is no default nullability. If a method can return `null` as a return value, you must add `@Nullable` annotation to the return type. Currently, `Nonnull` annotation is not mandatory if the method never return `null`.
43+
44+
When you add a new package, you must add `package-info.java` and add `@javax.annotation.ParametersAreNonnullByDefault` to the package. Please note that you can't add multiple `package-info.java` in the same package but different location (for example, main and androidTest). When you add a package to both main and androidTest, you only need to add `package-info.java` to main.
45+
3646
### Unit Tests
3747

3848
All PR's must be accompanied by related unit tests. All bug fixes must have a unit test proving that the bug is fixed.

README.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ The API reference is located at [realm.io/docs/java/api](https://realm.io/docs/j
2424
- **Need help with your code?**: Look for previous questions on the [#realm tag](https://stackoverflow.com/questions/tagged/realm?sort=newest) — or [ask a new question](http://stackoverflow.com/questions/ask?tags=realm). We activtely monitor & answer questions on SO!
2525
- **Have a bug to report?** [Open an issue](https://github.com/realm/realm-java/issues/new). If possible, include the version of Realm, a full log, the Realm file, and a project that shows the issue.
2626
- **Have a feature request?** [Open an issue](https://github.com/realm/realm-java/issues/new). Tell us what the feature should do, and why you want the feature.
27-
- Sign up for our [**Community Newsletter**](http://eepurl.com/VEKCn) to get regular tips, learn about other use-cases and get alerted of blogposts and tutorials about Realm.
27+
- Sign up for our [**Community Newsletter**](https://go.pardot.com/l/210132/2017-04-26/3j74l) to get regular tips, learn about other use-cases and get alerted of blogposts and tutorials about Realm.
2828

2929
## Using Snapshots
3030

@@ -256,15 +256,17 @@ style/lint in the drop-down to the left of the Manage... button.
256256
## License
257257
258258
Realm Java is published under the Apache 2.0 license.
259-
The underlying core is available under the [Realm Core Binary License](LICENSE#L210-L243) while we [work to open-source it under the Apache 2.0 license](https://realm.io/docs/java/#faq).
259+
260+
Realm Core is also published under the Apache 2.0 license and is available
261+
[here](https://github.com/realm/realm-core).
260262
261263
**This product is not being made available to any person located in Cuba, Iran,
262264
North Korea, Sudan, Syria or the Crimea region, or to any other person that is
263265
not eligible to receive the product under U.S. law.**
264266
265267
## Feedback
266268
267-
**_If you use Realm and are happy with it, all we ask is that you please consider sending out a tweet mentioning [@realm](http://twitter.com/realm), announce your app on [our mailing-list](https://groups.google.com/forum/#!forum/realm-java), or email [help@realm.io](mailto:help@realm.io) to let us know about it!_**
269+
**_If you use Realm and are happy with it, all we ask is that you please consider sending out a tweet mentioning [@realm](http://twitter.com/realm) to share your thoughts!_**
268270
269271
**_And if you don't like it, please let us know what you would like improved, so we can fix it!_**
270272

SUPPORT.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Support
2+
3+
The Realm team is here to help you with your Realm-related issues!
4+
5+
## Documentation
6+
7+
Before asking questions, please familiarize yourself with our [Java](https://realm.io/docs/java/latest) documentation. We also have a number of [Tech Notes](https://realm.io/docs/tech-notes/) which cover various topics that may be of interest.
8+
9+
## Stack Overflow
10+
11+
If you have questions about configuring or using Realm you can ask them on Stack Overflow. We continually monitor the [`realm` tag](https://stackoverflow.com/tags/realm). Please also tag your question with `java`, `android`, or other tags as appropriate.
12+
13+
When asking questions on Stack Overflow, please keep in mind Stack Overflow's [question guidelines](https://stackoverflow.com/help/how-to-ask), and please use their search functionality to see if your question has been asked before.
14+
15+
## GitHub Issues
16+
17+
If you are running into issues with Realm, including potential bugs or feature requests, we encourage you to file an issue on our [GitHub issue tracker](https://github.com/realm/realm-java/issues). Please check out our [Contribution Guidelines](CONTRIBUTING.md) for information on how to properly file an issue.
18+
19+
We greatly appreciate demonstration projects that we can run for ourselves in order to see issues or potential bugs; we prioritize clearly-written tickets that include reproduction cases. You may attach these to the ticket; let us know if you need to share them confidentially, and we’ll provide instructions on how to do so.

dependencies.list

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Realm Sync Core release used by Realm Java
22
# https://github.com/realm/realm-sync/releases
3-
REALM_SYNC_VERSION=1.10.5
4-
REALM_SYNC_SHA256=c93caa9b0ff1391550ce6b68ab3822fea7e6ae921498a3ebf3a5e6b17c56fa9b
3+
REALM_SYNC_VERSION=1.10.8
4+
REALM_SYNC_SHA256=ee47cbce2bcbd105a27d0a6b64316f8ffcb1a090e697c8025d738ef5917de408
55

66
# Object Server Release used by Integration tests
77
# `realm` is stable releases, `realm-testing` is developer builds.

examples/kotlinExample/src/main/kotlin/io/realm/examples/kotlin/KotlinExampleActivity.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ class KotlinExampleActivity : Activity() {
9797
}
9898

9999
// Find the first person (no query conditions) and read a field
100-
val person = realm.where(Person::class.java).findFirst()
100+
val person = realm.where(Person::class.java).findFirst()!!
101101
showStatus(person.name + ": " + person.age)
102102

103103
// Update person in a transaction
@@ -112,7 +112,7 @@ class KotlinExampleActivity : Activity() {
112112
showStatus("\nPerforming basic Query operation...")
113113
showStatus("Number of persons: ${realm.where(Person::class.java).count()}")
114114

115-
val results = realm.where(Person::class.java).equalTo("age", 99).findAll()
115+
val results = realm.where(Person::class.java).equalTo("age", 99.toInt()).findAll()
116116

117117
showStatus("Size of result set: " + results.size)
118118
}

examples/secureTokenAndroidKeyStore/src/main/java/io/realm/examples/securetokenandroidkeystore/MainActivity.java

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323

2424
import com.example.securetokenandroidkeystore.R;
2525

26-
import org.json.JSONArray;
2726
import org.json.JSONException;
2827
import org.json.JSONObject;
2928

@@ -35,7 +34,6 @@
3534
import io.realm.SyncManager;
3635
import io.realm.SyncUser;
3736
import io.realm.android.SecureUserStore;
38-
import io.realm.internal.objectserver.ObjectServerUser;
3937
import io.realm.internal.objectserver.Token;
4038

4139
/**
@@ -97,24 +95,16 @@ private void buildSyncConf() {
9795

9896
// Helpers
9997
private final static String USER_TOKEN = UUID.randomUUID().toString();
100-
private final static String REALM_TOKEN = UUID.randomUUID().toString();
10198

10299
private static SyncUser createTestUser(long expires) {
103100
Token userToken = new Token(USER_TOKEN, "JohnDoe", null, expires, null);
104-
Token accessToken = new Token(REALM_TOKEN, "JohnDoe", "/foo", expires, new Token.Permission[]{Token.Permission.DOWNLOAD});
105-
ObjectServerUser.AccessDescription desc = new ObjectServerUser.AccessDescription(accessToken, "/data/data/myapp/files/default", false);
106-
107101
JSONObject obj = new JSONObject();
108102
try {
109-
JSONArray realmList = new JSONArray();
110103
JSONObject realmDesc = new JSONObject();
111104
realmDesc.put("uri", "realm://objectserver.realm.io/default");
112-
realmDesc.put("description", desc.toJson());
113-
realmList.put(realmDesc);
114105

115106
obj.put("authUrl", "http://objectserver.realm.io/auth");
116107
obj.put("userToken", userToken.toJson());
117-
obj.put("realms", realmList);
118108
return SyncUser.fromJson(obj.toString());
119109
} catch (JSONException e) {
120110
throw new RuntimeException(e);

realm/realm-annotations-processor/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ sourceCompatibility = '1.6'
88
targetCompatibility = '1.6'
99

1010
dependencies {
11-
compile group:'com.squareup', name:'javawriter', version:'2.5.0'
11+
compile "com.squareup:javawriter:2.5.0"
1212
compile "io.realm:realm-annotations:${version}"
1313

1414
testCompile files('../realm-library/build/intermediates/bundles/baseRelease/classes.jar') // Java projects cannot depend on AAR files

realm/realm-annotations-processor/src/main/java/io/realm/processor/ClassMetaData.java

Lines changed: 64 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,13 @@
5050
* Utility class for holding metadata for RealmProxy classes.
5151
*/
5252
public class ClassMetaData {
53-
5453
private final TypeElement classType; // Reference to model class.
5554
private final String className; // Model class simple name.
5655
private final List<VariableElement> fields = new ArrayList<VariableElement>(); // List of all fields in the class except those @Ignored.
5756
private final List<VariableElement> indexedFields = new ArrayList<VariableElement>(); // list of all fields marked @Index.
5857
private final Set<Backlink> backlinks = new HashSet<Backlink>();
5958
private final Set<VariableElement> nullableFields = new HashSet<VariableElement>(); // Set of fields which can be nullable
59+
6060
private String packageName; // package name for model class.
6161
private boolean hasDefaultConstructor; // True if model has a public no-arg constructor.
6262
private VariableElement primaryKey; // Reference to field used as primary key, if any.
@@ -332,11 +332,17 @@ private boolean checkDefaultConstructor() {
332332

333333
private boolean checkForFinalFields() {
334334
for (VariableElement field : fields) {
335-
if (field.getModifiers().contains(Modifier.FINAL)) {
336-
Utils.error(String.format(Locale.US,
337-
"Class \"%s\" contains illegal final field \"%s\".", className, field.getSimpleName().toString()));
338-
return false;
335+
if (!field.getModifiers().contains(Modifier.FINAL)) {
336+
continue;
339337
}
338+
if (Utils.isMutableRealmInteger(field)) {
339+
continue;
340+
}
341+
342+
Utils.error(String.format(Locale.US, "Class \"%s\" contains illegal final field \"%s\".", className,
343+
field.getSimpleName().toString()));
344+
345+
return false;
340346
}
341347
return true;
342348
}
@@ -385,32 +391,48 @@ private boolean categorizeField(Element element) {
385391
if (!categorizePrimaryKeyField(field)) { return false; }
386392
}
387393

388-
// Check @LinkingObjects last since it is not allowed to be either @Index, @Required or @PrimaryKey
394+
// @LinkingObjects cannot be @PrimaryKey or @Index.
389395
if (field.getAnnotation(LinkingObjects.class) != null) {
396+
// Do not add backlinks to fields list.
390397
return categorizeBacklinkField(field);
391398
}
392399

393-
// Standard field that appear valid (more fine grained checks might fail later).
400+
// Similarly, a MutableRealmInteger cannot be a @PrimaryKey or @LinkingObject.
401+
if (Utils.isMutableRealmInteger(field)) {
402+
if (!categorizeMutableRealmIntegerField(field)) { return false; }
403+
}
404+
405+
// Standard field that appears to be valid (more fine grained checks might fail later).
394406
fields.add(field);
395407

396408
return true;
397409
}
398410

411+
// The field has the @Index annotation. It's only valid for column types:
412+
// STRING, DATE, INTEGER, BOOLEAN, and RealmMutableInteger
399413
private boolean categorizeIndexField(Element element, VariableElement variableElement) {
400-
// The field has the @Index annotation. It's only valid for column types:
401-
// STRING, DATE, INTEGER, BOOLEAN
402-
Constants.RealmFieldType realmType = Constants.JAVA_TO_REALM_TYPES.get(variableElement.asType().toString());
403-
if (realmType != null) {
404-
switch (realmType) {
405-
case STRING:
406-
case DATE:
407-
case INTEGER:
408-
case BOOLEAN:
409-
indexedFields.add(variableElement);
410-
return true;
414+
boolean indexable = false;
415+
416+
if (Utils.isMutableRealmInteger(variableElement)) {
417+
indexable = true;
418+
} else {
419+
Constants.RealmFieldType realmType = Constants.JAVA_TO_REALM_TYPES.get(variableElement.asType().toString());
420+
if (realmType != null) {
421+
switch (realmType) {
422+
case STRING:
423+
case DATE:
424+
case INTEGER:
425+
case BOOLEAN:
426+
indexable = true;
427+
}
411428
}
412429
}
413430

431+
if (indexable) {
432+
indexedFields.add(variableElement);
433+
return true;
434+
}
435+
414436
Utils.error(String.format(Locale.US, "Field \"%s\" of type \"%s\" cannot be an @Index.", element, element.asType()));
415437
return false;
416438
}
@@ -420,17 +442,21 @@ private void categorizeRequiredField(Element element, VariableElement variableEl
420442
if (Utils.isPrimitiveType(variableElement)) {
421443
Utils.error(String.format(Locale.US,
422444
"@Required annotation is unnecessary for primitive field \"%s\".", element));
423-
} else if (Utils.isRealmList(variableElement) || Utils.isRealmModel(variableElement)) {
445+
return;
446+
}
447+
448+
if (Utils.isRealmList(variableElement) || Utils.isRealmModel(variableElement)) {
424449
Utils.error(String.format(Locale.US,
425450
"Field \"%s\" with type \"%s\" cannot be @Required.", element, element.asType()));
426-
} else {
427-
// Should never get here - user should remove @Required
428-
if (nullableFields.contains(variableElement)) {
429-
Utils.error(String.format(Locale.US,
430-
"Field \"%s\" with type \"%s\" appears to be nullable. Consider removing @Required.",
431-
element,
432-
element.asType()));
433-
}
451+
return;
452+
}
453+
454+
// Should never get here - user should remove @Required
455+
if (nullableFields.contains(variableElement)) {
456+
Utils.error(String.format(Locale.US,
457+
"Field \"%s\" with type \"%s\" appears to be nullable. Consider removing @Required.",
458+
element,
459+
element.asType()));
434460
}
435461
}
436462

@@ -473,6 +499,17 @@ private boolean categorizeBacklinkField(VariableElement variableElement) {
473499
return true;
474500
}
475501

502+
private boolean categorizeMutableRealmIntegerField(VariableElement field) {
503+
if (field.getModifiers().contains(Modifier.FINAL)) {
504+
return true;
505+
}
506+
507+
Utils.error(String.format(Locale.US,
508+
"Field \"%s\", a MutableRealmInteger, must be final.",
509+
field.getSimpleName().toString()));
510+
return false;
511+
}
512+
476513
private boolean isValidPrimaryKeyType(TypeMirror type) {
477514
for (TypeMirror validType : validPrimaryKeyTypes) {
478515
if (typeUtils.isAssignable(type, validType)) {

realm/realm-annotations-processor/src/main/java/io/realm/processor/Constants.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ public enum RealmFieldType {
5151
STRING("STRING", "String"),
5252
DATE("DATE", "Date"),
5353
BINARY("BINARY", "BinaryByteArray"),
54+
REALM_INTEGER("INTEGER", "Long"),
5455
OBJECT("OBJECT", "Object"),
5556
LIST("LIST", "List"),
5657
BACKLINK("BACKLINK", null);

0 commit comments

Comments
 (0)