Table.java 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. /**
  2. *
  3. */
  4. package com.primeton.dsp.datarelease.api.model;
  5. import com.google.common.collect.Lists;
  6. import java.util.ArrayList;
  7. import java.util.Arrays;
  8. import java.util.List;
  9. /**
  10. *
  11. * 服务发布生成预览SQL 的 table 类
  12. *
  13. * @author zhaopx
  14. *
  15. */
  16. public class Table {
  17. /**
  18. * 表名称
  19. */
  20. String tableName;
  21. /**
  22. * 关联时的别名
  23. */
  24. String alias;
  25. /**
  26. * 关联后 select 的表字段,当前表字段
  27. */
  28. final List<Field> fields = new ArrayList<>();
  29. /**
  30. * 默认构造方法,JSON 能反序列化
  31. */
  32. public Table() {
  33. this("TABLE", "A");
  34. }
  35. /**
  36. * 表名,别名为第一个字符
  37. * @param tableName
  38. */
  39. public Table(String tableName) {
  40. this(tableName, new String(new char[] {tableName.charAt(0)}));
  41. }
  42. /**
  43. * 构造方法
  44. * @param tableName 表名
  45. * @param alias 别名
  46. */
  47. public Table(String tableName, String alias) {
  48. this.tableName = tableName;
  49. this.alias = alias;
  50. }
  51. public Table(String tableName, String alias, String field) {
  52. this(tableName, alias, (List)Lists.newArrayList(field));
  53. }
  54. public Table(String tableName, String alias, List<Field> fields) {
  55. this(tableName, alias);
  56. this.setFields(fields);
  57. }
  58. public Table(String tableName, String alias, Field... fields) {
  59. this(tableName, alias, Arrays.asList(fields));
  60. }
  61. public String getTableName() {
  62. return tableName;
  63. }
  64. public void setTableName(String tableName) {
  65. this.tableName = tableName;
  66. }
  67. public String getAlias() {
  68. return alias;
  69. }
  70. public void setAlias(String alias) {
  71. this.alias = alias;
  72. }
  73. public List<Field> getFields() {
  74. return fields;
  75. }
  76. public void setFields(List<Field> fields) {
  77. this.fields.clear();
  78. this.fields.addAll(fields);
  79. }
  80. public void addField(String field) {
  81. this.fields.add(new Field(field));
  82. }
  83. public void addField(Field field) {
  84. this.fields.add(field);
  85. }
  86. public void addFields(Field... fields) {
  87. this.fields.addAll(Arrays.asList(fields));
  88. }
  89. @Override
  90. public String toString() {
  91. return "Table{" +
  92. "tableName='" + tableName + '\'' +
  93. ", alias='" + alias + '\'' +
  94. ", fields=" + fields +
  95. '}';
  96. }
  97. }