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.v4_3_0;
16  
17  import com.liferay.portal.kernel.upgrade.UpgradeProcess;
18  import com.liferay.portal.kernel.upgrade.util.SwapUpgradeColumnImpl;
19  import com.liferay.portal.kernel.upgrade.util.UpgradeColumn;
20  import com.liferay.portal.kernel.upgrade.util.UpgradeTable;
21  import com.liferay.portal.kernel.upgrade.util.UpgradeTableFactoryUtil;
22  import com.liferay.portal.upgrade.util.PKUpgradeColumnImpl;
23  import com.liferay.portal.upgrade.v4_3_0.util.AvailableMappersUtil;
24  import com.liferay.portal.upgrade.v4_3_0.util.ClassNameIdUpgradeColumnImpl;
25  import com.liferay.portal.upgrade.v4_3_0.util.ClassPKContainer;
26  import com.liferay.portal.upgrade.v4_3_0.util.ClassPKUpgradeColumnImpl;
27  import com.liferay.portal.upgrade.v4_3_0.util.SubscriptionTable;
28  import com.liferay.portal.util.PortalUtil;
29  import com.liferay.portlet.messageboards.model.MBCategory;
30  
31  import java.sql.Types;
32  
33  import java.util.HashMap;
34  import java.util.Map;
35  
36  /**
37   * <a href="UpgradeSubscription.java.html"><b><i>View Source</i></b></a>
38   *
39   * @author Alexander Chow
40   * @author Brian Wing Shun Chan
41   */
42  public class UpgradeSubscription extends UpgradeProcess {
43  
44      protected void doUpgrade() throws Exception {
45  
46          // Subscription
47  
48          UpgradeColumn upgradeUserIdColumn = new SwapUpgradeColumnImpl(
49              "userId", new Integer(Types.VARCHAR),
50              AvailableMappersUtil.getUserIdMapper());
51  
52          ClassNameIdUpgradeColumnImpl classNameIdColumn =
53              new ClassNameIdUpgradeColumnImpl();
54  
55          Map<Long, ClassPKContainer> classPKContainers =
56              new HashMap<Long, ClassPKContainer>();
57  
58          classPKContainers.put(
59              new Long(PortalUtil.getClassNameId(MBCategory.class.getName())),
60              new ClassPKContainer(
61                  AvailableMappersUtil.getMBCategoryIdMapper(), true));
62  
63          UpgradeColumn upgradeClassPKColumn = new ClassPKUpgradeColumnImpl(
64              classNameIdColumn, classPKContainers);
65  
66          UpgradeTable upgradeTable = UpgradeTableFactoryUtil.getUpgradeTable(
67              SubscriptionTable.TABLE_NAME, SubscriptionTable.TABLE_COLUMNS,
68              new PKUpgradeColumnImpl("subscriptionId", false),
69              upgradeUserIdColumn, classNameIdColumn, upgradeClassPKColumn);
70  
71          upgradeTable.setCreateSQL(SubscriptionTable.TABLE_SQL_CREATE);
72  
73          upgradeTable.updateTable();
74      }
75  
76  }