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.model.Contact;
023    import com.liferay.portal.model.Organization;
024    import com.liferay.portal.upgrade.util.PKUpgradeColumnImpl;
025    import com.liferay.portal.upgrade.v4_3_0.util.AvailableMappersUtil;
026    import com.liferay.portal.upgrade.v4_3_0.util.ClassNameIdUpgradeColumnImpl;
027    import com.liferay.portal.upgrade.v4_3_0.util.ClassPKContainer;
028    import com.liferay.portal.upgrade.v4_3_0.util.ClassPKUpgradeColumnImpl;
029    import com.liferay.portal.upgrade.v4_3_0.util.ValueMapperUtil;
030    import com.liferay.portal.upgrade.v4_3_0.util.WebsiteTable;
031    import com.liferay.portal.util.PortalUtil;
032    
033    import java.sql.Types;
034    
035    import java.util.HashMap;
036    import java.util.Map;
037    
038    /**
039     * @author Alexander Chow
040     * @author Brian Wing Shun Chan
041     */
042    public class UpgradeWebsite extends UpgradeProcess {
043    
044            protected void doUpgrade() throws Exception {
045    
046                    // Website
047    
048                    UpgradeColumn upgradeUserIdColumn = new SwapUpgradeColumnImpl(
049                            "userId", new Integer(Types.VARCHAR),
050                            AvailableMappersUtil.getUserIdMapper());
051    
052                    PKUpgradeColumnImpl upgradePKColumn = new PKUpgradeColumnImpl(
053                            "websiteId", true);
054    
055                    ClassNameIdUpgradeColumnImpl classNameIdColumn =
056                            new ClassNameIdUpgradeColumnImpl();
057    
058                    Map<Long, ClassPKContainer> classPKContainers =
059                            new HashMap<Long, ClassPKContainer>();
060    
061                    classPKContainers.put(
062                            new Long(PortalUtil.getClassNameId(Contact.class.getName())),
063                            new ClassPKContainer(
064                                    AvailableMappersUtil.getContactIdMapper(), false));
065    
066                    classPKContainers.put(
067                            new Long(PortalUtil.getClassNameId(Organization.class.getName())),
068                            new ClassPKContainer(
069                                    AvailableMappersUtil.getOrganizationIdMapper(), true));
070    
071                    UpgradeColumn upgradeClassPKColumn = new ClassPKUpgradeColumnImpl(
072                            classNameIdColumn, classPKContainers);
073    
074                    UpgradeTable upgradeTable = UpgradeTableFactoryUtil.getUpgradeTable(
075                            WebsiteTable.TABLE_NAME, WebsiteTable.TABLE_COLUMNS,
076                            upgradePKColumn, upgradeUserIdColumn, classNameIdColumn,
077                            upgradeClassPKColumn);
078    
079                    upgradeTable.setCreateSQL(WebsiteTable.TABLE_SQL_CREATE);
080    
081                    upgradeTable.updateTable();
082    
083                    ValueMapperUtil.persist(upgradePKColumn.getValueMapper(), "website-id");
084            }
085    
086    }