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.RatingsEntryTable;
28  import com.liferay.portal.upgrade.v4_3_0.util.RatingsStatsTable;
29  import com.liferay.portal.util.PortalUtil;
30  import com.liferay.portlet.documentlibrary.model.DLFileEntry;
31  
32  import java.sql.Types;
33  
34  import java.util.HashMap;
35  import java.util.Map;
36  
37  /**
38   * <a href="UpgradeRatings.java.html"><b><i>View Source</i></b></a>
39   *
40   * @author Brian Wing Shun Chan
41   */
42  public class UpgradeRatings extends UpgradeProcess {
43  
44      protected void doUpgrade() throws Exception {
45  
46          // RatingsEntry
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(DLFileEntry.class.getName())),
60              new ClassPKContainer(
61                  AvailableMappersUtil.getDLFileEntryIdMapper(), false));
62  
63          UpgradeColumn upgradeClassPKColumn = new ClassPKUpgradeColumnImpl(
64              classNameIdColumn, classPKContainers);
65  
66          UpgradeTable upgradeTable = UpgradeTableFactoryUtil.getUpgradeTable(
67              RatingsEntryTable.TABLE_NAME, RatingsEntryTable.TABLE_COLUMNS,
68              new PKUpgradeColumnImpl("entryId", false), upgradeUserIdColumn,
69              classNameIdColumn, upgradeClassPKColumn);
70  
71          upgradeTable.setCreateSQL(RatingsEntryTable.TABLE_SQL_CREATE);
72  
73          upgradeTable.updateTable();
74  
75          // RatingsStats
76  
77          upgradeTable = UpgradeTableFactoryUtil.getUpgradeTable(
78              RatingsStatsTable.TABLE_NAME, RatingsStatsTable.TABLE_COLUMNS,
79              new PKUpgradeColumnImpl("statsId", false), classNameIdColumn,
80              upgradeClassPKColumn);
81  
82          upgradeTable.setCreateSQL(RatingsStatsTable.TABLE_SQL_CREATE);
83  
84          upgradeTable.updateTable();
85      }
86  
87  }