001
014
015 package com.liferay.portal.upgrade.v7_0_0;
016
017 import com.liferay.portal.kernel.dao.jdbc.DataAccess;
018 import com.liferay.portal.kernel.upgrade.UpgradeProcess;
019 import com.liferay.portal.kernel.util.StringBundler;
020 import com.liferay.portal.model.ReleaseConstants;
021
022 import java.io.IOException;
023
024 import java.sql.PreparedStatement;
025 import java.sql.ResultSet;
026 import java.sql.SQLException;
027 import java.sql.Timestamp;
028
029
032 public class UpgradeModules extends UpgradeProcess {
033
034 protected void addRelease(String... bundleSymbolicNames)
035 throws SQLException {
036
037 Timestamp timestamp = new Timestamp(System.currentTimeMillis());
038
039 PreparedStatement ps = null;
040 ResultSet rs = null;
041
042 try {
043 StringBundler sb = new StringBundler(5);
044
045 sb.append("insert into Release_ (mvccVersion, releaseId, ");
046 sb.append("createDate, modifiedDate, servletContextName, ");
047 sb.append("schemaVersion, buildNumber, buildDate, verified, ");
048 sb.append("state_, testString) values (?, ?, ?, ?, ?, ?, ?, ?, ");
049 sb.append("?, ?, ?)");
050
051 String sql = sb.toString();
052
053 ps = connection.prepareStatement(sql);
054
055 for (String bundleSymbolicName : bundleSymbolicNames) {
056 ps.setLong(1, 0);
057 ps.setLong(2, increment());
058 ps.setTimestamp(3, timestamp);
059 ps.setTimestamp(4, timestamp);
060 ps.setString(5, bundleSymbolicName);
061 ps.setString(6, "0.0.1");
062 ps.setInt(7, 001);
063 ps.setTimestamp(8, timestamp);
064 ps.setBoolean(9, false);
065 ps.setInt(10, 0);
066 ps.setString(11, ReleaseConstants.TEST_STRING);
067
068 ps.addBatch();
069 }
070
071 ps.executeBatch();
072 }
073 finally {
074 DataAccess.cleanUp(ps, rs);
075 }
076 }
077
078 @Override
079 protected void doUpgrade() throws Exception {
080 updateExtractedModules();
081
082 updateConvertedLegacyModules();
083 }
084
085 protected boolean hasPortlet(String portletId) throws SQLException {
086 PreparedStatement ps = null;
087 ResultSet rs = null;
088
089 try {
090 ps = connection.prepareStatement(
091 "select portletId from Portlet where portletId like ?");
092
093 ps.setString(1, portletId);
094
095 rs = ps.executeQuery();
096
097 if (rs.next()) {
098 return true;
099 }
100 }
101 finally {
102 DataAccess.cleanUp(ps, rs);
103 }
104
105 return false;
106 }
107
108 protected boolean hasServiceComponent(String buildNamespace)
109 throws SQLException {
110
111 PreparedStatement ps = null;
112 ResultSet rs = null;
113
114 try {
115 ps = connection.prepareStatement(
116 "select serviceComponentId from ServiceComponent " +
117 "where buildNamespace = ?");
118
119 ps.setString(1, buildNamespace);
120
121 rs = ps.executeQuery();
122
123 if (rs.next()) {
124 return true;
125 }
126 }
127 finally {
128 DataAccess.cleanUp(ps, rs);
129 }
130
131 return false;
132 }
133
134 protected void updateConvertedLegacyModules()
135 throws IOException, SQLException {
136
137 for (String[] convertedLegacyModule : _convertedLegacyModules) {
138 String oldServletContextName = convertedLegacyModule[0];
139 String newServletContextName = convertedLegacyModule[1];
140 String buildNamespace = convertedLegacyModule[2];
141 String portletId = convertedLegacyModule[3];
142
143 PreparedStatement ps = null;
144 ResultSet rs = null;
145
146 try {
147 ps = connection.prepareStatement(
148 "select servletContextName, buildNumber from Release_ " +
149 "where servletContextName = ?");
150
151 ps.setString(1, oldServletContextName);
152
153 rs = ps.executeQuery();
154
155 if (!rs.next()) {
156 if (hasPortlet(portletId) ||
157 hasServiceComponent(buildNamespace)) {
158
159 addRelease(newServletContextName);
160 }
161 }
162 else {
163 updateServletContextName(
164 oldServletContextName, newServletContextName);
165 }
166 }
167 finally {
168 DataAccess.cleanUp(ps, rs);
169 }
170 }
171 }
172
173 protected void updateExtractedModules() throws SQLException {
174 addRelease(_bundleSymbolicNames);
175 }
176
177 protected void updateServletContextName(
178 String oldServletContextName, String newServletContextName)
179 throws IOException, SQLException {
180
181 runSQL(
182 "update Release_ set servletContextName = '" +
183 newServletContextName + "' where servletContextName = '" +
184 oldServletContextName + "'");
185 }
186
187 private static final String[] _bundleSymbolicNames = new String[] {
188 "com.liferay.amazon.rankings.web", "com.liferay.announcements.web",
189 "com.liferay.asset.browser.web",
190 "com.liferay.asset.categories.admin.web",
191 "com.liferay.asset.categories.navigation.web",
192 "com.liferay.asset.publisher.web", "com.liferay.asset.tags.admin.web",
193 "com.liferay.asset.tags.compiler.web",
194 "com.liferay.asset.tags.navigation.web",
195 "com.liferay.blogs.recent.bloggers.web", "com.liferay.blogs.web",
196 "com.liferay.bookmarks.service", "com.liferay.bookmarks.web",
197 "com.liferay.comment.page.comments.web",
198 "com.liferay.currency.converter.web", "com.liferay.dictionary.web",
199 "com.liferay.document.library.web",
200 "com.liferay.dynamic.data.lists.service",
201 "com.liferay.dynamic.data.lists.web",
202 "com.liferay.dynamic.data.mapping.service", "com.liferay.expando.web",
203 "com.liferay.exportimport.web", "com.liferay.flags.web",
204 "com.liferay.hello.velocity.web", "com.liferay.iframe.web",
205 "com.liferay.invitation.web", "com.liferay.item.selector.web",
206 "com.liferay.journal.content.search.web",
207 "com.liferay.journal.content.web", "com.liferay.journal.service",
208 "com.liferay.journal.web", "com.liferay.layout.admin.web",
209 "com.liferay.layout.prototype.web",
210 "com.liferay.layout.set.prototype.web",
211 "com.liferay.loan.calculator.web", "com.liferay.message.boards.web",
212 "com.liferay.mobile.device.rules.web", "com.liferay.my.account.web",
213 "com.liferay.nested.portlets.web", "com.liferay.network.utilities.web",
214 "com.liferay.password.generator.web",
215 "com.liferay.password.policies.admin.web",
216 "com.liferay.plugins.admin.web", "com.liferay.polls.service",
217 "com.liferay.portal.instances.web", "com.liferay.portal.lock.service",
218 "com.liferay.portal.settings.web",
219 "com.liferay.portlet.configuration.web", "com.liferay.portlet.css.web",
220 "com.liferay.quick.note.web.uprade;",
221 "com.liferay.ratings.page.ratings.web", "com.liferay.roles.admin.web",
222 "com.liferay.rss.web", "com.liferay.search.web",
223 "com.liferay.server.admin.web", "com.liferay.shopping.service",
224 "com.liferay.shopping.web", "com.liferay.site.admin.web",
225 "com.liferay.site.browser.web", "com.liferay.site.memberships.web",
226 "com.liferay.site.my.sites.web",
227 "com.liferay.site.navigation.breadcrumb.web",
228 "com.liferay.site.navigation.directory.web",
229 "com.liferay.site.navigation.language.web",
230 "com.liferay.site.navigation.menu.web",
231 "com.liferay.site.navigation.site.map.web",
232 "com.liferay.site.teams.web", "com.liferay.social.activities.web",
233 "com.liferay.social.activity.web",
234 "com.liferay.social.group.statistics.web",
235 "com.liferay.social.requests.web",
236 "com.liferay.social.user.statistics.web", "com.liferay.staging.bar.web",
237 "com.liferay.translator.web", "com.liferay.trash.web",
238 "com.liferay.unit.converter.web", "com.liferay.user.groups.admin.web",
239 "com.liferay.users.admin.web", "com.liferay.web.proxy.web",
240 "com.liferay.wiki.service", "com.liferay.wiki.web",
241 "com.liferay.xsl.content.web"
242 };
243 private static final String[][] _convertedLegacyModules = {
244 {
245 "calendar-portlet", "com.liferay.calendar.service", "Calendar",
246 "%calendarportlet"
247 },
248 {
249 "calendar-portlet", "com.liferay.calendar.web", "Calendar",
250 "%calendarportlet"
251 },
252 {
253 "social-networking-portlet",
254 "com.liferay.social.networking.service", "SN",
255 "%socialnetworkingportlet"
256 },
257 {
258 "marketplace-portlet", "com.liferay.marketplace.service",
259 "Marketplace", "%marketplace"
260 },
261 {
262 "kaleo-web", "com.liferay.portal.workflow.kaleo.service", "Kaleo",
263 "%kaleo%"
264 },
265 {
266 "microblogs-portlet", "com.liferay.microblogs.service",
267 "Microblogs", "%microblogsportlet"
268 }
269 };
270
271 }