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

com.liferay.notification.internal.upgrade.v3_9_0.NotificationRecipientSettingUpgradeProcess Maven / Gradle / Ivy

/**
 * 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_9_0;

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

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

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

	@Override
	protected void doUpgrade() throws Exception {
		try (PreparedStatement preparedStatement1 = connection.prepareStatement(
				"select notificationRecipientId, companyId, userId, userName " +
					"from NotificationRecipient");
			PreparedStatement preparedStatement2 =
				AutoBatchPreparedStatementUtil.concurrentAutoBatch(
					connection,
					StringBundler.concat(
						"insert into NotificationRecipientSetting (uuid_, ",
						"notificationRecipientSettingId, companyId, userId, ",
						"userName, createDate, modifiedDate, ",
						"notificationRecipientId, name, value) values (?, ?, ",
						"?, ?, ?, ?, ?, ?, ?, ?)"));
			ResultSet resultSet = preparedStatement1.executeQuery()) {

			while (resultSet.next()) {
				preparedStatement2.setString(1, PortalUUIDUtil.generate());
				preparedStatement2.setLong(2, increment());
				preparedStatement2.setLong(3, resultSet.getLong("companyId"));
				preparedStatement2.setLong(4, resultSet.getLong("userId"));
				preparedStatement2.setString(
					5, resultSet.getString("userName"));

				Timestamp timestamp = new Timestamp(System.currentTimeMillis());

				preparedStatement2.setTimestamp(6, timestamp);
				preparedStatement2.setTimestamp(7, timestamp);

				preparedStatement2.setLong(
					8, resultSet.getLong("notificationRecipientId"));
				preparedStatement2.setString(9, "singleRecipient");
				preparedStatement2.setString(10, StringPool.TRUE);

				preparedStatement2.addBatch();
			}

			preparedStatement2.executeBatch();
		}
	}

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy