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 = AutoBatchPreparedStatementUtil.autoBatch(
041 connection.prepareStatement(updateSQL))) {
042
043 while (rs.next()) {
044 long resourcePermissionId = rs.getLong("resourcePermissionId");
045 long primKeyId = rs.getLong("primKeyId");
046 long actionIds = rs.getLong("actionIds");
047 boolean viewActionId = rs.getBoolean("viewActionId");
048
049 long newPrimKeyId = GetterUtil.getLong(rs.getString("primKey"));
050 boolean newViewActionId = (actionIds % 2 == 1);
051
052 if ((primKeyId == newPrimKeyId) &&
053 (newViewActionId == viewActionId)) {
054
055 continue;
056 }
057
058 ps2.setLong(1, newPrimKeyId);
059
060 if (newViewActionId) {
061 ps2.setBoolean(2, true);
062 }
063 else {
064 ps2.setBoolean(2, false);
065 }
066
067 ps2.setLong(3, resourcePermissionId);
068
069 ps2.addBatch();
070 }
071
072 ps2.executeBatch();
073 }
074 }
075
076 }