001
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.GetterUtil;
019 import com.liferay.portal.upgrade.AutoBatchPreparedStatementUtil;
020
021 import java.sql.PreparedStatement;
022 import java.sql.ResultSet;
023
024
027 public class UpgradeResourcePermission extends UpgradeProcess {
028
029 @Override
030 protected void doUpgrade() throws Exception {
031 String selectSQL =
032 "select resourcePermissionId, primKey, primKeyId, actionIds, " +
033 "viewActionId from ResourcePermission";
034 String updateSQL =
035 "update ResourcePermission set primKeyId = ?, viewActionId = ? " +
036 "where resourcePermissionId = ?";
037
038 try (PreparedStatement ps1 = connection.prepareStatement(selectSQL);
039 ResultSet rs = ps1.executeQuery();
040 PreparedStatement ps2 =
041 AutoBatchPreparedStatementUtil.autoBatch(
042 connection.prepareStatement(updateSQL))) {
043
044 while (rs.next()) {
045 long resourcePermissionId = rs.getLong("resourcePermissionId");
046 long primKeyId = rs.getLong("primKeyId");
047 long actionIds = rs.getLong("actionIds");
048 boolean viewActionId = rs.getBoolean("viewActionId");
049
050 long newPrimKeyId = GetterUtil.getLong(rs.getString("primKey"));
051 boolean newViewActionId = (actionIds % 2 == 1);
052
053 if ((primKeyId == newPrimKeyId) &&
054 (newViewActionId == viewActionId)) {
055
056 continue;
057 }
058
059 ps2.setLong(1, newPrimKeyId);
060
061 if (newViewActionId) {
062 ps2.setBoolean(2, true);
063 }
064 else {
065 ps2.setBoolean(2, false);
066 }
067
068 ps2.setLong(3, resourcePermissionId);
069
070 ps2.addBatch();
071 }
072
073 ps2.executeBatch();
074 }
075 }
076
077 }