1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    *
5    *
6    *
7    * The contents of this file are subject to the terms of the Liferay Enterprise
8    * Subscription License ("License"). You may not use this file except in
9    * compliance with the License. You can obtain a copy of the License by
10   * contacting Liferay, Inc. See the License for the specific language governing
11   * permissions and limitations under the License, including but not limited to
12   * distribution rights of the Software.
13   *
14   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20   * SOFTWARE.
21   */
22  
23  package com.liferay.portal.events;
24  
25  import com.liferay.portal.kernel.dao.db.DB;
26  import com.liferay.portal.kernel.dao.db.DBFactoryUtil;
27  import com.liferay.portal.kernel.log.Log;
28  import com.liferay.portal.kernel.log.LogFactoryUtil;
29  import com.liferay.portal.kernel.upgrade.UpgradeException;
30  import com.liferay.portal.kernel.util.PortalClassLoaderUtil;
31  import com.liferay.portal.kernel.util.PropsKeys;
32  import com.liferay.portal.kernel.util.StringUtil;
33  import com.liferay.portal.upgrade.UpgradeProcessUtil;
34  import com.liferay.portal.util.PropsUtil;
35  import com.liferay.portal.verify.VerifyException;
36  import com.liferay.portal.verify.VerifyProcessUtil;
37  
38  /**
39   * <a href="StartupHelper.java.html"><b><i>View Source</i></b></a>
40   *
41   * @author Brian Wing Shun Chan
42   * @author Alexander Chow
43   * @author Raymond Augé
44   */
45  public class StartupHelper {
46  
47      public void setDropIndexes(boolean dropIndexes) {
48          _dropIndexes = dropIndexes;
49      }
50  
51      public void updateIndexes() {
52          try {
53              DB db = DBFactoryUtil.getDB();
54  
55              Thread currentThread = Thread.currentThread();
56  
57              ClassLoader classLoader = currentThread.getContextClassLoader();
58  
59              String tablesSQL = StringUtil.read(
60                  classLoader,
61                  "com/liferay/portal/tools/sql/dependencies/portal-tables.sql");
62  
63              String indexesSQL = StringUtil.read(
64                  classLoader,
65                  "com/liferay/portal/tools/sql/dependencies/indexes.sql");
66  
67              String indexesProperties = StringUtil.read(
68                  classLoader,
69                  "com/liferay/portal/tools/sql/dependencies/indexes.properties");
70  
71              db.updateIndexes(
72                  tablesSQL, indexesSQL, indexesProperties, _dropIndexes);
73          }
74          catch (Exception e) {
75              _log.error(e, e);
76          }
77      }
78  
79      public void upgradeProcess(int buildNumber) throws UpgradeException {
80          String[] upgradeProcessClassNames = PropsUtil.getArray(
81              PropsKeys.UPGRADE_PROCESSES);
82  
83          _upgraded = UpgradeProcessUtil.upgradeProcess(
84              buildNumber, upgradeProcessClassNames,
85              PortalClassLoaderUtil.getClassLoader());
86      }
87  
88      public void verifyProcess(boolean verified) throws VerifyException {
89          _verified = VerifyProcessUtil.verifyProcess(_upgraded, verified);
90      }
91  
92      public boolean isUpgraded() {
93          return _upgraded;
94      }
95  
96      public boolean isVerified() {
97          return _verified;
98      }
99  
100     private static Log _log = LogFactoryUtil.getLog(StartupHelper.class);
101 
102     private boolean _dropIndexes;
103     private boolean _upgraded;
104     private boolean _verified;
105 
106 }