1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    *
5    *
6    *
7    * The contents of this file are subject to the terms of the Liferay Enterprise
8    * Subscription License ("License"). You may not use this file except in
9    * compliance with the License. You can obtain a copy of the License by
10   * contacting Liferay, Inc. See the License for the specific language governing
11   * permissions and limitations under the License, including but not limited to
12   * distribution rights of the Software.
13   *
14   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20   * SOFTWARE.
21   */
22  
23  package com.liferay.portal.upgrade.v4_3_0;
24  
25  import com.liferay.portal.upgrade.UpgradeProcess;
26  import com.liferay.portal.upgrade.util.DefaultPKMapper;
27  import com.liferay.portal.upgrade.util.DefaultUpgradeTableImpl;
28  import com.liferay.portal.upgrade.util.PKUpgradeColumnImpl;
29  import com.liferay.portal.upgrade.util.SwapUpgradeColumnImpl;
30  import com.liferay.portal.upgrade.util.TempUpgradeColumnImpl;
31  import com.liferay.portal.upgrade.util.UpgradeColumn;
32  import com.liferay.portal.upgrade.util.UpgradeTable;
33  import com.liferay.portal.upgrade.util.ValueMapper;
34  import com.liferay.portal.upgrade.v4_3_0.util.AccountTable;
35  import com.liferay.portal.upgrade.v4_3_0.util.AvailableMappersUtil;
36  import com.liferay.portal.upgrade.v4_3_0.util.ContactTable;
37  import com.liferay.portal.upgrade.v4_3_0.util.CyrusUserTable;
38  import com.liferay.portal.upgrade.v4_3_0.util.CyrusVirtualTable;
39  import com.liferay.portal.upgrade.v4_3_0.util.PasswordTrackerTable;
40  import com.liferay.portal.upgrade.v4_3_0.util.UserPortraitIdUpgradeColumnImpl;
41  import com.liferay.portal.upgrade.v4_3_0.util.UserTable;
42  
43  import java.sql.Types;
44  
45  /**
46   * <a href="UpgradeUser.java.html"><b><i>View Source</i></b></a>
47   *
48   * @author Alexander Chow
49   * @author Brian Wing Shun Chan
50   * @author Bruno Farache
51   */
52  public class UpgradeUser extends UpgradeProcess {
53  
54      protected void doUpgrade() throws Exception {
55  
56          // User_
57  
58          PKUpgradeColumnImpl upgradePKColumn =
59              new PKUpgradeColumnImpl("userId", new Integer(Types.VARCHAR), true);
60  
61          UpgradeColumn upgradeCompanyIdColumn = new TempUpgradeColumnImpl(
62              "companyId", new Integer(Types.VARCHAR));
63  
64          UpgradeColumn upgradeContactIdColumn = new TempUpgradeColumnImpl(
65              "contactId", new Integer(Types.VARCHAR));
66  
67          UpgradeColumn upgradeUserPortraitIdColumn =
68              new UserPortraitIdUpgradeColumnImpl(
69                  upgradePKColumn, AvailableMappersUtil.getImageIdMapper());
70  
71          UpgradeTable upgradeTable = new DefaultUpgradeTableImpl(
72              UserTable.TABLE_NAME, UserTable.TABLE_COLUMNS, upgradePKColumn,
73              upgradeCompanyIdColumn, upgradeContactIdColumn,
74              upgradeUserPortraitIdColumn);
75  
76          upgradeTable.updateTable();
77  
78          ValueMapper userIdMapper = new DefaultPKMapper(
79              upgradePKColumn.getValueMapper());
80  
81          AvailableMappersUtil.setUserIdMapper(userIdMapper);
82  
83          UpgradeColumn upgradeUserIdColumn = new SwapUpgradeColumnImpl(
84              "userId", new Integer(Types.VARCHAR), userIdMapper);
85  
86          // Account
87  
88          upgradeTable = new DefaultUpgradeTableImpl(
89              AccountTable.TABLE_NAME, AccountTable.TABLE_COLUMNS,
90              upgradeUserIdColumn);
91  
92          upgradeTable.setCreateSQL(AccountTable.TABLE_SQL_CREATE);
93  
94          upgradeTable.updateTable();
95  
96          // Contact
97  
98          UpgradeColumn upgradeAccountIdColumn = new TempUpgradeColumnImpl(
99              "accountId", new Integer(Types.VARCHAR));
100 
101         UpgradeColumn upgradeParentContactIdColumn = new TempUpgradeColumnImpl(
102             "parentContactId", new Integer(Types.VARCHAR));
103 
104         UpgradeColumn upgradePrefixIdColumn = new TempUpgradeColumnImpl(
105             "prefixId", new Integer(Types.VARCHAR));
106 
107         UpgradeColumn upgradeSuffixIdColumn = new TempUpgradeColumnImpl(
108             "suffixId", new Integer(Types.VARCHAR));
109 
110         upgradeTable = new DefaultUpgradeTableImpl(
111             ContactTable.TABLE_NAME, ContactTable.TABLE_COLUMNS,
112             upgradeContactIdColumn, upgradeCompanyIdColumn, upgradeUserIdColumn,
113             upgradeAccountIdColumn, upgradeParentContactIdColumn,
114             upgradePrefixIdColumn, upgradeSuffixIdColumn);
115 
116         upgradeTable.updateTable();
117 
118         // CyrusUser
119 
120         upgradeTable = new DefaultUpgradeTableImpl(
121             CyrusUserTable.TABLE_NAME, CyrusUserTable.TABLE_COLUMNS,
122             upgradeUserIdColumn);
123 
124         upgradeTable.updateTable();
125 
126         // CyrusVirtual
127 
128         upgradeTable = new DefaultUpgradeTableImpl(
129             CyrusVirtualTable.TABLE_NAME, CyrusVirtualTable.TABLE_COLUMNS,
130             upgradeUserIdColumn);
131 
132         upgradeTable.updateTable();
133 
134         // PasswordTracker
135 
136         upgradeTable = new DefaultUpgradeTableImpl(
137             PasswordTrackerTable.TABLE_NAME, PasswordTrackerTable.TABLE_COLUMNS,
138             new PKUpgradeColumnImpl("passwordTrackerId", false),
139             upgradeUserIdColumn);
140 
141         upgradeTable.setCreateSQL(PasswordTrackerTable.TABLE_SQL_CREATE);
142 
143         upgradeTable.updateTable();
144     }
145 
146 }