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