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.portal.kernel.log.Log;
23  import com.liferay.portal.kernel.log.LogFactoryUtil;
24  import com.liferay.portal.model.impl.ContactImpl;
25  import com.liferay.portal.model.impl.UserImpl;
26  import com.liferay.portal.upgrade.UpgradeException;
27  import com.liferay.portal.upgrade.UpgradeProcess;
28  import com.liferay.portal.upgrade.util.DefaultPKMapper;
29  import com.liferay.portal.upgrade.util.DefaultUpgradeTableImpl;
30  import com.liferay.portal.upgrade.util.PKUpgradeColumnImpl;
31  import com.liferay.portal.upgrade.util.TempUpgradeColumnImpl;
32  import com.liferay.portal.upgrade.util.UpgradeColumn;
33  import com.liferay.portal.upgrade.util.UpgradeTable;
34  import com.liferay.portal.upgrade.util.ValueMapper;
35  import com.liferay.portal.upgrade.v4_3_0.util.AvailableMappersUtil;
36  import com.liferay.portal.upgrade.v4_3_0.util.ContactIdUpgradeColumnImpl;
37  
38  import java.sql.Types;
39  
40  /**
41   * <a href="UpgradeContact.java.html"><b><i>View Source</i></b></a>
42   *
43   * @author Alexander Chow
44   * @author Brian Wing Shun Chan
45   *
46   */
47  public class UpgradeContact extends UpgradeProcess {
48  
49      public void upgrade() throws UpgradeException {
50          _log.info("Upgrading");
51  
52          try {
53              doUpgrade();
54          }
55          catch (Exception e) {
56              throw new UpgradeException(e);
57          }
58      }
59  
60      protected void doUpgrade() throws Exception {
61  
62          // Contact_
63  
64          PKUpgradeColumnImpl upgradePKColumn = new PKUpgradeColumnImpl(
65              "contactId", new Integer(Types.VARCHAR), true);
66  
67          UpgradeTable upgradeTable = new DefaultUpgradeTableImpl(
68              ContactImpl.TABLE_NAME, ContactImpl.TABLE_COLUMNS, upgradePKColumn);
69  
70          upgradeTable.setCreateSQL(ContactImpl.TABLE_SQL_CREATE);
71  
72          upgradeTable.updateTable();
73  
74          ValueMapper contactIdMapper = new DefaultPKMapper(
75              upgradePKColumn.getValueMapper());
76  
77          AvailableMappersUtil.setContactIdMapper(contactIdMapper);
78  
79          // User_
80  
81          UpgradeColumn upgradeScreenNameColumn =
82              new TempUpgradeColumnImpl("screenName");
83  
84          UpgradeColumn upgradeContactIdColumn = new ContactIdUpgradeColumnImpl(
85              upgradeScreenNameColumn, contactIdMapper);
86  
87          upgradeTable = new DefaultUpgradeTableImpl(
88              UserImpl.TABLE_NAME, UserImpl.TABLE_COLUMNS,
89              upgradeScreenNameColumn, upgradeContactIdColumn);
90  
91          upgradeTable.setCreateSQL(UserImpl.TABLE_SQL_CREATE);
92  
93          upgradeTable.updateTable();
94      }
95  
96      private static Log _log = LogFactoryUtil.getLog(UpgradeContact.class);
97  
98  }