AbstractChainWrapper.java 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319
  1. /*
  2. * Copyright (c) 2011-2020, baomidou (jobob@qq.com).
  3. * <p>
  4. * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  5. * use this file except in compliance with the License. You may obtain a copy of
  6. * the License at
  7. * <p>
  8. * https://www.apache.org/licenses/LICENSE-2.0
  9. * <p>
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  12. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  13. * License for the specific language governing permissions and limitations under
  14. * the License.
  15. */
  16. package com.baomidou.mybatisplus.extension.conditions;
  17. import com.baomidou.mybatisplus.core.conditions.AbstractWrapper;
  18. import com.baomidou.mybatisplus.core.conditions.Wrapper;
  19. import com.baomidou.mybatisplus.core.conditions.interfaces.Compare;
  20. import com.baomidou.mybatisplus.core.conditions.interfaces.Func;
  21. import com.baomidou.mybatisplus.core.conditions.interfaces.Join;
  22. import com.baomidou.mybatisplus.core.conditions.interfaces.Nested;
  23. import com.baomidou.mybatisplus.core.conditions.segments.MergeSegments;
  24. import com.baomidou.mybatisplus.core.toolkit.ExceptionUtils;
  25. import java.util.Collection;
  26. import java.util.Map;
  27. import java.util.function.BiPredicate;
  28. import java.util.function.Consumer;
  29. /**
  30. * 所有包装类都继承此抽象类,此抽象类代理了大部分生成 where 条件的方法
  31. * <li> 泛型: Children ,表示子类 </li>
  32. * <li> 泛型: Param ,表示子类所包装的具体 Wrapper 类型 </li>
  33. *
  34. * @author miemie
  35. * @since 2018-12-19
  36. */
  37. @SuppressWarnings({"serial", "unchecked"})
  38. public abstract class AbstractChainWrapper<T, R, Children extends AbstractChainWrapper<T, R, Children, Param>, Param>
  39. extends Wrapper<T> implements Compare<Children, R>, Func<Children, R>, Join<Children>, Nested<Param, Children> {
  40. protected final Children typedThis = (Children) this;
  41. /**
  42. * 子类所包装的具体 Wrapper 类型
  43. */
  44. protected Param wrapperChildren;
  45. /**
  46. * 必须的构造函数
  47. */
  48. public AbstractChainWrapper() {
  49. }
  50. @SuppressWarnings("rawtypes")
  51. public AbstractWrapper getWrapper() {
  52. return (AbstractWrapper) wrapperChildren;
  53. }
  54. @Override
  55. public <V> Children allEq(boolean condition, Map<R, V> params, boolean null2IsNull) {
  56. getWrapper().allEq(condition, params, null2IsNull);
  57. return typedThis;
  58. }
  59. @Override
  60. public <V> Children allEq(boolean condition, BiPredicate<R, V> filter, Map<R, V> params, boolean null2IsNull) {
  61. getWrapper().allEq(condition, filter, params, null2IsNull);
  62. return typedThis;
  63. }
  64. @Override
  65. public Children eq(boolean condition, R column, Object val) {
  66. getWrapper().eq(condition, column, val);
  67. return typedThis;
  68. }
  69. @Override
  70. public Children ne(boolean condition, R column, Object val) {
  71. getWrapper().ne(condition, column, val);
  72. return typedThis;
  73. }
  74. @Override
  75. public Children gt(boolean condition, R column, Object val) {
  76. getWrapper().gt(condition, column, val);
  77. return typedThis;
  78. }
  79. @Override
  80. public Children ge(boolean condition, R column, Object val) {
  81. getWrapper().ge(condition, column, val);
  82. return typedThis;
  83. }
  84. @Override
  85. public Children lt(boolean condition, R column, Object val) {
  86. getWrapper().lt(condition, column, val);
  87. return typedThis;
  88. }
  89. @Override
  90. public Children le(boolean condition, R column, Object val) {
  91. getWrapper().le(condition, column, val);
  92. return typedThis;
  93. }
  94. @Override
  95. public Children between(boolean condition, R column, Object val1, Object val2) {
  96. getWrapper().between(condition, column, val1, val2);
  97. return typedThis;
  98. }
  99. @Override
  100. public Children notBetween(boolean condition, R column, Object val1, Object val2) {
  101. getWrapper().notBetween(condition, column, val1, val2);
  102. return typedThis;
  103. }
  104. @Override
  105. public Children like(boolean condition, R column, Object val) {
  106. getWrapper().like(condition, column, val);
  107. return typedThis;
  108. }
  109. @Override
  110. public Children notLike(boolean condition, R column, Object val) {
  111. getWrapper().notLike(condition, column, val);
  112. return typedThis;
  113. }
  114. @Override
  115. public Children likeLeft(boolean condition, R column, Object val) {
  116. getWrapper().likeLeft(condition, column, val);
  117. return typedThis;
  118. }
  119. @Override
  120. public Children likeRight(boolean condition, R column, Object val) {
  121. getWrapper().likeRight(condition, column, val);
  122. return typedThis;
  123. }
  124. @Override
  125. public Children isNull(boolean condition, R column) {
  126. getWrapper().isNull(condition, column);
  127. return typedThis;
  128. }
  129. @Override
  130. public Children isNotNull(boolean condition, R column) {
  131. getWrapper().isNotNull(condition, column);
  132. return typedThis;
  133. }
  134. @Override
  135. public Children in(boolean condition, R column, Collection<?> coll) {
  136. getWrapper().in(condition, column, coll);
  137. return typedThis;
  138. }
  139. @Override
  140. public Children notIn(boolean condition, R column, Collection<?> coll) {
  141. getWrapper().notIn(condition, column, coll);
  142. return typedThis;
  143. }
  144. @Override
  145. public Children inSql(boolean condition, R column, String inValue) {
  146. getWrapper().inSql(condition, column, inValue);
  147. return typedThis;
  148. }
  149. @Override
  150. public Children notInSql(boolean condition, R column, String inValue) {
  151. getWrapper().notInSql(condition, column, inValue);
  152. return typedThis;
  153. }
  154. @Override
  155. public Children groupBy(boolean condition, R... columns) {
  156. getWrapper().groupBy(condition, columns);
  157. return typedThis;
  158. }
  159. @Override
  160. public Children orderBy(boolean condition, boolean isAsc, R... columns) {
  161. getWrapper().orderBy(condition, isAsc, columns);
  162. return typedThis;
  163. }
  164. @Override
  165. public Children having(boolean condition, String sqlHaving, Object... params) {
  166. getWrapper().having(condition, sqlHaving, params);
  167. return typedThis;
  168. }
  169. @Override
  170. public Children func(boolean condition, Consumer<Children> consumer) {
  171. getWrapper().func(condition, consumer);
  172. return typedThis;
  173. }
  174. @Override
  175. public Children or(boolean condition) {
  176. getWrapper().or(condition);
  177. return typedThis;
  178. }
  179. @Override
  180. public Children apply(boolean condition, String applySql, Object... value) {
  181. getWrapper().apply(condition, applySql, value);
  182. return typedThis;
  183. }
  184. @Override
  185. public Children last(boolean condition, String lastSql) {
  186. getWrapper().last(condition, lastSql);
  187. return typedThis;
  188. }
  189. @Override
  190. public Children comment(boolean condition, String comment) {
  191. getWrapper().comment(condition, comment);
  192. return typedThis;
  193. }
  194. @Override
  195. public Children first(boolean condition, String firstSql) {
  196. getWrapper().first(condition, firstSql);
  197. return typedThis;
  198. }
  199. @Override
  200. public Children exists(boolean condition, String existsSql) {
  201. getWrapper().exists(condition, existsSql);
  202. return typedThis;
  203. }
  204. @Override
  205. public Children notExists(boolean condition, String notExistsSql) {
  206. getWrapper().notExists(condition, notExistsSql);
  207. return typedThis;
  208. }
  209. @Override
  210. public Children and(boolean condition, Consumer<Param> consumer) {
  211. getWrapper().and(condition, consumer);
  212. return typedThis;
  213. }
  214. @Override
  215. public Children or(boolean condition, Consumer<Param> consumer) {
  216. getWrapper().or(condition, consumer);
  217. return typedThis;
  218. }
  219. @Override
  220. public Children nested(boolean condition, Consumer<Param> consumer) {
  221. getWrapper().nested(condition, consumer);
  222. return typedThis;
  223. }
  224. @Override
  225. public String getSqlSegment() {
  226. throw ExceptionUtils.mpe("can not use this method for \"%s\"", "getSqlSegment");
  227. }
  228. @Override
  229. public String getSqlFirst() {
  230. throw ExceptionUtils.mpe("can not use this method for \"%s\"", "getSqlFirst");
  231. }
  232. @Override
  233. public String getSqlSelect() {
  234. throw ExceptionUtils.mpe("can not use this method for \"%s\"", "getSqlSelect");
  235. }
  236. @Override
  237. public String getSqlSet() {
  238. throw ExceptionUtils.mpe("can not use this method for \"%s\"", "getSqlSet");
  239. }
  240. @Override
  241. public String getSqlComment() {
  242. throw ExceptionUtils.mpe("can not use this method for \"%s\"", "getSqlComment");
  243. }
  244. @Override
  245. public String getTargetSql() {
  246. throw ExceptionUtils.mpe("can not use this method for \"%s\"", "getTargetSql");
  247. }
  248. @Override
  249. public T getEntity() {
  250. throw ExceptionUtils.mpe("can not use this method for \"%s\"", "getEntity");
  251. }
  252. @Override
  253. public MergeSegments getExpression() {
  254. throw ExceptionUtils.mpe("can not use this method for \"%s\"", "getExpression");
  255. }
  256. @Override
  257. public String getCustomSqlSegment() {
  258. throw ExceptionUtils.mpe("can not use this method for \"%s\"", "getCustomSqlSegment");
  259. }
  260. @Override
  261. public void clear() {
  262. throw ExceptionUtils.mpe("can not use this method for \"%s\"", "clear");
  263. }
  264. @Override
  265. protected Object clone() throws CloneNotSupportedException {
  266. throw ExceptionUtils.mpe("can not use this method for \"%s\"", "clone");
  267. }
  268. }