forked from liferay/liferay-portal
/
StartupHelper.java
202 lines (162 loc) · 5.42 KB
/
StartupHelper.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
/**
* Copyright (c) 2000-present Liferay, Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the Free
* Software Foundation; either version 2.1 of the License, or (at your option)
* any later version.
*
* This library is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
* details.
*/
package com.liferay.portal.events;
import com.liferay.portal.kernel.dao.db.DB;
import com.liferay.portal.kernel.dao.db.DBFactoryUtil;
import com.liferay.portal.kernel.dao.jdbc.DataAccess;
import com.liferay.portal.kernel.log.Log;
import com.liferay.portal.kernel.log.LogFactoryUtil;
import com.liferay.portal.kernel.upgrade.UpgradeException;
import com.liferay.portal.kernel.upgrade.UpgradeProcess;
import com.liferay.portal.kernel.upgrade.util.UpgradeProcessUtil;
import com.liferay.portal.kernel.util.ClassLoaderUtil;
import com.liferay.portal.kernel.util.GetterUtil;
import com.liferay.portal.kernel.util.PropsKeys;
import com.liferay.portal.kernel.util.ReleaseInfo;
import com.liferay.portal.kernel.util.StringPool;
import com.liferay.portal.kernel.util.StringUtil;
import com.liferay.portal.util.PropsUtil;
import com.liferay.portal.verify.VerifyException;
import com.liferay.portal.verify.VerifyProcessUtil;
import java.sql.Connection;
import java.util.List;
/**
* @author Brian Wing Shun Chan
* @author Alexander Chow
* @author Raymond Augé
*/
public class StartupHelper {
public boolean isDBNew() {
return _dbNew;
}
public boolean isStartupFinished() {
return _startupFinished;
}
public boolean isUpgraded() {
return _upgraded;
}
public boolean isUpgrading() {
return _upgrading;
}
public boolean isVerified() {
return _verified;
}
public void setDbNew(boolean dbNew) {
_dbNew = dbNew;
}
public void setDropIndexes(boolean dropIndexes) {
_dropIndexes = dropIndexes;
}
public void setStartupFinished(boolean startupFinished) {
_startupFinished = startupFinished;
}
public void updateIndexes() {
updateIndexes(_dropIndexes);
}
public void updateIndexes(boolean dropIndexes) {
DB db = DBFactoryUtil.getDB();
Connection connection = null;
try {
connection = DataAccess.getConnection();
updateIndexes(db, connection, dropIndexes);
}
catch (Exception e) {
if (_log.isWarnEnabled()) {
_log.warn(e, e);
}
}
finally {
DataAccess.cleanUp(connection);
}
}
public void updateIndexes(
DB db, Connection connection, boolean dropIndexes) {
try {
ClassLoader classLoader = ClassLoaderUtil.getContextClassLoader();
String tablesSQL = StringUtil.read(
classLoader,
"com/liferay/portal/tools/sql/dependencies/portal-tables.sql");
String indexesSQL = StringUtil.read(
classLoader,
"com/liferay/portal/tools/sql/dependencies/indexes.sql");
db.updateIndexes(connection, tablesSQL, indexesSQL, dropIndexes);
}
catch (Exception e) {
if (_log.isWarnEnabled()) {
_log.warn(e, e);
}
}
}
public void upgradeProcess(int buildNumber) throws UpgradeException {
_upgrading = true;
try {
if (buildNumber == ReleaseInfo.getParentBuildNumber()) {
if (_log.isDebugEnabled()) {
_log.debug(
"Skipping upgrade process from " + buildNumber +
" to " + ReleaseInfo.getParentBuildNumber());
}
return;
}
String[] upgradeProcessClassNames = getUpgradeProcessClassNames(
PropsKeys.UPGRADE_PROCESSES);
if (upgradeProcessClassNames.length == 0) {
upgradeProcessClassNames = getUpgradeProcessClassNames(
PropsKeys.UPGRADE_PROCESSES + StringPool.PERIOD +
buildNumber);
if (upgradeProcessClassNames.length == 0) {
if (_log.isInfoEnabled()) {
_log.info(
"Upgrading from " + buildNumber + " to " +
ReleaseInfo.getParentBuildNumber() +
" is not supported");
}
System.exit(0);
}
}
List<UpgradeProcess> upgradeProcesses =
UpgradeProcessUtil.initUpgradeProcesses(
ClassLoaderUtil.getPortalClassLoader(),
upgradeProcessClassNames);
_upgraded = UpgradeProcessUtil.upgradeProcess(
buildNumber, upgradeProcesses);
}
finally {
_upgrading = false;
}
}
public void verifyProcess(boolean newBuildNumber, boolean verified)
throws VerifyException {
_verified = VerifyProcessUtil.verifyProcess(
_upgraded, newBuildNumber, verified);
}
protected String[] getUpgradeProcessClassNames(String key) {
// We would normally call PropsUtil#getArray(String) to return a String
// array based on a comma delimited value. However, there is a bug with
// Apache Commons Configuration where multi-line comma delimited values
// do not interpolate properly (i.e. cannot be referenced by other
// properties). The workaround to the bug is to escape commas with a
// back slash. To get the configured String array, we have to call
// PropsUtil#get(String) and manually split the value into a String
// array instead of simply calling PropsUtil#getArray(String).
return StringUtil.split(GetterUtil.getString(PropsUtil.get(key)));
}
private static final Log _log = LogFactoryUtil.getLog(StartupHelper.class);
private boolean _dbNew;
private boolean _dropIndexes;
private boolean _startupFinished;
private boolean _upgraded;
private boolean _upgrading;
private boolean _verified;
}