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.util;
016    
017    import com.liferay.portal.kernel.upgrade.util.BaseUpgradeColumnImpl;
018    import com.liferay.portal.kernel.upgrade.util.ValueMapper;
019    import com.liferay.portal.kernel.upgrade.util.ValueMapperFactoryUtil;
020    
021    import java.sql.Types;
022    
023    /**
024     * @author Brian Wing Shun Chan
025     * @author Alexander Chow
026     */
027    public class PKUpgradeColumnImpl extends BaseUpgradeColumnImpl {
028    
029            public PKUpgradeColumnImpl(String name, boolean trackValues) {
030                    this(name, null, trackValues);
031            }
032    
033            public PKUpgradeColumnImpl(
034                    String name, Integer oldColumnType, boolean trackValues) {
035    
036                    super(name, oldColumnType);
037    
038                    _newColumnType = new Integer(Types.BIGINT);
039                    _trackValues = trackValues;
040    
041                    if (_trackValues) {
042                            _valueMapper = ValueMapperFactoryUtil.getValueMapper();
043                    }
044            }
045    
046            public Integer getNewColumnType(Integer defaultType) {
047                    return _newColumnType;
048            }
049    
050            public Object getNewValue(Object oldValue) throws Exception {
051                    Long newValue = new Long(increment());
052    
053                    if (_trackValues) {
054                            _valueMapper.mapValue(oldValue, newValue);
055                    }
056    
057                    return newValue;
058            }
059    
060            public boolean isTrackValues() {
061                    return _trackValues;
062            }
063    
064            public ValueMapper getValueMapper() {
065                    return _valueMapper;
066            }
067    
068            private Integer _newColumnType;
069            private boolean _trackValues;
070            private ValueMapper _valueMapper;
071    
072    }