Skip to content
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 RealmCursor #53

Closed
wants to merge 14 commits into from
Closed

add RealmCursor #53

wants to merge 14 commits into from

Conversation

larsgrefer
Copy link
Contributor

fix #6

is it correct to open pull requests against the master branch, or should I PR against the releases branch instead?

@@ -0,0 +1,601 @@
package io.realm;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing license header

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

@cmelchior
Copy link
Contributor

cmelchior commented Jun 22, 2016

Hi @larsgrefer
Sorry for being late getting to this. Thanks a lot for this PR, but for issues like this that are kinda large in scope, it might have been better if you reached out before doing the work since there is a number of issues with the code that could have been addressed before you did the work 😢

A few general comments:

  • Any reason you implemented the Cursor from scratch? Work was already begun here: https://github.com/realm/realm-java/pull/1090/files and it would probably have been easier to start from there. Especially you are missing tests for everything.
  • Have you checked that {@inheritDoc} is actually working when inheriting from Android classes, we had problems with this before.
  • Mising javadoc for the class header. Cursors based on a RealmResults has a few differences that we should very clearly document for now. 1) It doesn't work across processes (=cannot be used in ContentProviders shared between apps) 2) Following links is problematic as normal cursors doesn't allow that 3) It doesn't work across threads.

If you want to move forward with this PR there is a number of things that needs to be discussed/clarified first:

  1. I'm fine with leaving out interprocess support for now. It will be extremely complicated to get right.
  2. We need to figure out how linked objects should be supported if at all. See the description in RealmCursor realm-java#1090. Any comments you have would be helpful.
  3. We need to figure out if we should disable auto-update for Cursors. I have a feeling that auto-update will work really poorly with how Cursors are currently used in Android. Comments are welcome as well.

First steps should as a minimum be porting all the unit tests over.

/cc @realm/java

*/
@Override
public int getColumnIndexOrThrow(@NonNull String columnName) throws IllegalArgumentException {
if (data == null)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use curly brackets

@larsgrefer
Copy link
Contributor Author

@cmelchior

Any reason you implemented the Cursor from scratch?

I've seen this too late

Have you checked that {@inheritDoc} is actually working when inheriting from Android classes, we had problems with this before.

What kind of problems do you mean?
I've updated the javadoc options in order to link against https://developer.android.com/reference, but their server sends a X-Frame-Options: "SAMEORIGIN" header

  1. I'm fine with leaving out interprocess support for now. It will be extremely complicated to get right.

👍

  1. We need to figure out how linked objects should be supported if at all.

I think this should not be supported.
Any existing code, which expects a Cursor, should only expect simple tabular data.

First steps should as a minimum be porting all the unit tests over.

I will do this.

if (aLong >= Integer.MAX_VALUE)
return Integer.MAX_VALUE;
return (int) aLong;
if (aLong > Integer.MIN_VALUE && aLong < Integer.MAX_VALUE)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it acceptable that if the value is out of range, nothing (undefined) is returned?

Copy link

@stk1m1 stk1m1 Jun 27, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this code path will throw with canNotConvert() since there is no break.

Edit> You are right. This can be re-written for clarification.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True. But do we wish the same message for the two cases: out of range, and wrong type?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's good point. I think this is updated and you'd perhaps want to comment on new commits.


import io.realm.entity.AllJavaTypes;

public class RealmCursorTest extends AndroidTestCase {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All of these should be converted to JUnit4 since that is what we are writing all new tests with. This also include removing the test prefix. See https://github.com/realm/realm-java/blob/master/CONTRIBUTING.md#unit-tests

@cmelchior
Copy link
Contributor

Our original implementation also had the concept of setting an "_id" column, which is required for a number of Android framework classes. I would like for this functionality to be present as well.

Unit tests are still failing btw:
Test Result (2 failures / +2)
io.realm.RealmCursorTest.testRegisterContentObserverRealmChanged
io.realm.RealmCursorTest.testUnregisterContentObserver

@larsgrefer
Copy link
Contributor Author

Unit tests are still failing btw:
Test Result (2 failures / +2)
io.realm.RealmCursorTest.testRegisterContentObserverRealmChanged
io.realm.RealmCursorTest.testUnregisterContentObserver

The tests are not running in Looper-Threads so they can't add ChangeListeners

@beeender
Copy link
Contributor

beeender commented Jul 1, 2016

Testing failed with below information

testStarted io.realm.RealmCursorTest#registerDataSetObserver_closed
testFailed FAILURE/java.lang.IllegalStateException: You can't register a listener from a non-Looper thread 
    at io.realm.RealmResults.addChangeListener(RealmResults.java:929)
    at io.realm.RealmCursor.registerDataSetObserver(RealmCursor.java:680)
    at io.realm.RealmCursorTest.registerDataSetObserver_closed(RealmCursorTest.java:489)
    at java.lang.reflect.Method.invoke(Native Method)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
    at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
    at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
    at org.junit.runners.Suite.runChild(Suite.java:128)
    at org.junit.runners.Suite.runChild(Suite.java:27)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
    at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
    at org.junit.runner.JUnitCore.run(JUnitCore.java:115)
    at android.support.test.internal.runner.TestExecutor.execute(TestExecutor.java:54)
    at android.support.test.runner.AndroidJUnitRunner.onStart(AndroidJUnitRunner.java:240)
    at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1879)

testEnded io.realm.RealmCursorTest#registerDataSetObserver_closed
testStarted io.realm.RealmCursorTest#registerContentObserver_realmChanged
testFailed FAILURE/java.lang.IllegalStateException: You can't register a listener from a non-Looper thread 
    at io.realm.RealmResults.addChangeListener(RealmResults.java:929)
    at io.realm.RealmCursor.registerContentObserver(RealmCursor.java:648)
    at io.realm.RealmCursorTest.registerContentObserver_realmChanged(RealmCursorTest.java:504)
    at java.lang.reflect.Method.invoke(Native Method)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
    at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
    at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
    at org.junit.runners.Suite.runChild(Suite.java:128)
    at org.junit.runners.Suite.runChild(Suite.java:27)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
    at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
    at org.junit.runner.JUnitCore.run(JUnitCore.java:115)
    at android.support.test.internal.runner.TestExecutor.execute(TestExecutor.java:54)
    at android.support.test.runner.AndroidJUnitRunner.onStart(AndroidJUnitRunner.java:240)
    at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1879)

@larsgrefer
Copy link
Contributor Author

@beeender same reason as in #53 (comment)

to solve this, I would need these classes from realm-java:
https://github.com/realm/realm-java/tree/master/realm/realm-library/src/androidTest/java/io/realm/rule

Shall I copy the classes or do you want to build a new artifact which contains them?

@cmelchior
Copy link
Contributor

@larsgrefer Copying the rules is fine with me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

RealmCursor
7 participants