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.events;
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.log.Log;
020    import com.liferay.portal.kernel.log.LogFactoryUtil;
021    import com.liferay.portal.kernel.upgrade.UpgradeException;
022    import com.liferay.portal.kernel.util.PortalClassLoaderUtil;
023    import com.liferay.portal.kernel.util.PropsKeys;
024    import com.liferay.portal.kernel.util.StringUtil;
025    import com.liferay.portal.upgrade.UpgradeProcessUtil;
026    import com.liferay.portal.util.PropsUtil;
027    import com.liferay.portal.verify.VerifyException;
028    import com.liferay.portal.verify.VerifyProcessUtil;
029    
030    /**
031     * @author Brian Wing Shun Chan
032     * @author Alexander Chow
033     * @author Raymond Augé
034     */
035    public class StartupHelper {
036    
037            public void setDropIndexes(boolean dropIndexes) {
038                    _dropIndexes = dropIndexes;
039            }
040    
041            public void updateIndexes() {
042                    try {
043                            DB db = DBFactoryUtil.getDB();
044    
045                            Thread currentThread = Thread.currentThread();
046    
047                            ClassLoader classLoader = currentThread.getContextClassLoader();
048    
049                            String tablesSQL = StringUtil.read(
050                                    classLoader,
051                                    "com/liferay/portal/tools/sql/dependencies/portal-tables.sql");
052    
053                            String indexesSQL = StringUtil.read(
054                                    classLoader,
055                                    "com/liferay/portal/tools/sql/dependencies/indexes.sql");
056    
057                            String indexesProperties = StringUtil.read(
058                                    classLoader,
059                                    "com/liferay/portal/tools/sql/dependencies/indexes.properties");
060    
061                            db.updateIndexes(
062                                    tablesSQL, indexesSQL, indexesProperties, _dropIndexes);
063                    }
064                    catch (Exception e) {
065                            _log.error(e, e);
066                    }
067            }
068    
069            public void upgradeProcess(int buildNumber) throws UpgradeException {
070                    String[] upgradeProcessClassNames = PropsUtil.getArray(
071                            PropsKeys.UPGRADE_PROCESSES);
072    
073                    _upgraded = UpgradeProcessUtil.upgradeProcess(
074                            buildNumber, upgradeProcessClassNames,
075                            PortalClassLoaderUtil.getClassLoader());
076            }
077    
078            public void verifyProcess(boolean verified) throws VerifyException {
079                    _verified = VerifyProcessUtil.verifyProcess(_upgraded, verified);
080            }
081    
082            public boolean isUpgraded() {
083                    return _upgraded;
084            }
085    
086            public boolean isVerified() {
087                    return _verified;
088            }
089    
090            private static Log _log = LogFactoryUtil.getLog(StartupHelper.class);
091    
092            private boolean _dropIndexes;
093            private boolean _upgraded;
094            private boolean _verified;
095    
096    }