001
014
015 package com.liferay.portal.upgrade.v7_0_0;
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.GetterUtil;
020 import com.liferay.portal.kernel.util.StringBundler;
021
022 import java.sql.Connection;
023 import java.sql.PreparedStatement;
024 import java.sql.ResultSet;
025
026
029 public class UpgradeResourcePermission 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 resourcePermissionId, primKey, primKeyId, actionIds, " +
042 "viewActionId from ResourcePermission");
043
044 rs = ps.executeQuery();
045
046 while (rs.next()) {
047 long resourcePermissionId = rs.getLong("resourcePermissionId");
048 long primKeyId = rs.getLong("primKeyId");
049 long actionIds = rs.getLong("actionIds");
050 boolean viewActionId = rs.getBoolean("viewActionId");
051
052 long newPrimKeyId = GetterUtil.getLong(rs.getString("primKey"));
053 boolean newViewActionId = (actionIds % 2 == 1);
054
055 if ((primKeyId == newPrimKeyId) &&
056 (newViewActionId == viewActionId)) {
057
058 continue;
059 }
060
061 StringBundler sb = new StringBundler(6);
062
063 sb.append("update ResourcePermission set primKeyId = ");
064 sb.append(newPrimKeyId);
065 sb.append(", viewActionId = ");
066
067 if (newViewActionId) {
068 sb.append("[$TRUE$]");
069 }
070 else {
071 sb.append("[$FALSE$]");
072 }
073
074 sb.append(" where resourcePermissionId = ");
075 sb.append(resourcePermissionId);
076
077 runSQL(sb.toString());
078 }
079 }
080 finally {
081 DataAccess.cleanUp(con, ps, rs);
082 }
083 }
084
085 }