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

com.mybatishelper.core.wrapper.query.SelectWrapper Maven / Gradle / Ivy

package com.mybatishelper.core.wrapper.query;

import com.mybatishelper.core.base.Page;
import com.mybatishelper.core.base.meta.SelectInfo;
import com.mybatishelper.core.base.meta.SortInfo;
import com.mybatishelper.core.util.Assert;
import com.mybatishelper.core.util.StringUtils;
import com.mybatishelper.core.wrapper.IOrder;
import com.mybatishelper.core.wrapper.IPager;
import com.mybatishelper.core.wrapper.ISelectorWrapper;
import com.mybatishelper.core.wrapper.bridge.AbstractConditionWrapper;
import com.mybatishelper.core.wrapper.bridge.AbstractQueryWrapper;
import lombok.Getter;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;

@SuppressWarnings("WeakerAccess")
public class SelectWrapper
        extends AbstractQueryWrapper>
        implements ISelectorWrapper,C>,
        IPager>, IOrder>
{
    /**
     * 选取的field字段
     */
    List selectItems;
    List sortItems;

    @Getter
    Page page;
    protected boolean selectMain;
    protected boolean lock;
    public SelectWrapper(C where){
        super(where,new ArrayList<>(AbstractConditionWrapper.DEFAULT_CONDITION_ELEMENTS_SIZE));
        this.selectItems = new ArrayList<>(AbstractConditionWrapper.DEFAULT_CONDITION_ELEMENTS_SIZE);
        this.selectMain = false;
        sortItems = new ArrayList<>(1<<3);
    }
    @Override
    public Collection selects() {
        return this.selectItems;
    }

    @Override
    public SelectWrapper select(SelectInfo... fields) {
        Assert.notEmpty(fields,"items can not be empty");
        Collections.addAll(selectItems, fields);
        return this;
    }
    @Override
    public SelectWrapper select(String fields) {
        if(StringUtils.isEmpty(fields)){
            return this;
        }
        String[] split = fields.split(",");
        for (String s : split) {
            this.selectItems.add(SelectInfo.withField(s));
        }
        return this;
    }

    @Override
    public SelectWrapper selectMain(boolean selectMain) {
        this.selectMain = selectMain;
        return this;
    }

    @Override
    public SelectWrapper orderBy(SortInfo...sortInfos){
        Assert.notEmpty(sortInfos,"items can not be empty");
        Collections.addAll(sortItems, sortInfos);
        return this;
    }
    @Override
    public SelectWrapper orderBy(String strings){
        if(StringUtils.isEmpty(strings)){
            return this;
        }
        String[] split = strings.split(",");
        for (String s : split) {
            this.sortItems.add(SortInfo.withField(s));
        }
        return this;
    }
    @Override
    public SelectWrapper page(Page page){
        this.page = page;
        return this;
    }
    @Override
    public SelectWrapper lock(boolean lock){
        this.lock = lock;
        return this;
    }
    @Override
    public > N back(){
        return (N)this;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy