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

net.guerlab.cloud.server.mybatis.plus.metadata.MetaObjectHandlerChain Maven / Gradle / Ivy

There is a newer version: 2024.10.7
Show newest version
/*
 * Copyright 2018-2025 guerlab.net and other contributors.
 *
 * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE, Version 3 (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.gnu.org/licenses/lgpl-3.0.html
 *
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package net.guerlab.cloud.server.mybatis.plus.metadata;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.reflection.MetaObject;

import org.springframework.beans.factory.ObjectProvider;

/**
 * 元数据处理链.
 *
 * @author guer
 */
@Slf4j
public class MetaObjectHandlerChain implements MetaObjectHandler {

	@Resource
	private ObjectProvider handlers;

	@Override
	public void insertFill(MetaObject metaObject) {
		handlers.stream().filter(this::canUse).filter(MetaObjectHandler::openInsertFill)
				.forEach(handler -> {
					log.debug("use MetaObjectHandler: {}", handler);
					handler.insertFill(metaObject);
				});
	}

	@Override
	public void updateFill(MetaObject metaObject) {
		handlers.stream().filter(this::canUse).filter(MetaObjectHandler::openUpdateFill)
				.forEach(handler -> {
					log.debug("use MetaObjectHandler: {}", handler);
					handler.updateFill(metaObject);
				});
	}

	private boolean canUse(MetaObjectHandler handler) {
		return !(handler instanceof MetaObjectHandlerChain);
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy