001    /**
002     * Copyright (c) 2000-2010 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;
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    import com.liferay.portal.kernel.log.Log;
021    import com.liferay.portal.kernel.log.LogFactoryUtil;
022    
023    import java.io.IOException;
024    
025    import java.sql.SQLException;
026    
027    import javax.naming.NamingException;
028    
029    /**
030     * @author Brian Wing Shun Chan
031     * @author Alexander Chow
032     */
033    public abstract class UpgradeProcess {
034    
035            public UpgradeProcess() {
036            }
037    
038            public int getThreshold() {
039    
040                    // This upgrade process will only run if the build number is larger than
041                    // the returned threshold value. Return 0 to always run this upgrade
042                    // process.
043    
044                    return 0;
045            }
046    
047            public long increment() throws SystemException {
048                    DB db = DBFactoryUtil.getDB();
049    
050                    return db.increment();
051            }
052    
053            public boolean isSupportsAlterColumnName() {
054                    DB db = DBFactoryUtil.getDB();
055    
056                    return db.isSupportsAlterColumnName();
057            }
058    
059            public boolean isSupportsAlterColumnType() {
060                    DB db = DBFactoryUtil.getDB();
061    
062                    return db.isSupportsAlterColumnType();
063            }
064    
065            public boolean isSupportsStringCaseSensitiveQuery() {
066                    DB db = DBFactoryUtil.getDB();
067    
068                    return db.isSupportsStringCaseSensitiveQuery();
069            }
070    
071            public boolean isSupportsUpdateWithInnerJoin() {
072                    DB db = DBFactoryUtil.getDB();
073    
074                    return db.isSupportsUpdateWithInnerJoin();
075            }
076    
077            public void runSQL(String template) throws IOException, SQLException {
078                    DB db = DBFactoryUtil.getDB();
079    
080                    db.runSQL(template);
081            }
082    
083            public void runSQL(String[] templates) throws IOException, SQLException {
084                    DB db = DBFactoryUtil.getDB();
085    
086                    db.runSQL(templates);
087            }
088    
089            public void runSQLTemplate(String path)
090                    throws IOException, NamingException, SQLException {
091    
092                    DB db = DBFactoryUtil.getDB();
093    
094                    db.runSQLTemplate(path);
095            }
096    
097            public void runSQLTemplate(String path, boolean failOnError)
098                    throws IOException, NamingException, SQLException {
099    
100                    DB db = DBFactoryUtil.getDB();
101    
102                    db.runSQLTemplate(path, failOnError);
103            }
104    
105            public void upgrade() throws UpgradeException {
106                    try {
107                            if (_log.isInfoEnabled()) {
108                                    _log.info("Upgrading " + getClass().getName());
109                            }
110    
111                            doUpgrade();
112                    }
113                    catch (Exception e) {
114                            throw new UpgradeException(e);
115                    }
116            }
117    
118            public void upgrade(Class<?> upgradeProcessClass)
119                    throws UpgradeException {
120    
121                    UpgradeProcess upgradeProcess = null;
122    
123                    try {
124                            upgradeProcess = (UpgradeProcess)upgradeProcessClass.newInstance();
125                    }
126                    catch (Exception e) {
127                            throw new UpgradeException(e);
128                    }
129    
130                    upgradeProcess.upgrade();
131            }
132    
133            public void upgrade(UpgradeProcess upgradeProcess)
134                    throws UpgradeException {
135    
136                    upgradeProcess.upgrade();
137            }
138    
139            protected void doUpgrade() throws Exception {
140            }
141    
142            private static Log _log = LogFactoryUtil.getLog(UpgradeProcess.class);
143    
144    }