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