{"action":"created","comment":{"url":"https://api.github.com/repos/realm/realm-java/pulls/comments/24971812","id":24971812,"diff_hunk":"@@ -657,75 +657,93 @@ JNIEXPORT void JNICALL Java_io_realm_internal_TableQuery_nativeEqual__J_3JZ(\n \n // String\n \n-JNIEXPORT void JNICALL Java_io_realm_internal_TableQuery_nativeEqual__J_3JLjava_lang_String_2Z(\n-    JNIEnv *env, jobject, jlong nativeQueryPtr, jlongArray columnIndexes, jstring value, jboolean caseSensitive)\n-{\n+enum StringPredicate {\n+    StringEqual,\n+    StringNotEqual,\n+    StringContains,\n+    StringBeginsWith,\n+    StringEndsWith\n+};\n+\n+\n+void TableQuery_StringPredicate(JNIEnv *env, jlong nativeQueryPtr, jlongArray columnIndexes, jstring value, jboolean caseSensitive, StringPredicate predicate) {\n     GET_ARRAY()\n     try {\n+        bool isCaseSensitive = caseSensitive ? true : false;\n         JStringAccessor value2(env, value); // throws\n         if (arr_len == 1) {\n             if (!QUERY_COL_TYPE_VALID(env, nativeQueryPtr, arr[0], type_String))\n                 return;\n-            Q(nativeQueryPtr)->equal(S(arr[0]), value2, caseSensitive ? true : false);\n+            switch (predicate) {\n+            case StringEqual:\n+                Q(nativeQueryPtr)->equal(S(arr[0]), value2, isCaseSensitive);\n+                break;\n+            case StringNotEqual:\n+                Q(nativeQueryPtr)->not_equal(S(arr[0]), value2, isCaseSensitive);\n+                break;\n+            case StringContains:\n+                Q(nativeQueryPtr)->contains(S(arr[0]), value2, isCaseSensitive);\n+                break;\n+            case StringBeginsWith:\n+                Q(nativeQueryPtr)->begins_with(S(arr[0]), value2, isCaseSensitive);\n+                break;\n+            case StringEndsWith:\n+                Q(nativeQueryPtr)->ends_with(S(arr[0]), value2, isCaseSensitive);\n+                break;\n+            }\n         }\n         else {\n             Table* tbl = getTableLink(nativeQueryPtr, arr, arr_len);\n-            Q(nativeQueryPtr)->and_query(tbl->column<String>(size_t(arr[arr_len-1])) == StringData(value2));\n+            switch (predicate) {\n+            case StringEqual:\n+                Q(nativeQueryPtr)->and_query(tbl->column<String>(size_t(arr[arr_len-1])).equal(StringData(value2), isCaseSensitive));\n+                break;\n+            case StringNotEqual:\n+                Q(nativeQueryPtr)->and_query(tbl->column<String>(size_t(arr[arr_len-1])).not_equal(StringData(value2), isCaseSensitive));\n+                break;\n+            case StringContains:\n+                Q(nativeQueryPtr)->and_query(tbl->column<String>(size_t(arr[arr_len-1])).contains(StringData(value2), isCaseSensitive));\n+                break;\n+            case StringBeginsWith:\n+                Q(nativeQueryPtr)->and_query(tbl->column<String>(size_t(arr[arr_len-1])).begins_with(StringData(value2), isCaseSensitive));\n+                break;\n+            case StringEndsWith:\n+                Q(nativeQueryPtr)->and_query(tbl->column<String>(size_t(arr[arr_len-1])).ends_with(StringData(value2), isCaseSensitive));\n+                break;\n+            }\n         }\n     } CATCH_STD()\n     RELEASE_ARRAY()\n }\n \n+JNIEXPORT void JNICALL Java_io_realm_internal_TableQuery_nativeEqual__J_3JLjava_lang_String_2Z(\n+    JNIEnv *env, jobject, jlong nativeQueryPtr, jlongArray columnIndexes, jstring value, jboolean caseSensitive)","path":"realm-jni/src/io_realm_internal_TableQuery.cpp","position":69,"original_position":69,"commit_id":"9d4c9a168514d40825b6820992cd5682442226d1","original_commit_id":"9d4c9a168514d40825b6820992cd5682442226d1","user":{"login":"kneth","id":1225363,"avatar_url":"https://avatars.githubusercontent.com/u/1225363?v=3","gravatar_id":"","url":"https://api.github.com/users/kneth","html_url":"https://github.com/kneth","followers_url":"https://api.github.com/users/kneth/followers","following_url":"https://api.github.com/users/kneth/following{/other_user}","gists_url":"https://api.github.com/users/kneth/gists{/gist_id}","starred_url":"https://api.github.com/users/kneth/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kneth/subscriptions","organizations_url":"https://api.github.com/users/kneth/orgs","repos_url":"https://api.github.com/users/kneth/repos","events_url":"https://api.github.com/users/kneth/events{/privacy}","received_events_url":"https://api.github.com/users/kneth/received_events","type":"User","site_admin":false},"body":"I was thinking the same when I wrote it but decided to keep them in order to have the same structure as the other types. Could we refactor the code (for all types) in another branch later?","created_at":"2015-02-19T08:29:05Z","updated_at":"2015-02-19T08:29:05Z","html_url":"https://github.com/realm/realm-java/pull/856#discussion_r24971812","pull_request_url":"https://api.github.com/repos/realm/realm-java/pulls/856","_links":{"self":{"href":"https://api.github.com/repos/realm/realm-java/pulls/comments/24971812"},"html":{"href":"https://github.com/realm/realm-java/pull/856#discussion_r24971812"},"pull_request":{"href":"https://api.github.com/repos/realm/realm-java/pulls/856"}}},"pull_request":{"url":"https://api.github.com/repos/realm/realm-java/pulls/856","id":29375157,"html_url":"https://github.com/realm/realm-java/pull/856","diff_url":"https://github.com/realm/realm-java/pull/856.diff","patch_url":"https://github.com/realm/realm-java/pull/856.patch","issue_url":"https://api.github.com/repos/realm/realm-java/issues/856","number":856,"state":"open","locked":false,"title":"Case sensitive queries on relationships","user":{"login":"kneth","id":1225363,"avatar_url":"https://avatars.githubusercontent.com/u/1225363?v=3","gravatar_id":"","url":"https://api.github.com/users/kneth","html_url":"https://github.com/kneth","followers_url":"https://api.github.com/users/kneth/followers","following_url":"https://api.github.com/users/kneth/following{/other_user}","gists_url":"https://api.github.com/users/kneth/gists{/gist_id}","starred_url":"https://api.github.com/users/kneth/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kneth/subscriptions","organizations_url":"https://api.github.com/users/kneth/orgs","repos_url":"https://api.github.com/users/kneth/repos","events_url":"https://api.github.com/users/kneth/events{/privacy}","received_events_url":"https://api.github.com/users/kneth/received_events","type":"User","site_admin":false},"body":"Core has implemented case sensitive queries on links (relationships) long time ago, and we forgot to follow up on that: all five predicates support it (equal, not equal, contains, begins with, and ends with).\r\n\r\nI took the liberty to simplify the string predicates on the JNI level instead of having so much duplicate code.\r\n\r\nI have to redo `generate_jni_headers.sh` as we more and more depend on Android. The workaround is to compile using Android Studio (and probably fail), run the script, and then recompile without errors. I hope that the upcoming native plugin for Gradle will solve this problem elegantly.\r\n\r\n@bmunkholm @emanuelez @cmelchior ","created_at":"2015-02-16T14:08:31Z","updated_at":"2015-02-19T08:29:05Z","closed_at":null,"merged_at":null,"merge_commit_sha":"754d249f987dd1581cf90693c610c502d656633f","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/realm/realm-java/pulls/856/commits","review_comments_url":"https://api.github.com/repos/realm/realm-java/pulls/856/comments","review_comment_url":"https://api.github.com/repos/realm/realm-java/pulls/comments/{number}","comments_url":"https://api.github.com/repos/realm/realm-java/issues/856/comments","statuses_url":"https://api.github.com/repos/realm/realm-java/statuses/9d4c9a168514d40825b6820992cd5682442226d1","head":{"label":"kg-linkqueries-case-insensitive","ref":"kg-linkqueries-case-insensitive","sha":"9d4c9a168514d40825b6820992cd5682442226d1","user":{"login":"realm","id":7575099,"avatar_url":"https://avatars.githubusercontent.com/u/7575099?v=3","gravatar_id":"","url":"https://api.github.com/users/realm","html_url":"https://github.com/realm","followers_url":"https://api.github.com/users/realm/followers","following_url":"https://api.github.com/users/realm/following{/other_user}","gists_url":"https://api.github.com/users/realm/gists{/gist_id}","starred_url":"https://api.github.com/users/realm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/realm/subscriptions","organizations_url":"https://api.github.com/users/realm/orgs","repos_url":"https://api.github.com/users/realm/repos","events_url":"https://api.github.com/users/realm/events{/privacy}","received_events_url":"https://api.github.com/users/realm/received_events","type":"Organization","site_admin":false},"repo":{"id":4084908,"name":"realm-java","full_name":"realm/realm-java","owner":{"login":"realm","id":7575099,"avatar_url":"https://avatars.githubusercontent.com/u/7575099?v=3","gravatar_id":"","url":"https://api.github.com/users/realm","html_url":"https://github.com/realm","followers_url":"https://api.github.com/users/realm/followers","following_url":"https://api.github.com/users/realm/following{/other_user}","gists_url":"https://api.github.com/users/realm/gists{/gist_id}","starred_url":"https://api.github.com/users/realm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/realm/subscriptions","organizations_url":"https://api.github.com/users/realm/orgs","repos_url":"https://api.github.com/users/realm/repos","events_url":"https://api.github.com/users/realm/events{/privacy}","received_events_url":"https://api.github.com/users/realm/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/realm/realm-java","description":"Realm is a mobile database: a replacement for SQLite & ORMs","fork":false,"url":"https://api.github.com/repos/realm/realm-java","forks_url":"https://api.github.com/repos/realm/realm-java/forks","keys_url":"https://api.github.com/repos/realm/realm-java/keys{/key_id}","collaborators_url":"https://api.github.com/repos/realm/realm-java/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/realm/realm-java/teams","hooks_url":"https://api.github.com/repos/realm/realm-java/hooks","issue_events_url":"https://api.github.com/repos/realm/realm-java/issues/events{/number}","events_url":"https://api.github.com/repos/realm/realm-java/events","assignees_url":"https://api.github.com/repos/realm/realm-java/assignees{/user}","branches_url":"https://api.github.com/repos/realm/realm-java/branches{/branch}","tags_url":"https://api.github.com/repos/realm/realm-java/tags","blobs_url":"https://api.github.com/repos/realm/realm-java/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/realm/realm-java/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/realm/realm-java/git/refs{/sha}","trees_url":"https://api.github.com/repos/realm/realm-java/git/trees{/sha}","statuses_url":"https://api.github.com/repos/realm/realm-java/statuses/{sha}","languages_url":"https://api.github.com/repos/realm/realm-java/languages","stargazers_url":"https://api.github.com/repos/realm/realm-java/stargazers","contributors_url":"https://api.github.com/repos/realm/realm-java/contributors","subscribers_url":"https://api.github.com/repos/realm/realm-java/subscribers","subscription_url":"https://api.github.com/repos/realm/realm-java/subscription","commits_url":"https://api.github.com/repos/realm/realm-java/commits{/sha}","git_commits_url":"https://api.github.com/repos/realm/realm-java/git/commits{/sha}","comments_url":"https://api.github.com/repos/realm/realm-java/comments{/number}","issue_comment_url":"https://api.github.com/repos/realm/realm-java/issues/comments/{number}","contents_url":"https://api.github.com/repos/realm/realm-java/contents/{+path}","compare_url":"https://api.github.com/repos/realm/realm-java/compare/{base}...{head}","merges_url":"https://api.github.com/repos/realm/realm-java/merges","archive_url":"https://api.github.com/repos/realm/realm-java/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/realm/realm-java/downloads","issues_url":"https://api.github.com/repos/realm/realm-java/issues{/number}","pulls_url":"https://api.github.com/repos/realm/realm-java/pulls{/number}","milestones_url":"https://api.github.com/repos/realm/realm-java/milestones{/number}","notifications_url":"https://api.github.com/repos/realm/realm-java/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/realm/realm-java/labels{/name}","releases_url":"https://api.github.com/repos/realm/realm-java/releases{/id}","created_at":"2012-04-20T09:18:42Z","updated_at":"2015-02-18T21:24:03Z","pushed_at":"2015-02-19T06:54:15Z","git_url":"git://github.com/realm/realm-java.git","ssh_url":"git@github.com:realm/realm-java.git","clone_url":"https://github.com/realm/realm-java.git","svn_url":"https://github.com/realm/realm-java","homepage":"http://realm.io","size":50362,"stargazers_count":1284,"watchers_count":1284,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":94,"mirror_url":null,"open_issues_count":76,"forks":94,"open_issues":76,"watchers":1284,"default_branch":"master"}},"base":{"label":"master","ref":"master","sha":"cd8d64c274bda8f6f6b1695876eb5d61844be29b","user":{"login":"realm","id":7575099,"avatar_url":"https://avatars.githubusercontent.com/u/7575099?v=3","gravatar_id":"","url":"https://api.github.com/users/realm","html_url":"https://github.com/realm","followers_url":"https://api.github.com/users/realm/followers","following_url":"https://api.github.com/users/realm/following{/other_user}","gists_url":"https://api.github.com/users/realm/gists{/gist_id}","starred_url":"https://api.github.com/users/realm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/realm/subscriptions","organizations_url":"https://api.github.com/users/realm/orgs","repos_url":"https://api.github.com/users/realm/repos","events_url":"https://api.github.com/users/realm/events{/privacy}","received_events_url":"https://api.github.com/users/realm/received_events","type":"Organization","site_admin":false},"repo":{"id":4084908,"name":"realm-java","full_name":"realm/realm-java","owner":{"login":"realm","id":7575099,"avatar_url":"https://avatars.githubusercontent.com/u/7575099?v=3","gravatar_id":"","url":"https://api.github.com/users/realm","html_url":"https://github.com/realm","followers_url":"https://api.github.com/users/realm/followers","following_url":"https://api.github.com/users/realm/following{/other_user}","gists_url":"https://api.github.com/users/realm/gists{/gist_id}","starred_url":"https://api.github.com/users/realm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/realm/subscriptions","organizations_url":"https://api.github.com/users/realm/orgs","repos_url":"https://api.github.com/users/realm/repos","events_url":"https://api.github.com/users/realm/events{/privacy}","received_events_url":"https://api.github.com/users/realm/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/realm/realm-java","description":"Realm is a mobile database: a replacement for SQLite & ORMs","fork":false,"url":"https://api.github.com/repos/realm/realm-java","forks_url":"https://api.github.com/repos/realm/realm-java/forks","keys_url":"https://api.github.com/repos/realm/realm-java/keys{/key_id}","collaborators_url":"https://api.github.com/repos/realm/realm-java/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/realm/realm-java/teams","hooks_url":"https://api.github.com/repos/realm/realm-java/hooks","issue_events_url":"https://api.github.com/repos/realm/realm-java/issues/events{/number}","events_url":"https://api.github.com/repos/realm/realm-java/events","assignees_url":"https://api.github.com/repos/realm/realm-java/assignees{/user}","branches_url":"https://api.github.com/repos/realm/realm-java/branches{/branch}","tags_url":"https://api.github.com/repos/realm/realm-java/tags","blobs_url":"https://api.github.com/repos/realm/realm-java/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/realm/realm-java/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/realm/realm-java/git/refs{/sha}","trees_url":"https://api.github.com/repos/realm/realm-java/git/trees{/sha}","statuses_url":"https://api.github.com/repos/realm/realm-java/statuses/{sha}","languages_url":"https://api.github.com/repos/realm/realm-java/languages","stargazers_url":"https://api.github.com/repos/realm/realm-java/stargazers","contributors_url":"https://api.github.com/repos/realm/realm-java/contributors","subscribers_url":"https://api.github.com/repos/realm/realm-java/subscribers","subscription_url":"https://api.github.com/repos/realm/realm-java/subscription","commits_url":"https://api.github.com/repos/realm/realm-java/commits{/sha}","git_commits_url":"https://api.github.com/repos/realm/realm-java/git/commits{/sha}","comments_url":"https://api.github.com/repos/realm/realm-java/comments{/number}","issue_comment_url":"https://api.github.com/repos/realm/realm-java/issues/comments/{number}","contents_url":"https://api.github.com/repos/realm/realm-java/contents/{+path}","compare_url":"https://api.github.com/repos/realm/realm-java/compare/{base}...{head}","merges_url":"https://api.github.com/repos/realm/realm-java/merges","archive_url":"https://api.github.com/repos/realm/realm-java/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/realm/realm-java/downloads","issues_url":"https://api.github.com/repos/realm/realm-java/issues{/number}","pulls_url":"https://api.github.com/repos/realm/realm-java/pulls{/number}","milestones_url":"https://api.github.com/repos/realm/realm-java/milestones{/number}","notifications_url":"https://api.github.com/repos/realm/realm-java/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/realm/realm-java/labels{/name}","releases_url":"https://api.github.com/repos/realm/realm-java/releases{/id}","created_at":"2012-04-20T09:18:42Z","updated_at":"2015-02-18T21:24:03Z","pushed_at":"2015-02-19T06:54:15Z","git_url":"git://github.com/realm/realm-java.git","ssh_url":"git@github.com:realm/realm-java.git","clone_url":"https://github.com/realm/realm-java.git","svn_url":"https://github.com/realm/realm-java","homepage":"http://realm.io","size":50362,"stargazers_count":1284,"watchers_count":1284,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":94,"mirror_url":null,"open_issues_count":76,"forks":94,"open_issues":76,"watchers":1284,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/realm/realm-java/pulls/856"},"html":{"href":"https://github.com/realm/realm-java/pull/856"},"issue":{"href":"https://api.github.com/repos/realm/realm-java/issues/856"},"comments":{"href":"https://api.github.com/repos/realm/realm-java/issues/856/comments"},"review_comments":{"href":"https://api.github.com/repos/realm/realm-java/pulls/856/comments"},"review_comment":{"href":"https://api.github.com/repos/realm/realm-java/pulls/comments/{number}"},"commits":{"href":"https://api.github.com/repos/realm/realm-java/pulls/856/commits"},"statuses":{"href":"https://api.github.com/repos/realm/realm-java/statuses/9d4c9a168514d40825b6820992cd5682442226d1"}}}}