1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * This library is free software; you can redistribute it and/or modify it under
5    * the terms of the GNU Lesser General Public License as published by the Free
6    * Software Foundation; either version 2.1 of the License, or (at your option)
7    * any later version.
8    *
9    * This library is distributed in the hope that it will be useful, but WITHOUT
10   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11   * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12   * details.
13   */
14  
15  package com.liferay.portal.upgrade.v5_1_5;
16  
17  import com.liferay.portal.kernel.upgrade.UpgradeProcess;
18  
19  /**
20   * <a href="UpgradeMessageBoards.java.html"><b><i>View Source</i></b></a>
21   *
22   * @author Brian Wing Shun Chan
23   */
24  public class UpgradeMessageBoards extends UpgradeProcess {
25  
26      protected void doUpgrade() throws Exception {
27          updateGroupId();
28          updateMessageClassNameId();
29          updateMessageFlagThreadId();
30          updateMessagePriority();
31      }
32  
33      protected void updateGroupId() throws Exception {
34          StringBuilder sb = new StringBuilder();
35  
36          sb.append("update MBCategory set threadCount = (select count(*) from ");
37          sb.append("MBThread where MBThread.categoryId = ");
38          sb.append("MBCategory.categoryId)");
39  
40          runSQL(sb.toString());
41  
42          sb = new StringBuilder();
43  
44          sb.append("update MBCategory set messageCount = (select count(*) ");
45          sb.append("from MBMessage where MBMessage.categoryId = ");
46          sb.append("MBCategory.categoryId)");
47  
48          runSQL(sb.toString());
49  
50          sb = new StringBuilder();
51  
52          sb.append("update MBMessage set groupId = (select groupId from ");
53          sb.append("MBCategory where MBCategory.categoryId = ");
54          sb.append("MBMessage.categoryId)");
55  
56          runSQL(sb.toString());
57  
58          sb = new StringBuilder();
59  
60          sb.append("update MBThread set groupId = (select groupId from ");
61          sb.append("MBCategory where MBCategory.categoryId = ");
62          sb.append("MBThread.categoryId)");
63  
64          runSQL(sb.toString());
65      }
66  
67      protected void updateMessageClassNameId() throws Exception {
68          StringBuilder sb = new StringBuilder();
69  
70          sb.append("update MBMessage set classNameId = (select classNameId ");
71          sb.append("from MBDiscussion where MBDiscussion.threadId = ");
72          sb.append("MBMessage.threadId), classPK = (select classPK from ");
73          sb.append("MBDiscussion where MBDiscussion.threadId = ");
74          sb.append("MBMessage.threadId)");
75  
76          runSQL(sb.toString());
77      }
78  
79      protected void updateMessageFlagThreadId() throws Exception {
80          StringBuilder sb = new StringBuilder();
81  
82          sb.append("update MBMessageFlag set threadId = (select threadId from ");
83          sb.append("MBMessage where MBMessage.messageId = ");
84          sb.append("MBMessageFlag.messageId)");
85  
86          runSQL(sb.toString());
87      }
88  
89      protected void updateMessagePriority() throws Exception {
90          StringBuilder sb = new StringBuilder();
91  
92          sb.append("update MBMessage set priority = (select priority from ");
93          sb.append("MBThread where MBThread.threadId = MBMessage.threadId)");
94  
95          runSQL(sb.toString());
96      }
97  
98  }