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

me.magicall.biz.service.DomainServicesSupport Maven / Gradle / Ivy

There is a newer version: 2.13.0
Show newest version
/*
 * Copyright (c) 2024 Liang Wenjian
 * magicall is licensed under Mulan PSL v2.
 * You can use this software according to the terms and conditions of the Mulan PSL v2.
 * You may obtain a copy of Mulan PSL v2 at:
 *          http://license.coscl.org.cn/MulanPSL2
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
 * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
 * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
 * See the Mulan PSL v2 for more details.
 */

package me.magicall.biz.service;

import me.magicall.biz.DomainObject;
import me.magicall.biz.Op;
import me.magicall.biz.event.Notice;
import me.magicall.biz.event.Plan;
import me.magicall.biz.event.SimplePlanRealizedNotice;
import me.magicall.biz.event.SimpleTarget;

/**
 * 为各种Service类的实现类提供一些技术支持。
 *
 * @param <_Id>          id属性的类型。
 * @param <_ValueObject> 值对象的类型。
 * @param <_Domain>      领域对象的类型。
 * @param <_Entity>      实体对象的类型。
 */
public interface DomainServicesSupport<_Id, _Domain extends DomainObject<_Id, _ValueObject>, _ValueObject, _Entity>
		extends DomainServices<_Id, _Domain, _ValueObject>, ServicesSupport<_Domain, _ValueObject, _Entity> {

	@Override
	@SuppressWarnings("unchecked")
	default _Domain merge(final _Domain exist, final _ValueObject newValue) {
		return (_Domain) exist.accept(newValue);
	}

	/**
	 * 根据指定id获取一个领域对象。
	 * 获取前发布{@link Plan},获取后发布{@link Notice}。
	 *
	 * @return 领域对象。
	 */
	@Override
	default _Domain find(final _Id id) {
		final _Domain raw = DomainServices.super.find(id);
		final var plan = Plan.from(this).rightNow().goingTo(Op.GET)
				.against(new SimpleTarget<>(this, resourceName(), raw)).build();
		publish(plan);
		final _Domain rt;
		if (plan.hasAdvices()) {
			rt = plan.getLastAdvice().getTarget().getVal();
		} else {
			rt = raw;
		}
		final var event = new SimplePlanRealizedNotice<>(plan, rt);
		publish(event);
		return rt;
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy