1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * The contents of this file are subject to the terms of the Liferay Enterprise
5    * Subscription License ("License"). You may not use this file except in
6    * compliance with the License. You can obtain a copy of the License by
7    * contacting Liferay, Inc. See the License for the specific language governing
8    * permissions and limitations under the License, including but not limited to
9    * distribution rights of the Software.
10   *
11   *
12   *
13   */
14  
15  package com.liferay.portal.upgrade.v4_3_0;
16  
17  import com.liferay.portal.kernel.upgrade.UpgradeProcess;
18  import com.liferay.portal.kernel.upgrade.util.TempUpgradeColumnImpl;
19  import com.liferay.portal.kernel.upgrade.util.UpgradeColumn;
20  import com.liferay.portal.kernel.upgrade.util.UpgradeTable;
21  import com.liferay.portal.kernel.upgrade.util.UpgradeTableFactoryUtil;
22  import com.liferay.portal.kernel.util.ArrayUtil;
23  import com.liferay.portal.model.Group;
24  import com.liferay.portal.model.Layout;
25  import com.liferay.portal.model.Location;
26  import com.liferay.portal.model.Organization;
27  import com.liferay.portal.model.Role;
28  import com.liferay.portal.model.User;
29  import com.liferay.portal.model.UserGroup;
30  import com.liferay.portal.upgrade.v4_3_0.util.AvailableMappersUtil;
31  import com.liferay.portal.upgrade.v4_3_0.util.ClassPKContainer;
32  import com.liferay.portal.upgrade.v4_3_0.util.MBMessageIdMapper;
33  import com.liferay.portal.upgrade.v4_3_0.util.ResourceCodeIdUpgradeColumnImpl;
34  import com.liferay.portal.upgrade.v4_3_0.util.ResourcePrimKeyUpgradeColumnImpl;
35  import com.liferay.portal.upgrade.v4_3_0.util.ResourceTable;
36  import com.liferay.portal.util.PortalUtil;
37  import com.liferay.portlet.blogs.model.BlogsEntry;
38  import com.liferay.portlet.bookmarks.model.BookmarksEntry;
39  import com.liferay.portlet.bookmarks.model.BookmarksFolder;
40  import com.liferay.portlet.calendar.model.CalEvent;
41  import com.liferay.portlet.documentlibrary.model.DLFileEntry;
42  import com.liferay.portlet.documentlibrary.model.DLFileShortcut;
43  import com.liferay.portlet.documentlibrary.model.DLFolder;
44  import com.liferay.portlet.imagegallery.model.IGFolder;
45  import com.liferay.portlet.imagegallery.model.IGImage;
46  import com.liferay.portlet.journal.model.JournalArticle;
47  import com.liferay.portlet.journal.model.JournalStructure;
48  import com.liferay.portlet.journal.model.JournalTemplate;
49  import com.liferay.portlet.messageboards.model.MBCategory;
50  import com.liferay.portlet.messageboards.model.MBMessage;
51  import com.liferay.portlet.polls.model.PollsQuestion;
52  import com.liferay.portlet.shopping.model.ShoppingCategory;
53  import com.liferay.portlet.shopping.model.ShoppingItem;
54  import com.liferay.portlet.wiki.model.WikiNode;
55  import com.liferay.portlet.wiki.model.WikiPage;
56  
57  import java.sql.Types;
58  
59  import java.util.HashMap;
60  import java.util.Map;
61  
62  /**
63   * <a href="UpgradeResource.java.html"><b><i>View Source</i></b></a>
64   *
65   * @author     Alexander Chow
66   * @author     Brian Wing Shun Chan
67   * @deprecated
68   */
69  public class UpgradeResource extends UpgradeProcess {
70  
71      protected Map<Long, ClassPKContainer> getClassPKContainers() {
72          Map<Long, ClassPKContainer> classPKContainers =
73              new HashMap<Long, ClassPKContainer>();
74  
75          // BlogsEntry
76  
77          classPKContainers.put(
78              new Long(PortalUtil.getClassNameId(BlogsEntry.class.getName())),
79              new ClassPKContainer(
80                  AvailableMappersUtil.getBlogsEntryIdMapper(), true));
81  
82          // BookmarksEntry
83  
84          classPKContainers.put(
85              new Long(PortalUtil.getClassNameId(BookmarksEntry.class.getName())),
86              new ClassPKContainer(
87                  AvailableMappersUtil.getBookmarksEntryIdMapper(), true));
88  
89          // BookmarksFolder
90  
91          classPKContainers.put(
92              new Long(PortalUtil.getClassNameId(
93                  BookmarksFolder.class.getName())),
94              new ClassPKContainer(
95                  AvailableMappersUtil.getBookmarksFolderIdMapper(), true));
96  
97          // CalEvent
98  
99          classPKContainers.put(
100             new Long(PortalUtil.getClassNameId(CalEvent.class.getName())),
101             new ClassPKContainer(
102                 AvailableMappersUtil.getCalEventIdMapper(), true));
103 
104         // DLFileEntry
105 
106         classPKContainers.put(
107             new Long(PortalUtil.getClassNameId(DLFileEntry.class.getName())),
108             new ClassPKContainer(
109                 AvailableMappersUtil.getDLFileEntryIdMapper(), false));
110 
111         // DLFileShortcut
112 
113         classPKContainers.put(
114             new Long(PortalUtil.getClassNameId(DLFileShortcut.class.getName())),
115             new ClassPKContainer(
116                 AvailableMappersUtil.getDLFileShortcutIdMapper(), true));
117 
118         // DLFolder
119 
120         classPKContainers.put(
121             new Long(PortalUtil.getClassNameId(DLFolder.class.getName())),
122             new ClassPKContainer(
123                 AvailableMappersUtil.getDLFolderIdMapper(), true));
124 
125         // Group
126 
127         classPKContainers.put(
128             new Long(PortalUtil.getClassNameId(Group.class.getName())),
129             new ClassPKContainer(
130                 AvailableMappersUtil.getGroupIdMapper(), true));
131 
132         // IGFolder
133 
134         classPKContainers.put(
135             new Long(PortalUtil.getClassNameId(IGFolder.class.getName())),
136             new ClassPKContainer(
137                 AvailableMappersUtil.getIGFolderIdMapper(), true));
138 
139         // IGImage
140 
141         classPKContainers.put(
142             new Long(PortalUtil.getClassNameId(IGImage.class.getName())),
143             new ClassPKContainer(
144                 AvailableMappersUtil.getIGImageIdMapper(), false));
145 
146         // JournalArticle
147 
148         classPKContainers.put(
149             new Long(PortalUtil.getClassNameId(JournalArticle.class.getName())),
150             new ClassPKContainer(
151                 AvailableMappersUtil.getJournalArticleIdMapper(), false));
152 
153         // JournalStructure
154 
155         classPKContainers.put(
156             new Long(PortalUtil.getClassNameId(
157                 JournalStructure.class.getName())),
158             new ClassPKContainer(
159                 AvailableMappersUtil.getJournalStructureIdMapper(), false));
160 
161         // JournalTemplate
162 
163         classPKContainers.put(
164             new Long(PortalUtil.getClassNameId(
165                 JournalTemplate.class.getName())),
166             new ClassPKContainer(
167                 AvailableMappersUtil.getJournalTemplateIdMapper(), false));
168 
169         // Layout
170 
171         classPKContainers.put(
172             new Long(PortalUtil.getClassNameId(Layout.class.getName())),
173             new ClassPKContainer(
174                 AvailableMappersUtil.getLayoutPlidMapper(), false));
175 
176         // Location
177 
178         classPKContainers.put(
179             new Long(PortalUtil.getClassNameId(Location.class.getName())),
180             new ClassPKContainer(
181                 AvailableMappersUtil.getOrganizationIdMapper(), true));
182 
183         // MBCategory
184 
185         classPKContainers.put(
186             new Long(PortalUtil.getClassNameId(MBCategory.class.getName())),
187             new ClassPKContainer(
188                 AvailableMappersUtil.getMBCategoryIdMapper(), true));
189 
190         // MBMessage
191 
192         classPKContainers.put(
193             new Long(PortalUtil.getClassNameId(MBMessage.class.getName())),
194             new ClassPKContainer(
195                 new MBMessageIdMapper(
196                     AvailableMappersUtil.getMBMessageIdMapper()),
197                 false));
198 
199         // Organization
200 
201         classPKContainers.put(
202             new Long(PortalUtil.getClassNameId(Organization.class.getName())),
203             new ClassPKContainer(
204                 AvailableMappersUtil.getOrganizationIdMapper(), true));
205 
206         // PollsQuestion
207 
208         classPKContainers.put(
209             new Long(PortalUtil.getClassNameId(PollsQuestion.class.getName())),
210             new ClassPKContainer(
211                 AvailableMappersUtil.getPollsQuestionIdMapper(), true));
212 
213         // Role
214 
215         classPKContainers.put(
216             new Long(PortalUtil.getClassNameId(Role.class.getName())),
217             new ClassPKContainer(AvailableMappersUtil.getRoleIdMapper(), true));
218 
219         // ShoppingCategory
220 
221         classPKContainers.put(
222             new Long(PortalUtil.getClassNameId(
223                 ShoppingCategory.class.getName())),
224             new ClassPKContainer(
225                 AvailableMappersUtil.getShoppingCategoryIdMapper(), true));
226 
227         // ShoppingItem
228 
229         classPKContainers.put(
230             new Long(PortalUtil.getClassNameId(ShoppingItem.class.getName())),
231             new ClassPKContainer(
232                 AvailableMappersUtil.getShoppingItemIdMapper(), true));
233 
234         // User
235 
236         classPKContainers.put(
237             new Long(PortalUtil.getClassNameId(User.class.getName())),
238             new ClassPKContainer(
239                 AvailableMappersUtil.getUserIdMapper(), false));
240 
241         // UserGroup
242 
243         classPKContainers.put(
244             new Long(PortalUtil.getClassNameId(UserGroup.class.getName())),
245             new ClassPKContainer(
246                 AvailableMappersUtil.getUserGroupIdMapper(), true));
247 
248         // WikiNode
249 
250         classPKContainers.put(
251             new Long(PortalUtil.getClassNameId(WikiNode.class.getName())),
252             new ClassPKContainer(
253                 AvailableMappersUtil.getWikiNodeIdMapper(), true));
254 
255         // WikiPage
256 
257         classPKContainers.put(
258             new Long(PortalUtil.getClassNameId(WikiPage.class.getName())),
259             new ClassPKContainer(
260                 AvailableMappersUtil.getWikiPageIdMapper(), false));
261 
262         return classPKContainers;
263     }
264 
265     protected void doUpgrade() throws Exception {
266 
267         // Resource
268 
269         Object[][] resourceColumns1 = {
270             {"companyId", new Integer(Types.BIGINT)},
271             {"name", new Integer(Types.VARCHAR)},
272             {"scope", new Integer(Types.VARCHAR)}
273         };
274         Object[][] resourceColumns2 = ResourceTable.TABLE_COLUMNS.clone();
275 
276         Object[][] resourceColumns = ArrayUtil.append(
277             resourceColumns1, resourceColumns2);
278 
279         UpgradeColumn companyIdColumn = new TempUpgradeColumnImpl("companyId");
280 
281         UpgradeColumn nameColumn = new TempUpgradeColumnImpl("name");
282 
283         UpgradeColumn scopeColumn = new TempUpgradeColumnImpl("scope");
284 
285         ResourceCodeIdUpgradeColumnImpl codeIdColumn =
286             new ResourceCodeIdUpgradeColumnImpl(
287                 companyIdColumn, nameColumn, scopeColumn);
288 
289         UpgradeColumn primKeyColumn = new ResourcePrimKeyUpgradeColumnImpl(
290             nameColumn, codeIdColumn, AvailableMappersUtil.getGroupIdMapper(),
291             getClassPKContainers(), AvailableMappersUtil.getLayoutPlidMapper());
292 
293         UpgradeTable upgradeTable = UpgradeTableFactoryUtil.getUpgradeTable(
294             ResourceTable.TABLE_NAME, resourceColumns, companyIdColumn,
295             nameColumn, scopeColumn, codeIdColumn, primKeyColumn);
296 
297         String createSQL = ResourceTable.TABLE_SQL_CREATE;
298 
299         createSQL =
300             createSQL.substring(0, createSQL.length() - 1) +
301                 ",companyId VARCHAR(75) null, name VARCHAR(75) null, " +
302                     "scope VARCHAR(75) null)";
303 
304         upgradeTable.setCreateSQL(createSQL);
305 
306         upgradeTable.updateTable();
307 
308         // Schema
309 
310         runSQL(_UPGRADE_SCHEMA);
311     }
312 
313     private static final String[] _UPGRADE_SCHEMA = {
314         "alter table Resource_ drop column companyId",
315         "alter table Resource_ drop column name",
316         "alter table Resource_ drop column scope"
317     };
318 
319 }