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.model.Contact;
23  import com.liferay.portal.model.Organization;
24  import com.liferay.portal.upgrade.util.PKUpgradeColumnImpl;
25  import com.liferay.portal.upgrade.v4_3_0.util.AvailableMappersUtil;
26  import com.liferay.portal.upgrade.v4_3_0.util.ClassNameIdUpgradeColumnImpl;
27  import com.liferay.portal.upgrade.v4_3_0.util.ClassPKContainer;
28  import com.liferay.portal.upgrade.v4_3_0.util.ClassPKUpgradeColumnImpl;
29  import com.liferay.portal.upgrade.v4_3_0.util.PhoneTable;
30  import com.liferay.portal.upgrade.v4_3_0.util.ValueMapperUtil;
31  import com.liferay.portal.util.PortalUtil;
32  
33  import java.sql.Types;
34  
35  import java.util.HashMap;
36  import java.util.Map;
37  
38  /**
39   * <a href="UpgradePhone.java.html"><b><i>View Source</i></b></a>
40   *
41   * @author Alexander Chow
42   * @author Brian Wing Shun Chan
43   */
44  public class UpgradePhone extends UpgradeProcess {
45  
46      protected void doUpgrade() throws Exception {
47  
48          // Phone
49  
50          UpgradeColumn upgradeUserIdColumn = new SwapUpgradeColumnImpl(
51              "userId", new Integer(Types.VARCHAR),
52              AvailableMappersUtil.getUserIdMapper());
53  
54          PKUpgradeColumnImpl upgradePKColumn = new PKUpgradeColumnImpl(
55              "phoneId", true);
56  
57          ClassNameIdUpgradeColumnImpl classNameIdColumn =
58              new ClassNameIdUpgradeColumnImpl();
59  
60          Map<Long, ClassPKContainer> classPKContainers =
61              new HashMap<Long, ClassPKContainer>();
62  
63          classPKContainers.put(
64              new Long(PortalUtil.getClassNameId(Contact.class.getName())),
65              new ClassPKContainer(
66                  AvailableMappersUtil.getContactIdMapper(), false));
67  
68          classPKContainers.put(
69              new Long(PortalUtil.getClassNameId(Organization.class.getName())),
70              new ClassPKContainer(
71                  AvailableMappersUtil.getOrganizationIdMapper(), true));
72  
73          UpgradeColumn upgradeClassPKColumn = new ClassPKUpgradeColumnImpl(
74              classNameIdColumn, classPKContainers);
75  
76          UpgradeTable upgradeTable = UpgradeTableFactoryUtil.getUpgradeTable(
77              PhoneTable.TABLE_NAME, PhoneTable.TABLE_COLUMNS, upgradePKColumn,
78              upgradeUserIdColumn, classNameIdColumn, upgradeClassPKColumn);
79  
80          upgradeTable.setCreateSQL(PhoneTable.TABLE_SQL_CREATE);
81  
82          upgradeTable.updateTable();
83  
84          ValueMapperUtil.persist(upgradePKColumn.getValueMapper(), "phone-id");
85      }
86  
87  }