{"action":"created","comment":{"url":"https://api.github.com/repos/Kinvey/java-library/pulls/comments/173720805","pull_request_review_id":102954298,"id":173720805,"diff_hunk":"@@ -211,6 +212,52 @@ public void clear() {\n         }\n     }\n \n+    @Override\n+    public <T extends GenericJson> void clearCollection(String collection, Class<T> collectionItemClass, Long ttl) {\n+        synchronized (LOCK) {\n+            DynamicRealm realm = getDynamicRealm();\n+            try {\n+                realm.beginTransaction();\n+                List<String> schemas = new ArrayList<>();\n+                schemas.add(TableNameManager.getShortName(collection, realm));\n+                schemas.addAll(getEmbeddedObjectSchemas(collection, realm));\n+                removeSchemas(schemas, realm);\n+                String cacheKey = getClientHash() + File.separator + collection;\n+                RealmCache<T> cache = (RealmCache<T>) mCacheMap.get(cacheKey);\n+                if (cache != null) {\n+                    cache.createRealmTable(realm);\n+                }\n+                realm.commitTransaction();\n+            } finally {\n+                realm.close();\n+            }\n+        }\n+    }\n+\n+    private List<String> getEmbeddedObjectSchemas(String tableName, DynamicRealm realm) {\n+        RealmSchema currentSchema = realm.getSchema();\n+        String originalName;\n+        String className;\n+        List<String> embeddedObjectSchemas = new ArrayList<>();\n+        Set<RealmObjectSchema> schemas = currentSchema.getAll();\n+        for (RealmObjectSchema schema : schemas) {\n+            className = schema.getClassName();\n+            if (className.equals(TableNameManager.getShortName(tableName, realm))) {\n+                for (RealmObjectSchema subClassSchema : schemas) {\n+                    originalName = TableNameManager.getOriginalName(subClassSchema.getClassName(), realm);\n+                    if (originalName == null) {\n+                        continue;\n+                    }\n+                    if (originalName.startsWith(className + \"_\")) {","path":"android-lib/src/main/java/com/kinvey/android/cache/RealmCacheManager.java","position":48,"original_position":48,"commit_id":"f1201fb6207d6bdef6eae2aee3459de01a8202ad","original_commit_id":"f1201fb6207d6bdef6eae2aee3459de01a8202ad","user":{"login":"yuliya-guseva","id":28727986,"avatar_url":"https://avatars2.githubusercontent.com/u/28727986?v=4","gravatar_id":"","url":"https://api.github.com/users/yuliya-guseva","html_url":"https://github.com/yuliya-guseva","followers_url":"https://api.github.com/users/yuliya-guseva/followers","following_url":"https://api.github.com/users/yuliya-guseva/following{/other_user}","gists_url":"https://api.github.com/users/yuliya-guseva/gists{/gist_id}","starred_url":"https://api.github.com/users/yuliya-guseva/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/yuliya-guseva/subscriptions","organizations_url":"https://api.github.com/users/yuliya-guseva/orgs","repos_url":"https://api.github.com/users/yuliya-guseva/repos","events_url":"https://api.github.com/users/yuliya-guseva/events{/privacy}","received_events_url":"https://api.github.com/users/yuliya-guseva/received_events","type":"User","site_admin":false},"body":"I agree. Constants.UNDERSCORE was added to another branch (MLIBZ-2392). I'll update it after merging MLIBZ-2392 branch to indev.","created_at":"2018-03-12T08:36:37Z","updated_at":"2018-03-12T08:36:37Z","html_url":"https://github.com/Kinvey/java-library/pull/148#discussion_r173720805","pull_request_url":"https://api.github.com/repos/Kinvey/java-library/pulls/148","author_association":"COLLABORATOR","_links":{"self":{"href":"https://api.github.com/repos/Kinvey/java-library/pulls/comments/173720805"},"html":{"href":"https://github.com/Kinvey/java-library/pull/148#discussion_r173720805"},"pull_request":{"href":"https://api.github.com/repos/Kinvey/java-library/pulls/148"}},"in_reply_to_id":173323559},"pull_request":{"url":"https://api.github.com/repos/Kinvey/java-library/pulls/148","id":172666138,"html_url":"https://github.com/Kinvey/java-library/pull/148","diff_url":"https://github.com/Kinvey/java-library/pull/148.diff","patch_url":"https://github.com/Kinvey/java-library/pull/148.patch","issue_url":"https://api.github.com/repos/Kinvey/java-library/issues/148","number":148,"state":"open","locked":false,"title":"feat: MLIBZ-2185 Clear does not clear metadata for data synced in previous sdk versions","user":{"login":"yuliya-guseva","id":28727986,"avatar_url":"https://avatars2.githubusercontent.com/u/28727986?v=4","gravatar_id":"","url":"https://api.github.com/users/yuliya-guseva","html_url":"https://github.com/yuliya-guseva","followers_url":"https://api.github.com/users/yuliya-guseva/followers","following_url":"https://api.github.com/users/yuliya-guseva/following{/other_user}","gists_url":"https://api.github.com/users/yuliya-guseva/gists{/gist_id}","starred_url":"https://api.github.com/users/yuliya-guseva/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/yuliya-guseva/subscriptions","organizations_url":"https://api.github.com/users/yuliya-guseva/orgs","repos_url":"https://api.github.com/users/yuliya-guseva/repos","events_url":"https://api.github.com/users/yuliya-guseva/events{/privacy}","received_events_url":"https://api.github.com/users/yuliya-guseva/received_events","type":"User","site_admin":false},"body":"#### Description\r\n`DataStore#clear` does not clear metadata for data synced in previous SDK versions.\r\n\r\n#### Changes\r\nAdded new method `clearCollection` to CacheManager. The method deletes the collection and creates its new version. Current method `clear` just deletes realm file, this logic was saved. Logic for `DataStore.clear` was updated from `CacheManager#clear` to `CacheManager#clearCollection`.\r\n\r\n#### Tests\r\nInstrumented, Manual. Manual testing is necessary in this case because we have to update library version from 3.0.5 to latest version, it's impossible to check in the tests. Anyway, the small test for checking was added, the test checks that `CacheManager#clearCollection` doesn't crash.\r\n","created_at":"2018-03-03T12:56:05Z","updated_at":"2018-03-12T08:36:37Z","closed_at":null,"merged_at":null,"merge_commit_sha":"f74e61c14c59827969563ab69359781ce0bdbad8","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/Kinvey/java-library/pulls/148/commits","review_comments_url":"https://api.github.com/repos/Kinvey/java-library/pulls/148/comments","review_comment_url":"https://api.github.com/repos/Kinvey/java-library/pulls/comments{/number}","comments_url":"https://api.github.com/repos/Kinvey/java-library/issues/148/comments","statuses_url":"https://api.github.com/repos/Kinvey/java-library/statuses/f1201fb6207d6bdef6eae2aee3459de01a8202ad","head":{"label":"Kinvey:feature/MLIBZ-2185_clear_does_not_clear_metadata_for_data_synced_in_previous_SDK_versions","ref":"feature/MLIBZ-2185_clear_does_not_clear_metadata_for_data_synced_in_previous_SDK_versions","sha":"f1201fb6207d6bdef6eae2aee3459de01a8202ad","user":{"login":"Kinvey","id":1276480,"avatar_url":"https://avatars2.githubusercontent.com/u/1276480?v=4","gravatar_id":"","url":"https://api.github.com/users/Kinvey","html_url":"https://github.com/Kinvey","followers_url":"https://api.github.com/users/Kinvey/followers","following_url":"https://api.github.com/users/Kinvey/following{/other_user}","gists_url":"https://api.github.com/users/Kinvey/gists{/gist_id}","starred_url":"https://api.github.com/users/Kinvey/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Kinvey/subscriptions","organizations_url":"https://api.github.com/users/Kinvey/orgs","repos_url":"https://api.github.com/users/Kinvey/repos","events_url":"https://api.github.com/users/Kinvey/events{/privacy}","received_events_url":"https://api.github.com/users/Kinvey/received_events","type":"Organization","site_admin":false},"repo":{"id":26016266,"name":"java-library","full_name":"Kinvey/java-library","owner":{"login":"Kinvey","id":1276480,"avatar_url":"https://avatars2.githubusercontent.com/u/1276480?v=4","gravatar_id":"","url":"https://api.github.com/users/Kinvey","html_url":"https://github.com/Kinvey","followers_url":"https://api.github.com/users/Kinvey/followers","following_url":"https://api.github.com/users/Kinvey/following{/other_user}","gists_url":"https://api.github.com/users/Kinvey/gists{/gist_id}","starred_url":"https://api.github.com/users/Kinvey/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Kinvey/subscriptions","organizations_url":"https://api.github.com/users/Kinvey/orgs","repos_url":"https://api.github.com/users/Kinvey/repos","events_url":"https://api.github.com/users/Kinvey/events{/privacy}","received_events_url":"https://api.github.com/users/Kinvey/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/Kinvey/java-library","description":"SDK for Java and Android applications","fork":false,"url":"https://api.github.com/repos/Kinvey/java-library","forks_url":"https://api.github.com/repos/Kinvey/java-library/forks","keys_url":"https://api.github.com/repos/Kinvey/java-library/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Kinvey/java-library/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Kinvey/java-library/teams","hooks_url":"https://api.github.com/repos/Kinvey/java-library/hooks","issue_events_url":"https://api.github.com/repos/Kinvey/java-library/issues/events{/number}","events_url":"https://api.github.com/repos/Kinvey/java-library/events","assignees_url":"https://api.github.com/repos/Kinvey/java-library/assignees{/user}","branches_url":"https://api.github.com/repos/Kinvey/java-library/branches{/branch}","tags_url":"https://api.github.com/repos/Kinvey/java-library/tags","blobs_url":"https://api.github.com/repos/Kinvey/java-library/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Kinvey/java-library/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Kinvey/java-library/git/refs{/sha}","trees_url":"https://api.github.com/repos/Kinvey/java-library/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Kinvey/java-library/statuses/{sha}","languages_url":"https://api.github.com/repos/Kinvey/java-library/languages","stargazers_url":"https://api.github.com/repos/Kinvey/java-library/stargazers","contributors_url":"https://api.github.com/repos/Kinvey/java-library/contributors","subscribers_url":"https://api.github.com/repos/Kinvey/java-library/subscribers","subscription_url":"https://api.github.com/repos/Kinvey/java-library/subscription","commits_url":"https://api.github.com/repos/Kinvey/java-library/commits{/sha}","git_commits_url":"https://api.github.com/repos/Kinvey/java-library/git/commits{/sha}","comments_url":"https://api.github.com/repos/Kinvey/java-library/comments{/number}","issue_comment_url":"https://api.github.com/repos/Kinvey/java-library/issues/comments{/number}","contents_url":"https://api.github.com/repos/Kinvey/java-library/contents/{+path}","compare_url":"https://api.github.com/repos/Kinvey/java-library/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Kinvey/java-library/merges","archive_url":"https://api.github.com/repos/Kinvey/java-library/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Kinvey/java-library/downloads","issues_url":"https://api.github.com/repos/Kinvey/java-library/issues{/number}","pulls_url":"https://api.github.com/repos/Kinvey/java-library/pulls{/number}","milestones_url":"https://api.github.com/repos/Kinvey/java-library/milestones{/number}","notifications_url":"https://api.github.com/repos/Kinvey/java-library/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Kinvey/java-library/labels{/name}","releases_url":"https://api.github.com/repos/Kinvey/java-library/releases{/id}","deployments_url":"https://api.github.com/repos/Kinvey/java-library/deployments","created_at":"2014-10-31T12:58:54Z","updated_at":"2017-01-26T16:26:40Z","pushed_at":"2018-03-12T08:16:57Z","git_url":"git://github.com/Kinvey/java-library.git","ssh_url":"git@github.com:Kinvey/java-library.git","clone_url":"https://github.com/Kinvey/java-library.git","svn_url":"https://github.com/Kinvey/java-library","homepage":"https://devcenter.kinvey.com/","size":100330,"stargazers_count":0,"watchers_count":0,"language":"Java","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"archived":false,"open_issues_count":4,"license":{"key":"other","name":"Other","spdx_id":null,"url":null},"forks":1,"open_issues":4,"watchers":0,"default_branch":"master"}},"base":{"label":"Kinvey:indev","ref":"indev","sha":"69e80cf0754040557790f56e8f446628c7fdc02e","user":{"login":"Kinvey","id":1276480,"avatar_url":"https://avatars2.githubusercontent.com/u/1276480?v=4","gravatar_id":"","url":"https://api.github.com/users/Kinvey","html_url":"https://github.com/Kinvey","followers_url":"https://api.github.com/users/Kinvey/followers","following_url":"https://api.github.com/users/Kinvey/following{/other_user}","gists_url":"https://api.github.com/users/Kinvey/gists{/gist_id}","starred_url":"https://api.github.com/users/Kinvey/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Kinvey/subscriptions","organizations_url":"https://api.github.com/users/Kinvey/orgs","repos_url":"https://api.github.com/users/Kinvey/repos","events_url":"https://api.github.com/users/Kinvey/events{/privacy}","received_events_url":"https://api.github.com/users/Kinvey/received_events","type":"Organization","site_admin":false},"repo":{"id":26016266,"name":"java-library","full_name":"Kinvey/java-library","owner":{"login":"Kinvey","id":1276480,"avatar_url":"https://avatars2.githubusercontent.com/u/1276480?v=4","gravatar_id":"","url":"https://api.github.com/users/Kinvey","html_url":"https://github.com/Kinvey","followers_url":"https://api.github.com/users/Kinvey/followers","following_url":"https://api.github.com/users/Kinvey/following{/other_user}","gists_url":"https://api.github.com/users/Kinvey/gists{/gist_id}","starred_url":"https://api.github.com/users/Kinvey/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Kinvey/subscriptions","organizations_url":"https://api.github.com/users/Kinvey/orgs","repos_url":"https://api.github.com/users/Kinvey/repos","events_url":"https://api.github.com/users/Kinvey/events{/privacy}","received_events_url":"https://api.github.com/users/Kinvey/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/Kinvey/java-library","description":"SDK for Java and Android applications","fork":false,"url":"https://api.github.com/repos/Kinvey/java-library","forks_url":"https://api.github.com/repos/Kinvey/java-library/forks","keys_url":"https://api.github.com/repos/Kinvey/java-library/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Kinvey/java-library/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Kinvey/java-library/teams","hooks_url":"https://api.github.com/repos/Kinvey/java-library/hooks","issue_events_url":"https://api.github.com/repos/Kinvey/java-library/issues/events{/number}","events_url":"https://api.github.com/repos/Kinvey/java-library/events","assignees_url":"https://api.github.com/repos/Kinvey/java-library/assignees{/user}","branches_url":"https://api.github.com/repos/Kinvey/java-library/branches{/branch}","tags_url":"https://api.github.com/repos/Kinvey/java-library/tags","blobs_url":"https://api.github.com/repos/Kinvey/java-library/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Kinvey/java-library/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Kinvey/java-library/git/refs{/sha}","trees_url":"https://api.github.com/repos/Kinvey/java-library/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Kinvey/java-library/statuses/{sha}","languages_url":"https://api.github.com/repos/Kinvey/java-library/languages","stargazers_url":"https://api.github.com/repos/Kinvey/java-library/stargazers","contributors_url":"https://api.github.com/repos/Kinvey/java-library/contributors","subscribers_url":"https://api.github.com/repos/Kinvey/java-library/subscribers","subscription_url":"https://api.github.com/repos/Kinvey/java-library/subscription","commits_url":"https://api.github.com/repos/Kinvey/java-library/commits{/sha}","git_commits_url":"https://api.github.com/repos/Kinvey/java-library/git/commits{/sha}","comments_url":"https://api.github.com/repos/Kinvey/java-library/comments{/number}","issue_comment_url":"https://api.github.com/repos/Kinvey/java-library/issues/comments{/number}","contents_url":"https://api.github.com/repos/Kinvey/java-library/contents/{+path}","compare_url":"https://api.github.com/repos/Kinvey/java-library/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Kinvey/java-library/merges","archive_url":"https://api.github.com/repos/Kinvey/java-library/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Kinvey/java-library/downloads","issues_url":"https://api.github.com/repos/Kinvey/java-library/issues{/number}","pulls_url":"https://api.github.com/repos/Kinvey/java-library/pulls{/number}","milestones_url":"https://api.github.com/repos/Kinvey/java-library/milestones{/number}","notifications_url":"https://api.github.com/repos/Kinvey/java-library/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Kinvey/java-library/labels{/name}","releases_url":"https://api.github.com/repos/Kinvey/java-library/releases{/id}","deployments_url":"https://api.github.com/repos/Kinvey/java-library/deployments","created_at":"2014-10-31T12:58:54Z","updated_at":"2017-01-26T16:26:40Z","pushed_at":"2018-03-12T08:16:57Z","git_url":"git://github.com/Kinvey/java-library.git","ssh_url":"git@github.com:Kinvey/java-library.git","clone_url":"https://github.com/Kinvey/java-library.git","svn_url":"https://github.com/Kinvey/java-library","homepage":"https://devcenter.kinvey.com/","size":100330,"stargazers_count":0,"watchers_count":0,"language":"Java","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"archived":false,"open_issues_count":4,"license":{"key":"other","name":"Other","spdx_id":null,"url":null},"forks":1,"open_issues":4,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/Kinvey/java-library/pulls/148"},"html":{"href":"https://github.com/Kinvey/java-library/pull/148"},"issue":{"href":"https://api.github.com/repos/Kinvey/java-library/issues/148"},"comments":{"href":"https://api.github.com/repos/Kinvey/java-library/issues/148/comments"},"review_comments":{"href":"https://api.github.com/repos/Kinvey/java-library/pulls/148/comments"},"review_comment":{"href":"https://api.github.com/repos/Kinvey/java-library/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/Kinvey/java-library/pulls/148/commits"},"statuses":{"href":"https://api.github.com/repos/Kinvey/java-library/statuses/f1201fb6207d6bdef6eae2aee3459de01a8202ad"}},"author_association":"COLLABORATOR"}}
{"actor":{"display_login":"yuliya-guseva"}}