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

com.github.wz2cool.dynamic.mybatis.mapper.SelectByGroupedQueryMapper Maven / Gradle / Ivy

There is a newer version: 3.2.32
Show newest version
package com.github.wz2cool.dynamic.mybatis.mapper;

import com.github.wz2cool.dynamic.GroupedQuery;
import com.github.wz2cool.dynamic.mybatis.mapper.constant.MapperConstants;
import com.github.wz2cool.dynamic.mybatis.mapper.provider.GroupedQueryProvider;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.SelectProvider;
import org.apache.ibatis.session.RowBounds;
import tk.mybatis.mapper.annotation.RegisterMapper;

import java.util.List;
import java.util.Optional;

/**
 * @author Frank
 **/
@RegisterMapper
@SuppressWarnings("java:S119")
public interface SelectByGroupedQueryMapper {

    /**
     * select by grouped query
     *
     * @param groupedQuery grouped query
     * @return list of item
     */
    @SelectProvider(type = GroupedQueryProvider.class, method = "dynamicSQL")
    List selectByGroupedQuery(@Param(MapperConstants.GROUPED_QUERY) GroupedQuery groupedQuery);

    /**
     * select row rounds by grouped query.
     *
     * @param groupedQuery grouped query
     * @param rowBounds    row bounds
     * @return the list of items
     */
    @SelectProvider(type = GroupedQueryProvider.class, method = "dynamicSQL")
    List selectRowBoundsByGroupedQuery(
            @Param(MapperConstants.GROUPED_QUERY) GroupedQuery groupedQuery,
            RowBounds rowBounds);

    /**
     * select first record by grouped query
     *
     * @param groupedQuery grouped query
     * @return matched first record
     */
    default Optional selectFirstByGroupedQuery(GroupedQuery groupedQuery) {
        RowBounds rowBounds = new RowBounds(0, 1);
        List result = selectRowBoundsByGroupedQuery(groupedQuery, rowBounds);
        if (result == null || result.isEmpty()) {
            return Optional.empty();
        } else {
            return Optional.ofNullable(result.get(0));
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy