{"action":"created","comment":{"url":"https://api.github.com/repos/realm/realm-java/pulls/comments/80629900","pull_request_review_id":1674251,"id":80629900,"diff_hunk":"@@ -0,0 +1,257 @@\n+/*\n+ * Copyright 2016 Realm Inc.\n+ *\n+ * Licensed under the Apache License, Version 2.0 (the \"License\");\n+ * you may not use this file except in compliance with the License.\n+ * You may obtain a copy of the License at\n+ *\n+ * http://www.apache.org/licenses/LICENSE-2.0\n+ *\n+ * Unless required by applicable law or agreed to in writing, software\n+ * distributed under the License is distributed on an \"AS IS\" BASIS,\n+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n+ * See the License for the specific language governing permissions and\n+ * limitations under the License.\n+ */\n+\n+package io.realm.internal;\n+\n+import android.support.test.InstrumentationRegistry;\n+import android.support.test.runner.AndroidJUnit4;\n+\n+import org.junit.After;\n+import org.junit.Before;\n+import org.junit.Rule;\n+import org.junit.Test;\n+import org.junit.runner.RunWith;\n+\n+import java.io.IOException;\n+import java.util.Arrays;\n+import java.util.List;\n+\n+import io.realm.RealmConfiguration;\n+import io.realm.RealmFieldType;\n+import io.realm.exceptions.RealmError;\n+import io.realm.exceptions.RealmException;\n+import io.realm.exceptions.RealmPrimaryKeyConstraintException;\n+import io.realm.rule.TestRealmConfigurationFactory;\n+\n+import static junit.framework.Assert.assertFalse;\n+import static org.junit.Assert.assertEquals;\n+import static org.junit.Assert.assertTrue;\n+import static org.junit.Assert.fail;\n+\n+@RunWith(AndroidJUnit4.class)\n+public class PrimaryKeyTests {\n+\n+    @Rule\n+    public final TestRealmConfigurationFactory configFactory = new TestRealmConfigurationFactory();\n+\n+    private android.content.Context context;\n+    private RealmConfiguration config;\n+    private SharedRealm sharedRealm;\n+\n+    @Before\n+    public void setUp() throws Exception {\n+        config = configFactory.createConfiguration();\n+        context = InstrumentationRegistry.getInstrumentation().getContext();\n+    }\n+\n+    @After\n+    public void tearDown() {\n+        if (sharedRealm != null && !sharedRealm.isClosed()) {\n+            sharedRealm.close();\n+        }\n+    }\n+\n+    private Table getTableWithStringPrimaryKey() {\n+        sharedRealm = SharedRealm.getInstance(config);\n+        sharedRealm.beginTransaction();\n+        Table t = sharedRealm.getTable(\"TestTable\");\n+        long column = t.addColumn(RealmFieldType.STRING, \"colName\", true);\n+        t.addSearchIndex(column);\n+        t.setPrimaryKey(\"colName\");\n+        return t;\n+    }\n+\n+    private Table getTableWithIntegerPrimaryKey() {\n+        sharedRealm = SharedRealm.getInstance(config);\n+        sharedRealm.beginTransaction();\n+        Table t = sharedRealm.getTable(\"TestTable\");\n+        long column = t.addColumn(RealmFieldType.INTEGER, \"colName\");\n+        t.addSearchIndex(column);\n+        t.setPrimaryKey(\"colName\");\n+        return t;\n+    }\n+\n+    // Test that primary key constraints are actually removed\n+    @Test\n+    public void removingPrimaryKeyRemovesConstraint_typeSetters() {\n+        RealmConfiguration config = configFactory.createConfigurationBuilder()\n+                .name(\"removeConstraints\").build();\n+        SharedRealm sharedRealm = SharedRealm.getInstance(config);\n+\n+        sharedRealm.beginTransaction();\n+        Table tbl = sharedRealm.getTable(\"EmployeeTable\");\n+        tbl.addColumn(RealmFieldType.STRING, \"name\");\n+        tbl.setPrimaryKey(\"name\");\n+\n+        // Create first entry with name \"Foo\"\n+        tbl.setString(0, tbl.addEmptyRow(), \"Foo\", false);\n+\n+        long rowIndex = tbl.addEmptyRow();\n+        try {\n+            tbl.setString(0, rowIndex, \"Foo\", false); // Try to create 2nd entry with name Foo\n+        } catch (RealmPrimaryKeyConstraintException e1) {\n+            tbl.setPrimaryKey(\"\"); // Primary key check worked, now remove it and try again.\n+            try {\n+                tbl.setString(0, rowIndex, \"Foo\", false);\n+                return;","path":"realm/realm-library/src/androidTest/java/io/realm/internal/PrimaryKeyTests.java","position":109,"original_position":109,"commit_id":"84419c9934b817314f2a8b013a3a0e6e2f4a80a2","original_commit_id":"84419c9934b817314f2a8b013a3a0e6e2f4a80a2","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":"`sharedRealm` not closed","created_at":"2016-09-27T06:57:09Z","updated_at":"2016-09-27T07:03:50Z","html_url":"https://github.com/realm/realm-java/pull/3488#discussion_r80629900","pull_request_url":"https://api.github.com/repos/realm/realm-java/pulls/3488","_links":{"self":{"href":"https://api.github.com/repos/realm/realm-java/pulls/comments/80629900"},"html":{"href":"https://github.com/realm/realm-java/pull/3488#discussion_r80629900"},"pull_request":{"href":"https://api.github.com/repos/realm/realm-java/pulls/3488"}}},"pull_request":{"url":"https://api.github.com/repos/realm/realm-java/pulls/3488","id":86446348,"html_url":"https://github.com/realm/realm-java/pull/3488","diff_url":"https://github.com/realm/realm-java/pull/3488.diff","patch_url":"https://github.com/realm/realm-java/pull/3488.patch","issue_url":"https://api.github.com/repos/realm/realm-java/issues/3488","number":3488,"state":"open","locked":false,"title":"Use set_string_unique to set primary key","user":{"login":"beeender","id":449296,"avatar_url":"https://avatars.githubusercontent.com/u/449296?v=3","gravatar_id":"","url":"https://api.github.com/users/beeender","html_url":"https://github.com/beeender","followers_url":"https://api.github.com/users/beeender/followers","following_url":"https://api.github.com/users/beeender/following{/other_user}","gists_url":"https://api.github.com/users/beeender/gists{/gist_id}","starred_url":"https://api.github.com/users/beeender/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/beeender/subscriptions","organizations_url":"https://api.github.com/users/beeender/orgs","repos_url":"https://api.github.com/users/beeender/repos","events_url":"https://api.github.com/users/beeender/events{/privacy}","received_events_url":"https://api.github.com/users/beeender/received_events","type":"User","site_admin":false},"body":"See the change in OS https://github.com/realm/realm-object-store/pull/168","created_at":"2016-09-23T02:45:18Z","updated_at":"2016-09-27T07:03:51Z","closed_at":null,"merged_at":null,"merge_commit_sha":"8378288068729c9e1980e1e0a6a2c6e367ea38ac","assignee":{"login":"beeender","id":449296,"avatar_url":"https://avatars.githubusercontent.com/u/449296?v=3","gravatar_id":"","url":"https://api.github.com/users/beeender","html_url":"https://github.com/beeender","followers_url":"https://api.github.com/users/beeender/followers","following_url":"https://api.github.com/users/beeender/following{/other_user}","gists_url":"https://api.github.com/users/beeender/gists{/gist_id}","starred_url":"https://api.github.com/users/beeender/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/beeender/subscriptions","organizations_url":"https://api.github.com/users/beeender/orgs","repos_url":"https://api.github.com/users/beeender/repos","events_url":"https://api.github.com/users/beeender/events{/privacy}","received_events_url":"https://api.github.com/users/beeender/received_events","type":"User","site_admin":false},"assignees":[{"login":"beeender","id":449296,"avatar_url":"https://avatars.githubusercontent.com/u/449296?v=3","gravatar_id":"","url":"https://api.github.com/users/beeender","html_url":"https://github.com/beeender","followers_url":"https://api.github.com/users/beeender/followers","following_url":"https://api.github.com/users/beeender/following{/other_user}","gists_url":"https://api.github.com/users/beeender/gists{/gist_id}","starred_url":"https://api.github.com/users/beeender/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/beeender/subscriptions","organizations_url":"https://api.github.com/users/beeender/orgs","repos_url":"https://api.github.com/users/beeender/repos","events_url":"https://api.github.com/users/beeender/events{/privacy}","received_events_url":"https://api.github.com/users/beeender/received_events","type":"User","site_admin":false}],"milestone":null,"commits_url":"https://api.github.com/repos/realm/realm-java/pulls/3488/commits","review_comments_url":"https://api.github.com/repos/realm/realm-java/pulls/3488/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/3488/comments","statuses_url":"https://api.github.com/repos/realm/realm-java/statuses/84419c9934b817314f2a8b013a3a0e6e2f4a80a2","head":{"label":"realm:mc/change-pk-by-set-unique","ref":"mc/change-pk-by-set-unique","sha":"84419c9934b817314f2a8b013a3a0e6e2f4a80a2","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}","deployments_url":"https://api.github.com/repos/realm/realm-java/deployments","created_at":"2012-04-20T09:18:42Z","updated_at":"2016-09-27T03:45:23Z","pushed_at":"2016-09-27T02:21:21Z","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":66961,"stargazers_count":6066,"watchers_count":6066,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":901,"mirror_url":null,"open_issues_count":311,"forks":901,"open_issues":311,"watchers":6066,"default_branch":"master"}},"base":{"label":"realm:master","ref":"master","sha":"070cf094688958b270aee42568f6a926e8e4d9a3","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}","deployments_url":"https://api.github.com/repos/realm/realm-java/deployments","created_at":"2012-04-20T09:18:42Z","updated_at":"2016-09-27T03:45:23Z","pushed_at":"2016-09-27T02:21:21Z","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":66961,"stargazers_count":6066,"watchers_count":6066,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":901,"mirror_url":null,"open_issues_count":311,"forks":901,"open_issues":311,"watchers":6066,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/realm/realm-java/pulls/3488"},"html":{"href":"https://github.com/realm/realm-java/pull/3488"},"issue":{"href":"https://api.github.com/repos/realm/realm-java/issues/3488"},"comments":{"href":"https://api.github.com/repos/realm/realm-java/issues/3488/comments"},"review_comments":{"href":"https://api.github.com/repos/realm/realm-java/pulls/3488/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/3488/commits"},"statuses":{"href":"https://api.github.com/repos/realm/realm-java/statuses/84419c9934b817314f2a8b013a3a0e6e2f4a80a2"}}}}
{"actor":{"display_login":"kneth"}}