{"action":"created","comment":{"url":"https://api.github.com/repos/wso2/andes/pulls/comments/30014781","id":30014781,"diff_hunk":"@@ -1328,4 +1341,330 @@ public int deleteAllMessageMetadataFromDLC(String storageQueueName, String DLCQu\n         return messageCountInDLCForQueue;\n     }\n \n+    /**\n+     * {@inheritDoc}\n+     */\n+    @Override\n+    public void storeRetainedMessages(List<AndesMessage> retainList) throws AndesException {\n+        Connection connection = null;\n+        PreparedStatement updateMetadataPreparedStatement = null;\n+        PreparedStatement deleteContentPreparedStatement = null;\n+        PreparedStatement insertContentPreparedStatement = null;\n+        boolean batchEmpty = true;\n+\n+        try {\n+            connection = getConnection();\n+            connection.setAutoCommit(false);\n+\n+            updateMetadataPreparedStatement = connection.prepareStatement(RDBMSConstants.PS_UPDATE_RETAINED_METADATA);\n+            deleteContentPreparedStatement = connection.prepareStatement(RDBMSConstants.PS_DELETE_RETAIN_MESSAGE_PARTS);\n+            insertContentPreparedStatement = connection.prepareStatement(RDBMSConstants.PS_INSERT_RETAIN_MESSAGE_PART);\n+\n+            for (AndesMessage message : retainList) {\n+                AndesMessageMetadata metadata = message.getMetadata();\n+                String destination = metadata.getDestination();\n+                RetainedItemData retainedItemData = retainedMsgCache.get(destination);\n+\n+                if (null != retainedItemData) {\n+                    if (batchEmpty) {\n+                        batchEmpty = false;\n+                    }\n+                    addRetainedMessageToUpdateBatch(updateMetadataPreparedStatement, deleteContentPreparedStatement,\n+                                                    insertContentPreparedStatement,\n+                                                    message, metadata, retainedItemData);\n+                    retainedItemData.messageID = metadata.getMessageID();\n+                } else {\n+                    retainedItemData = getRetainedTopicID(connection, destination);\n+\n+                    if (null == retainedItemData) {\n+                        retainedMsgCache.put(destination, createRetainedEntry(connection, message));\n+                    } else {\n+                        addRetainedMessageToUpdateBatch(updateMetadataPreparedStatement, deleteContentPreparedStatement,\n+                                                        insertContentPreparedStatement,\n+                                                        message, metadata, retainedItemData);\n+                        retainedItemData.messageID = metadata.getMessageID();\n+                        retainedMsgCache.put(destination, retainedItemData);\n+                    }\n+\n+                }\n+            }\n+\n+            if (!batchEmpty) {\n+                deleteContentPreparedStatement.executeBatch();\n+                updateMetadataPreparedStatement.executeBatch();\n+                insertContentPreparedStatement.executeBatch();\n+                connection.commit();\n+            }\n+        } catch (SQLException e) {\n+            rollback(connection, RDBMSConstants.TASK_STORING_RETAINED_MESSAGE_PARTS);\n+            e.printStackTrace();\n+            throw new AndesException(\"Error occurred while adding retained message content to DB \", e);\n+        } finally {\n+            close(updateMetadataPreparedStatement, RDBMSConstants.TASK_STORING_RETAINED_MESSAGE_PARTS);\n+            close(deleteContentPreparedStatement, RDBMSConstants.TASK_STORING_RETAINED_MESSAGE_PARTS);\n+            close(insertContentPreparedStatement, RDBMSConstants.TASK_STORING_RETAINED_MESSAGE_PARTS);\n+            close(connection, RDBMSConstants.TASK_STORING_RETAINED_MESSAGE_PARTS);\n+        }\n+    }\n+\n+\n+    /**\n+     * Used to store details about a retained item entry\n+     */\n+    private static class RetainedItemData {\n+        /**\n+         * Topic id of the DB entry\n+         */\n+        public int topicID;\n+\n+        /**\n+         * Retained message ID for the topic\n+         */\n+        public long messageID;\n+\n+        private RetainedItemData(Integer topicID, long messageID) {\n+            this.topicID = topicID;\n+            this.messageID = messageID;\n+        }\n+    }\n+\n+    /**\n+     * Update batching prepared statements with current message\n+     *\n+     * @param updateMetadataPreparedStatement\n+     *         update prepared statement\n+     * @param deleteContentPreparedStatement\n+     *         delete prepared statement\n+     * @param insertContentPreparedStatement\n+     *         insert prepared statement\n+     * @param message\n+     *         current message\n+     * @param metadata\n+     *         current message metadata\n+     * @param retainedItemData\n+     *         retained item data\n+     * @throws SQLException\n+     */\n+    private void addRetainedMessageToUpdateBatch(PreparedStatement updateMetadataPreparedStatement,\n+                                                 PreparedStatement deleteContentPreparedStatement,\n+                                                 PreparedStatement insertContentPreparedStatement,\n+                                                 AndesMessage message,\n+                                                 AndesMessageMetadata metadata, RetainedItemData retainedItemData)\n+            throws SQLException {\n+        // update metadata\n+        updateMetadataPreparedStatement.setLong(1, metadata.getMessageID());\n+        updateMetadataPreparedStatement.setBytes(2, metadata.getMetadata());\n+        updateMetadataPreparedStatement.setInt(3, retainedItemData.topicID);\n+        updateMetadataPreparedStatement.addBatch();\n+\n+        // update content\n+        deleteContentPreparedStatement.setLong(1, // todo: ask asankaAB why this ?? -> retainedItemData.messageID\n+                                               retainedItemData.messageID);\n+        log.info(\"retainedItemData.messageID : \" + retainedItemData.messageID);","path":"modules/andes-core/broker/src/main/java/org/wso2/andes/store/rdbms/RDBMSMessageStoreImpl.java","position":157,"original_position":157,"commit_id":"40ebd73b29e9ebf6dc0658529fd38243c8dc97fb","original_commit_id":"40ebd73b29e9ebf6dc0658529fd38243c8dc97fb","user":{"login":"ramith","id":3402882,"avatar_url":"https://avatars.githubusercontent.com/u/3402882?v=3","gravatar_id":"","url":"https://api.github.com/users/ramith","html_url":"https://github.com/ramith","followers_url":"https://api.github.com/users/ramith/followers","following_url":"https://api.github.com/users/ramith/following{/other_user}","gists_url":"https://api.github.com/users/ramith/gists{/gist_id}","starred_url":"https://api.github.com/users/ramith/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ramith/subscriptions","organizations_url":"https://api.github.com/users/ramith/orgs","repos_url":"https://api.github.com/users/ramith/repos","events_url":"https://api.github.com/users/ramith/events{/privacy}","received_events_url":"https://api.github.com/users/ramith/received_events","type":"User","site_admin":false},"body":"please remove these in the final PR (and add meaning full logs if applicable)","created_at":"2015-05-11T06:12:16Z","updated_at":"2015-05-11T06:12:16Z","html_url":"https://github.com/wso2/andes/pull/115#discussion_r30014781","pull_request_url":"https://api.github.com/repos/wso2/andes/pulls/115","_links":{"self":{"href":"https://api.github.com/repos/wso2/andes/pulls/comments/30014781"},"html":{"href":"https://github.com/wso2/andes/pull/115#discussion_r30014781"},"pull_request":{"href":"https://api.github.com/repos/wso2/andes/pulls/115"}}},"pull_request":{"url":"https://api.github.com/repos/wso2/andes/pulls/115","id":35065808,"html_url":"https://github.com/wso2/andes/pull/115","diff_url":"https://github.com/wso2/andes/pull/115.diff","patch_url":"https://github.com/wso2/andes/pull/115.patch","issue_url":"https://api.github.com/repos/wso2/andes/issues/115","number":115,"state":"open","locked":false,"title":"[WIP][MB-867] mqtt retain feature","user":{"login":"pumudu88","id":8552767,"avatar_url":"https://avatars.githubusercontent.com/u/8552767?v=3","gravatar_id":"","url":"https://api.github.com/users/pumudu88","html_url":"https://github.com/pumudu88","followers_url":"https://api.github.com/users/pumudu88/followers","following_url":"https://api.github.com/users/pumudu88/following{/other_user}","gists_url":"https://api.github.com/users/pumudu88/gists{/gist_id}","starred_url":"https://api.github.com/users/pumudu88/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pumudu88/subscriptions","organizations_url":"https://api.github.com/users/pumudu88/orgs","repos_url":"https://api.github.com/users/pumudu88/repos","events_url":"https://api.github.com/users/pumudu88/events{/privacy}","received_events_url":"https://api.github.com/users/pumudu88/received_events","type":"User","site_admin":false},"body":"This will add retain feature to mb.\r\njira - https://wso2.org/jira/browse/MB-867","created_at":"2015-05-09T12:09:48Z","updated_at":"2015-05-11T06:12:17Z","closed_at":null,"merged_at":null,"merge_commit_sha":"e2f9957feee483259b9c3dfdf1cf0974268ae33c","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/wso2/andes/pulls/115/commits","review_comments_url":"https://api.github.com/repos/wso2/andes/pulls/115/comments","review_comment_url":"https://api.github.com/repos/wso2/andes/pulls/comments{/number}","comments_url":"https://api.github.com/repos/wso2/andes/issues/115/comments","statuses_url":"https://api.github.com/repos/wso2/andes/statuses/40ebd73b29e9ebf6dc0658529fd38243c8dc97fb","head":{"label":"pumudu88:mqtt-retain","ref":"mqtt-retain","sha":"40ebd73b29e9ebf6dc0658529fd38243c8dc97fb","user":{"login":"pumudu88","id":8552767,"avatar_url":"https://avatars.githubusercontent.com/u/8552767?v=3","gravatar_id":"","url":"https://api.github.com/users/pumudu88","html_url":"https://github.com/pumudu88","followers_url":"https://api.github.com/users/pumudu88/followers","following_url":"https://api.github.com/users/pumudu88/following{/other_user}","gists_url":"https://api.github.com/users/pumudu88/gists{/gist_id}","starred_url":"https://api.github.com/users/pumudu88/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pumudu88/subscriptions","organizations_url":"https://api.github.com/users/pumudu88/orgs","repos_url":"https://api.github.com/users/pumudu88/repos","events_url":"https://api.github.com/users/pumudu88/events{/privacy}","received_events_url":"https://api.github.com/users/pumudu88/received_events","type":"User","site_admin":false},"repo":{"id":30340525,"name":"andes","full_name":"pumudu88/andes","owner":{"login":"pumudu88","id":8552767,"avatar_url":"https://avatars.githubusercontent.com/u/8552767?v=3","gravatar_id":"","url":"https://api.github.com/users/pumudu88","html_url":"https://github.com/pumudu88","followers_url":"https://api.github.com/users/pumudu88/followers","following_url":"https://api.github.com/users/pumudu88/following{/other_user}","gists_url":"https://api.github.com/users/pumudu88/gists{/gist_id}","starred_url":"https://api.github.com/users/pumudu88/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pumudu88/subscriptions","organizations_url":"https://api.github.com/users/pumudu88/orgs","repos_url":"https://api.github.com/users/pumudu88/repos","events_url":"https://api.github.com/users/pumudu88/events{/privacy}","received_events_url":"https://api.github.com/users/pumudu88/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/pumudu88/andes","description":"","fork":true,"url":"https://api.github.com/repos/pumudu88/andes","forks_url":"https://api.github.com/repos/pumudu88/andes/forks","keys_url":"https://api.github.com/repos/pumudu88/andes/keys{/key_id}","collaborators_url":"https://api.github.com/repos/pumudu88/andes/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/pumudu88/andes/teams","hooks_url":"https://api.github.com/repos/pumudu88/andes/hooks","issue_events_url":"https://api.github.com/repos/pumudu88/andes/issues/events{/number}","events_url":"https://api.github.com/repos/pumudu88/andes/events","assignees_url":"https://api.github.com/repos/pumudu88/andes/assignees{/user}","branches_url":"https://api.github.com/repos/pumudu88/andes/branches{/branch}","tags_url":"https://api.github.com/repos/pumudu88/andes/tags","blobs_url":"https://api.github.com/repos/pumudu88/andes/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/pumudu88/andes/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/pumudu88/andes/git/refs{/sha}","trees_url":"https://api.github.com/repos/pumudu88/andes/git/trees{/sha}","statuses_url":"https://api.github.com/repos/pumudu88/andes/statuses/{sha}","languages_url":"https://api.github.com/repos/pumudu88/andes/languages","stargazers_url":"https://api.github.com/repos/pumudu88/andes/stargazers","contributors_url":"https://api.github.com/repos/pumudu88/andes/contributors","subscribers_url":"https://api.github.com/repos/pumudu88/andes/subscribers","subscription_url":"https://api.github.com/repos/pumudu88/andes/subscription","commits_url":"https://api.github.com/repos/pumudu88/andes/commits{/sha}","git_commits_url":"https://api.github.com/repos/pumudu88/andes/git/commits{/sha}","comments_url":"https://api.github.com/repos/pumudu88/andes/comments{/number}","issue_comment_url":"https://api.github.com/repos/pumudu88/andes/issues/comments{/number}","contents_url":"https://api.github.com/repos/pumudu88/andes/contents/{+path}","compare_url":"https://api.github.com/repos/pumudu88/andes/compare/{base}...{head}","merges_url":"https://api.github.com/repos/pumudu88/andes/merges","archive_url":"https://api.github.com/repos/pumudu88/andes/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/pumudu88/andes/downloads","issues_url":"https://api.github.com/repos/pumudu88/andes/issues{/number}","pulls_url":"https://api.github.com/repos/pumudu88/andes/pulls{/number}","milestones_url":"https://api.github.com/repos/pumudu88/andes/milestones{/number}","notifications_url":"https://api.github.com/repos/pumudu88/andes/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/pumudu88/andes/labels{/name}","releases_url":"https://api.github.com/repos/pumudu88/andes/releases{/id}","created_at":"2015-02-05T05:59:33Z","updated_at":"2015-04-22T07:02:28Z","pushed_at":"2015-05-09T10:35:03Z","git_url":"git://github.com/pumudu88/andes.git","ssh_url":"git@github.com:pumudu88/andes.git","clone_url":"https://github.com/pumudu88/andes.git","svn_url":"https://github.com/pumudu88/andes","homepage":null,"size":64171,"stargazers_count":0,"watchers_count":0,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":true,"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":"wso2:master","ref":"master","sha":"92ee318f8449fc4dfee1fd69bd29fd3e7c0aeea1","user":{"login":"wso2","id":533043,"avatar_url":"https://avatars.githubusercontent.com/u/533043?v=3","gravatar_id":"","url":"https://api.github.com/users/wso2","html_url":"https://github.com/wso2","followers_url":"https://api.github.com/users/wso2/followers","following_url":"https://api.github.com/users/wso2/following{/other_user}","gists_url":"https://api.github.com/users/wso2/gists{/gist_id}","starred_url":"https://api.github.com/users/wso2/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/wso2/subscriptions","organizations_url":"https://api.github.com/users/wso2/orgs","repos_url":"https://api.github.com/users/wso2/repos","events_url":"https://api.github.com/users/wso2/events{/privacy}","received_events_url":"https://api.github.com/users/wso2/received_events","type":"Organization","site_admin":false},"repo":{"id":20559270,"name":"andes","full_name":"wso2/andes","owner":{"login":"wso2","id":533043,"avatar_url":"https://avatars.githubusercontent.com/u/533043?v=3","gravatar_id":"","url":"https://api.github.com/users/wso2","html_url":"https://github.com/wso2","followers_url":"https://api.github.com/users/wso2/followers","following_url":"https://api.github.com/users/wso2/following{/other_user}","gists_url":"https://api.github.com/users/wso2/gists{/gist_id}","starred_url":"https://api.github.com/users/wso2/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/wso2/subscriptions","organizations_url":"https://api.github.com/users/wso2/orgs","repos_url":"https://api.github.com/users/wso2/repos","events_url":"https://api.github.com/users/wso2/events{/privacy}","received_events_url":"https://api.github.com/users/wso2/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/wso2/andes","description":"","fork":false,"url":"https://api.github.com/repos/wso2/andes","forks_url":"https://api.github.com/repos/wso2/andes/forks","keys_url":"https://api.github.com/repos/wso2/andes/keys{/key_id}","collaborators_url":"https://api.github.com/repos/wso2/andes/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/wso2/andes/teams","hooks_url":"https://api.github.com/repos/wso2/andes/hooks","issue_events_url":"https://api.github.com/repos/wso2/andes/issues/events{/number}","events_url":"https://api.github.com/repos/wso2/andes/events","assignees_url":"https://api.github.com/repos/wso2/andes/assignees{/user}","branches_url":"https://api.github.com/repos/wso2/andes/branches{/branch}","tags_url":"https://api.github.com/repos/wso2/andes/tags","blobs_url":"https://api.github.com/repos/wso2/andes/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/wso2/andes/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/wso2/andes/git/refs{/sha}","trees_url":"https://api.github.com/repos/wso2/andes/git/trees{/sha}","statuses_url":"https://api.github.com/repos/wso2/andes/statuses/{sha}","languages_url":"https://api.github.com/repos/wso2/andes/languages","stargazers_url":"https://api.github.com/repos/wso2/andes/stargazers","contributors_url":"https://api.github.com/repos/wso2/andes/contributors","subscribers_url":"https://api.github.com/repos/wso2/andes/subscribers","subscription_url":"https://api.github.com/repos/wso2/andes/subscription","commits_url":"https://api.github.com/repos/wso2/andes/commits{/sha}","git_commits_url":"https://api.github.com/repos/wso2/andes/git/commits{/sha}","comments_url":"https://api.github.com/repos/wso2/andes/comments{/number}","issue_comment_url":"https://api.github.com/repos/wso2/andes/issues/comments{/number}","contents_url":"https://api.github.com/repos/wso2/andes/contents/{+path}","compare_url":"https://api.github.com/repos/wso2/andes/compare/{base}...{head}","merges_url":"https://api.github.com/repos/wso2/andes/merges","archive_url":"https://api.github.com/repos/wso2/andes/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/wso2/andes/downloads","issues_url":"https://api.github.com/repos/wso2/andes/issues{/number}","pulls_url":"https://api.github.com/repos/wso2/andes/pulls{/number}","milestones_url":"https://api.github.com/repos/wso2/andes/milestones{/number}","notifications_url":"https://api.github.com/repos/wso2/andes/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/wso2/andes/labels{/name}","releases_url":"https://api.github.com/repos/wso2/andes/releases{/id}","created_at":"2014-06-06T10:04:24Z","updated_at":"2015-05-05T14:31:31Z","pushed_at":"2015-05-09T12:09:48Z","git_url":"git://github.com/wso2/andes.git","ssh_url":"git@github.com:wso2/andes.git","clone_url":"https://github.com/wso2/andes.git","svn_url":"https://github.com/wso2/andes","homepage":null,"size":66155,"stargazers_count":0,"watchers_count":0,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":34,"mirror_url":null,"open_issues_count":8,"forks":34,"open_issues":8,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/wso2/andes/pulls/115"},"html":{"href":"https://github.com/wso2/andes/pull/115"},"issue":{"href":"https://api.github.com/repos/wso2/andes/issues/115"},"comments":{"href":"https://api.github.com/repos/wso2/andes/issues/115/comments"},"review_comments":{"href":"https://api.github.com/repos/wso2/andes/pulls/115/comments"},"review_comment":{"href":"https://api.github.com/repos/wso2/andes/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/wso2/andes/pulls/115/commits"},"statuses":{"href":"https://api.github.com/repos/wso2/andes/statuses/40ebd73b29e9ebf6dc0658529fd38243c8dc97fb"}}}}