001
014
015 package com.liferay.portal.upgrade.v4_3_0;
016
017 import com.liferay.portal.kernel.upgrade.UpgradeProcess;
018 import com.liferay.portal.kernel.upgrade.util.TempUpgradeColumnImpl;
019 import com.liferay.portal.kernel.upgrade.util.UpgradeColumn;
020 import com.liferay.portal.kernel.upgrade.util.UpgradeTable;
021 import com.liferay.portal.kernel.upgrade.util.UpgradeTableFactoryUtil;
022 import com.liferay.portal.kernel.util.ArrayUtil;
023 import com.liferay.portal.model.Group;
024 import com.liferay.portal.model.Layout;
025 import com.liferay.portal.model.Location;
026 import com.liferay.portal.model.Organization;
027 import com.liferay.portal.model.Role;
028 import com.liferay.portal.model.User;
029 import com.liferay.portal.model.UserGroup;
030 import com.liferay.portal.upgrade.v4_3_0.util.AvailableMappersUtil;
031 import com.liferay.portal.upgrade.v4_3_0.util.ClassPKContainer;
032 import com.liferay.portal.upgrade.v4_3_0.util.MBMessageIdMapper;
033 import com.liferay.portal.upgrade.v4_3_0.util.ResourceCodeIdUpgradeColumnImpl;
034 import com.liferay.portal.upgrade.v4_3_0.util.ResourcePrimKeyUpgradeColumnImpl;
035 import com.liferay.portal.upgrade.v4_3_0.util.ResourceTable;
036 import com.liferay.portal.util.PortalUtil;
037 import com.liferay.portlet.blogs.model.BlogsEntry;
038 import com.liferay.portlet.bookmarks.model.BookmarksEntry;
039 import com.liferay.portlet.bookmarks.model.BookmarksFolder;
040 import com.liferay.portlet.calendar.model.CalEvent;
041 import com.liferay.portlet.documentlibrary.model.DLFileEntry;
042 import com.liferay.portlet.documentlibrary.model.DLFileShortcut;
043 import com.liferay.portlet.documentlibrary.model.DLFolder;
044 import com.liferay.portlet.imagegallery.model.IGFolder;
045 import com.liferay.portlet.imagegallery.model.IGImage;
046 import com.liferay.portlet.journal.model.JournalArticle;
047 import com.liferay.portlet.journal.model.JournalStructure;
048 import com.liferay.portlet.journal.model.JournalTemplate;
049 import com.liferay.portlet.messageboards.model.MBCategory;
050 import com.liferay.portlet.messageboards.model.MBMessage;
051 import com.liferay.portlet.polls.model.PollsQuestion;
052 import com.liferay.portlet.shopping.model.ShoppingCategory;
053 import com.liferay.portlet.shopping.model.ShoppingItem;
054 import com.liferay.portlet.wiki.model.WikiNode;
055 import com.liferay.portlet.wiki.model.WikiPage;
056
057 import java.sql.Types;
058
059 import java.util.HashMap;
060 import java.util.Map;
061
062
067 public class UpgradeResource extends UpgradeProcess {
068
069 protected Map<Long, ClassPKContainer> getClassPKContainers() {
070 Map<Long, ClassPKContainer> classPKContainers =
071 new HashMap<Long, ClassPKContainer>();
072
073
074
075 classPKContainers.put(
076 new Long(PortalUtil.getClassNameId(BlogsEntry.class.getName())),
077 new ClassPKContainer(
078 AvailableMappersUtil.getBlogsEntryIdMapper(), true));
079
080
081
082 classPKContainers.put(
083 new Long(PortalUtil.getClassNameId(BookmarksEntry.class.getName())),
084 new ClassPKContainer(
085 AvailableMappersUtil.getBookmarksEntryIdMapper(), true));
086
087
088
089 classPKContainers.put(
090 new Long(PortalUtil.getClassNameId(
091 BookmarksFolder.class.getName())),
092 new ClassPKContainer(
093 AvailableMappersUtil.getBookmarksFolderIdMapper(), true));
094
095
096
097 classPKContainers.put(
098 new Long(PortalUtil.getClassNameId(CalEvent.class.getName())),
099 new ClassPKContainer(
100 AvailableMappersUtil.getCalEventIdMapper(), true));
101
102
103
104 classPKContainers.put(
105 new Long(PortalUtil.getClassNameId(DLFileEntry.class.getName())),
106 new ClassPKContainer(
107 AvailableMappersUtil.getDLFileEntryIdMapper(), false));
108
109
110
111 classPKContainers.put(
112 new Long(PortalUtil.getClassNameId(DLFileShortcut.class.getName())),
113 new ClassPKContainer(
114 AvailableMappersUtil.getDLFileShortcutIdMapper(), true));
115
116
117
118 classPKContainers.put(
119 new Long(PortalUtil.getClassNameId(DLFolder.class.getName())),
120 new ClassPKContainer(
121 AvailableMappersUtil.getDLFolderIdMapper(), true));
122
123
124
125 classPKContainers.put(
126 new Long(PortalUtil.getClassNameId(Group.class.getName())),
127 new ClassPKContainer(
128 AvailableMappersUtil.getGroupIdMapper(), true));
129
130
131
132 classPKContainers.put(
133 new Long(PortalUtil.getClassNameId(IGFolder.class.getName())),
134 new ClassPKContainer(
135 AvailableMappersUtil.getIGFolderIdMapper(), true));
136
137
138
139 classPKContainers.put(
140 new Long(PortalUtil.getClassNameId(IGImage.class.getName())),
141 new ClassPKContainer(
142 AvailableMappersUtil.getIGImageIdMapper(), false));
143
144
145
146 classPKContainers.put(
147 new Long(PortalUtil.getClassNameId(JournalArticle.class.getName())),
148 new ClassPKContainer(
149 AvailableMappersUtil.getJournalArticleIdMapper(), false));
150
151
152
153 classPKContainers.put(
154 new Long(PortalUtil.getClassNameId(
155 JournalStructure.class.getName())),
156 new ClassPKContainer(
157 AvailableMappersUtil.getJournalStructureIdMapper(), false));
158
159
160
161 classPKContainers.put(
162 new Long(PortalUtil.getClassNameId(
163 JournalTemplate.class.getName())),
164 new ClassPKContainer(
165 AvailableMappersUtil.getJournalTemplateIdMapper(), false));
166
167
168
169 classPKContainers.put(
170 new Long(PortalUtil.getClassNameId(Layout.class.getName())),
171 new ClassPKContainer(
172 AvailableMappersUtil.getLayoutPlidMapper(), false));
173
174
175
176 classPKContainers.put(
177 new Long(PortalUtil.getClassNameId(Location.class.getName())),
178 new ClassPKContainer(
179 AvailableMappersUtil.getOrganizationIdMapper(), true));
180
181
182
183 classPKContainers.put(
184 new Long(PortalUtil.getClassNameId(MBCategory.class.getName())),
185 new ClassPKContainer(
186 AvailableMappersUtil.getMBCategoryIdMapper(), true));
187
188
189
190 classPKContainers.put(
191 new Long(PortalUtil.getClassNameId(MBMessage.class.getName())),
192 new ClassPKContainer(
193 new MBMessageIdMapper(
194 AvailableMappersUtil.getMBMessageIdMapper()),
195 false));
196
197
198
199 classPKContainers.put(
200 new Long(PortalUtil.getClassNameId(Organization.class.getName())),
201 new ClassPKContainer(
202 AvailableMappersUtil.getOrganizationIdMapper(), true));
203
204
205
206 classPKContainers.put(
207 new Long(PortalUtil.getClassNameId(PollsQuestion.class.getName())),
208 new ClassPKContainer(
209 AvailableMappersUtil.getPollsQuestionIdMapper(), true));
210
211
212
213 classPKContainers.put(
214 new Long(PortalUtil.getClassNameId(Role.class.getName())),
215 new ClassPKContainer(AvailableMappersUtil.getRoleIdMapper(), true));
216
217
218
219 classPKContainers.put(
220 new Long(PortalUtil.getClassNameId(
221 ShoppingCategory.class.getName())),
222 new ClassPKContainer(
223 AvailableMappersUtil.getShoppingCategoryIdMapper(), true));
224
225
226
227 classPKContainers.put(
228 new Long(PortalUtil.getClassNameId(ShoppingItem.class.getName())),
229 new ClassPKContainer(
230 AvailableMappersUtil.getShoppingItemIdMapper(), true));
231
232
233
234 classPKContainers.put(
235 new Long(PortalUtil.getClassNameId(User.class.getName())),
236 new ClassPKContainer(
237 AvailableMappersUtil.getUserIdMapper(), false));
238
239
240
241 classPKContainers.put(
242 new Long(PortalUtil.getClassNameId(UserGroup.class.getName())),
243 new ClassPKContainer(
244 AvailableMappersUtil.getUserGroupIdMapper(), true));
245
246
247
248 classPKContainers.put(
249 new Long(PortalUtil.getClassNameId(WikiNode.class.getName())),
250 new ClassPKContainer(
251 AvailableMappersUtil.getWikiNodeIdMapper(), true));
252
253
254
255 classPKContainers.put(
256 new Long(PortalUtil.getClassNameId(WikiPage.class.getName())),
257 new ClassPKContainer(
258 AvailableMappersUtil.getWikiPageIdMapper(), false));
259
260 return classPKContainers;
261 }
262
263 protected void doUpgrade() throws Exception {
264
265
266
267 Object[][] resourceColumns1 = {
268 {"companyId", new Integer(Types.BIGINT)},
269 {"name", new Integer(Types.VARCHAR)},
270 {"scope", new Integer(Types.VARCHAR)}
271 };
272 Object[][] resourceColumns2 = ResourceTable.TABLE_COLUMNS.clone();
273
274 Object[][] resourceColumns = ArrayUtil.append(
275 resourceColumns1, resourceColumns2);
276
277 UpgradeColumn companyIdColumn = new TempUpgradeColumnImpl("companyId");
278
279 UpgradeColumn nameColumn = new TempUpgradeColumnImpl("name");
280
281 UpgradeColumn scopeColumn = new TempUpgradeColumnImpl("scope");
282
283 ResourceCodeIdUpgradeColumnImpl codeIdColumn =
284 new ResourceCodeIdUpgradeColumnImpl(
285 companyIdColumn, nameColumn, scopeColumn);
286
287 UpgradeColumn primKeyColumn = new ResourcePrimKeyUpgradeColumnImpl(
288 nameColumn, codeIdColumn, AvailableMappersUtil.getGroupIdMapper(),
289 getClassPKContainers(), AvailableMappersUtil.getLayoutPlidMapper());
290
291 UpgradeTable upgradeTable = UpgradeTableFactoryUtil.getUpgradeTable(
292 ResourceTable.TABLE_NAME, resourceColumns, companyIdColumn,
293 nameColumn, scopeColumn, codeIdColumn, primKeyColumn);
294
295 String createSQL = ResourceTable.TABLE_SQL_CREATE;
296
297 createSQL =
298 createSQL.substring(0, createSQL.length() - 1) +
299 ",companyId VARCHAR(75) null, name VARCHAR(75) null, " +
300 "scope VARCHAR(75) null)";
301
302 upgradeTable.setCreateSQL(createSQL);
303
304 upgradeTable.updateTable();
305
306
307
308 runSQL(_UPGRADE_SCHEMA);
309 }
310
311 private static final String[] _UPGRADE_SCHEMA = {
312 "alter table Resource_ drop column companyId",
313 "alter table Resource_ drop column name",
314 "alter table Resource_ drop column scope"
315 };
316
317 }