001    /**
002     * Copyright (c) 2000-present Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portal.upgrade.v7_0_0;
016    
017    import java.io.IOException;
018    
019    import java.sql.Connection;
020    import java.sql.SQLException;
021    
022    /**
023     * @author Brian Wing Shun Chan
024     */
025    @SuppressWarnings("deprecation")
026    public class UpgradeCompanyId
027            extends com.liferay.portal.upgrade.util.UpgradeCompanyId {
028    
029            @Override
030            protected TableUpdater[] getTableUpdaters() {
031                    return new TableUpdater[] {
032                            new TableUpdater("AnnouncementsFlag", "User_", "userId"),
033                            new TableUpdater(
034                                    "AssetEntries_AssetCategories", "AssetCategory", "categoryId"),
035                            new TableUpdater("AssetEntries_AssetTags", "AssetTag", "tagId"),
036                            new TableUpdater("AssetTagStats", "AssetTag", "tagId"),
037                            new TableUpdater("BrowserTracker", "User_", "userId"),
038                            new TableUpdater(
039                                    "DLFileEntryMetadata", "DLFileEntry", "fileEntryId"),
040                            new TableUpdater(
041                                    "DLFileEntryTypes_DLFolders", "DLFolder", "folderId"),
042                            new DLSyncEventTableUpdater("DLSyncEvent"),
043                            new TableUpdater("Groups_Orgs", "Group_", "groupId"),
044                            new TableUpdater("Groups_Roles", "Group_", "groupId"),
045                            new TableUpdater("Groups_UserGroups", "Group_", "groupId"),
046                            new TableUpdater(
047                                    "Image", "imageId",
048                                    new String[][] {
049                                            {"BlogsEntry", "smallImageId"}, {"Company", "logoId"},
050                                            {"DDMTemplate", "smallImageId"},
051                                            {"DLFileEntry", "largeImageId"},
052                                            {"JournalArticle", "smallImageId"},
053                                            {"Layout", "iconImageId"},
054                                            {"LayoutRevision", "iconImageId"},
055                                            {"LayoutSetBranch", "logoId"}, {"Organization_", "logoId"},
056                                            {"User_", "portraitId"}
057                                    }),
058                            new TableUpdater("MBStatsUser", "Group_", "groupId"),
059                            new TableUpdater("OrgGroupRole", "Organization_", "organizationId"),
060                            new TableUpdater("OrgLabor", "Organization_", "organizationId"),
061                            new TableUpdater(
062                                    "PasswordPolicyRel", "PasswordPolicy", "passwordPolicyId"),
063                            new TableUpdater("PasswordTracker", "User_", "userId"),
064                            new PortletPreferencesTableUpdater("PortletPreferences"),
065                            new TableUpdater(
066                                    "RatingsStats", "classPK",
067                                    new String[][] {
068                                            {"BookmarksEntry", "entryId"},
069                                            {"BookmarksFolder", "folderId"}, {"BlogsEntry", "entryId"},
070                                            {"DDLRecord", "recordId"}, {"DLFileEntry", "fileEntryId"},
071                                            {"DLFolder", "folderId"},
072                                            {"JournalArticle", "resourcePrimKey"},
073                                            {"JournalFolder", "folderId"},
074                                            {"MBDiscussion", "discussionId"},
075                                            {"MBMessage", "messageId"}, {"WikiPage", "pageId"}
076                                    }),
077                            new TableUpdater(
078                                    "ResourceBlockPermission", "ResourceBlock", "resourceBlockId"),
079                            new TableUpdater("TrashVersion", "TrashEntry", "entryId"),
080                            new TableUpdater("UserGroupGroupRole", "UserGroup", "userGroupId"),
081                            new TableUpdater("UserGroupRole", "User_", "userId"),
082                            new TableUpdater("UserGroups_Teams", "UserGroup", "userGroupId"),
083                            new TableUpdater("UserIdMapper", "User_", "userId"),
084                            new TableUpdater("Users_Groups", "User_", "userId"),
085                            new TableUpdater("Users_Orgs", "User_", "userId"),
086                            new TableUpdater("Users_Roles", "User_", "userId"),
087                            new TableUpdater("Users_Teams", "User_", "userId"),
088                            new TableUpdater("Users_UserGroups", "User_", "userId"),
089                            new TableUpdater("UserTrackerPath", "UserTracker", "userTrackerId")
090                    };
091            }
092    
093            protected class DLSyncEventTableUpdater extends TableUpdater {
094    
095                    public DLSyncEventTableUpdater(String tableName) {
096                            super(tableName, "", "");
097                    }
098    
099                    @Override
100                    public void update(Connection connection)
101                            throws IOException, SQLException {
102    
103                            // DLFileEntry
104    
105                            String selectSQL =
106                                    "select companyId from DLFileEntry where DLSyncEvent.type_ = " +
107                                            "'file' and DLFileEntry.fileEntryId = DLSyncEvent.typePK";
108    
109                            runSQL(connection, getUpdateSQL(selectSQL));
110    
111                            // DLFolder
112    
113                            selectSQL =
114                                    "select companyId from DLFolder where DLSyncEvent.type_ = " +
115                                            "'folder' and DLFolder.folderId = DLSyncEvent.typePK";
116    
117                            runSQL(connection, getUpdateSQL(selectSQL));
118                    }
119    
120            }
121    
122            protected class PortletPreferencesTableUpdater extends TableUpdater {
123    
124                    public PortletPreferencesTableUpdater(String tableName) {
125                            super(tableName, "", "");
126                    }
127    
128                    @Override
129                    public void update(Connection connection)
130                            throws IOException, SQLException {
131    
132                            // Company
133    
134                            String selectSQL =
135                                    "select companyId from Company where Company.companyId = " +
136                                            "PortletPreferences.ownerId";
137    
138                            runSQL(connection, getUpdateSQL(selectSQL));
139    
140                            // Group
141    
142                            selectSQL =
143                                    "select companyId from Group_ where Group_.groupId = " +
144                                            "PortletPreferences.ownerId";
145    
146                            runSQL(connection, getUpdateSQL(selectSQL));
147    
148                            // Layout
149    
150                            selectSQL =
151                                    "select companyId from Layout where Layout.plid = " +
152                                            "PortletPreferences.ownerId";
153    
154                            runSQL(connection, getUpdateSQL(selectSQL));
155    
156                            // Organization
157    
158                            selectSQL =
159                                    "select companyId from Organization_ where " +
160                                            "Organization_.organizationId = PortletPreferences.ownerId";
161    
162                            runSQL(connection, getUpdateSQL(selectSQL));
163    
164                            // User_
165    
166                            selectSQL =
167                                    "select companyId from User_ where User_.userId = " +
168                                            "PortletPreferences.ownerId";
169    
170                            runSQL(connection, getUpdateSQL(selectSQL));
171                    }
172    
173            }
174    
175    }