001    /**
002     * Copyright (c) 2000-2013 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.v6_1_1;
016    
017    import com.liferay.portal.kernel.dao.jdbc.DataAccess;
018    import com.liferay.portal.kernel.upgrade.UpgradeProcess;
019    import com.liferay.portal.kernel.util.StringBundler;
020    
021    import java.sql.Connection;
022    import java.sql.PreparedStatement;
023    import java.sql.ResultSet;
024    
025    /**
026     * @author Jorge Ferrer
027     * @author Julio Camarero
028     */
029    public class UpgradeLayoutSet extends UpgradeProcess {
030    
031            @Override
032            protected void doUpgrade() throws Exception {
033                    Connection con = null;
034                    PreparedStatement ps = null;
035                    ResultSet rs = null;
036    
037                    try {
038                            con = DataAccess.getUpgradeOptimizedConnection();
039    
040                            StringBundler sb = new StringBundler(4);
041    
042                            sb.append("select Group_.groupId, Group_.liveGroupId, ");
043                            sb.append("LayoutSet.layoutSetId from LayoutSet inner join ");
044                            sb.append("Group_ on (LayoutSet.groupId = Group_.groupId and ");
045                            sb.append("Group_.liveGroupId > 0 and LayoutSet.logo = ?)");
046    
047                            ps = con.prepareStatement(sb.toString());
048    
049                            ps.setBoolean(1, true);
050    
051                            rs = ps.executeQuery();
052    
053                            while (rs.next()) {
054                                    long groupId = rs.getLong("Group_.groupId");
055                                    long layoutSetId = rs.getLong("LayoutSet.layoutSetId");
056    
057                                    runSQL(
058                                            "update LayoutSet set logoId = 0 where groupId = " +
059                                                    groupId + " and layoutSetId = " + layoutSetId);
060                            }
061                    }
062                    finally {
063                            DataAccess.cleanUp(con, ps, rs);
064                    }
065            }
066    
067    }