001package io.ebean.typequery;
002
003
004/**
005 * Base property for all comparable types.
006 *
007 * @param <R> the root query bean type
008 * @param <T> the type of the scalar property
009 */
010@SuppressWarnings("rawtypes")
011public class PBaseCompareable<R, T> extends PBaseValueEqual<R, T> {
012
013  /**
014   * Construct with a property name and root instance.
015   *
016   * @param name property name
017   * @param root the root query bean instance
018   */
019  public PBaseCompareable(String name, R root) {
020    super(name, root);
021  }
022
023  /**
024   * Construct with additional path prefix.
025   */
026  public PBaseCompareable(String name, R root, String prefix) {
027    super(name, root, prefix);
028  }
029
030  // ---- range comparisons -------
031
032  /**
033   * Greater than.
034   *
035   * @param value the bind value
036   * @return the root query bean instance
037   */
038  public final R gt(T value) {
039    expr().gt(_name, value);
040    return _root;
041  }
042
043  /**
044   * Greater than OR Null.
045   *
046   * @param value the bind value
047   * @return the root query bean instance
048   */
049  public final R gtOrNull(T value) {
050    expr().gtOrNull(_name, value);
051    return _root;
052  }
053
054  /**
055   * Greater than or Equal to.
056   *
057   * @param value the bind value
058   * @return the root query bean instance
059   */
060  public final R ge(T value) {
061    expr().ge(_name, value);
062    return _root;
063  }
064
065  /**
066   * Greater than or Equal to OR Null.
067   *
068   * @param value the bind value
069   * @return the root query bean instance
070   */
071  public final R geOrNull(T value) {
072    expr().geOrNull(_name, value);
073    return _root;
074  }
075
076  /**
077   * Less than.
078   *
079   * @param value the bind value
080   * @return the root query bean instance
081   */
082  public final R lt(T value) {
083    expr().lt(_name, value);
084    return _root;
085  }
086
087  /**
088   * Less than OR Null.
089   *
090   * @param value the bind value
091   * @return the root query bean instance
092   */
093  public final R ltOrNull(T value) {
094    expr().ltOrNull(_name, value);
095    return _root;
096  }
097
098  /**
099   * Less than or Equal to.
100   *
101   * @param value the bind value
102   * @return the root query bean instance
103   */
104  public final R le(T value) {
105    expr().le(_name, value);
106    return _root;
107  }
108
109  /**
110   * Less than or Equal to.
111   *
112   * @param value the bind value
113   * @return the root query bean instance
114   */
115  public final R leOrNull(T value) {
116    expr().leOrNull(_name, value);
117    return _root;
118  }
119
120  /**
121   * Greater or equal to lower value and strictly less than upper value.
122   * <p>
123   * This is generally preferable over Between for date and datetime types
124   * as SQL Between is inclusive on the upper bound (<=) and generally we
125   * need the upper bound to be exclusive (<).
126   * </p>
127   *
128   * @param lower the lower bind value (>=)
129   * @param upper the upper bind value (<)
130   * @return the root query bean instance
131   */
132  public final R inRange(T lower, T upper) {
133    expr().inRange(_name, lower, upper);
134    return _root;
135  }
136
137  /**
138   * Value in Range between 2 properties.
139   *
140   * <pre>{@code
141   *
142   *    .startDate.inRangeWith(endDate, now)
143   *
144   *    // which equates to
145   *    startDate <= now and (endDate > now or endDate is null)
146   *
147   * }</pre>
148   *
149   * <p>
150   * This is a convenience expression combining a number of simple expressions.
151   * The most common use of this could be called "effective dating" where 2 date or
152   * timestamp columns represent the date range in which
153   */
154  public final R inRangeWith(TQProperty<R> highProperty, T value) {
155    expr().inRangeWith(_name, highProperty._name, value);
156    return _root;
157  }
158
159  /**
160   * Between lower and upper values.
161   *
162   * @param lower the lower bind value
163   * @param upper the upper bind value
164   * @return the root query bean instance
165   */
166  public final R between(T lower, T upper) {
167    expr().between(_name, lower, upper);
168    return _root;
169  }
170
171  /**
172   * Greater than.
173   *
174   * @param value the bind value
175   * @return the root query bean instance
176   */
177  public final R greaterThan(T value) {
178    expr().gt(_name, value);
179    return _root;
180  }
181
182  /**
183   * Greater than or Null.
184   *
185   * @param value the bind value
186   * @return the root query bean instance
187   */
188  public final R greaterThanOrNull(T value) {
189    expr().gtOrNull(_name, value);
190    return _root;
191  }
192
193  /**
194   * Greater than or Equal to.
195   *
196   * @param value the bind value
197   * @return the root query bean instance
198   */
199  public final R greaterOrEqualTo(T value) {
200    expr().ge(_name, value);
201    return _root;
202  }
203
204  /**
205   * Less than.
206   *
207   * @param value the bind value
208   * @return the root query bean instance
209   */
210  public final R lessThan(T value) {
211    expr().lt(_name, value);
212    return _root;
213  }
214
215  /**
216   * Less than or Null.
217   *
218   * @param value the bind value
219   * @return the root query bean instance
220   */
221  public final R lessThanOrNull(T value) {
222    expr().ltOrNull(_name, value);
223    return _root;
224  }
225
226  /**
227   * Less than or Equal to.
228   *
229   * @param value the bind value
230   * @return the root query bean instance
231   */
232  public final R lessOrEqualTo(T value) {
233    expr().le(_name, value);
234    return _root;
235  }
236
237}