-
Notifications
You must be signed in to change notification settings - Fork 25
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
Add example of creating interop between Realm Kotlin and a Java project. #42
Conversation
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.
LGTM. Should also be added to the root's README
list of samples.
var favoriteChild: Child? = null | ||
|
||
// Expose method making it easier to use from Java | ||
fun setChildren(children: ArrayList<Child>) { |
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.
If named set
then we should probably clear the underlying list before adding children
.
… both a Maven and Gradle App module as well.
I restructured the sample a bit and added all the needed docs. This PR should now be ready for review |
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.
LGTM 😎
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.
LGTM
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.
LGTM 👍
} | ||
|
||
lateinit var realm: Realm | ||
val realmDispatchers = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors() - 1).asCoroutineDispatcher() |
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.
Why not use a fixed single thread? this is only used from realm.query<Person>
fun closeRealm() { | ||
checkRealm() | ||
realmScope.cancel("Closing Realm") | ||
realmDispatchers.close() |
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.
shouldn't we also shutdown the realmDispatchers
executor?
val config = RealmConfiguration.Builder(schema = setOf(Person::class, Child::class)) | ||
.name("javainterop-example.realm") | ||
.build() | ||
Realm.deleteRealm(config) // Cleanup any old test data |
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.
Minor: This might be surprising if the user re-run the same app unless documented ...
} | ||
|
||
fun writeData(person: Person): Person { | ||
return realm.writeBlocking { |
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.
missing checkRealm()
same for the below functions
callback.update(event) | ||
} | ||
} | ||
return CancellationToken(job) |
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.
You could also return Java's Closeable instead of CancellationToken
We are getting a few questions on how to do this. This sample project demonstrates one way of doing it by exposing a
RealmRepository
from the Kotlin module that has a Java-friendly interface.It should probably not be merged as is and needs to be discussed.