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 Equal to.
045   *
046   * @param value the bind value
047   * @return the root query bean instance
048   */
049  public final R ge(T value) {
050    expr().ge(_name, value);
051    return _root;
052  }
053
054  /**
055   * Less than.
056   *
057   * @param value the bind value
058   * @return the root query bean instance
059   */
060  public final R lt(T value) {
061    expr().lt(_name, value);
062    return _root;
063  }
064
065
066  /**
067   * Less than or Equal to.
068   *
069   * @param value the bind value
070   * @return the root query bean instance
071   */
072  public final R le(T value) {
073    expr().le(_name, value);
074    return _root;
075  }
076
077  /**
078   * Greater or equal to lower value and strictly less than upper value.
079   * <p>
080   * This is generally preferable over Between for date and datetime types
081   * as SQL Between is inclusive on the upper bound (<=) and generally we
082   * need the upper bound to be exclusive (<).
083   * </p>
084   *
085   * @param lower the lower bind value (>=)
086   * @param upper the upper bind value (<)
087   * @return the root query bean instance
088   */
089  public final R inRange(T lower, T upper) {
090    expr().inRange(_name, lower, upper);
091    return _root;
092  }
093
094  /**
095   * Value in Range between 2 properties.
096   *
097   * <pre>{@code
098   *
099   *    .startDate.inRangeWith(endDate, now)
100   *
101   *    // which equates to
102   *    startDate <= now and (endDate > now or endDate is null)
103   *
104   * }</pre>
105   *
106   * <p>
107   * This is a convenience expression combining a number of simple expressions.
108   * The most common use of this could be called "effective dating" where 2 date or
109   * timestamp columns represent the date range in which
110   */
111  public final R inRangeWith(TQProperty<R> highProperty, T value) {
112    expr().inRangeWith(_name, highProperty._name, value);
113    return _root;
114  }
115
116  /**
117   * Between lower and upper values.
118   *
119   * @param lower the lower bind value
120   * @param upper the upper bind value
121   * @return the root query bean instance
122   */
123  public final R between(T lower, T upper) {
124    expr().between(_name, lower, upper);
125    return _root;
126  }
127
128  /**
129   * Greater than.
130   *
131   * @param value the bind value
132   * @return the root query bean instance
133   */
134  public final R greaterThan(T value) {
135    expr().gt(_name, value);
136    return _root;
137  }
138
139  /**
140   * Greater than or Null.
141   *
142   * @param value the bind value
143   * @return the root query bean instance
144   */
145  public final R greaterThanOrNull(T value) {
146    expr().gtOrNull(_name, value);
147    return _root;
148  }
149
150  /**
151   * Greater than or Equal to.
152   *
153   * @param value the bind value
154   * @return the root query bean instance
155   */
156  public final R greaterOrEqualTo(T value) {
157    expr().ge(_name, value);
158    return _root;
159  }
160
161  /**
162   * Less than.
163   *
164   * @param value the bind value
165   * @return the root query bean instance
166   */
167  public final R lessThan(T value) {
168    expr().lt(_name, value);
169    return _root;
170  }
171
172  /**
173   * Less than or Null.
174   *
175   * @param value the bind value
176   * @return the root query bean instance
177   */
178  public final R lessThanOrNull(T value) {
179    expr().ltOrNull(_name, value);
180    return _root;
181  }
182
183  /**
184   * Less than or Equal to.
185   *
186   * @param value the bind value
187   * @return the root query bean instance
188   */
189  public final R lessOrEqualTo(T value) {
190    expr().le(_name, value);
191    return _root;
192  }
193
194}