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.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.RatingsEntryTable;
028    import com.liferay.portal.upgrade.v4_3_0.util.RatingsStatsTable;
029    import com.liferay.portal.util.PortalUtil;
030    import com.liferay.portlet.documentlibrary.model.DLFileEntry;
031    
032    import java.sql.Types;
033    
034    import java.util.HashMap;
035    import java.util.Map;
036    
037    /**
038     * @author Brian Wing Shun Chan
039     */
040    public class UpgradeRatings extends UpgradeProcess {
041    
042            protected void doUpgrade() throws Exception {
043    
044                    // RatingsEntry
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(DLFileEntry.class.getName())),
058                            new ClassPKContainer(
059                                    AvailableMappersUtil.getDLFileEntryIdMapper(), false));
060    
061                    UpgradeColumn upgradeClassPKColumn = new ClassPKUpgradeColumnImpl(
062                            classNameIdColumn, classPKContainers);
063    
064                    UpgradeTable upgradeTable = UpgradeTableFactoryUtil.getUpgradeTable(
065                            RatingsEntryTable.TABLE_NAME, RatingsEntryTable.TABLE_COLUMNS,
066                            new PKUpgradeColumnImpl("entryId", false), upgradeUserIdColumn,
067                            classNameIdColumn, upgradeClassPKColumn);
068    
069                    upgradeTable.setCreateSQL(RatingsEntryTable.TABLE_SQL_CREATE);
070    
071                    upgradeTable.updateTable();
072    
073                    // RatingsStats
074    
075                    upgradeTable = UpgradeTableFactoryUtil.getUpgradeTable(
076                            RatingsStatsTable.TABLE_NAME, RatingsStatsTable.TABLE_COLUMNS,
077                            new PKUpgradeColumnImpl("statsId", false), classNameIdColumn,
078                            upgradeClassPKColumn);
079    
080                    upgradeTable.setCreateSQL(RatingsStatsTable.TABLE_SQL_CREATE);
081    
082                    upgradeTable.updateTable();
083            }
084    
085    }