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.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.EmailAddressTable;
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="UpgradeEmailAddress.java.html"><b><i>View Source</i></b></a>
40   *
41   * @author Alexander Chow
42   * @author Brian Wing Shun Chan
43   */
44  public class UpgradeEmailAddress extends UpgradeProcess {
45  
46      protected void doUpgrade() throws Exception {
47  
48          // EmailAddress
49  
50          UpgradeColumn upgradeUserIdColumn = new SwapUpgradeColumnImpl(
51              "userId", new Integer(Types.VARCHAR),
52              AvailableMappersUtil.getUserIdMapper());
53  
54          PKUpgradeColumnImpl upgradePKColumn = new PKUpgradeColumnImpl(
55              "emailAddressId", 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              EmailAddressTable.TABLE_NAME, EmailAddressTable.TABLE_COLUMNS,
78              upgradePKColumn, upgradeUserIdColumn, classNameIdColumn,
79              upgradeClassPKColumn);
80  
81          upgradeTable.setCreateSQL(EmailAddressTable.TABLE_SQL_CREATE);
82  
83          upgradeTable.updateTable();
84  
85          ValueMapperUtil.persist(
86              upgradePKColumn.getValueMapper(), "email-address-id");
87      }
88  
89  }