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

Added Realm.isEmpty() #1713

Merged
merged 1 commit into from Nov 3, 2015
Merged

Added Realm.isEmpty() #1713

merged 1 commit into from Nov 3, 2015

Conversation

dalinaum
Copy link
Contributor

@dalinaum dalinaum commented Nov 2, 2015

Please review this @realm/java

JNIEnv*, jobject, jlong nativeGroupPtr)
{
Group* grp = G(nativeGroupPtr);
const std::string table_prefix = "class_";
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe this one should be in a common header? Like util.hpp?

Copy link
Contributor

Choose a reason for hiding this comment

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

Currently Table.java also has a constant with this: Table.TABLE_PREFIX. Having it as an accessible constant from C++ would probably be nice, so we only have it defined 1 place.

Copy link
Member

Choose a reason for hiding this comment

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

Yes, it is declared in io.realm.internal.Table but apparently javah does not generate macros for string constants.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I tried the following code:

    jclass class_id = GetClass(env, class_name);
    if (class_id == NULL) {
        return false;
    }
    jfieldID field_id = env->GetStaticFieldID(class_id, "TABLE_PREFIX", "[Ljava/lang/String;");
    if (field_id == NULL) {
        ThrowException(env, NoSuchField, class_name);
        return false;
    }
    jstring jstring_table_name = (jstring) env->GetStaticObjectField(class_id, field_id);
    if (jstring_table_name == NULL) {
        ThrowException(env, NoSuchField, class_name);
        return false;
    }
    const char *table_prefix_c_str = env->GetStringUTFChars(jstring_table_name, 0);
    const std::string table_prefix(table_prefix_c_str);

And I got the following error:

Caused by: java.lang.ClassNotFoundException: Didn't find class "Ljava.lang.String" on path: DexPathList[[zip file "/system/framework/android.test.runner.jar", zip file "/data/app/io.realm.test-1/base.apk", zip file "/data/app/io.realm.test-1/base.apk"],nativeLibraryDirectories=[/data/app/io.realm.test-1/lib/x86, /data/app/io.realm.test-1/lib/x86, /vendor/lib, /system/lib]]

Is there any solution to use Table.TABLE_PREFIX correctly?


for (size_t i = 0; i < grp->size(); ++i) {
ConstTableRef table = grp->get_table(i);
const std::string table_name = table->get_name();
Copy link
Member

Choose a reason for hiding this comment

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

No need for std::.

@dalinaum dalinaum force-pushed the lk-realm-is-empty branch 3 times, most recently from 9ec87cc to 3b331c9 Compare November 2, 2015 16:08
@dalinaum
Copy link
Contributor Author

dalinaum commented Nov 2, 2015

Thanks for reviews and please review this again @realm/java

PS: @cmelchior I wonder whether I understand your proposal #1716 (comment) correctly.

@@ -584,4 +584,6 @@ inline jobject NewFloat(JNIEnv* env, float value)
return env->NewObject(java_lang_float, java_lang_float_init, value);
}

extern const char * const TABLE_PREFIX;
Copy link
Contributor

Choose a reason for hiding this comment

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

-> extern const char*, remove the space.

@beeender
Copy link
Contributor

beeender commented Nov 3, 2015

Except the formatting issue, 👍

@@ -226,6 +226,17 @@ public void writeToFile(File file, byte[] key) throws IOException {
return nativeWriteToMem(nativePtr);
}

/*
* Check if the Group contains any objects. It only checked for "class_"
Copy link
Contributor

Choose a reason for hiding this comment

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

checked -> checks

@cmelchior
Copy link
Contributor

Looks good. Except for the comments 👍

dalinaum added a commit that referenced this pull request Nov 3, 2015
@dalinaum dalinaum merged commit fb6eaa4 into master Nov 3, 2015
@dalinaum dalinaum removed the Review label Nov 3, 2015
@dalinaum dalinaum deleted the lk-realm-is-empty branch November 3, 2015 10:08
emanuelez added a commit that referenced this pull request Nov 11, 2015
This reverts commit fb6eaa4, reversing
changes made to 4031387.

Conflicts:
	changelog.txt
	realm/realm-library/src/androidTest/java/io/realm/RealmTest.java
	realm/realm-library/src/main/java/io/realm/BaseRealm.java
	realm/realm-library/src/main/java/io/realm/internal/Group.java
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 16, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants