1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    * Permission is hereby granted, free of charge, to any person obtaining a copy
5    * of this software and associated documentation files (the "Software"), to deal
6    * in the Software without restriction, including without limitation the rights
7    * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8    * copies of the Software, and to permit persons to whom the Software is
9    * furnished to do so, subject to the following conditions:
10   *
11   * The above copyright notice and this permission notice shall be included in
12   * all copies or substantial portions of the Software.
13   *
14   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20   * SOFTWARE.
21   */
22  
23  package com.liferay.portal.upgrade.v4_3_0;
24  
25  import com.liferay.portal.kernel.log.Log;
26  import com.liferay.portal.kernel.log.LogFactoryUtil;
27  import com.liferay.portal.kernel.util.ArrayUtil;
28  import com.liferay.portal.model.Group;
29  import com.liferay.portal.model.Layout;
30  import com.liferay.portal.model.Location;
31  import com.liferay.portal.model.Organization;
32  import com.liferay.portal.model.Role;
33  import com.liferay.portal.model.User;
34  import com.liferay.portal.model.UserGroup;
35  import com.liferay.portal.model.impl.ResourceImpl;
36  import com.liferay.portal.upgrade.UpgradeException;
37  import com.liferay.portal.upgrade.UpgradeProcess;
38  import com.liferay.portal.upgrade.util.DefaultUpgradeTableImpl;
39  import com.liferay.portal.upgrade.util.TempUpgradeColumnImpl;
40  import com.liferay.portal.upgrade.util.UpgradeColumn;
41  import com.liferay.portal.upgrade.util.UpgradeTable;
42  import com.liferay.portal.upgrade.v4_3_0.util.AvailableMappersUtil;
43  import com.liferay.portal.upgrade.v4_3_0.util.ClassPKContainer;
44  import com.liferay.portal.upgrade.v4_3_0.util.MBMessageIdMapper;
45  import com.liferay.portal.upgrade.v4_3_0.util.ResourceCodeIdUpgradeColumnImpl;
46  import com.liferay.portal.upgrade.v4_3_0.util.ResourcePrimKeyUpgradeColumnImpl;
47  import com.liferay.portal.util.PortalUtil;
48  import com.liferay.portlet.blogs.model.BlogsEntry;
49  import com.liferay.portlet.bookmarks.model.BookmarksEntry;
50  import com.liferay.portlet.bookmarks.model.BookmarksFolder;
51  import com.liferay.portlet.calendar.model.CalEvent;
52  import com.liferay.portlet.documentlibrary.model.DLFileEntry;
53  import com.liferay.portlet.documentlibrary.model.DLFileShortcut;
54  import com.liferay.portlet.documentlibrary.model.DLFolder;
55  import com.liferay.portlet.imagegallery.model.IGFolder;
56  import com.liferay.portlet.imagegallery.model.IGImage;
57  import com.liferay.portlet.journal.model.JournalArticle;
58  import com.liferay.portlet.journal.model.JournalStructure;
59  import com.liferay.portlet.journal.model.JournalTemplate;
60  import com.liferay.portlet.messageboards.model.MBCategory;
61  import com.liferay.portlet.messageboards.model.MBMessage;
62  import com.liferay.portlet.polls.model.PollsQuestion;
63  import com.liferay.portlet.shopping.model.ShoppingCategory;
64  import com.liferay.portlet.shopping.model.ShoppingItem;
65  import com.liferay.portlet.wiki.model.WikiNode;
66  import com.liferay.portlet.wiki.model.WikiPage;
67  
68  import java.sql.Types;
69  
70  import java.util.HashMap;
71  import java.util.Map;
72  
73  /**
74   * <a href="UpgradeResource.java.html"><b><i>View Source</i></b></a>
75   *
76   * @author Alexander Chow
77   * @author Brian Wing Shun Chan
78   *
79   * @deprecated
80   *
81   */
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<Long, ClassPKContainer> getClassPKContainers() {
96          Map<Long, ClassPKContainer> classPKContainers =
97              new HashMap<Long, ClassPKContainer>();
98  
99          // BlogsEntry
100 
101         classPKContainers.put(
102             new Long(PortalUtil.getClassNameId(BlogsEntry.class.getName())),
103             new ClassPKContainer(
104                 AvailableMappersUtil.getBlogsEntryIdMapper(), true));
105 
106         // BookmarksEntry
107 
108         classPKContainers.put(
109             new Long(PortalUtil.getClassNameId(BookmarksEntry.class.getName())),
110             new ClassPKContainer(
111                 AvailableMappersUtil.getBookmarksEntryIdMapper(), true));
112 
113         // BookmarksFolder
114 
115         classPKContainers.put(
116             new Long(PortalUtil.getClassNameId(
117                 BookmarksFolder.class.getName())),
118             new ClassPKContainer(
119                 AvailableMappersUtil.getBookmarksFolderIdMapper(), true));
120 
121         // CalEvent
122 
123         classPKContainers.put(
124             new Long(PortalUtil.getClassNameId(CalEvent.class.getName())),
125             new ClassPKContainer(
126                 AvailableMappersUtil.getCalEventIdMapper(), true));
127 
128         // DLFileEntry
129 
130         classPKContainers.put(
131             new Long(PortalUtil.getClassNameId(DLFileEntry.class.getName())),
132             new ClassPKContainer(
133                 AvailableMappersUtil.getDLFileEntryIdMapper(), false));
134 
135         // DLFileShortcut
136 
137         classPKContainers.put(
138             new Long(PortalUtil.getClassNameId(DLFileShortcut.class.getName())),
139             new ClassPKContainer(
140                 AvailableMappersUtil.getDLFileShortcutIdMapper(), true));
141 
142         // DLFolder
143 
144         classPKContainers.put(
145             new Long(PortalUtil.getClassNameId(DLFolder.class.getName())),
146             new ClassPKContainer(
147                 AvailableMappersUtil.getDLFolderIdMapper(), true));
148 
149         // Group
150 
151         classPKContainers.put(
152             new Long(PortalUtil.getClassNameId(Group.class.getName())),
153             new ClassPKContainer(
154                 AvailableMappersUtil.getGroupIdMapper(), true));
155 
156         // IGFolder
157 
158         classPKContainers.put(
159             new Long(PortalUtil.getClassNameId(IGFolder.class.getName())),
160             new ClassPKContainer(
161                 AvailableMappersUtil.getIGFolderIdMapper(), true));
162 
163         // IGImage
164 
165         classPKContainers.put(
166             new Long(PortalUtil.getClassNameId(IGImage.class.getName())),
167             new ClassPKContainer(
168                 AvailableMappersUtil.getIGImageIdMapper(), false));
169 
170         // JournalArticle
171 
172         classPKContainers.put(
173             new Long(PortalUtil.getClassNameId(JournalArticle.class.getName())),
174             new ClassPKContainer(
175                 AvailableMappersUtil.getJournalArticleIdMapper(), false));
176 
177         // JournalStructure
178 
179         classPKContainers.put(
180             new Long(PortalUtil.getClassNameId(
181                 JournalStructure.class.getName())),
182             new ClassPKContainer(
183                 AvailableMappersUtil.getJournalStructureIdMapper(), false));
184 
185         // JournalTemplate
186 
187         classPKContainers.put(
188             new Long(PortalUtil.getClassNameId(
189                 JournalTemplate.class.getName())),
190             new ClassPKContainer(
191                 AvailableMappersUtil.getJournalTemplateIdMapper(), false));
192 
193         // Layout
194 
195         classPKContainers.put(
196             new Long(PortalUtil.getClassNameId(Layout.class.getName())),
197             new ClassPKContainer(
198                 AvailableMappersUtil.getLayoutPlidMapper(), false));
199 
200         // Location
201 
202         classPKContainers.put(
203             new Long(PortalUtil.getClassNameId(Location.class.getName())),
204             new ClassPKContainer(
205                 AvailableMappersUtil.getOrganizationIdMapper(), true));
206 
207         // MBCategory
208 
209         classPKContainers.put(
210             new Long(PortalUtil.getClassNameId(MBCategory.class.getName())),
211             new ClassPKContainer(
212                 AvailableMappersUtil.getMBCategoryIdMapper(), true));
213 
214         // MBMessage
215 
216         classPKContainers.put(
217             new Long(PortalUtil.getClassNameId(MBMessage.class.getName())),
218             new ClassPKContainer(
219                 new MBMessageIdMapper(
220                     AvailableMappersUtil.getMBMessageIdMapper()),
221                 false));
222 
223         // Organization
224 
225         classPKContainers.put(
226             new Long(PortalUtil.getClassNameId(Organization.class.getName())),
227             new ClassPKContainer(
228                 AvailableMappersUtil.getOrganizationIdMapper(), true));
229 
230         // PollsQuestion
231 
232         classPKContainers.put(
233             new Long(PortalUtil.getClassNameId(PollsQuestion.class.getName())),
234             new ClassPKContainer(
235                 AvailableMappersUtil.getPollsQuestionIdMapper(), true));
236 
237         // Role
238 
239         classPKContainers.put(
240             new Long(PortalUtil.getClassNameId(Role.class.getName())),
241             new ClassPKContainer(AvailableMappersUtil.getRoleIdMapper(), true));
242 
243         // ShoppingCategory
244 
245         classPKContainers.put(
246             new Long(PortalUtil.getClassNameId(
247                 ShoppingCategory.class.getName())),
248             new ClassPKContainer(
249                 AvailableMappersUtil.getShoppingCategoryIdMapper(), true));
250 
251         // ShoppingItem
252 
253         classPKContainers.put(
254             new Long(PortalUtil.getClassNameId(ShoppingItem.class.getName())),
255             new ClassPKContainer(
256                 AvailableMappersUtil.getShoppingItemIdMapper(), true));
257 
258         // User
259 
260         classPKContainers.put(
261             new Long(PortalUtil.getClassNameId(User.class.getName())),
262             new ClassPKContainer(
263                 AvailableMappersUtil.getUserIdMapper(), false));
264 
265         // UserGroup
266 
267         classPKContainers.put(
268             new Long(PortalUtil.getClassNameId(UserGroup.class.getName())),
269             new ClassPKContainer(
270                 AvailableMappersUtil.getUserGroupIdMapper(), true));
271 
272         // WikiNode
273 
274         classPKContainers.put(
275             new Long(PortalUtil.getClassNameId(WikiNode.class.getName())),
276             new ClassPKContainer(
277                 AvailableMappersUtil.getWikiNodeIdMapper(), true));
278 
279         // WikiPage
280 
281         classPKContainers.put(
282             new Long(PortalUtil.getClassNameId(WikiPage.class.getName())),
283             new ClassPKContainer(
284                 AvailableMappersUtil.getWikiPageIdMapper(), false));
285 
286         return classPKContainers;
287     }
288 
289     protected void doUpgrade() throws Exception {
290 
291         // Resource
292 
293         Object[][] resourceColumns1 = {
294             {"companyId", new Integer(Types.BIGINT)},
295             {"name", new Integer(Types.VARCHAR)},
296             {"scope", new Integer(Types.VARCHAR)}
297         };
298         Object[][] resourceColumns2 = ResourceImpl.TABLE_COLUMNS.clone();
299 
300         Object[][] resourceColumns = ArrayUtil.append(
301             resourceColumns1, resourceColumns2);
302 
303         UpgradeColumn companyIdColumn = new TempUpgradeColumnImpl("companyId");
304 
305         UpgradeColumn nameColumn = new TempUpgradeColumnImpl("name");
306 
307         UpgradeColumn scopeColumn = new TempUpgradeColumnImpl("scope");
308 
309         ResourceCodeIdUpgradeColumnImpl codeIdColumn =
310             new ResourceCodeIdUpgradeColumnImpl(
311                 companyIdColumn, nameColumn, scopeColumn);
312 
313         UpgradeColumn primKeyColumn = new ResourcePrimKeyUpgradeColumnImpl(
314             nameColumn, codeIdColumn, AvailableMappersUtil.getGroupIdMapper(),
315             getClassPKContainers(), AvailableMappersUtil.getLayoutPlidMapper());
316 
317         UpgradeTable upgradeTable = new DefaultUpgradeTableImpl(
318             ResourceImpl.TABLE_NAME, resourceColumns, companyIdColumn,
319             nameColumn, scopeColumn, codeIdColumn, primKeyColumn);
320 
321         String createSQL = ResourceImpl.TABLE_SQL_CREATE;
322 
323         createSQL =
324             createSQL.substring(0, createSQL.length() - 1) +
325                 ",companyId VARCHAR(75) null, name VARCHAR(75) null, " +
326                     "scope VARCHAR(75) null)";
327 
328         upgradeTable.setCreateSQL(createSQL);
329 
330         upgradeTable.updateTable();
331 
332         // Schema
333 
334         runSQL(_UPGRADE_SCHEMA);
335     }
336 
337     private static final String[] _UPGRADE_SCHEMA = {
338         "alter table Resource_ drop column companyId",
339         "alter table Resource_ drop column name",
340         "alter table Resource_ drop column scope"
341     };
342 
343     private static Log _log = LogFactoryUtil.getLog(UpgradeResource.class);
344 
345 }