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

com.github.freegeese.maven.plugin.autocode.metadata.Table Maven / Gradle / Ivy

There is a newer version: 1.1
Show newest version
package com.github.freegeese.maven.plugin.autocode.metadata;

import com.github.freegeese.maven.plugin.autocode.Helper;
import com.github.freegeese.maven.plugin.autocode.configuration.ModelType;

import java.util.*;

/**
 * Created by Administrator on 2017/3/29.
 */
public class Table {
    private String tableCat;
    private String tableSchem;
    private String tableName;
    private String tableType;
    private String remarks;
    private String typeCat;
    private String typeSchem;
    private String typeName;
    private String selfReferencingColName;
    private List columns;
    private List primaryKeys;
    // 自定义字段----------------------------------
    // 模型名称
    private String modelName;
    // 导入列
    private List includeColumns;
    // 排除列
    private List excludeColumns;
    // 主键列
    private Column idColumn;
    // 最终过滤后的列
    private List filteredColumns;
    // 模型类型
    private ModelType modelType;

    public Table() {
    }

    public Table(String tableCat, String tableSchem, String tableName, String tableType, String remarks, String typeCat, String typeSchem, String typeName, String selfReferencingColName) {
        this.tableCat = tableCat;
        this.tableSchem = tableSchem;
        this.tableName = tableName;
        this.tableType = tableType;
        this.remarks = remarks;
        this.typeCat = typeCat;
        this.typeSchem = typeSchem;
        this.typeName = typeName;
        this.selfReferencingColName = selfReferencingColName;
    }

    public String getTableCat() {
        return tableCat;
    }

    public void setTableCat(String tableCat) {
        this.tableCat = tableCat;
    }

    public String getTableSchem() {
        return tableSchem;
    }

    public void setTableSchem(String tableSchem) {
        this.tableSchem = tableSchem;
    }

    public String getTableName() {
        return tableName;
    }

    public void setTableName(String tableName) {
        this.tableName = tableName;
    }

    public String getTableType() {
        return tableType;
    }

    public void setTableType(String tableType) {
        this.tableType = tableType;
    }

    public String getRemarks() {
        return remarks;
    }

    public void setRemarks(String remarks) {
        this.remarks = remarks;
    }

    public String getTypeCat() {
        return typeCat;
    }

    public void setTypeCat(String typeCat) {
        this.typeCat = typeCat;
    }

    public String getTypeSchem() {
        return typeSchem;
    }

    public void setTypeSchem(String typeSchem) {
        this.typeSchem = typeSchem;
    }

    public String getTypeName() {
        return typeName;
    }

    public void setTypeName(String typeName) {
        this.typeName = typeName;
    }

    public String getSelfReferencingColName() {
        return selfReferencingColName;
    }

    public void setSelfReferencingColName(String selfReferencingColName) {
        this.selfReferencingColName = selfReferencingColName;
    }

    public void setColumns(List columns) {
        this.columns = columns;
    }

    public List getColumns() {
        return columns;
    }

    public List getPrimaryKeys() {
        return primaryKeys;
    }

    public void setPrimaryKeys(List primaryKeys) {
        this.primaryKeys = primaryKeys;
    }

    public String getModelName() {
        return modelName;
    }

    public void setModelName(String modelName) {
        this.modelName = modelName;
    }

    public List getIncludeColumns() {
        return includeColumns;
    }

    public void setIncludeColumns(List includeColumns) {
        this.includeColumns = includeColumns;
    }

    public List getExcludeColumns() {
        return excludeColumns;
    }

    public void setExcludeColumns(List excludeColumns) {
        this.excludeColumns = excludeColumns;
    }

    public Column getIdColumn() {
        return idColumn;
    }

    public void setIdColumn(Column idColumn) {
        this.idColumn = idColumn;
    }

    public List getFilteredColumns() {
        return filteredColumns;
    }

    public void setFilteredColumns(List filteredColumns) {
        this.filteredColumns = filteredColumns;
    }

    public ModelType getModelType() {
        return modelType;
    }

    public void setModelType(ModelType modelType) {
        this.modelType = modelType;
    }

    // 针对于 Model ------------------------------
    public Set getModelImports() {
        Set returnValue = new LinkedHashSet<>();
        for (Column column : getFilteredColumns()) {
            if (!Helper.isLangPackageClass(column.getJavaType())) {
                returnValue.add(column.getJavaType().getName());
            }
        }
        return returnValue;
    }

    // 针对于 Mybatis Mapper ------------------------------
    public String getBaseColumnList() {
        StringBuilder columns = new StringBuilder();
        for (int i = 0; i < this.filteredColumns.size(); i++) {
            columns.append(this.filteredColumns.get(i).getColumnName());
            if (i < this.filteredColumns.size() - 1) {
                columns.append(", ");
            }
        }
        return columns.toString();
    }

    public String getInsertColumnList() {
        StringBuilder columns = new StringBuilder();
        for (int i = 0; i < this.filteredColumns.size(); i++) {
            Column column = this.filteredColumns.get(i);
            if (!column.isAutoincrement()) {
                columns.append(column.getColumnName());
                if (i < this.filteredColumns.size() - 1) {
                    columns.append(", ");
                }
            }
        }
        return columns.toString();
    }

    public List getInsertSelectiveColumnList() {
        List columns = new ArrayList<>();
        for (int i = 0; i < this.filteredColumns.size(); i++) {
            Column column = this.filteredColumns.get(i);
            if (!column.isAutoincrement()) {
                columns.add(column);
            }
        }
        return columns;
    }

    public String getInsertValues() {
        StringBuilder columns = new StringBuilder();
        for (int i = 0; i < this.filteredColumns.size(); i++) {
            Column column = this.filteredColumns.get(i);
            if (!column.isAutoincrement()) {
                columns.append("#{" + column.getProperty() + ",jdbcType=" + column.getJdbcType() + "}");
                if (i < this.filteredColumns.size() - 1) {
                    columns.append(", ");
                }
            }
        }
        return columns.toString();
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy