1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * The contents of this file are subject to the terms of the Liferay Enterprise
5    * Subscription License ("License"). You may not use this file except in
6    * compliance with the License. You can obtain a copy of the License by
7    * contacting Liferay, Inc. See the License for the specific language governing
8    * permissions and limitations under the License, including but not limited to
9    * distribution rights of the Software.
10   *
11   *
12   *
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.kernel.upgrade.util.ValueMapper;
23  import com.liferay.portal.upgrade.util.PKUpgradeColumnImpl;
24  import com.liferay.portal.upgrade.v4_3_0.util.AvailableMappersUtil;
25  import com.liferay.portal.upgrade.v4_3_0.util.PollsChoiceIdUpgradeColumnImpl;
26  import com.liferay.portal.upgrade.v4_3_0.util.PollsChoiceTable;
27  import com.liferay.portal.upgrade.v4_3_0.util.PollsQuestionTable;
28  import com.liferay.portal.upgrade.v4_3_0.util.PollsVoteChoiceIdUpgradeColumnImpl;
29  import com.liferay.portal.upgrade.v4_3_0.util.PollsVoteTable;
30  
31  import java.sql.Types;
32  
33  /**
34   * <a href="UpgradePolls.java.html"><b><i>View Source</i></b></a>
35   *
36   * @author Brian Wing Shun Chan
37   */
38  public class UpgradePolls extends UpgradeProcess {
39  
40      protected void doUpgrade() throws Exception {
41  
42          // PollsQuestion
43  
44          UpgradeColumn upgradeGroupIdColumn = new SwapUpgradeColumnImpl(
45              "groupId", AvailableMappersUtil.getGroupIdMapper());
46  
47          UpgradeColumn upgradeUserIdColumn = new SwapUpgradeColumnImpl(
48              "userId", new Integer(Types.VARCHAR),
49              AvailableMappersUtil.getUserIdMapper());
50  
51          PKUpgradeColumnImpl upgradePKColumn = new PKUpgradeColumnImpl(
52              "questionId", true);
53  
54          UpgradeTable upgradeTable = UpgradeTableFactoryUtil.getUpgradeTable(
55              PollsQuestionTable.TABLE_NAME, PollsQuestionTable.TABLE_COLUMNS,
56              upgradePKColumn, upgradeGroupIdColumn, upgradeUserIdColumn);
57  
58          upgradeTable.setCreateSQL(PollsQuestionTable.TABLE_SQL_CREATE);
59  
60          upgradeTable.updateTable();
61  
62          ValueMapper questionIdMapper = upgradePKColumn.getValueMapper();
63  
64          AvailableMappersUtil.setPollsQuestionIdMapper(questionIdMapper);
65  
66          UpgradeColumn upgradeQuestionIdColumn = new SwapUpgradeColumnImpl(
67              "questionId", questionIdMapper);
68  
69          // PollsChoice
70  
71          PKUpgradeColumnImpl upgradeChoiceId =
72              new PollsChoiceIdUpgradeColumnImpl(upgradeQuestionIdColumn);
73  
74          upgradeTable = UpgradeTableFactoryUtil.getUpgradeTable(
75              PollsChoiceTable.TABLE_NAME, PollsChoiceTable.TABLE_COLUMNS,
76              upgradeQuestionIdColumn, upgradeChoiceId);
77  
78          upgradeTable.setCreateSQL(PollsChoiceTable.TABLE_SQL_CREATE);
79  
80          upgradeTable.updateTable();
81  
82          ValueMapper choiceIdMapper = upgradeChoiceId.getValueMapper();
83  
84          // PollsVote
85  
86          UpgradeColumn upgradeVoteChoiceIdColumn =
87              new PollsVoteChoiceIdUpgradeColumnImpl(
88                  upgradeQuestionIdColumn, choiceIdMapper);
89  
90          upgradeTable = UpgradeTableFactoryUtil.getUpgradeTable(
91              PollsVoteTable.TABLE_NAME, PollsVoteTable.TABLE_COLUMNS,
92              new PKUpgradeColumnImpl("voteId", false), upgradeUserIdColumn,
93              upgradeQuestionIdColumn, upgradeVoteChoiceIdColumn);
94  
95          upgradeTable.setCreateSQL(PollsVoteTable.TABLE_SQL_CREATE);
96  
97          upgradeTable.updateTable();
98      }
99  
100 }