QueryResult.java 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. package com.primeton.dsp.dataservice.utils;
  2. import com.alibaba.fastjson.JSONObject;
  3. import java.util.List;
  4. import java.util.Map;
  5. /**
  6. *
  7. * 执行查询 SQL 输出的结果类。 返回查询行数、字段表头、数据行。
  8. *
  9. * <pre>
  10. *
  11. * Created by zhaopx.
  12. * User: zhaopx
  13. * Date: 2020-03-26
  14. * Time: 10:20
  15. *
  16. * </pre>
  17. *
  18. * @author zhaopx
  19. */
  20. public class QueryResult {
  21. /**
  22. * 是否成功
  23. */
  24. boolean success = true;
  25. /**
  26. * 当前是否成功
  27. */
  28. String message = "OK";
  29. /**
  30. * 执行的 SQL
  31. */
  32. String sql;
  33. /**
  34. * 执行查询结果集的行数
  35. */
  36. final int rows;
  37. /**
  38. * 表头,和类型
  39. */
  40. final List<Map<String, Object>> fields;
  41. /**
  42. * 数据集,多行
  43. */
  44. final List<Map<String, Object>> dataset;
  45. public QueryResult(List<Map<String, Object>> fields, List<Map<String, Object>> dataset) {
  46. this.fields = fields;
  47. this.dataset = dataset;
  48. this.rows = dataset.size();
  49. }
  50. public int getRows() {
  51. return rows;
  52. }
  53. public List<Map<String, Object>> getFields() {
  54. return fields;
  55. }
  56. public List<Map<String, Object>> getDataset() {
  57. return dataset;
  58. }
  59. /**
  60. * 返回一个结果
  61. * @return
  62. */
  63. public Map<String, Object> getOne() {
  64. return dataset.size() > 0 ? dataset.get(0) : null;
  65. }
  66. public boolean isSuccess() {
  67. return success;
  68. }
  69. public String getMessage() {
  70. return message;
  71. }
  72. public void setSuccess(boolean success) {
  73. this.success = success;
  74. }
  75. public void setMessage(String message) {
  76. this.message = message;
  77. }
  78. public String getSql() {
  79. return sql;
  80. }
  81. public void setSql(String sql) {
  82. this.sql = sql;
  83. }
  84. @Override
  85. public String toString() {
  86. return JSONObject.toJSONString(this);
  87. }
  88. }