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

org.springframework.data.relational.core.conversion.MutableAggregateChange Maven / Gradle / Ivy

/*
 * Copyright 2020-2023 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.springframework.data.relational.core.conversion;

import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.ClassUtils;

/**
 * Represents the change happening to the aggregate (as used in the context of Domain Driven Design) as a whole.
 *
 * @author Jens Schauder
 * @author Mark Paluch
 * @author Chirag Tailor
 * @since 2.0
 */
public interface MutableAggregateChange extends AggregateChange {

	/**
	 * Factory method to create an {@link MutableAggregateChange} for saving entities.
	 *
	 * @param entity aggregate root to save.
	 * @param  entity type.
	 * @return the {@link MutableAggregateChange} for saving the root {@code entity}.
	 * @since 1.2
	 */
	static  MutableAggregateChange forSave(T entity) {
		return forSave(entity, null);
	}

	/**
	 * Factory method to create an {@link MutableAggregateChange} for saving entities.
	 *
	 * @param entity aggregate root to save.
	 * @param previousVersion the previous version assigned to the instance being saved. May be {@literal null}.
	 * @param  entity type.
	 * @return the {@link MutableAggregateChange} for saving the root {@code entity}.
	 * @since 2.4
	 */
	@SuppressWarnings("unchecked")
	static  MutableAggregateChange forSave(T entity, @Nullable Number previousVersion) {

		Assert.notNull(entity, "Entity must not be null");

		return new DefaultAggregateChange<>(Kind.SAVE, (Class) ClassUtils.getUserClass(entity), entity, previousVersion);
	}

	/**
	 * Factory method to create an {@link MutableAggregateChange} for deleting entities.
	 *
	 * @param entity aggregate root to delete.
	 * @param  entity type.
	 * @return the {@link MutableAggregateChange} for deleting the root {@code entity}.
	 * @since 1.2
	 */
	@SuppressWarnings("unchecked")
	static  MutableAggregateChange forDelete(T entity) {

		Assert.notNull(entity, "Entity must not be null");

		return forDelete((Class) ClassUtils.getUserClass(entity), entity);
	}

	/**
	 * Factory method to create an {@link MutableAggregateChange} for deleting entities.
	 *
	 * @param entityClass aggregate root type.
	 * @param entity aggregate root to delete.
	 * @param  entity type.
	 * @return the {@link MutableAggregateChange} for deleting the root {@code entity}.
	 * @since 1.2
	 */
	static  MutableAggregateChange forDelete(Class entityClass, @Nullable T entity) {
		return forDelete(entityClass, entity, null);
	}

	/**
	 * Factory method to create an {@link MutableAggregateChange} for deleting entities.
	 *
	 * @param entityClass aggregate root type.
	 * @param entity aggregate root to delete.
	 * @param previousVersion the previous version assigned to the instance being saved. May be {@literal null}.
	 * @param  entity type.
	 * @return the {@link MutableAggregateChange} for deleting the root {@code entity}.
	 * @since 2.4
	 */
	static  MutableAggregateChange forDelete(Class entityClass, @Nullable T entity, @Nullable Number previousVersion) {

		Assert.notNull(entityClass, "Entity class must not be null");

		return new DefaultAggregateChange<>(Kind.DELETE, entityClass, entity, previousVersion);
	}

	/**
	 * Adds an action to this {@code AggregateChange}.
	 *
	 * @param action must not be {@literal null}.
	 */
	void addAction(DbAction action);

	/**
	 * Set the root object of the {@code AggregateChange}.
	 *
	 * @param aggregateRoot may be {@literal null} if the change refers to a list of aggregates or references it by id.
	 */
	void setEntity(@Nullable T aggregateRoot);

	@Nullable
	Number getPreviousVersion();
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy