1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    * Permission is hereby granted, free of charge, to any person obtaining a copy
5    * of this software and associated documentation files (the "Software"), to deal
6    * in the Software without restriction, including without limitation the rights
7    * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8    * copies of the Software, and to permit persons to whom the Software is
9    * furnished to do so, subject to the following conditions:
10   *
11   * The above copyright notice and this permission notice shall be included in
12   * all copies or substantial portions of the Software.
13   *
14   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20   * SOFTWARE.
21   */
22  
23  package com.liferay.portal.upgrade.v5_1_5;
24  
25  import com.liferay.portal.upgrade.UpgradeProcess;
26  
27  /**
28   * <a href="UpgradeMessageBoards.java.html"><b><i>View Source</i></b></a>
29   *
30   * @author Brian Wing Shun Chan
31   */
32  public class UpgradeMessageBoards extends UpgradeProcess {
33  
34      protected void doUpgrade() throws Exception {
35          updateGroupId();
36          updateMessageClassNameId();
37          updateMessageFlagThreadId();
38          updateMessagePriority();
39      }
40  
41      protected void updateGroupId() throws Exception {
42          StringBuilder sb = new StringBuilder();
43  
44          sb.append("update MBCategory set threadCount = (select count(*) from ");
45          sb.append("MBThread where MBThread.categoryId = ");
46          sb.append("MBCategory.categoryId)");
47  
48          runSQL(sb.toString());
49  
50          sb = new StringBuilder();
51  
52          sb.append("update MBCategory set messageCount = (select count(*) ");
53          sb.append("from MBMessage where MBMessage.categoryId = ");
54          sb.append("MBCategory.categoryId)");
55  
56          runSQL(sb.toString());
57  
58          sb = new StringBuilder();
59  
60          sb.append("update MBMessage set groupId = (select groupId from ");
61          sb.append("MBCategory where MBCategory.categoryId = ");
62          sb.append("MBMessage.categoryId)");
63  
64          runSQL(sb.toString());
65  
66          sb = new StringBuilder();
67  
68          sb.append("update MBThread set groupId = (select groupId from ");
69          sb.append("MBCategory where MBCategory.categoryId = ");
70          sb.append("MBThread.categoryId)");
71  
72          runSQL(sb.toString());
73      }
74  
75      protected void updateMessageClassNameId() throws Exception {
76          StringBuilder sb = new StringBuilder();
77  
78          sb.append("update MBMessage set classNameId = (select classNameId ");
79          sb.append("from MBDiscussion where MBDiscussion.threadId = ");
80          sb.append("MBMessage.threadId), classPK = (select classPK from ");
81          sb.append("MBDiscussion where MBDiscussion.threadId = ");
82          sb.append("MBMessage.threadId)");
83  
84          runSQL(sb.toString());
85      }
86  
87      protected void updateMessageFlagThreadId() throws Exception {
88          StringBuilder sb = new StringBuilder();
89  
90          sb.append("update MBMessageFlag set threadId = (select threadId from ");
91          sb.append("MBMessage where MBMessage.messageId = ");
92          sb.append("MBMessageFlag.messageId)");
93  
94          runSQL(sb.toString());
95      }
96  
97      protected void updateMessagePriority() throws Exception {
98          StringBuilder sb = new StringBuilder();
99  
100         sb.append("update MBMessage set priority = (select priority from ");
101         sb.append("MBThread where MBThread.threadId = MBMessage.threadId)");
102 
103         runSQL(sb.toString());
104     }
105 
106 }