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.DefaultPKMapper;
19  import com.liferay.portal.kernel.upgrade.util.TempUpgradeColumnImpl;
20  import com.liferay.portal.kernel.upgrade.util.UpgradeColumn;
21  import com.liferay.portal.kernel.upgrade.util.UpgradeTable;
22  import com.liferay.portal.kernel.upgrade.util.UpgradeTableFactoryUtil;
23  import com.liferay.portal.kernel.upgrade.util.ValueMapper;
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.ContactIdUpgradeColumnImpl;
27  import com.liferay.portal.upgrade.v4_3_0.util.ContactTable;
28  import com.liferay.portal.upgrade.v4_3_0.util.UserTable;
29  
30  import java.sql.Types;
31  
32  /**
33   * <a href="UpgradeContact.java.html"><b><i>View Source</i></b></a>
34   *
35   * @author Alexander Chow
36   * @author Brian Wing Shun Chan
37   */
38  public class UpgradeContact extends UpgradeProcess {
39  
40      protected void doUpgrade() throws Exception {
41  
42          // Contact_
43  
44          PKUpgradeColumnImpl upgradePKColumn = new PKUpgradeColumnImpl(
45              "contactId", new Integer(Types.VARCHAR), true);
46  
47          UpgradeTable upgradeTable = UpgradeTableFactoryUtil.getUpgradeTable(
48              ContactTable.TABLE_NAME, ContactTable.TABLE_COLUMNS,
49              upgradePKColumn);
50  
51          upgradeTable.setCreateSQL(ContactTable.TABLE_SQL_CREATE);
52  
53          upgradeTable.updateTable();
54  
55          ValueMapper contactIdMapper = new DefaultPKMapper(
56              upgradePKColumn.getValueMapper());
57  
58          AvailableMappersUtil.setContactIdMapper(contactIdMapper);
59  
60          // User_
61  
62          UpgradeColumn upgradeScreenNameColumn =
63              new TempUpgradeColumnImpl("screenName");
64  
65          UpgradeColumn upgradeContactIdColumn = new ContactIdUpgradeColumnImpl(
66              upgradeScreenNameColumn, contactIdMapper);
67  
68          upgradeTable = UpgradeTableFactoryUtil.getUpgradeTable(
69              UserTable.TABLE_NAME, UserTable.TABLE_COLUMNS,
70              upgradeScreenNameColumn, upgradeContactIdColumn);
71  
72          upgradeTable.setCreateSQL(UserTable.TABLE_SQL_CREATE);
73  
74          upgradeTable.updateTable();
75      }
76  
77  }