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

me.magicall.biz.service.SimpleDomainServices 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.event.Bulletin;
import me.magicall.biz.event.NoticeWatcherRegistry;
import me.magicall.biz.event.PlanPublisher;

/**
 * 最简单的使用场景:
 * 1,不细分DomainObject、ValueObject,都是用Entity对象。
 * 2,用domainClass类名做资源名。
 *
 * @param <_Id> id的类型
 * @param    资源对象的类型
 */
public class SimpleDomainServices<_Id, T extends DomainObject<_Id, T>> extends AbsDomainServices<_Id, T, T, T> {
	public SimpleDomainServices(final Class domainClass, final Repo repo, final PlanPublisher planPublisher,
															final Bulletin bulletin, final NoticeWatcherRegistry noticeWatcherRegistry) {
		super(domainClass, repo, planPublisher, bulletin, noticeWatcherRegistry);
	}

	public SimpleDomainServices(final Class domainClass, final Repo repo,
															final NoticeWatcherRegistry noticeWatcherRegistry) {
		this(domainClass, repo, PlanPublisher.DO_NOTHING, Bulletin.DO_NOTHING, noticeWatcherRegistry);
	}

	public SimpleDomainServices(final Class domainClass, final Repo repo) {
		this(domainClass, repo, PlanPublisher.DO_NOTHING, Bulletin.DO_NOTHING, null);
	}

	@Override
	public T findEntityByDomain(final T domain) {
		return domain;
	}

	@Override
	public T checkExist(final T vo) {
		return repo.all().stream().filter(e -> e.equals(vo)).findFirst().orElse(null);
	}

	@Override
	public T entityToDomain(final T entity) {
		return entity;
	}

	@Override
	public T voToEntity(final T vo) {
		return vo;
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy