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.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    }