123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124 |
- /**
- *
- */
- package com.primeton.dsp.datarelease.api.model;
- import com.google.common.collect.Lists;
- import java.util.ArrayList;
- import java.util.Arrays;
- import java.util.List;
- /**
- *
- * 服务发布生成预览SQL 的 table 类
- *
- * @author zhaopx
- *
- */
- public class Table {
-
- /**
- * 表名称
- */
- String tableName;
- /**
- * 关联时的别名
- */
- String alias;
- /**
- * 关联后 select 的表字段,当前表字段
- */
- final List<Field> fields = new ArrayList<>();
- /**
- * 默认构造方法,JSON 能反序列化
- */
- public Table() {
- this("TABLE", "A");
- }
- /**
- * 表名,别名为第一个字符
- * @param tableName
- */
- public Table(String tableName) {
- this(tableName, new String(new char[] {tableName.charAt(0)}));
- }
- /**
- * 构造方法
- * @param tableName 表名
- * @param alias 别名
- */
- public Table(String tableName, String alias) {
- this.tableName = tableName;
- this.alias = alias;
- }
- public Table(String tableName, String alias, String field) {
- this(tableName, alias, (List)Lists.newArrayList(field));
- }
- public Table(String tableName, String alias, List<Field> fields) {
- this(tableName, alias);
- this.setFields(fields);
- }
- public Table(String tableName, String alias, Field... fields) {
- this(tableName, alias, Arrays.asList(fields));
- }
- public String getTableName() {
- return tableName;
- }
- public void setTableName(String tableName) {
- this.tableName = tableName;
- }
- public String getAlias() {
- return alias;
- }
- public void setAlias(String alias) {
- this.alias = alias;
- }
- public List<Field> getFields() {
- return fields;
- }
- public void setFields(List<Field> fields) {
- this.fields.clear();
- this.fields.addAll(fields);
- }
- public void addField(String field) {
- this.fields.add(new Field(field));
- }
- public void addField(Field field) {
- this.fields.add(field);
- }
- public void addFields(Field... fields) {
- this.fields.addAll(Arrays.asList(fields));
- }
- @Override
- public String toString() {
- return "Table{" +
- "tableName='" + tableName + '\'' +
- ", alias='" + alias + '\'' +
- ", fields=" + fields +
- '}';
- }
- }
|