001package org.avaje.ebean.typequery;
002
003import com.avaje.ebean.ExpressionList;
004
005/**
006 * A property used in type query.
007 *
008 * @param <R> The type of the owning root bean
009 */
010public class TQProperty<R> {
011
012  protected final String name;
013
014  protected final R root;
015
016  /**
017   * Construct with a property name and root instance.
018   *
019   * @param name the name of the property
020   * @param root the root query bean instance
021   */
022  public TQProperty(String name, R root) {
023    this(name, root, null);
024  }
025
026  /**
027   * Construct with additional path prefix.
028   */
029  public TQProperty(String name, R root, String prefix) {
030    this.root = root;
031    this.name = TQPath.add(prefix, name);
032  }
033
034  public String toString() {
035    return name;
036  }
037
038  /**
039   * Internal method to return the underlying expression list.
040   */
041  protected ExpressionList<?> expr() {
042    return ((TQRootBean) root).peekExprList();
043  }
044
045  /**
046   * Is null.
047   */
048  public R isNull() {
049    expr().isNull(name);
050    return root;
051  }
052
053  /**
054   * Is not null.
055   */
056  public R isNotNull() {
057    expr().isNotNull(name);
058    return root;
059  }
060
061  /**
062   * Order by ascending on this property.
063   */
064  public R asc() {
065    expr().order().asc(name);
066    return root;
067  }
068
069  /**
070   * Order by descending on this property.
071   */
072  public R desc() {
073    expr().order().desc(name);
074    return root;
075  }
076
077  /**
078   * Return the property name.
079   */
080  protected String propertyName() {
081    return name;
082  }
083
084}