DbTableFieldModel.java 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. package jnpf.database.model.dbtable;
  2. import jnpf.database.constant.DbAliasConst;
  3. import jnpf.database.enums.DbAliasEnum;
  4. import jnpf.database.model.dbfield.DbFieldModel;
  5. import jnpf.database.model.dbtable.base.DbTableModelBase;
  6. import jnpf.database.model.dto.ModelDTO;
  7. import jnpf.database.model.interfaces.JdbcGetMod;
  8. import io.swagger.v3.oas.annotations.media.Schema;
  9. import jnpf.database.source.DbBase;
  10. import jnpf.util.StringUtil;
  11. import lombok.Data;
  12. import lombok.NoArgsConstructor;
  13. import lombok.ToString;
  14. import lombok.experimental.Accessors;
  15. import java.sql.ResultSet;
  16. import java.sql.SQLException;
  17. import java.util.List;
  18. /**
  19. *
  20. * @author JNPF开发平台组
  21. * @version V3.1.0
  22. * @copyright 引迈信息技术有限公司
  23. * @date 2021/06/18 By:YanYu
  24. */
  25. @Data
  26. @NoArgsConstructor
  27. @ToString(callSuper=true)
  28. @Accessors(chain = true)
  29. public class DbTableFieldModel extends DbTableModelBase implements JdbcGetMod {
  30. /**
  31. * 标识
  32. */
  33. @Schema(description = "标识")
  34. private String id;
  35. /**
  36. * 数据源主键
  37. */
  38. @Schema(description = "数据源主键")
  39. private String dbLinkId;
  40. /**
  41. * 数据库编码
  42. */
  43. @Schema(description = "数据库编码")
  44. private String dbEncode;
  45. /**
  46. * 更新时新表名
  47. */
  48. @Schema(description = "更新时新表名")
  49. private String updateNewTable;
  50. /**
  51. * 更新前的旧表名
  52. */
  53. @Schema(description = "更新前的旧表名")
  54. private String updateOldTable;
  55. /**
  56. * 字段信息集合
  57. */
  58. @Schema(description = "字段信息集合")
  59. private List<DbFieldModel> dbFieldModelList;
  60. /**
  61. * 表是否存在信息
  62. */
  63. @Schema(description = "表是否存在信息")
  64. private Boolean hasTableData;
  65. /**
  66. * 类型 0-表 1-视图
  67. */
  68. @Schema(description = "类型 0-表 1-视图")
  69. private Integer type;
  70. /**
  71. * 前端注释
  72. */
  73. public String getTableName(){
  74. return getComment();
  75. }
  76. public void setTableName(String comment) {
  77. super.setComment(comment);
  78. }
  79. public DbTableFieldModel(String table, String tableComment, List<DbFieldModel> dbFieldModelList){
  80. this.setTable(table);
  81. this.setComment(tableComment);
  82. this.dbFieldModelList = dbFieldModelList;
  83. }
  84. @Override
  85. public void setMod(ModelDTO modelDTO) {
  86. try {
  87. String dbEncode = modelDTO.getDbEncode();
  88. ResultSet resultSet = modelDTO.getResultSet();
  89. // ============== 表名 ==============
  90. try {
  91. String table = resultSet.getString(DbAliasEnum.TABLE_NAME.getAlias(dbEncode));
  92. this.setTable(table);
  93. } catch (Exception e) {
  94. }
  95. // ============== 表注释 ==============
  96. try {
  97. String tableComment = resultSet.getString(DbAliasEnum.TABLE_COMMENT.getAlias(dbEncode));
  98. this.setComment(tableComment);
  99. } catch (Exception e) {
  100. }
  101. // ============== 表总数 ==============
  102. this.setSum("0");
  103. try {
  104. String sum = resultSet.getString(DbAliasEnum.TABLE_SUM.getAlias(dbEncode));
  105. if(sum != null)
  106. this.setSum(sum);
  107. } catch (Exception e) {
  108. }
  109. this.setType(0);
  110. try {
  111. String tableType = resultSet.getString(DbAliasEnum.TABLE_TYPE.getAlias(dbEncode));
  112. if (StringUtil.isNotEmpty(tableType)) {
  113. if (dbEncode.equals(DbBase.SQL_SERVER) && tableType.equalsIgnoreCase("V ")) {
  114. this.setType(1);
  115. } else if ((dbEncode.equals(DbBase.ORACLE) || dbEncode.equals(DbBase.MYSQL)
  116. || dbEncode.equals(DbBase.DM) || dbEncode.equals(DbBase.POSTGRE_SQL) || dbEncode.equals(DbBase.KINGBASE_ES)
  117. )
  118. && tableType.equalsIgnoreCase("VIEW")) {
  119. this.setType(1);
  120. }
  121. }
  122. } catch (Exception e) {
  123. }
  124. // ============== 表大小(由于部分数据库,版本取消了此功能)==============
  125. /*String size = resultSet.getString(DbAliasEnum.TABLE_SIZE.AS());*/
  126. this.setDbEncode(dbEncode);
  127. // this.setSize(size);
  128. } catch (Exception e) {
  129. e.printStackTrace();
  130. }
  131. }
  132. }