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