001    /**
002     * Copyright (c) 2000-2012 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.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            public String getName() {
036                    return _name;
037            }
038    
039            public Integer getNewColumnType(Integer defaultType) {
040                    return defaultType;
041            }
042    
043            public Object getNewValue() {
044                    return _newValue;
045            }
046    
047            public Integer getOldColumnType(Integer defaultType) {
048                    if (_oldColumnType == null) {
049                            return defaultType;
050                    }
051                    else {
052                            return _oldColumnType;
053                    }
054            }
055    
056            public Object getOldValue() {
057                    return _oldValue;
058            }
059    
060            public long increment() throws SystemException {
061                    DB db = DBFactoryUtil.getDB();
062    
063                    return db.increment();
064            }
065    
066            public boolean isApplicable(String name) {
067                    if (_name.equals(name)) {
068                            return true;
069                    }
070                    else {
071                            return false;
072                    }
073            }
074    
075            public void setNewValue(Object newValue) {
076                    _newValue = newValue;
077            }
078    
079            public void setOldValue(Object oldValue) {
080                    _oldValue = oldValue;
081            }
082    
083            private String _name;
084            private Object _newValue;
085            private Integer _oldColumnType;
086            private Object _oldValue;
087    
088    }