All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.liferay.notification.internal.upgrade.v3_8_0.NotificationQueueEntryUpgradeProcess Maven / Gradle / Ivy

There is a newer version: 1.0.86
Show newest version
/**
 * SPDX-FileCopyrightText: (c) 2023 Liferay, Inc. https://liferay.com
 * SPDX-License-Identifier: LGPL-2.1-or-later OR LicenseRef-Liferay-DXP-EULA-2.0.0-2023-06
 */

package com.liferay.notification.internal.upgrade.v3_8_0;

import com.liferay.petra.string.StringBundler;
import com.liferay.portal.kernel.dao.jdbc.AutoBatchPreparedStatementUtil;
import com.liferay.portal.kernel.upgrade.UpgradeProcess;

import java.sql.PreparedStatement;
import java.sql.ResultSet;

/**
 * @author Selton Guedes
 */
public class NotificationQueueEntryUpgradeProcess extends UpgradeProcess {

	@Override
	protected void doUpgrade() throws Exception {
		try (PreparedStatement preparedStatement1 = connection.prepareStatement(
				StringBundler.concat(
					"select distinct NotificationQueueEntry.",
					"notificationTemplateId, NotificationTemplate.companyId ",
					"from NotificationQueueEntry inner join ",
					"NotificationTemplate on NotificationQueueEntry.",
					"notificationTemplateId = NotificationTemplate.",
					"notificationTemplateId where NotificationQueueEntry.",
					"companyId = 0"));
			PreparedStatement preparedStatement2 =
				AutoBatchPreparedStatementUtil.concurrentAutoBatch(
					connection,
					"update NotificationQueueEntry set companyId = ? where " +
						"notificationTemplateId = ?");
			ResultSet resultSet = preparedStatement1.executeQuery()) {

			while (resultSet.next()) {
				preparedStatement2.setLong(1, resultSet.getLong("companyId"));
				preparedStatement2.setLong(
					2, resultSet.getLong("notificationTemplateId"));

				preparedStatement2.addBatch();
			}

			preparedStatement2.executeBatch();
		}
	}

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy