001    /**
002     * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
013     */
014    
015    package com.liferay.portal.upgrade.v4_3_0;
016    
017    import com.liferay.portal.kernel.upgrade.UpgradeProcess;
018    import com.liferay.portal.kernel.upgrade.util.SwapUpgradeColumnImpl;
019    import com.liferay.portal.kernel.upgrade.util.UpgradeColumn;
020    import com.liferay.portal.kernel.upgrade.util.UpgradeTable;
021    import com.liferay.portal.kernel.upgrade.util.UpgradeTableFactoryUtil;
022    import com.liferay.portal.upgrade.util.PKUpgradeColumnImpl;
023    import com.liferay.portal.upgrade.v4_3_0.util.AvailableMappersUtil;
024    import com.liferay.portal.upgrade.v4_3_0.util.ClassNameIdUpgradeColumnImpl;
025    import com.liferay.portal.upgrade.v4_3_0.util.ClassPKContainer;
026    import com.liferay.portal.upgrade.v4_3_0.util.ClassPKUpgradeColumnImpl;
027    import com.liferay.portal.upgrade.v4_3_0.util.SubscriptionTable;
028    import com.liferay.portal.util.PortalUtil;
029    import com.liferay.portlet.messageboards.model.MBCategory;
030    
031    import java.sql.Types;
032    
033    import java.util.HashMap;
034    import java.util.Map;
035    
036    /**
037     * @author Alexander Chow
038     * @author Brian Wing Shun Chan
039     */
040    public class UpgradeSubscription extends UpgradeProcess {
041    
042            protected void doUpgrade() throws Exception {
043    
044                    // Subscription
045    
046                    UpgradeColumn upgradeUserIdColumn = new SwapUpgradeColumnImpl(
047                            "userId", new Integer(Types.VARCHAR),
048                            AvailableMappersUtil.getUserIdMapper());
049    
050                    ClassNameIdUpgradeColumnImpl classNameIdColumn =
051                            new ClassNameIdUpgradeColumnImpl();
052    
053                    Map<Long, ClassPKContainer> classPKContainers =
054                            new HashMap<Long, ClassPKContainer>();
055    
056                    classPKContainers.put(
057                            new Long(PortalUtil.getClassNameId(MBCategory.class.getName())),
058                            new ClassPKContainer(
059                                    AvailableMappersUtil.getMBCategoryIdMapper(), true));
060    
061                    UpgradeColumn upgradeClassPKColumn = new ClassPKUpgradeColumnImpl(
062                            classNameIdColumn, classPKContainers);
063    
064                    UpgradeTable upgradeTable = UpgradeTableFactoryUtil.getUpgradeTable(
065                            SubscriptionTable.TABLE_NAME, SubscriptionTable.TABLE_COLUMNS,
066                            new PKUpgradeColumnImpl("subscriptionId", false),
067                            upgradeUserIdColumn, classNameIdColumn, upgradeClassPKColumn);
068    
069                    upgradeTable.setCreateSQL(SubscriptionTable.TABLE_SQL_CREATE);
070    
071                    upgradeTable.updateTable();
072            }
073    
074    }