1   /**
2    * Copyright (c) 2000-2009 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   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
12   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
13   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
14   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
15   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
16   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
17   * SOFTWARE.
18   */
19  
20  package com.liferay.portal.upgrade.v4_3_0;
21  
22  import com.liferay.mail.model.CyrusUser;
23  import com.liferay.mail.model.CyrusVirtual;
24  import com.liferay.portal.kernel.log.Log;
25  import com.liferay.portal.kernel.log.LogFactoryUtil;
26  import com.liferay.portal.model.impl.AccountImpl;
27  import com.liferay.portal.model.impl.ContactImpl;
28  import com.liferay.portal.model.impl.PasswordTrackerImpl;
29  import com.liferay.portal.model.impl.UserImpl;
30  import com.liferay.portal.upgrade.UpgradeException;
31  import com.liferay.portal.upgrade.UpgradeProcess;
32  import com.liferay.portal.upgrade.util.DefaultPKMapper;
33  import com.liferay.portal.upgrade.util.DefaultUpgradeTableImpl;
34  import com.liferay.portal.upgrade.util.PKUpgradeColumnImpl;
35  import com.liferay.portal.upgrade.util.SwapUpgradeColumnImpl;
36  import com.liferay.portal.upgrade.util.TempUpgradeColumnImpl;
37  import com.liferay.portal.upgrade.util.UpgradeColumn;
38  import com.liferay.portal.upgrade.util.UpgradeTable;
39  import com.liferay.portal.upgrade.util.ValueMapper;
40  import com.liferay.portal.upgrade.v4_3_0.util.AvailableMappersUtil;
41  import com.liferay.portal.upgrade.v4_3_0.util.UserPortraitIdUpgradeColumnImpl;
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   */
53  public class UpgradeUser extends UpgradeProcess {
54  
55      public void upgrade() throws UpgradeException {
56          _log.info("Upgrading");
57  
58          try {
59              doUpgrade();
60          }
61          catch (Exception e) {
62              throw new UpgradeException(e);
63          }
64      }
65  
66      protected void doUpgrade() throws Exception {
67  
68          // User_
69  
70          PKUpgradeColumnImpl upgradePKColumn =
71              new PKUpgradeColumnImpl("userId", new Integer(Types.VARCHAR), true);
72  
73          UpgradeColumn upgradeCompanyIdColumn = new TempUpgradeColumnImpl(
74              "companyId", new Integer(Types.VARCHAR));
75  
76          UpgradeColumn upgradeContactIdColumn = new TempUpgradeColumnImpl(
77              "contactId", new Integer(Types.VARCHAR));
78  
79          UpgradeColumn upgradeUserPortraitIdColumn =
80              new UserPortraitIdUpgradeColumnImpl(
81                  upgradePKColumn, AvailableMappersUtil.getImageIdMapper());
82  
83          UpgradeTable upgradeTable = new DefaultUpgradeTableImpl(
84              UserImpl.TABLE_NAME, UserImpl.TABLE_COLUMNS, upgradePKColumn,
85              upgradeCompanyIdColumn, upgradeContactIdColumn,
86              upgradeUserPortraitIdColumn);
87  
88          upgradeTable.updateTable();
89  
90          ValueMapper userIdMapper = new DefaultPKMapper(
91              upgradePKColumn.getValueMapper());
92  
93          AvailableMappersUtil.setUserIdMapper(userIdMapper);
94  
95          UpgradeColumn upgradeUserIdColumn = new SwapUpgradeColumnImpl(
96              "userId", new Integer(Types.VARCHAR), userIdMapper);
97  
98          // Account
99  
100         upgradeTable = new DefaultUpgradeTableImpl(
101             AccountImpl.TABLE_NAME, AccountImpl.TABLE_COLUMNS,
102             upgradeUserIdColumn);
103 
104         upgradeTable.setCreateSQL(AccountImpl.TABLE_SQL_CREATE);
105 
106         upgradeTable.updateTable();
107 
108         // Contact
109 
110         UpgradeColumn upgradeAccountIdColumn = new TempUpgradeColumnImpl(
111             "accountId", new Integer(Types.VARCHAR));
112 
113         UpgradeColumn upgradeParentContactIdColumn = new TempUpgradeColumnImpl(
114             "parentContactId", new Integer(Types.VARCHAR));
115 
116         UpgradeColumn upgradePrefixIdColumn = new TempUpgradeColumnImpl(
117             "prefixId", new Integer(Types.VARCHAR));
118 
119         UpgradeColumn upgradeSuffixIdColumn = new TempUpgradeColumnImpl(
120             "suffixId", new Integer(Types.VARCHAR));
121 
122         upgradeTable = new DefaultUpgradeTableImpl(
123             ContactImpl.TABLE_NAME, ContactImpl.TABLE_COLUMNS,
124             upgradeContactIdColumn, upgradeCompanyIdColumn, upgradeUserIdColumn,
125             upgradeAccountIdColumn, upgradeParentContactIdColumn,
126             upgradePrefixIdColumn, upgradeSuffixIdColumn);
127 
128         upgradeTable.updateTable();
129 
130         // CyrusUser
131 
132         upgradeTable = new DefaultUpgradeTableImpl(
133             CyrusUser.TABLE_NAME, CyrusUser.TABLE_COLUMNS, upgradeUserIdColumn);
134 
135         upgradeTable.updateTable();
136 
137         // CyrusVirtual
138 
139         upgradeTable = new DefaultUpgradeTableImpl(
140             CyrusVirtual.TABLE_NAME, CyrusVirtual.TABLE_COLUMNS,
141             upgradeUserIdColumn);
142 
143         upgradeTable.updateTable();
144 
145         // PasswordTracker
146 
147         upgradeTable = new DefaultUpgradeTableImpl(
148             PasswordTrackerImpl.TABLE_NAME, PasswordTrackerImpl.TABLE_COLUMNS,
149             new PKUpgradeColumnImpl("passwordTrackerId", false),
150             upgradeUserIdColumn);
151 
152         upgradeTable.setCreateSQL(PasswordTrackerImpl.TABLE_SQL_CREATE);
153 
154         upgradeTable.updateTable();
155     }
156 
157     private static Log _log = LogFactoryUtil.getLog(UpgradeUser.class);
158 
159 }