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 com.liferay.portal.kernel.upgrade.UpgradeProcess;
018    import com.liferay.portal.kernel.util.LoggingTimer;
019    
020    import java.sql.PreparedStatement;
021    
022    /**
023     * @author Adolfo P??rez
024     */
025    public class UpgradeRepository extends UpgradeProcess {
026    
027            @Override
028            protected void doUpgrade() throws Exception {
029                    updateRepositoryPortletId();
030            }
031    
032            protected String[][] getRenamePortletNamesArray() {
033                    return new String[][] {
034                            new String[] {"19", "com.liferay.message.boards"},
035                            new String[] {"33", "com.liferay.blogs"},
036                            new String[] {"36", "com.liferay.wiki"}
037                    };
038            }
039    
040            protected void updateRepositoryPortletId() throws Exception {
041                    try (LoggingTimer loggingTimer = new LoggingTimer()) {
042                            for (String[] renamePortletNames : getRenamePortletNamesArray()) {
043                                    String oldPortletName = renamePortletNames[0];
044                                    String newPortletName = renamePortletNames[1];
045    
046                                    try (PreparedStatement ps = connection.prepareStatement(
047                                                    "update Repository set portletId = ?, name = ? where " +
048                                                            "portletId = ?")) {
049    
050                                            ps.setString(1, newPortletName);
051                                            ps.setString(2, newPortletName);
052                                            ps.setString(3, oldPortletName);
053    
054                                            ps.executeUpdate();
055                                    }
056                            }
057                    }
058            }
059    
060    }