001
014
015 package com.liferay.portal.upgrade.v7_0_0;
016
017 import com.liferay.portal.kernel.model.ReleaseConstants;
018 import com.liferay.portal.kernel.upgrade.UpgradeProcess;
019 import com.liferay.portal.kernel.util.LoggingTimer;
020 import com.liferay.portal.kernel.util.StringBundler;
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 public String[] getBundleSymbolicNames() {
035 return _BUNDLE_SYMBOLIC_NAMES;
036 }
037
038 public String[][] getConvertedLegacyModules() {
039 return _CONVERTED_LEGACY_MODULES;
040 }
041
042 protected void addRelease(String... bundleSymbolicNames)
043 throws SQLException {
044
045 Timestamp timestamp = new Timestamp(System.currentTimeMillis());
046
047 StringBundler sb = new StringBundler(4);
048
049 sb.append("insert into Release_ (mvccVersion, releaseId, ");
050 sb.append("createDate, modifiedDate, servletContextName, ");
051 sb.append("schemaVersion, buildNumber, buildDate, verified, state_, ");
052 sb.append("testString) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
053
054 try (PreparedStatement ps = connection.prepareStatement(
055 sb.toString())) {
056
057 for (String bundleSymbolicName : bundleSymbolicNames) {
058 ps.setLong(1, 0);
059 ps.setLong(2, increment());
060 ps.setTimestamp(3, timestamp);
061 ps.setTimestamp(4, timestamp);
062 ps.setString(5, bundleSymbolicName);
063 ps.setString(6, "0.0.1");
064 ps.setInt(7, 001);
065 ps.setTimestamp(8, timestamp);
066 ps.setBoolean(9, false);
067 ps.setInt(10, 0);
068 ps.setString(11, ReleaseConstants.TEST_STRING);
069
070 ps.addBatch();
071 }
072
073 ps.executeBatch();
074 }
075 }
076
077 @Override
078 protected void doUpgrade() throws Exception {
079 updateExtractedModules();
080
081 updateConvertedLegacyModules();
082 }
083
084 protected boolean hasServiceComponent(String buildNamespace)
085 throws SQLException {
086
087 try (PreparedStatement ps = connection.prepareStatement(
088 "select serviceComponentId from ServiceComponent " +
089 "where buildNamespace = ?")) {
090
091 ps.setString(1, buildNamespace);
092
093 try (ResultSet rs = ps.executeQuery()) {
094 if (rs.next()) {
095 return true;
096 }
097 }
098 }
099
100 return false;
101 }
102
103 protected void updateConvertedLegacyModules()
104 throws IOException, SQLException {
105
106 try (LoggingTimer loggingTimer = new LoggingTimer()) {
107 for (String[] convertedLegacyModule : getConvertedLegacyModules()) {
108 String oldServletContextName = convertedLegacyModule[0];
109 String newServletContextName = convertedLegacyModule[1];
110 String buildNamespace = convertedLegacyModule[2];
111
112 try (PreparedStatement ps = connection.prepareStatement(
113 "select servletContextName, buildNumber from Release_" +
114 " where servletContextName = ?")) {
115
116 ps.setString(1, oldServletContextName);
117
118 try (ResultSet rs = ps.executeQuery()) {
119 if (!rs.next()) {
120 if (hasServiceComponent(buildNamespace)) {
121 addRelease(newServletContextName);
122 }
123 }
124 else {
125 updateServletContextName(
126 oldServletContextName, newServletContextName);
127 }
128 }
129 }
130 }
131 }
132 }
133
134 protected void updateExtractedModules() throws SQLException {
135 try (LoggingTimer loggingTimer = new LoggingTimer()) {
136 addRelease(getBundleSymbolicNames());
137 }
138 }
139
140 protected void updateServletContextName(
141 String oldServletContextName, String newServletContextName)
142 throws IOException, SQLException {
143
144 runSQL(
145 "update Release_ set servletContextName = '" +
146 newServletContextName + "' where servletContextName = '" +
147 oldServletContextName + "'");
148 }
149
150 private static final String[] _BUNDLE_SYMBOLIC_NAMES = new String[] {
151 "com.liferay.amazon.rankings.web", "com.liferay.asset.browser.web",
152 "com.liferay.asset.categories.navigation.web",
153 "com.liferay.asset.publisher.web",
154 "com.liferay.asset.tags.compiler.web",
155 "com.liferay.asset.tags.navigation.web",
156 "com.liferay.blogs.recent.bloggers.web", "com.liferay.blogs.web",
157 "com.liferay.bookmarks.service", "com.liferay.bookmarks.web",
158 "com.liferay.calendar.web", "com.liferay.comment.page.comments.web",
159 "com.liferay.currency.converter.web", "com.liferay.dictionary.web",
160 "com.liferay.document.library.service",
161 "com.liferay.document.library.web",
162 "com.liferay.dynamic.data.lists.service",
163 "com.liferay.dynamic.data.lists.web",
164 "com.liferay.dynamic.data.mapping.service",
165 "com.liferay.exportimport.service", "com.liferay.exportimport.web",
166 "com.liferay.flags.web", "com.liferay.hello.velocity.web",
167 "com.liferay.hello.world.web", "com.liferay.iframe.web",
168 "com.liferay.invitation.web", "com.liferay.item.selector.web",
169 "com.liferay.journal.content.search.web",
170 "com.liferay.journal.content.web", "com.liferay.journal.service",
171 "com.liferay.journal.web", "com.liferay.layout.admin.web",
172 "com.liferay.license.manager.web", "com.liferay.loan.calculator.web",
173 "com.liferay.login.web", "com.liferay.message.boards.web",
174 "com.liferay.mobile.device.rules.service",
175 "com.liferay.mobile.device.rules.web", "com.liferay.my.account.web",
176 "com.liferay.nested.portlets.web", "com.liferay.network.utilities.web",
177 "com.liferay.password.generator.web", "com.liferay.plugins.admin.web",
178 "com.liferay.polls.service",
179 "com.liferay.portal.background.task.service",
180 "com.liferay.portal.instances.web", "com.liferay.portal.lock.service",
181 "com.liferay.portal.scheduler.quartz", "com.liferay.portal.search.web",
182 "com.liferay.portal.settings.web",
183 "com.liferay.portlet.configuration.css.web",
184 "com.liferay.portlet.configuration.web",
185 "com.liferay.product.navigation.product.menu.web",
186 "com.liferay.quick.note.web", "com.liferay.ratings.page.ratings.web",
187 "com.liferay.rss.web", "com.liferay.server.admin.web",
188 "com.liferay.shopping.service", "com.liferay.shopping.web",
189 "com.liferay.site.browser.web", "com.liferay.site.my.sites.web",
190 "com.liferay.site.navigation.breadcrumb.web",
191 "com.liferay.site.navigation.directory.web",
192 "com.liferay.site.navigation.language.web",
193 "com.liferay.site.navigation.menu.web",
194 "com.liferay.site.navigation.site.map.web",
195 "com.liferay.social.activities.web", "com.liferay.social.activity.web",
196 "com.liferay.social.group.statistics.web",
197 "com.liferay.social.requests.web",
198 "com.liferay.social.user.statistics.web", "com.liferay.staging.bar.web",
199 "com.liferay.translator.web", "com.liferay.trash.web",
200 "com.liferay.unit.converter.web", "com.liferay.web.proxy.web",
201 "com.liferay.wiki.service", "com.liferay.wiki.web",
202 "com.liferay.xsl.content.web"
203 };
204
205 private static final String[][] _CONVERTED_LEGACY_MODULES = {
206 {"calendar-portlet", "com.liferay.calendar.service", "Calendar"},
207 {
208 "kaleo-designer-portlet",
209 "com.liferay.portal.workflow.kaleo.designer.web", "KaleoDesigner"
210 },
211 {
212 "kaleo-forms-portlet",
213 "com.liferay.portal.workflow.kaleo.forms.web", "KaleoForms"
214 },
215 {"kaleo-web", "com.liferay.portal.workflow.kaleo.service", "Kaleo"},
216 {
217 "marketplace-portlet", "com.liferay.marketplace.service",
218 "Marketplace"
219 },
220 {"microblogs-portlet", "com.liferay.microblogs.service", "Microblogs"},
221 {"so-portlet", "com.liferay.invitation.invite.members.service", "SO"},
222 {
223 "social-networking-portlet",
224 "com.liferay.social.networking.service", "SN"
225 }
226 };
227
228 }