001package org.avaje.ebean.typequery;
002
003
004/**
005 * JSON document type.
006 * <p>
007 * Type that is JSON content mapped to database types such as Postgres JSON/JSONB and otherwise Varchar,Clob and Blob.
008 * </p>
009 * <p>
010 * The expressions on this type are valid of Postgres and Oracle.
011 * </p>
012 *
013 * <p>
014 * The path can reference a nested property in the JSON document using dot notation -
015 * for example "documentMeta.score" where "score" is an embedded attribute of "documentMeta"
016 * </p>
017 *
018 * @param <R> the root query bean type
019 */
020public class PJson<R> extends TQProperty<R> {
021
022  /**
023   * Construct with a property name and root instance.
024   *
025   * @param name property name
026   * @param root the root query bean instance
027   */
028  public PJson(String name, R root) {
029    super(name, root);
030  }
031
032  /**
033   * Construct with additional path prefix.
034   */
035  public PJson(String name, R root, String prefix) {
036    super(name, root, prefix);
037  }
038
039  /**
040   * Path exists - for the given path in a JSON document.
041   *
042   * <pre>{@code
043   *
044   *   new QSimpleDoc()
045   *    .content.jsonExists("meta.title")
046   *    .findList();
047   *
048   * }</pre>
049   *
050   * @param path the nested path in the JSON document in dot notation
051   */
052  public R jsonExists(String path) {
053    expr().jsonExists(name, path);
054    return root;
055  }
056
057  /**
058   * Path does not exist - for the given path in a JSON document.
059   *
060   * <pre>{@code
061   *
062   *   new QSimpleDoc()
063   *    .content.jsonNotExists("meta.title")
064   *    .findList();
065   *
066   * }</pre>
067   *
068   * @param path the nested path in the JSON document in dot notation
069   */
070  public R jsonNotExists(String path) {
071    expr().jsonNotExists(name, path);
072    return root;
073  }
074
075  /**
076   * Value at the given JSON path is equal to the given value.
077   *
078   *
079   * <pre>{@code
080   *
081   *   new QSimpleDoc()
082   *    .content.jsonEqualTo("title", "Rob JSON in the DB")
083   *    .findList();
084   *
085   * }</pre>
086   *
087   * <pre>{@code
088   *
089   *   new QSimpleDoc()
090   *    .content.jsonEqualTo("path.other", 34)
091   *    .findList();
092   *
093   * }</pre>
094   *
095   * @param path the dot notation path in the JSON document
096   * @param value the equal to bind value
097   */
098  public R jsonEqualTo(String path, Object value) {
099    expr().jsonEqualTo(name, path, value);
100    return root;
101  }
102
103  /**
104   * Not Equal to - for the given path in a JSON document.
105   *
106   * @param path the nested path in the JSON document in dot notation
107   * @param value the value used to test equality against the document path's value
108   */
109  public R jsonNotEqualTo(String path, Object value) {
110    expr().jsonNotEqualTo(name, path, value);
111    return root;
112  }
113
114  /**
115   * Greater than - for the given path in a JSON document.
116   *
117   * @param path the nested path in the JSON document in dot notation
118   * @param value the value used to test against the document path's value
119   */
120  public R jsonGreaterThan(String path, Object value) {
121    expr().jsonGreaterThan(name, path, value);
122    return root;
123  }
124
125  /**
126   * Greater than or equal to - for the given path in a JSON document.
127   *
128   * @param path the nested path in the JSON document in dot notation
129   * @param value the value used to test against the document path's value
130   */
131  public R jsonGreaterOrEqual(String path, Object value) {
132    expr().jsonGreaterOrEqual(name, path, value);
133    return root;
134  }
135
136  /**
137   * Less than - for the given path in a JSON document.
138   *
139   * @param path the nested path in the JSON document in dot notation
140   * @param value the value used to test against the document path's value
141   */
142  public R jsonLessThan(String path, Object value) {
143    expr().jsonLessThan(name, path, value);
144    return root;
145  }
146
147  /**
148   * Less than or equal to - for the given path in a JSON document.
149   *
150   * @param path the nested path in the JSON document in dot notation
151   * @param value the value used to test against the document path's value
152   */
153  public R jsonLessOrEqualTo(String path, Object value) {
154    expr().jsonLessOrEqualTo(name, path, value);
155    return root;
156  }
157}