1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    *
5    *
6    *
7    * The contents of this file are subject to the terms of the Liferay Enterprise
8    * Subscription License ("License"). You may not use this file except in
9    * compliance with the License. You can obtain a copy of the License by
10   * contacting Liferay, Inc. See the License for the specific language governing
11   * permissions and limitations under the License, including but not limited to
12   * distribution rights 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.v4_3_0;
24  
25  import com.liferay.portal.upgrade.UpgradeProcess;
26  import com.liferay.portal.upgrade.util.DefaultPKMapper;
27  import com.liferay.portal.upgrade.util.DefaultUpgradeTableImpl;
28  import com.liferay.portal.upgrade.util.LazyPKUpgradeColumnImpl;
29  import com.liferay.portal.upgrade.util.PKUpgradeColumnImpl;
30  import com.liferay.portal.upgrade.util.SwapUpgradeColumnImpl;
31  import com.liferay.portal.upgrade.util.UpgradeColumn;
32  import com.liferay.portal.upgrade.util.UpgradeTable;
33  import com.liferay.portal.upgrade.util.ValueMapper;
34  import com.liferay.portal.upgrade.v4_3_0.util.AvailableMappersUtil;
35  import com.liferay.portal.upgrade.v4_3_0.util.ClassNameIdUpgradeColumnImpl;
36  import com.liferay.portal.upgrade.v4_3_0.util.ClassPKContainer;
37  import com.liferay.portal.upgrade.v4_3_0.util.ClassPKUpgradeColumnImpl;
38  import com.liferay.portal.upgrade.v4_3_0.util.MBCategoryIdUpgradeColumnImpl;
39  import com.liferay.portal.upgrade.v4_3_0.util.MBCategoryTable;
40  import com.liferay.portal.upgrade.v4_3_0.util.MBDiscussionTable;
41  import com.liferay.portal.upgrade.v4_3_0.util.MBMessageAttachmentsUpgradeColumnImpl;
42  import com.liferay.portal.upgrade.v4_3_0.util.MBMessageFlagTable;
43  import com.liferay.portal.upgrade.v4_3_0.util.MBMessageTable;
44  import com.liferay.portal.upgrade.v4_3_0.util.MBStatsUserTable;
45  import com.liferay.portal.upgrade.v4_3_0.util.MBThreadTable;
46  import com.liferay.portal.util.PortalUtil;
47  import com.liferay.portlet.blogs.model.BlogsEntry;
48  
49  import java.sql.Types;
50  
51  import java.util.HashMap;
52  import java.util.Map;
53  
54  /**
55   * <a href="UpgradeMessageBoards.java.html"><b><i>View Source</i></b></a>
56   *
57   * @author Brian Wing Shun Chan
58   */
59  public class UpgradeMessageBoards extends UpgradeProcess {
60  
61      protected void doUpgrade() throws Exception {
62  
63          // MBCategory
64  
65          UpgradeColumn upgradeCompanyIdColumn = new SwapUpgradeColumnImpl(
66              "companyId", new Integer(Types.VARCHAR),
67              AvailableMappersUtil.getCompanyIdMapper());
68  
69          UpgradeColumn upgradeGroupIdColumn = new SwapUpgradeColumnImpl(
70              "groupId", AvailableMappersUtil.getGroupIdMapper());
71  
72          UpgradeColumn upgradeUserIdColumn = new SwapUpgradeColumnImpl(
73              "userId", new Integer(Types.VARCHAR),
74              AvailableMappersUtil.getUserIdMapper());
75  
76          PKUpgradeColumnImpl upgradePKColumn =
77              new MBCategoryIdUpgradeColumnImpl();
78  
79          UpgradeTable upgradeTable = new DefaultUpgradeTableImpl(
80              MBCategoryTable.TABLE_NAME, MBCategoryTable.TABLE_COLUMNS,
81              upgradePKColumn, upgradeGroupIdColumn, upgradeUserIdColumn);
82  
83          upgradeTable.setCreateSQL(MBCategoryTable.TABLE_SQL_CREATE);
84  
85          upgradeTable.updateTable();
86  
87          ValueMapper categoryIdMapper = new DefaultPKMapper(
88              upgradePKColumn.getValueMapper());
89  
90          AvailableMappersUtil.setMBCategoryIdMapper(categoryIdMapper);
91  
92          UpgradeColumn upgradeParentCategoryIdColumn = new SwapUpgradeColumnImpl(
93              "parentCategoryId", categoryIdMapper);
94  
95          upgradeTable = new DefaultUpgradeTableImpl(
96              MBCategoryTable.TABLE_NAME, MBCategoryTable.TABLE_COLUMNS,
97              upgradeParentCategoryIdColumn);
98  
99          upgradeTable.updateTable();
100 
101         UpgradeColumn upgradeCategoryIdColumn = new SwapUpgradeColumnImpl(
102             "categoryId", categoryIdMapper);
103 
104         // MBMessage
105 
106         upgradePKColumn = new PKUpgradeColumnImpl("messageId", true);
107 
108         PKUpgradeColumnImpl upgradeThreadIdPKColumn =
109             new LazyPKUpgradeColumnImpl("threadId");
110 
111         UpgradeColumn upgradeAttachmentsColumn =
112             new MBMessageAttachmentsUpgradeColumnImpl(
113                 upgradePKColumn, upgradeCompanyIdColumn,
114             upgradeThreadIdPKColumn);
115 
116         upgradeTable = new DefaultUpgradeTableImpl(
117             MBMessageTable.TABLE_NAME, MBMessageTable.TABLE_COLUMNS,
118             upgradePKColumn, upgradeCompanyIdColumn, upgradeUserIdColumn,
119             upgradeCategoryIdColumn, upgradeThreadIdPKColumn,
120             upgradeAttachmentsColumn);
121 
122         upgradeTable.setCreateSQL(MBMessageTable.TABLE_SQL_CREATE);
123 
124         upgradeTable.updateTable();
125 
126         ValueMapper messageIdMapper = new DefaultPKMapper(
127             upgradePKColumn.getValueMapper());
128 
129         AvailableMappersUtil.setMBMessageIdMapper(messageIdMapper);
130 
131         ValueMapper threadIdMapper = upgradeThreadIdPKColumn.getValueMapper();
132 
133         AvailableMappersUtil.setMBThreadIdMapper(threadIdMapper);
134 
135         UpgradeColumn upgradeParentMessageIdColumn = new SwapUpgradeColumnImpl(
136             "parentMessageId", messageIdMapper);
137 
138         upgradeTable = new DefaultUpgradeTableImpl(
139             MBMessageTable.TABLE_NAME, MBMessageTable.TABLE_COLUMNS,
140             upgradeParentMessageIdColumn);
141 
142         upgradeTable.updateTable();
143 
144         UpgradeColumn upgradeMessageIdColumn = new SwapUpgradeColumnImpl(
145             "messageId", messageIdMapper);
146 
147         UpgradeColumn upgradeRootMessageIdColumn = new SwapUpgradeColumnImpl(
148             "rootMessageId", messageIdMapper);
149 
150         // MBMessageFlag
151 
152         upgradePKColumn = new PKUpgradeColumnImpl("messageFlagId", true);
153 
154         upgradeTable = new DefaultUpgradeTableImpl(
155             MBMessageFlagTable.TABLE_NAME, MBMessageFlagTable.TABLE_COLUMNS,
156             upgradePKColumn, upgradeUserIdColumn, upgradeMessageIdColumn);
157 
158         upgradeTable.setCreateSQL(MBMessageFlagTable.TABLE_SQL_CREATE);
159 
160         upgradeTable.updateTable();
161 
162         // MBStatsUser
163 
164         upgradeTable = new DefaultUpgradeTableImpl(
165             MBStatsUserTable.TABLE_NAME, MBStatsUserTable.TABLE_COLUMNS,
166             new PKUpgradeColumnImpl("statsUserId", false),
167             upgradeGroupIdColumn, upgradeUserIdColumn);
168 
169         upgradeTable.setCreateSQL(MBStatsUserTable.TABLE_SQL_CREATE);
170 
171         upgradeTable.updateTable();
172 
173         // MBThread
174 
175         UpgradeColumn upgradeThreadIdColumn = new SwapUpgradeColumnImpl(
176             "threadId", threadIdMapper);
177 
178         UpgradeColumn upgradeLastPostByUserIdColumn = new SwapUpgradeColumnImpl(
179             "lastPostByUserId", new Integer(Types.VARCHAR),
180             AvailableMappersUtil.getUserIdMapper());
181 
182         upgradeTable = new DefaultUpgradeTableImpl(
183             MBThreadTable.TABLE_NAME, MBThreadTable.TABLE_COLUMNS,
184             upgradeThreadIdColumn, upgradeCategoryIdColumn,
185             upgradeRootMessageIdColumn, upgradeLastPostByUserIdColumn);
186 
187         upgradeTable.setCreateSQL(MBThreadTable.TABLE_SQL_CREATE);
188 
189         upgradeTable.updateTable();
190 
191         // MBDiscussion
192 
193         ClassNameIdUpgradeColumnImpl classNameIdColumn =
194             new ClassNameIdUpgradeColumnImpl();
195 
196         Map<Long, ClassPKContainer> classPKContainers =
197             new HashMap<Long, ClassPKContainer>();
198 
199         classPKContainers.put(
200             new Long(PortalUtil.getClassNameId(BlogsEntry.class.getName())),
201             new ClassPKContainer(
202                 AvailableMappersUtil.getBlogsEntryIdMapper(), true));
203 
204         UpgradeColumn upgradeClassPKColumn = new ClassPKUpgradeColumnImpl(
205             classNameIdColumn, classPKContainers);
206 
207         upgradeTable = new DefaultUpgradeTableImpl(
208             MBDiscussionTable.TABLE_NAME, MBDiscussionTable.TABLE_COLUMNS,
209             new PKUpgradeColumnImpl("discussionId", false),
210             classNameIdColumn, upgradeClassPKColumn, upgradeThreadIdColumn);
211 
212         upgradeTable.setCreateSQL(MBDiscussionTable.TABLE_SQL_CREATE);
213 
214         upgradeTable.updateTable();
215     }
216 
217 }