001    /**
002     * Copyright (c) 2000-2013 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.kernel.upgrade.util;
016    
017    import com.liferay.portal.kernel.dao.db.DB;
018    import com.liferay.portal.kernel.dao.db.DBFactoryUtil;
019    import com.liferay.portal.kernel.exception.SystemException;
020    
021    /**
022     * @author Brian Wing Shun Chan
023     */
024    public abstract class BaseUpgradeColumnImpl implements UpgradeColumn {
025    
026            public BaseUpgradeColumnImpl(String name) {
027                    this(name, null);
028            }
029    
030            public BaseUpgradeColumnImpl(String name, Integer oldColumnType) {
031                    _name = name;
032                    _oldColumnType = oldColumnType;
033            }
034    
035            @Override
036            public String getName() {
037                    return _name;
038            }
039    
040            @Override
041            public Integer getNewColumnType(Integer defaultType) {
042                    return defaultType;
043            }
044    
045            @Override
046            public Object getNewValue() {
047                    return _newValue;
048            }
049    
050            @Override
051            public Integer getOldColumnType(Integer defaultType) {
052                    if (_oldColumnType == null) {
053                            return defaultType;
054                    }
055                    else {
056                            return _oldColumnType;
057                    }
058            }
059    
060            @Override
061            public Object getOldValue() {
062                    return _oldValue;
063            }
064    
065            @Override
066            public long increment() throws SystemException {
067                    DB db = DBFactoryUtil.getDB();
068    
069                    return db.increment();
070            }
071    
072            @Override
073            public boolean isApplicable(String name) {
074                    if (_name.equals(name)) {
075                            return true;
076                    }
077                    else {
078                            return false;
079                    }
080            }
081    
082            @Override
083            public void setNewValue(Object newValue) {
084                    _newValue = newValue;
085            }
086    
087            @Override
088            public void setOldValue(Object oldValue) {
089                    _oldValue = oldValue;
090            }
091    
092            private String _name;
093            private Object _newValue;
094            private Integer _oldColumnType;
095            private Object _oldValue;
096    
097    }