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
Added Realm.isEmpty() #1713
Conversation
JNIEnv*, jobject, jlong nativeGroupPtr) | ||
{ | ||
Group* grp = G(nativeGroupPtr); | ||
const std::string table_prefix = "class_"; |
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.
Maybe this one should be in a common header? Like util.hpp
?
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.
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.
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.
Yes, it is declared in io.realm.internal.Table
but apparently javah
does not generate macros for string constants.
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.
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(); |
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.
No need for std::
.
9ec87cc
to
3b331c9
Compare
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; |
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.
-> extern const char*
, remove the space.
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_" |
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.
checked -> checks
Looks good. Except for the comments 👍 |
Closes #766
3b331c9
to
4453787
Compare
Please review this @realm/java