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.model.ReleaseConstants;
019 import com.liferay.portal.kernel.upgrade.UpgradeProcess;
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 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 hasServiceComponent(String buildNamespace)
086 throws SQLException {
087
088 PreparedStatement ps = null;
089 ResultSet rs = null;
090
091 try {
092 ps = connection.prepareStatement(
093 "select serviceComponentId from ServiceComponent " +
094 "where buildNamespace = ?");
095
096 ps.setString(1, buildNamespace);
097
098 rs = ps.executeQuery();
099
100 if (rs.next()) {
101 return true;
102 }
103 }
104 finally {
105 DataAccess.cleanUp(ps, rs);
106 }
107
108 return false;
109 }
110
111 protected void updateConvertedLegacyModules()
112 throws IOException, SQLException {
113
114 for (String[] convertedLegacyModule : _convertedLegacyModules) {
115 String oldServletContextName = convertedLegacyModule[0];
116 String newServletContextName = convertedLegacyModule[1];
117 String buildNamespace = convertedLegacyModule[2];
118
119 PreparedStatement ps = null;
120 ResultSet rs = null;
121
122 try {
123 ps = connection.prepareStatement(
124 "select servletContextName, buildNumber from Release_ " +
125 "where servletContextName = ?");
126
127 ps.setString(1, oldServletContextName);
128
129 rs = ps.executeQuery();
130
131 if (!rs.next()) {
132 if (hasServiceComponent(buildNamespace)) {
133 addRelease(newServletContextName);
134 }
135 }
136 else {
137 updateServletContextName(
138 oldServletContextName, newServletContextName);
139 }
140 }
141 finally {
142 DataAccess.cleanUp(ps, rs);
143 }
144 }
145 }
146
147 protected void updateExtractedModules() throws SQLException {
148 addRelease(_bundleSymbolicNames);
149 }
150
151 protected void updateServletContextName(
152 String oldServletContextName, String newServletContextName)
153 throws IOException, SQLException {
154
155 runSQL(
156 "update Release_ set servletContextName = '" +
157 newServletContextName + "' where servletContextName = '" +
158 oldServletContextName + "'");
159 }
160
161 private static final String[] _bundleSymbolicNames = new String[] {
162 "com.liferay.amazon.rankings.web", "com.liferay.asset.browser.web",
163 "com.liferay.asset.categories.navigation.web",
164 "com.liferay.asset.publisher.web",
165 "com.liferay.asset.tags.compiler.web",
166 "com.liferay.asset.tags.navigation.web",
167 "com.liferay.blogs.recent.bloggers.web", "com.liferay.blogs.web",
168 "com.liferay.bookmarks.service", "com.liferay.bookmarks.web",
169 "com.liferay.calendar.web", "com.liferay.comment.page.comments.web",
170 "com.liferay.currency.converter.web", "com.liferay.dictionary.web",
171 "com.liferay.document.library.web",
172 "com.liferay.dynamic.data.lists.service",
173 "com.liferay.dynamic.data.lists.web",
174 "com.liferay.dynamic.data.mapping.service",
175 "com.liferay.exportimport.service", "com.liferay.exportimport.web",
176 "com.liferay.flags.web", "com.liferay.hello.velocity.web",
177 "com.liferay.iframe.web", "com.liferay.invitation.web",
178 "com.liferay.item.selector.web",
179 "com.liferay.journal.content.search.web",
180 "com.liferay.journal.content.web", "com.liferay.journal.service",
181 "com.liferay.journal.web", "com.liferay.layout.admin.web",
182 "com.liferay.loan.calculator.web", "com.liferay.message.boards.web",
183 "com.liferay.mobile.device.rules.web", "com.liferay.my.account.web",
184 "com.liferay.nested.portlets.web", "com.liferay.network.utilities.web",
185 "com.liferay.password.generator.web", "com.liferay.plugins.admin.web",
186 "com.liferay.polls.service", "com.liferay.portal.instances.web",
187 "com.liferay.portal.lock.service",
188 "com.liferay.portal.scheduler.quartz",
189 "com.liferay.portal.settings.web",
190 "com.liferay.portlet.configuration.css.web",
191 "com.liferay.portlet.configuration.web", "com.liferay.quick.note.web",
192 "com.liferay.ratings.page.ratings.web", "com.liferay.rss.web",
193 "com.liferay.search.web", "com.liferay.server.admin.web",
194 "com.liferay.shopping.service", "com.liferay.shopping.web",
195 "com.liferay.site.browser.web", "com.liferay.site.my.sites.web",
196 "com.liferay.site.navigation.breadcrumb.web",
197 "com.liferay.site.navigation.directory.web",
198 "com.liferay.site.navigation.language.web",
199 "com.liferay.site.navigation.menu.web",
200 "com.liferay.site.navigation.site.map.web",
201 "com.liferay.social.activities.web", "com.liferay.social.activity.web",
202 "com.liferay.social.group.statistics.web",
203 "com.liferay.social.requests.web",
204 "com.liferay.social.user.statistics.web", "com.liferay.staging.bar.web",
205 "com.liferay.translator.web", "com.liferay.trash.web",
206 "com.liferay.unit.converter.web", "com.liferay.web.proxy.web",
207 "com.liferay.wiki.service", "com.liferay.wiki.web",
208 "com.liferay.xsl.content.web"
209 };
210 private static final String[][] _convertedLegacyModules = {
211 {
212 "calendar-portlet", "com.liferay.calendar.service", "Calendar"
213 },
214 {
215 "social-networking-portlet",
216 "com.liferay.social.networking.service", "SN"
217 },
218 {
219 "marketplace-portlet", "com.liferay.marketplace.service",
220 "Marketplace"
221 },
222 {
223 "kaleo-web", "com.liferay.portal.workflow.kaleo.service", "Kaleo"
224 },
225 {
226 "microblogs-portlet", "com.liferay.microblogs.service", "Microblogs"
227 }
228 };
229
230 }