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

net.guerlab.cloud.server.service.orm.QueryWrapperGetter Maven / Gradle / Ivy

There is a newer version: 2024.10.7
Show newest version
/*
 * Copyright 2018-2024 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.service.orm;

import com.baomidou.mybatisplus.core.conditions.interfaces.Join;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;

import net.guerlab.cloud.commons.entity.IBaseEntity;
import net.guerlab.cloud.searchparams.SearchParams;
import net.guerlab.cloud.searchparams.SearchParamsUtils;

/**
 * QueryWrapper获取接口.
 *
 * @param  实体类型
 * @param  搜索参数类型
 * @author guer
 */
@SuppressWarnings("unused")
public interface QueryWrapperGetter {

	/**
	 * 获取QueryWrapper,并通过searchParams对象对QueryWrapper进行赋值.
	 *
	 * @param searchParams 搜索对象
	 * @return QueryWrapper
	 */
	default QueryWrapper getQueryWrapperWithSelectMethod(Q searchParams) {
		return getQueryWrapper(searchParams);
	}

	/**
	 * 获取QueryWrapper.
	 *
	 * @return QueryWrapper
	 */
	default QueryWrapper getQueryWrapperWithSelectMethod() {
		return getQueryWrapper();
	}

	/**
	 * 获取QueryWrapper,并通过searchParams对象对QueryWrapper进行赋值.
	 *
	 * @param searchParams 搜索对象
	 * @return QueryWrapper
	 */
	default QueryWrapper getQueryWrapper(Q searchParams) {
		QueryWrapper wrapper = getQueryWrapper();

		SearchParamsUtils.handler(searchParams, wrapper);

		return wrapper;
	}

	/**
	 * 获取QueryWrapper.
	 *
	 * @return QueryWrapper
	 */
	default QueryWrapper getQueryWrapper() {
		QueryWrapper queryWrapper = new QueryWrapper<>();
		queryWrapper.setEntityClass(getEntityClass());
		return queryWrapper;
	}

	/**
	 * 获取LambdaQueryWrapper.
	 *
	 * @return LambdaQueryWrapper
	 */
	default LambdaQueryWrapper getLambdaQueryWrapper() {
		LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>();
		queryWrapper.setEntityClass(getEntityClass());
		return queryWrapper;
	}

	/**
	 * 获取实体类型.
	 *
	 * @return 实体类型
	 */
	Class getEntityClass();

	/**
	 * 查询加锁.
	 *
	 * @param wrapper QueryWrapper
	 */
	default void withLock(Join wrapper) {
		wrapper.last("FOR UPDATE");
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy