{"action":"created","comment":{"url":"https://api.github.com/repos/rhq-project/rhq/pulls/comments/62093779","id":62093779,"diff_hunk":"@@ -783,6 +789,62 @@ private boolean uninventoryResourceBulkDeleteAsyncWork(Subject overlord, int res\n                 resourceIds);\n         }\n \n+        // If this resource had packages installed, remove their version and bits\n+        if (installedPackages.size() > 0) {\n+            hasErrors |= cleanOrphanedPackages(overlord, installedPackages);\n+        }\n+\n+        return hasErrors;\n+    }\n+\n+    @SuppressWarnings(\"unchecked\")\n+    private List<Integer> getInstalledPackages(List<Integer> resourceIds) {\n+\n+        List<Integer> installed_packages = new ArrayList<Integer>();\n+\n+        try {\n+            installed_packages = entityManager.createNamedQuery(PackageVersion.QUERY_FIND_ID_PACKAGES_BY_RESOURCE_ID)\n+                         .setParameter(\"resourceIds\", resourceIds)\n+                .getResultList();\n+        } catch (Exception e) {\n+            LOG.warn(\"May not have been able get installed packages for\" + resourceIds\n+                + \". This is unlikely to be a problem.\", e);\n+            return installed_packages;\n+        }\n+\n+        return installed_packages;\n+    }\n+\n+    @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)\n+    private boolean cleanOrphanedPackages(Subject subject, List<Integer> packages) {\n+\n+        boolean hasErrors = false;\n+\n+        if (!authorizationManager.isOverlord(subject)) {\n+            throw new IllegalArgumentException(\"Only the overlord can execute arbitrary named query strings\");\n+        }\n+\n+        String[] namedQueriesToExecute = new String[] { //\n+        PackageVersion.DELETE_BY_PKG_IF_NO_CONTENT_SOURCES_OR_REPOS, //\n+            PackageBits.DELETE_IF_NO_PACKAGE_VERSION };\n+\n+        for (String namedQueryToExecute : namedQueriesToExecute) {\n+            try {\n+                Query namedQuery = entityManager.createNamedQuery(namedQueryToExecute);\n+                if (namedQueryToExecute.equals(PackageVersion.DELETE_BY_PKG_IF_NO_CONTENT_SOURCES_OR_REPOS)) {\n+                    namedQuery.setParameter(\"packageIds\", packages);","path":"modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/resource/ResourceManagerBean.java","position":68,"original_position":68,"commit_id":"31de375d1eb8b924d5d606b2eecb65c1d271d8fc","original_commit_id":"31de375d1eb8b924d5d606b2eecb65c1d271d8fc","user":{"login":"jshaughn","id":2104052,"avatar_url":"https://avatars.githubusercontent.com/u/2104052?v=3","gravatar_id":"","url":"https://api.github.com/users/jshaughn","html_url":"https://github.com/jshaughn","followers_url":"https://api.github.com/users/jshaughn/followers","following_url":"https://api.github.com/users/jshaughn/following{/other_user}","gists_url":"https://api.github.com/users/jshaughn/gists{/gist_id}","starred_url":"https://api.github.com/users/jshaughn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jshaughn/subscriptions","organizations_url":"https://api.github.com/users/jshaughn/orgs","repos_url":"https://api.github.com/users/jshaughn/repos","events_url":"https://api.github.com/users/jshaughn/events{/privacy}","received_events_url":"https://api.github.com/users/jshaughn/received_events","type":"User","site_admin":false},"body":"I think this will fail on Oracle if there are more than 1000 packages.  Oracle has an IN clause limit of 1000. The same could be true of getInstalledPackages(resourceIds) but actually it is OK because this logic is invoked on a single resource.  So, the limit is not an issue for getInstalledPackages and I doubt a single resource has that many packages.","created_at":"2016-05-04T18:49:36Z","updated_at":"2016-05-04T18:49:36Z","html_url":"https://github.com/rhq-project/rhq/pull/247#discussion_r62093779","pull_request_url":"https://api.github.com/repos/rhq-project/rhq/pulls/247","_links":{"self":{"href":"https://api.github.com/repos/rhq-project/rhq/pulls/comments/62093779"},"html":{"href":"https://github.com/rhq-project/rhq/pull/247#discussion_r62093779"},"pull_request":{"href":"https://api.github.com/repos/rhq-project/rhq/pulls/247"}}},"pull_request":{"url":"https://api.github.com/repos/rhq-project/rhq/pulls/247","id":68383342,"html_url":"https://github.com/rhq-project/rhq/pull/247","diff_url":"https://github.com/rhq-project/rhq/pull/247.diff","patch_url":"https://github.com/rhq-project/rhq/pull/247.patch","issue_url":"https://api.github.com/repos/rhq-project/rhq/issues/247","number":247,"state":"open","locked":false,"title":"Bug 1306602 - Uninventory of resource leaves orphaned content data in…","user":{"login":"rubenvp8510","id":3799716,"avatar_url":"https://avatars.githubusercontent.com/u/3799716?v=3","gravatar_id":"","url":"https://api.github.com/users/rubenvp8510","html_url":"https://github.com/rubenvp8510","followers_url":"https://api.github.com/users/rubenvp8510/followers","following_url":"https://api.github.com/users/rubenvp8510/following{/other_user}","gists_url":"https://api.github.com/users/rubenvp8510/gists{/gist_id}","starred_url":"https://api.github.com/users/rubenvp8510/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rubenvp8510/subscriptions","organizations_url":"https://api.github.com/users/rubenvp8510/orgs","repos_url":"https://api.github.com/users/rubenvp8510/repos","events_url":"https://api.github.com/users/rubenvp8510/events{/privacy}","received_events_url":"https://api.github.com/users/rubenvp8510/received_events","type":"User","site_admin":false},"body":"… the database","created_at":"2016-04-29T14:48:32Z","updated_at":"2016-05-04T18:49:36Z","closed_at":null,"merged_at":null,"merge_commit_sha":"64aaa7c4c411f2b4d459885a81b0a66ab51bb727","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/rhq-project/rhq/pulls/247/commits","review_comments_url":"https://api.github.com/repos/rhq-project/rhq/pulls/247/comments","review_comment_url":"https://api.github.com/repos/rhq-project/rhq/pulls/comments{/number}","comments_url":"https://api.github.com/repos/rhq-project/rhq/issues/247/comments","statuses_url":"https://api.github.com/repos/rhq-project/rhq/statuses/31de375d1eb8b924d5d606b2eecb65c1d271d8fc","head":{"label":"rubenvp8510:Bug/1306602","ref":"Bug/1306602","sha":"31de375d1eb8b924d5d606b2eecb65c1d271d8fc","user":{"login":"rubenvp8510","id":3799716,"avatar_url":"https://avatars.githubusercontent.com/u/3799716?v=3","gravatar_id":"","url":"https://api.github.com/users/rubenvp8510","html_url":"https://github.com/rubenvp8510","followers_url":"https://api.github.com/users/rubenvp8510/followers","following_url":"https://api.github.com/users/rubenvp8510/following{/other_user}","gists_url":"https://api.github.com/users/rubenvp8510/gists{/gist_id}","starred_url":"https://api.github.com/users/rubenvp8510/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rubenvp8510/subscriptions","organizations_url":"https://api.github.com/users/rubenvp8510/orgs","repos_url":"https://api.github.com/users/rubenvp8510/repos","events_url":"https://api.github.com/users/rubenvp8510/events{/privacy}","received_events_url":"https://api.github.com/users/rubenvp8510/received_events","type":"User","site_admin":false},"repo":{"id":52982919,"name":"rhq","full_name":"rubenvp8510/rhq","owner":{"login":"rubenvp8510","id":3799716,"avatar_url":"https://avatars.githubusercontent.com/u/3799716?v=3","gravatar_id":"","url":"https://api.github.com/users/rubenvp8510","html_url":"https://github.com/rubenvp8510","followers_url":"https://api.github.com/users/rubenvp8510/followers","following_url":"https://api.github.com/users/rubenvp8510/following{/other_user}","gists_url":"https://api.github.com/users/rubenvp8510/gists{/gist_id}","starred_url":"https://api.github.com/users/rubenvp8510/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rubenvp8510/subscriptions","organizations_url":"https://api.github.com/users/rubenvp8510/orgs","repos_url":"https://api.github.com/users/rubenvp8510/repos","events_url":"https://api.github.com/users/rubenvp8510/events{/privacy}","received_events_url":"https://api.github.com/users/rubenvp8510/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/rubenvp8510/rhq","description":"RHQ system management and monitoring framework","fork":true,"url":"https://api.github.com/repos/rubenvp8510/rhq","forks_url":"https://api.github.com/repos/rubenvp8510/rhq/forks","keys_url":"https://api.github.com/repos/rubenvp8510/rhq/keys{/key_id}","collaborators_url":"https://api.github.com/repos/rubenvp8510/rhq/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/rubenvp8510/rhq/teams","hooks_url":"https://api.github.com/repos/rubenvp8510/rhq/hooks","issue_events_url":"https://api.github.com/repos/rubenvp8510/rhq/issues/events{/number}","events_url":"https://api.github.com/repos/rubenvp8510/rhq/events","assignees_url":"https://api.github.com/repos/rubenvp8510/rhq/assignees{/user}","branches_url":"https://api.github.com/repos/rubenvp8510/rhq/branches{/branch}","tags_url":"https://api.github.com/repos/rubenvp8510/rhq/tags","blobs_url":"https://api.github.com/repos/rubenvp8510/rhq/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/rubenvp8510/rhq/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/rubenvp8510/rhq/git/refs{/sha}","trees_url":"https://api.github.com/repos/rubenvp8510/rhq/git/trees{/sha}","statuses_url":"https://api.github.com/repos/rubenvp8510/rhq/statuses/{sha}","languages_url":"https://api.github.com/repos/rubenvp8510/rhq/languages","stargazers_url":"https://api.github.com/repos/rubenvp8510/rhq/stargazers","contributors_url":"https://api.github.com/repos/rubenvp8510/rhq/contributors","subscribers_url":"https://api.github.com/repos/rubenvp8510/rhq/subscribers","subscription_url":"https://api.github.com/repos/rubenvp8510/rhq/subscription","commits_url":"https://api.github.com/repos/rubenvp8510/rhq/commits{/sha}","git_commits_url":"https://api.github.com/repos/rubenvp8510/rhq/git/commits{/sha}","comments_url":"https://api.github.com/repos/rubenvp8510/rhq/comments{/number}","issue_comment_url":"https://api.github.com/repos/rubenvp8510/rhq/issues/comments{/number}","contents_url":"https://api.github.com/repos/rubenvp8510/rhq/contents/{+path}","compare_url":"https://api.github.com/repos/rubenvp8510/rhq/compare/{base}...{head}","merges_url":"https://api.github.com/repos/rubenvp8510/rhq/merges","archive_url":"https://api.github.com/repos/rubenvp8510/rhq/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/rubenvp8510/rhq/downloads","issues_url":"https://api.github.com/repos/rubenvp8510/rhq/issues{/number}","pulls_url":"https://api.github.com/repos/rubenvp8510/rhq/pulls{/number}","milestones_url":"https://api.github.com/repos/rubenvp8510/rhq/milestones{/number}","notifications_url":"https://api.github.com/repos/rubenvp8510/rhq/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/rubenvp8510/rhq/labels{/name}","releases_url":"https://api.github.com/repos/rubenvp8510/rhq/releases{/id}","deployments_url":"https://api.github.com/repos/rubenvp8510/rhq/deployments","created_at":"2016-03-02T17:34:47Z","updated_at":"2016-03-02T17:35:17Z","pushed_at":"2016-05-04T17:14:41Z","git_url":"git://github.com/rubenvp8510/rhq.git","ssh_url":"git@github.com:rubenvp8510/rhq.git","clone_url":"https://github.com/rubenvp8510/rhq.git","svn_url":"https://github.com/rubenvp8510/rhq","homepage":"http://jboss.org/rhq","size":137911,"stargazers_count":0,"watchers_count":0,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"rhq-project:master","ref":"master","sha":"4387729f21ea8c9058a170c1fff3e0061a06cc93","user":{"login":"rhq-project","id":1080166,"avatar_url":"https://avatars.githubusercontent.com/u/1080166?v=3","gravatar_id":"","url":"https://api.github.com/users/rhq-project","html_url":"https://github.com/rhq-project","followers_url":"https://api.github.com/users/rhq-project/followers","following_url":"https://api.github.com/users/rhq-project/following{/other_user}","gists_url":"https://api.github.com/users/rhq-project/gists{/gist_id}","starred_url":"https://api.github.com/users/rhq-project/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rhq-project/subscriptions","organizations_url":"https://api.github.com/users/rhq-project/orgs","repos_url":"https://api.github.com/users/rhq-project/repos","events_url":"https://api.github.com/users/rhq-project/events{/privacy}","received_events_url":"https://api.github.com/users/rhq-project/received_events","type":"Organization","site_admin":false},"repo":{"id":17278009,"name":"rhq","full_name":"rhq-project/rhq","owner":{"login":"rhq-project","id":1080166,"avatar_url":"https://avatars.githubusercontent.com/u/1080166?v=3","gravatar_id":"","url":"https://api.github.com/users/rhq-project","html_url":"https://github.com/rhq-project","followers_url":"https://api.github.com/users/rhq-project/followers","following_url":"https://api.github.com/users/rhq-project/following{/other_user}","gists_url":"https://api.github.com/users/rhq-project/gists{/gist_id}","starred_url":"https://api.github.com/users/rhq-project/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rhq-project/subscriptions","organizations_url":"https://api.github.com/users/rhq-project/orgs","repos_url":"https://api.github.com/users/rhq-project/repos","events_url":"https://api.github.com/users/rhq-project/events{/privacy}","received_events_url":"https://api.github.com/users/rhq-project/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/rhq-project/rhq","description":"RHQ system management and monitoring framework","fork":false,"url":"https://api.github.com/repos/rhq-project/rhq","forks_url":"https://api.github.com/repos/rhq-project/rhq/forks","keys_url":"https://api.github.com/repos/rhq-project/rhq/keys{/key_id}","collaborators_url":"https://api.github.com/repos/rhq-project/rhq/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/rhq-project/rhq/teams","hooks_url":"https://api.github.com/repos/rhq-project/rhq/hooks","issue_events_url":"https://api.github.com/repos/rhq-project/rhq/issues/events{/number}","events_url":"https://api.github.com/repos/rhq-project/rhq/events","assignees_url":"https://api.github.com/repos/rhq-project/rhq/assignees{/user}","branches_url":"https://api.github.com/repos/rhq-project/rhq/branches{/branch}","tags_url":"https://api.github.com/repos/rhq-project/rhq/tags","blobs_url":"https://api.github.com/repos/rhq-project/rhq/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/rhq-project/rhq/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/rhq-project/rhq/git/refs{/sha}","trees_url":"https://api.github.com/repos/rhq-project/rhq/git/trees{/sha}","statuses_url":"https://api.github.com/repos/rhq-project/rhq/statuses/{sha}","languages_url":"https://api.github.com/repos/rhq-project/rhq/languages","stargazers_url":"https://api.github.com/repos/rhq-project/rhq/stargazers","contributors_url":"https://api.github.com/repos/rhq-project/rhq/contributors","subscribers_url":"https://api.github.com/repos/rhq-project/rhq/subscribers","subscription_url":"https://api.github.com/repos/rhq-project/rhq/subscription","commits_url":"https://api.github.com/repos/rhq-project/rhq/commits{/sha}","git_commits_url":"https://api.github.com/repos/rhq-project/rhq/git/commits{/sha}","comments_url":"https://api.github.com/repos/rhq-project/rhq/comments{/number}","issue_comment_url":"https://api.github.com/repos/rhq-project/rhq/issues/comments{/number}","contents_url":"https://api.github.com/repos/rhq-project/rhq/contents/{+path}","compare_url":"https://api.github.com/repos/rhq-project/rhq/compare/{base}...{head}","merges_url":"https://api.github.com/repos/rhq-project/rhq/merges","archive_url":"https://api.github.com/repos/rhq-project/rhq/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/rhq-project/rhq/downloads","issues_url":"https://api.github.com/repos/rhq-project/rhq/issues{/number}","pulls_url":"https://api.github.com/repos/rhq-project/rhq/pulls{/number}","milestones_url":"https://api.github.com/repos/rhq-project/rhq/milestones{/number}","notifications_url":"https://api.github.com/repos/rhq-project/rhq/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/rhq-project/rhq/labels{/name}","releases_url":"https://api.github.com/repos/rhq-project/rhq/releases{/id}","deployments_url":"https://api.github.com/repos/rhq-project/rhq/deployments","created_at":"2014-02-28T06:54:47Z","updated_at":"2016-03-31T08:29:10Z","pushed_at":"2016-05-04T18:15:12Z","git_url":"git://github.com/rhq-project/rhq.git","ssh_url":"git@github.com:rhq-project/rhq.git","clone_url":"https://github.com/rhq-project/rhq.git","svn_url":"https://github.com/rhq-project/rhq","homepage":"http://jboss.org/rhq","size":151908,"stargazers_count":90,"watchers_count":90,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":true,"forks_count":57,"mirror_url":null,"open_issues_count":26,"forks":57,"open_issues":26,"watchers":90,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/rhq-project/rhq/pulls/247"},"html":{"href":"https://github.com/rhq-project/rhq/pull/247"},"issue":{"href":"https://api.github.com/repos/rhq-project/rhq/issues/247"},"comments":{"href":"https://api.github.com/repos/rhq-project/rhq/issues/247/comments"},"review_comments":{"href":"https://api.github.com/repos/rhq-project/rhq/pulls/247/comments"},"review_comment":{"href":"https://api.github.com/repos/rhq-project/rhq/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/rhq-project/rhq/pulls/247/commits"},"statuses":{"href":"https://api.github.com/repos/rhq-project/rhq/statuses/31de375d1eb8b924d5d606b2eecb65c1d271d8fc"}}}}