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

cn.vonce.sql.bean.Insert Maven / Gradle / Ivy

The newest version!
package cn.vonce.sql.bean;

import cn.vonce.sql.define.ColumnFun;
import cn.vonce.sql.uitls.LambdaUtil;
import cn.vonce.sql.uitls.SqlBeanUtil;

import java.io.Serializable;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * 插入
 *
 * @author Jovi
 * @version 1.0
 * @email [email protected]
 * @date 2017年8月18日上午9:00:19
 */
public class Insert extends Common implements Serializable {

    private List beanList = null;//插入的实体对象
    private List columnList = new ArrayList<>();//列字段对象列表
    private List> valuesList = new ArrayList<>();//值对象列表

    /**
     * 获取插入实体类
     *
     * @return
     */
    public List getBean() {
        return beanList;
    }

    /**
     * 设置插入实体类
     *
     * @param beanList
     */
    public Insert setBean(List beanList) {
        this.beanList = beanList;
        return this;
    }

    /**
     * 设置插入实体类
     *
     * @param bean
     */
    public Insert setBean(T bean) {
        if (this.beanList == null) {
            this.beanList = new ArrayList<>();
        }
        if (bean.getClass().isArray()) {
            T[] arrays = (T[]) bean;
            for (T item : arrays) {
                this.beanList.add(item);
            }
        } else {
            this.beanList.add(bean);
        }
        return this;
    }

    /**
     * 获取列字段对象列表
     *
     * @return
     */
    public List getColumnList() {
        return columnList;
    }

    /**
     * 获取值对象列表
     *
     * @return
     */
    public List> getValuesList() {
        return valuesList;
    }

    /**
     * 指定字段
     *
     * @param clazz 对象信息
     * @return
     */
    public Insert column(Class clazz) {
        if (clazz != null) {
            List fieldList = SqlBeanUtil.getBeanAllField(clazz);
            if (fieldList != null && fieldList.size() > 0) {
                columnList.clear();
                for (Field field : fieldList) {
                    columnList.add(SqlBeanUtil.getColumnByField(field, clazz));
                }
            }
        }
        return this;
    }

    /**
     * 指定字段
     *
     * @param column 字段信息
     * @return
     */
    public Insert column(Column... column) {
        if (column != null && column.length > 0) {
            columnList.clear();
            columnList.addAll(Arrays.asList(column));
        }
        return this;
    }

    /**
     * 指定字段
     *
     * @param columnFun 字段信息
     * @param 
     * @return
     */
    public  Insert column(ColumnFun... columnFun) {
        if (columnFun != null && columnFun.length > 0) {
            columnList.clear();
            for (ColumnFun trColumnFun : columnFun) {
                columnList.add(LambdaUtil.getColumn(trColumnFun));
            }
        }
        return this;
    }

    /**
     * 设置字段值
     *
     * @param value 字段信息
     * @return
     */
    public Insert values(Object... value) {
        if (value != null && value.length > 0) {
            valuesList.add(Arrays.asList(value));
        }
        return this;
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy