1
22
23 package com.liferay.portal.upgrade.v4_3_0;
24
25 import com.liferay.portal.kernel.util.ArrayUtil;
26 import com.liferay.portal.model.Group;
27 import com.liferay.portal.model.Layout;
28 import com.liferay.portal.model.Location;
29 import com.liferay.portal.model.Organization;
30 import com.liferay.portal.model.Role;
31 import com.liferay.portal.model.User;
32 import com.liferay.portal.model.UserGroup;
33 import com.liferay.portal.model.impl.ResourceImpl;
34 import com.liferay.portal.upgrade.UpgradeException;
35 import com.liferay.portal.upgrade.UpgradeProcess;
36 import com.liferay.portal.upgrade.util.DefaultUpgradeTableImpl;
37 import com.liferay.portal.upgrade.util.TempUpgradeColumnImpl;
38 import com.liferay.portal.upgrade.util.UpgradeColumn;
39 import com.liferay.portal.upgrade.util.UpgradeTable;
40 import com.liferay.portal.upgrade.v4_3_0.util.AvailableMappersUtil;
41 import com.liferay.portal.upgrade.v4_3_0.util.ClassPKContainer;
42 import com.liferay.portal.upgrade.v4_3_0.util.MBMessageIdMapper;
43 import com.liferay.portal.upgrade.v4_3_0.util.ResourceCodeIdUpgradeColumnImpl;
44 import com.liferay.portal.upgrade.v4_3_0.util.ResourcePrimKeyUpgradeColumnImpl;
45 import com.liferay.portal.util.PortalUtil;
46 import com.liferay.portlet.blogs.model.BlogsCategory;
47 import com.liferay.portlet.blogs.model.BlogsEntry;
48 import com.liferay.portlet.bookmarks.model.BookmarksEntry;
49 import com.liferay.portlet.bookmarks.model.BookmarksFolder;
50 import com.liferay.portlet.calendar.model.CalEvent;
51 import com.liferay.portlet.documentlibrary.model.DLFileEntry;
52 import com.liferay.portlet.documentlibrary.model.DLFileShortcut;
53 import com.liferay.portlet.documentlibrary.model.DLFolder;
54 import com.liferay.portlet.imagegallery.model.IGFolder;
55 import com.liferay.portlet.imagegallery.model.IGImage;
56 import com.liferay.portlet.journal.model.JournalArticle;
57 import com.liferay.portlet.journal.model.JournalStructure;
58 import com.liferay.portlet.journal.model.JournalTemplate;
59 import com.liferay.portlet.messageboards.model.MBCategory;
60 import com.liferay.portlet.messageboards.model.MBMessage;
61 import com.liferay.portlet.polls.model.PollsQuestion;
62 import com.liferay.portlet.shopping.model.ShoppingCategory;
63 import com.liferay.portlet.shopping.model.ShoppingItem;
64 import com.liferay.portlet.wiki.model.WikiNode;
65 import com.liferay.portlet.wiki.model.WikiPage;
66 import com.liferay.util.CollectionFactory;
67
68 import java.sql.Types;
69
70 import java.util.Map;
71
72 import org.apache.commons.logging.Log;
73 import org.apache.commons.logging.LogFactory;
74
75
82 public class UpgradeResource extends UpgradeProcess {
83
84 public void upgrade() throws UpgradeException {
85 _log.info("Upgrading");
86
87 try {
88 doUpgrade();
89 }
90 catch (Exception e) {
91 throw new UpgradeException(e);
92 }
93 }
94
95 protected Map getClassPKContainers() {
96 Map classPKContainers = CollectionFactory.getHashMap();
97
98
100 classPKContainers.put(
101 new Long(PortalUtil.getClassNameId(BlogsCategory.class.getName())),
102 new ClassPKContainer(
103 AvailableMappersUtil.getBlogsCategoryIdMapper(), true));
104
105
107 classPKContainers.put(
108 new Long(PortalUtil.getClassNameId(BlogsEntry.class.getName())),
109 new ClassPKContainer(
110 AvailableMappersUtil.getBlogsEntryIdMapper(), true));
111
112
114 classPKContainers.put(
115 new Long(PortalUtil.getClassNameId(BookmarksEntry.class.getName())),
116 new ClassPKContainer(
117 AvailableMappersUtil.getBookmarksEntryIdMapper(), true));
118
119
121 classPKContainers.put(
122 new Long(PortalUtil.getClassNameId(
123 BookmarksFolder.class.getName())),
124 new ClassPKContainer(
125 AvailableMappersUtil.getBookmarksFolderIdMapper(), true));
126
127
129 classPKContainers.put(
130 new Long(PortalUtil.getClassNameId(CalEvent.class.getName())),
131 new ClassPKContainer(
132 AvailableMappersUtil.getCalEventIdMapper(), true));
133
134
136 classPKContainers.put(
137 new Long(PortalUtil.getClassNameId(DLFileEntry.class.getName())),
138 new ClassPKContainer(
139 AvailableMappersUtil.getDLFileEntryIdMapper(), false));
140
141
143 classPKContainers.put(
144 new Long(PortalUtil.getClassNameId(DLFileShortcut.class.getName())),
145 new ClassPKContainer(
146 AvailableMappersUtil.getDLFileShortcutIdMapper(), true));
147
148
150 classPKContainers.put(
151 new Long(PortalUtil.getClassNameId(DLFolder.class.getName())),
152 new ClassPKContainer(
153 AvailableMappersUtil.getDLFolderIdMapper(), true));
154
155
157 classPKContainers.put(
158 new Long(PortalUtil.getClassNameId(Group.class.getName())),
159 new ClassPKContainer(
160 AvailableMappersUtil.getGroupIdMapper(), true));
161
162
164 classPKContainers.put(
165 new Long(PortalUtil.getClassNameId(IGFolder.class.getName())),
166 new ClassPKContainer(
167 AvailableMappersUtil.getIGFolderIdMapper(), true));
168
169
171 classPKContainers.put(
172 new Long(PortalUtil.getClassNameId(IGImage.class.getName())),
173 new ClassPKContainer(
174 AvailableMappersUtil.getIGImageIdMapper(), false));
175
176
178 classPKContainers.put(
179 new Long(PortalUtil.getClassNameId(JournalArticle.class.getName())),
180 new ClassPKContainer(
181 AvailableMappersUtil.getJournalArticleIdMapper(), false));
182
183
185 classPKContainers.put(
186 new Long(PortalUtil.getClassNameId(
187 JournalStructure.class.getName())),
188 new ClassPKContainer(
189 AvailableMappersUtil.getJournalStructureIdMapper(), false));
190
191
193 classPKContainers.put(
194 new Long(PortalUtil.getClassNameId(
195 JournalTemplate.class.getName())),
196 new ClassPKContainer(
197 AvailableMappersUtil.getJournalTemplateIdMapper(), false));
198
199
201 classPKContainers.put(
202 new Long(PortalUtil.getClassNameId(Layout.class.getName())),
203 new ClassPKContainer(
204 AvailableMappersUtil.getLayoutPlidMapper(), false));
205
206
208 classPKContainers.put(
209 new Long(PortalUtil.getClassNameId(Location.class.getName())),
210 new ClassPKContainer(
211 AvailableMappersUtil.getOrganizationIdMapper(), true));
212
213
215 classPKContainers.put(
216 new Long(PortalUtil.getClassNameId(MBCategory.class.getName())),
217 new ClassPKContainer(
218 AvailableMappersUtil.getMBCategoryIdMapper(), true));
219
220
222 classPKContainers.put(
223 new Long(PortalUtil.getClassNameId(MBMessage.class.getName())),
224 new ClassPKContainer(
225 new MBMessageIdMapper(
226 AvailableMappersUtil.getMBMessageIdMapper()),
227 false));
228
229
231 classPKContainers.put(
232 new Long(PortalUtil.getClassNameId(Organization.class.getName())),
233 new ClassPKContainer(
234 AvailableMappersUtil.getOrganizationIdMapper(), true));
235
236
238 classPKContainers.put(
239 new Long(PortalUtil.getClassNameId(PollsQuestion.class.getName())),
240 new ClassPKContainer(
241 AvailableMappersUtil.getPollsQuestionIdMapper(), true));
242
243
245 classPKContainers.put(
246 new Long(PortalUtil.getClassNameId(Role.class.getName())),
247 new ClassPKContainer(AvailableMappersUtil.getRoleIdMapper(), true));
248
249
251 classPKContainers.put(
252 new Long(PortalUtil.getClassNameId(
253 ShoppingCategory.class.getName())),
254 new ClassPKContainer(
255 AvailableMappersUtil.getShoppingCategoryIdMapper(), true));
256
257
259 classPKContainers.put(
260 new Long(PortalUtil.getClassNameId(ShoppingItem.class.getName())),
261 new ClassPKContainer(
262 AvailableMappersUtil.getShoppingItemIdMapper(), true));
263
264
266 classPKContainers.put(
267 new Long(PortalUtil.getClassNameId(User.class.getName())),
268 new ClassPKContainer(
269 AvailableMappersUtil.getUserIdMapper(), false));
270
271
273 classPKContainers.put(
274 new Long(PortalUtil.getClassNameId(UserGroup.class.getName())),
275 new ClassPKContainer(
276 AvailableMappersUtil.getUserGroupIdMapper(), true));
277
278
280 classPKContainers.put(
281 new Long(PortalUtil.getClassNameId(WikiNode.class.getName())),
282 new ClassPKContainer(
283 AvailableMappersUtil.getWikiNodeIdMapper(), true));
284
285
287 classPKContainers.put(
288 new Long(PortalUtil.getClassNameId(WikiPage.class.getName())),
289 new ClassPKContainer(
290 AvailableMappersUtil.getWikiPageIdMapper(), false));
291
292 return classPKContainers;
293 }
294
295 protected void doUpgrade() throws Exception {
296
297
299 Object[][] resourceColumns1 = {
300 {"companyId", new Integer(Types.BIGINT)},
301 {"name", new Integer(Types.VARCHAR)},
302 {"scope", new Integer(Types.VARCHAR)}
303 };
304 Object[][] resourceColumns2 =
305 (Object[][])ResourceImpl.TABLE_COLUMNS.clone();
306
307 Object[][] resourceColumns = ArrayUtil.append(
308 resourceColumns1, resourceColumns2);
309
310 UpgradeColumn companyIdColumn = new TempUpgradeColumnImpl("companyId");
311
312 UpgradeColumn nameColumn = new TempUpgradeColumnImpl("name");
313
314 UpgradeColumn scopeColumn = new TempUpgradeColumnImpl("scope");
315
316 ResourceCodeIdUpgradeColumnImpl codeIdColumn =
317 new ResourceCodeIdUpgradeColumnImpl(
318 companyIdColumn, nameColumn, scopeColumn);
319
320 UpgradeColumn primKeyColumn = new ResourcePrimKeyUpgradeColumnImpl(
321 nameColumn, codeIdColumn, AvailableMappersUtil.getGroupIdMapper(),
322 getClassPKContainers(), AvailableMappersUtil.getLayoutPlidMapper());
323
324 UpgradeTable upgradeTable = new DefaultUpgradeTableImpl(
325 ResourceImpl.TABLE_NAME, resourceColumns, companyIdColumn,
326 nameColumn, scopeColumn, codeIdColumn, primKeyColumn);
327
328 String createSQL = ResourceImpl.TABLE_SQL_CREATE;
329
330 createSQL =
331 createSQL.substring(0, createSQL.length() - 1) +
332 ",companyId VARCHAR(75) null, name VARCHAR(75) null, " +
333 "scope VARCHAR(75) null)";
334
335 upgradeTable.setCreateSQL(createSQL);
336
337 upgradeTable.updateTable();
338
339
341 runSQL(_UPGRADE_SCHEMA);
342 }
343
344 private static final String[] _UPGRADE_SCHEMA = {
345 "alter table Resource_ drop column companyId",
346 "alter table Resource_ drop column name",
347 "alter table Resource_ drop column scope"
348 };
349
350 private static Log _log = LogFactory.getLog(UpgradeResource.class);
351
352 }