001    /**
002     * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portal.upgrade.v5_2_3;
016    
017    import com.liferay.portal.kernel.upgrade.UpgradeProcess;
018    import com.liferay.portal.kernel.util.StringBundler;
019    
020    /**
021     * @author Brian Wing Shun Chan
022     */
023    public class UpgradeMessageBoards extends UpgradeProcess {
024    
025            protected void doUpgrade() throws Exception {
026                    updateGroupId();
027                    updateMessageClassNameId();
028                    updateMessageFlagThreadId();
029                    updateMessagePriority();
030            }
031    
032            protected void updateGroupId() throws Exception {
033                    StringBundler sb = new StringBundler(3);
034    
035                    sb.append("update MBCategory set threadCount = (select count(*) from ");
036                    sb.append("MBThread where MBThread.categoryId = ");
037                    sb.append("MBCategory.categoryId)");
038    
039                    runSQL(sb.toString());
040    
041                    sb.setIndex(0);
042    
043                    sb.append("update MBCategory set messageCount = (select count(*) ");
044                    sb.append("from MBMessage where MBMessage.categoryId = ");
045                    sb.append("MBCategory.categoryId)");
046    
047                    runSQL(sb.toString());
048    
049                    sb.setIndex(0);
050    
051                    sb.append("update MBMessage set groupId = (select groupId from ");
052                    sb.append("MBCategory where MBCategory.categoryId = ");
053                    sb.append("MBMessage.categoryId)");
054    
055                    runSQL(sb.toString());
056    
057                    sb.setIndex(0);
058    
059                    sb.append("update MBThread set groupId = (select groupId from ");
060                    sb.append("MBCategory where MBCategory.categoryId = ");
061                    sb.append("MBThread.categoryId)");
062    
063                    runSQL(sb.toString());
064            }
065    
066            protected void updateMessageClassNameId() throws Exception {
067                    StringBundler sb = new StringBundler(5);
068    
069                    sb.append("update MBMessage set classNameId = (select classNameId ");
070                    sb.append("from MBDiscussion where MBDiscussion.threadId = ");
071                    sb.append("MBMessage.threadId), classPK = (select classPK from ");
072                    sb.append("MBDiscussion where MBDiscussion.threadId = ");
073                    sb.append("MBMessage.threadId)");
074    
075                    runSQL(sb.toString());
076            }
077    
078            protected void updateMessageFlagThreadId() throws Exception {
079                    StringBundler sb = new StringBundler(3);
080    
081                    sb.append("update MBMessageFlag set threadId = (select threadId from ");
082                    sb.append("MBMessage where MBMessage.messageId = ");
083                    sb.append("MBMessageFlag.messageId)");
084    
085                    runSQL(sb.toString());
086            }
087    
088            protected void updateMessagePriority() throws Exception {
089                    StringBundler sb = new StringBundler(2);
090    
091                    sb.append("update MBMessage set priority = (select priority from ");
092                    sb.append("MBThread where MBThread.threadId = MBMessage.threadId)");
093    
094                    runSQL(sb.toString());
095            }
096    
097    }