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_2_3;
16  
17  import com.liferay.portal.kernel.upgrade.UpgradeProcess;
18  import com.liferay.portal.kernel.util.StringBundler;
19  
20  /**
21   * <a href="UpgradeMessageBoards.java.html"><b><i>View Source</i></b></a>
22   *
23   * @author Brian Wing Shun Chan
24   */
25  public class UpgradeMessageBoards extends UpgradeProcess {
26  
27      protected void doUpgrade() throws Exception {
28          updateGroupId();
29          updateMessageClassNameId();
30          updateMessageFlagThreadId();
31          updateMessagePriority();
32      }
33  
34      protected void updateGroupId() throws Exception {
35          StringBundler sb = new StringBundler(3);
36  
37          sb.append("update MBCategory set threadCount = (select count(*) from ");
38          sb.append("MBThread where MBThread.categoryId = ");
39          sb.append("MBCategory.categoryId)");
40  
41          runSQL(sb.toString());
42  
43          sb.setIndex(0);
44  
45          sb.append("update MBCategory set messageCount = (select count(*) ");
46          sb.append("from MBMessage where MBMessage.categoryId = ");
47          sb.append("MBCategory.categoryId)");
48  
49          runSQL(sb.toString());
50  
51          sb.setIndex(0);
52  
53          sb.append("update MBMessage set groupId = (select groupId from ");
54          sb.append("MBCategory where MBCategory.categoryId = ");
55          sb.append("MBMessage.categoryId)");
56  
57          runSQL(sb.toString());
58  
59          sb.setIndex(0);
60  
61          sb.append("update MBThread set groupId = (select groupId from ");
62          sb.append("MBCategory where MBCategory.categoryId = ");
63          sb.append("MBThread.categoryId)");
64  
65          runSQL(sb.toString());
66      }
67  
68      protected void updateMessageClassNameId() throws Exception {
69          StringBundler sb = new StringBundler(5);
70  
71          sb.append("update MBMessage set classNameId = (select classNameId ");
72          sb.append("from MBDiscussion where MBDiscussion.threadId = ");
73          sb.append("MBMessage.threadId), classPK = (select classPK from ");
74          sb.append("MBDiscussion where MBDiscussion.threadId = ");
75          sb.append("MBMessage.threadId)");
76  
77          runSQL(sb.toString());
78      }
79  
80      protected void updateMessageFlagThreadId() throws Exception {
81          StringBundler sb = new StringBundler(3);
82  
83          sb.append("update MBMessageFlag set threadId = (select threadId from ");
84          sb.append("MBMessage where MBMessage.messageId = ");
85          sb.append("MBMessageFlag.messageId)");
86  
87          runSQL(sb.toString());
88      }
89  
90      protected void updateMessagePriority() throws Exception {
91          StringBundler sb = new StringBundler(2);
92  
93          sb.append("update MBMessage set priority = (select priority from ");
94          sb.append("MBThread where MBThread.threadId = MBMessage.threadId)");
95  
96          runSQL(sb.toString());
97      }
98  
99  }