001    /**
002     * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portal.upgrade.v4_3_0;
016    
017    import com.liferay.portal.kernel.upgrade.UpgradeProcess;
018    import com.liferay.portal.kernel.upgrade.util.DefaultPKMapper;
019    import com.liferay.portal.kernel.upgrade.util.TempUpgradeColumnImpl;
020    import com.liferay.portal.kernel.upgrade.util.UpgradeColumn;
021    import com.liferay.portal.kernel.upgrade.util.UpgradeTable;
022    import com.liferay.portal.kernel.upgrade.util.UpgradeTableFactoryUtil;
023    import com.liferay.portal.kernel.upgrade.util.ValueMapper;
024    import com.liferay.portal.upgrade.util.PKUpgradeColumnImpl;
025    import com.liferay.portal.upgrade.v4_3_0.util.AvailableMappersUtil;
026    import com.liferay.portal.upgrade.v4_3_0.util.ContactIdUpgradeColumnImpl;
027    import com.liferay.portal.upgrade.v4_3_0.util.ContactTable;
028    import com.liferay.portal.upgrade.v4_3_0.util.UserTable;
029    
030    import java.sql.Types;
031    
032    /**
033     * @author Alexander Chow
034     * @author Brian Wing Shun Chan
035     */
036    public class UpgradeContact extends UpgradeProcess {
037    
038            protected void doUpgrade() throws Exception {
039    
040                    // Contact_
041    
042                    PKUpgradeColumnImpl upgradePKColumn = new PKUpgradeColumnImpl(
043                            "contactId", new Integer(Types.VARCHAR), true);
044    
045                    UpgradeTable upgradeTable = UpgradeTableFactoryUtil.getUpgradeTable(
046                            ContactTable.TABLE_NAME, ContactTable.TABLE_COLUMNS,
047                            upgradePKColumn);
048    
049                    upgradeTable.setCreateSQL(ContactTable.TABLE_SQL_CREATE);
050    
051                    upgradeTable.updateTable();
052    
053                    ValueMapper contactIdMapper = new DefaultPKMapper(
054                            upgradePKColumn.getValueMapper());
055    
056                    AvailableMappersUtil.setContactIdMapper(contactIdMapper);
057    
058                    // User_
059    
060                    UpgradeColumn upgradeScreenNameColumn =
061                            new TempUpgradeColumnImpl("screenName");
062    
063                    UpgradeColumn upgradeContactIdColumn = new ContactIdUpgradeColumnImpl(
064                            upgradeScreenNameColumn, contactIdMapper);
065    
066                    upgradeTable = UpgradeTableFactoryUtil.getUpgradeTable(
067                            UserTable.TABLE_NAME, UserTable.TABLE_COLUMNS,
068                            upgradeScreenNameColumn, upgradeContactIdColumn);
069    
070                    upgradeTable.setCreateSQL(UserTable.TABLE_SQL_CREATE);
071    
072                    upgradeTable.updateTable();
073            }
074    
075    }