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