001    /**
002     * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
013     */
014    
015    package com.liferay.portal.upgrade.v4_3_0.util;
016    
017    import com.liferay.portal.kernel.upgrade.util.UpgradeColumn;
018    import com.liferay.portal.kernel.upgrade.util.ValueMapper;
019    import com.liferay.portal.kernel.upgrade.util.ValueMapperFactoryUtil;
020    import com.liferay.portal.upgrade.util.PKUpgradeColumnImpl;
021    
022    import java.sql.Types;
023    
024    /**
025     * @author Brian Wing Shun Chan
026     */
027    public class JournalTemplatePKUpgradeColumnImpl extends PKUpgradeColumnImpl {
028    
029            public JournalTemplatePKUpgradeColumnImpl(
030                    UpgradeColumn companyIdColumn, UpgradeColumn groupIdColumn) {
031    
032                    super("id_", new Integer(Types.VARCHAR), false);
033    
034                    _companyIdColumn = companyIdColumn;
035                    _groupIdColumn = groupIdColumn;
036                    _journalTemplateIdMapper = ValueMapperFactoryUtil.getValueMapper();
037            }
038    
039            public Object getNewValue(Object oldValue) throws Exception {
040                    Object newValue = super.getNewValue(oldValue);
041    
042                    String companyId = (String)_companyIdColumn.getOldValue();
043                    Long groupId = (Long)_groupIdColumn.getOldValue();
044                    String templateId = (String)oldValue;
045    
046                    String oldIdValue =
047                            "{companyId=" + companyId + ", groupId=" + groupId +
048                                    ", templateId=" + templateId + "}";
049    
050                    _journalTemplateIdMapper.mapValue(oldIdValue, newValue);
051    
052                    return newValue;
053            }
054    
055            public ValueMapper getValueMapper() {
056                    return _journalTemplateIdMapper;
057            }
058    
059            private UpgradeColumn _companyIdColumn;
060            private UpgradeColumn _groupIdColumn;
061            private ValueMapper _journalTemplateIdMapper;
062    
063    }