PredicateModel.java 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. package com.jtgh.yjpt.common;
  2. import java.util.Collection;
  3. /**
  4. * Predicate模型对象
  5. *
  6. * @author 袁晓冬
  7. *
  8. */
  9. public class PredicateModel {
  10. /**
  11. * 条件类型
  12. *
  13. * @author 袁晓冬
  14. *
  15. */
  16. public enum Operator {
  17. EQ, LIKE, LIKE_L, LIKE_R, GT, LT, GTE, LTE,
  18. /** IS NULL */
  19. NL,
  20. /** IS NOT NULL */
  21. NNL,
  22. /** not equal */
  23. NEQ,
  24. /** in,值必须是Iterable */
  25. IN
  26. }
  27. /**
  28. * 子模型连接方式
  29. *
  30. * @author 袁晓冬
  31. *
  32. */
  33. public enum JoinType {
  34. AND, OR
  35. }
  36. /** 查询字段名称 */
  37. private String fieldName;
  38. /** 查询字段值 */
  39. private Object value;
  40. /** 条件类型 */
  41. private Operator operator;
  42. /** 子模型链接方式(AND OR) */
  43. private JoinType joinType;
  44. /** 子模型集合 */
  45. private Collection<PredicateModel> subPms;
  46. /**
  47. * 构造无下级的模型对象
  48. *
  49. * @param fieldName
  50. * @param value
  51. * @param operator
  52. */
  53. public PredicateModel(String fieldName, Object value, Operator operator) {
  54. this(fieldName, value, operator, JoinType.AND);
  55. }
  56. /**
  57. * 构造无下级的模型对象
  58. *
  59. * @param fieldName
  60. * @param value
  61. * @param operator
  62. * @param type
  63. */
  64. public PredicateModel(String fieldName, Object value, Operator operator, JoinType type) {
  65. this.fieldName = fieldName;
  66. this.value = value;
  67. this.operator = operator;
  68. this.joinType = type;
  69. }
  70. /**
  71. * 构造带下级模型的对象,模型之间用指定的type(AND OR)连接
  72. *
  73. * @param type
  74. * @param subPms
  75. */
  76. public PredicateModel(JoinType type, Collection<PredicateModel> subPms) {
  77. this.joinType = type;
  78. this.subPms = subPms;
  79. }
  80. public PredicateModel() {
  81. }
  82. /**
  83. * 查询字段名称
  84. *
  85. * @return
  86. */
  87. public String getFieldName() {
  88. return fieldName;
  89. }
  90. /**
  91. * 条件类型
  92. *
  93. * @return
  94. */
  95. public Operator getOperator() {
  96. return operator;
  97. }
  98. /**
  99. * 子模型集合
  100. *
  101. * @return
  102. */
  103. public Collection<PredicateModel> getSubPms() {
  104. return subPms;
  105. }
  106. /**
  107. * 子模型链接方式(AND OR)
  108. *
  109. * @return
  110. */
  111. public JoinType getJoinType() {
  112. return joinType;
  113. }
  114. /**
  115. * 查询字段值
  116. *
  117. * @return
  118. */
  119. public Object getValue() {
  120. return value;
  121. }
  122. /**
  123. * 是否包含下级模型
  124. *
  125. * @return
  126. */
  127. public boolean hasSubPredicateModel() {
  128. return null != subPms && subPms.size() > 0;
  129. }
  130. public void setFieldName(String fieldName) {
  131. this.fieldName = fieldName;
  132. }
  133. public void setOperator(Operator operator) {
  134. this.operator = operator;
  135. }
  136. public void setSubPms(Collection<PredicateModel> subPms) {
  137. this.subPms = subPms;
  138. }
  139. public void setJoinType(JoinType type) {
  140. this.joinType = type;
  141. }
  142. public void setValue(Object value) {
  143. this.value = value;
  144. }
  145. }