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 UpgradeLayoutSetBranch 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                            ps = con.prepareStatement(
041                                    "select groupId, layoutSetBranchId, privateLayout from " +
042                                            "LayoutSetBranch");
043    
044                            rs = ps.executeQuery();
045    
046                            while (rs.next()) {
047                                    long layoutSetBranchId = rs.getLong("layoutSetBranchId");
048                                    long groupId = rs.getLong("groupId");
049                                    boolean privateLayout = rs.getBoolean("privateLayout");
050    
051                                    upgradeLayoutSetBranch(
052                                            layoutSetBranchId, groupId, privateLayout);
053                            }
054                    }
055                    finally {
056                            DataAccess.cleanUp(con, ps, rs);
057                    }
058            }
059    
060            protected void updateLayoutSetBranch(
061                            long layoutSetBranchId, String themeId, String colorSchemeId,
062                            String wapThemeId, String wapColorSchemeId, String css,
063                            String settings, String layoutSetPrototypeUuid,
064                            boolean layoutSetPrototypeLinkEnabled)
065                    throws Exception {
066    
067                    Connection con = null;
068                    PreparedStatement ps = null;
069    
070                    try {
071                            con = DataAccess.getUpgradeOptimizedConnection();
072    
073                            StringBundler sb = new StringBundler(5);
074    
075                            sb.append("update LayoutSetBranch set themeId = ?, colorSchemeId ");
076                            sb.append("= ?, wapThemeId = ?, wapColorSchemeId = ?, css = ?, ");
077                            sb.append("settings_ = ?, layoutSetPrototypeUuid = ?, ");
078                            sb.append("layoutSetPrototypeLinkEnabled = ? where ");
079                            sb.append("layoutSetBranchId = ?");
080    
081                            ps = con.prepareStatement(sb.toString());
082    
083                            ps.setString(1, themeId);
084                            ps.setString(2, colorSchemeId);
085                            ps.setString(3, wapThemeId);
086                            ps.setString(4, wapColorSchemeId);
087                            ps.setString(5, css);
088                            ps.setString(6, settings);
089                            ps.setString(7, layoutSetPrototypeUuid);
090                            ps.setBoolean(8, layoutSetPrototypeLinkEnabled);
091                            ps.setLong(9, layoutSetBranchId);
092    
093                            ps.executeUpdate();
094                    }
095                    finally {
096                            DataAccess.cleanUp(con, ps);
097                    }
098            }
099    
100            protected void upgradeLayoutSetBranch(
101                            long layoutSetBranchId, long groupId, boolean privateLayout)
102                    throws Exception {
103    
104                    Connection con = null;
105                    PreparedStatement ps = null;
106                    ResultSet rs = null;
107    
108                    try {
109                            con = DataAccess.getUpgradeOptimizedConnection();
110    
111                            StringBundler sb = new StringBundler(4);
112    
113                            sb.append("select themeId, colorSchemeId, wapThemeId, ");
114                            sb.append("wapColorSchemeId, css, settings_, ");
115                            sb.append("layoutSetPrototypeUuid, layoutSetPrototypeLinkEnabled ");
116                            sb.append("from LayoutSet where groupId = ? and privateLayout = ?");
117    
118                            ps = con.prepareStatement(sb.toString());
119    
120                            ps.setLong(1, groupId);
121                            ps.setBoolean(2, privateLayout);
122    
123                            rs = ps.executeQuery();
124    
125                            while (rs.next()) {
126                                    String themeId = rs.getString("themeId");
127                                    String colorSchemeId = rs.getString("colorSchemeId");
128                                    String wapThemeId = rs.getString("wapThemeId");
129                                    String wapColorSchemeId = rs.getString("wapColorSchemeId");
130                                    String css = rs.getString("css");
131                                    String settings = rs.getString("settings_");
132                                    String layoutSetPrototypeUuid = rs.getString(
133                                            "layoutSetPrototypeUuid");
134                                    boolean layoutSetPrototypeLinkEnabled = rs.getBoolean(
135                                            "layoutSetPrototypeLinkEnabled");
136    
137                                    updateLayoutSetBranch(
138                                            layoutSetBranchId, themeId, colorSchemeId, wapThemeId,
139                                            wapColorSchemeId, css, settings, layoutSetPrototypeUuid,
140                                            layoutSetPrototypeLinkEnabled);
141                            }
142                    }
143                    finally {
144                            DataAccess.cleanUp(con, ps, rs);
145                    }
146            }
147    
148    }