66
77/**
88 * A restricted set of query operations that apply to both kindless queries and typed queries.
9- *
9+ *
1010 * @author Jeff Schnitzer <jeff@infohazard.org>
1111 */
1212public interface SimpleQuery <T > extends QueryExecute <T >
1313{
1414 /**
1515 * <p>Create a filter on the key of an entity. Examples:</p>
16- *
16+ *
1717 * <ul>
1818 * <li>{@code filterKey(">=", key)} (standard inequalities)</li>
1919 * <li>{@code filterKey("=", key)} (wouldn't you rather do a load-by-key?)</li>
2020 * <li>{@code filterKey("", key)} (if no operator, = is assumed)</li>
2121 * <li>{@code filterKey("!=", key)}</li>
2222 * <li>{@code filterKey("in", keyList)} (wouldn't you rather do a batch load-by-key?)</li>
2323 * </ul>
24- *
24+ *
2525 * <p>The key parameter can be anything key-ish; a Key<?>, a native datastore key, a Ref, a pojo entity, etc.</p>
26- *
27- * <p>See the Google documentation for
26+ *
27+ * <p>See the Google documentation for
2828 * <a href="http://code.google.com/appengine/docs/java/datastore/queries.html#Introduction_to_Indexes">indexes</a>
2929 * for an explanation of what you can and cannot filter for.</p>
3030 */
3131 public SimpleQuery <T > filterKey (String condition , Object value );
32-
32+
3333 /**
3434 * An alias for {@code filterKey("=", value)}
3535 */
3636 public SimpleQuery <T > filterKey (Object value );
37-
37+
3838 /**
3939 * Restricts result set only to objects which have the given ancestor
4040 * somewhere in the chain. Doesn't need to be the immediate parent.
41- *
41+ *
4242 * @param keyOrEntity can be a Key, a Key<T>, or an Objectify entity object.
4343 */
4444 public SimpleQuery <T > ancestor (Object keyOrEntity );
45-
45+
4646 /**
4747 * Limit the fetched result set to a certain number of values.
48- *
48+ *
4949 * @param value must be >= 0. A value of 0 indicates no limit.
5050 */
5151 public SimpleQuery <T > limit (int value );
52-
52+
5353 /**
5454 * Starts the query results at a particular zero-based offset. This can be extraordinarily
5555 * expensive because each skipped entity is billed as a "minor datastore operation". If you
5656 * can, you probably want to use cursors instead.
57- *
57+ *
5858 * @param value must be >= 0
5959 */
6060 public SimpleQuery <T > offset (int value );
61-
61+
6262 /**
6363 * Starts query results at the specified Cursor. You can obtain a Cursor from
6464 * a QueryResultIterator by calling the getCursor() method.
65- *
65+ *
6666 * Note that limit() and offset() are NOT encoded within a cursor; they operate
6767 * on the results of the query after a cursor is established.
6868 */
6969 public SimpleQuery <T > startAt (Cursor value );
70-
70+
7171 /**
7272 * Ends query results at the specified Cursor. You can obtain a Cursor from
7373 * a QueryResultIterator by calling the getCursor() method.
74- *
74+ *
7575 * Note that limit() and offset() are NOT encoded within a cursor; they operate
7676 * on the results of the query after a cursor is established.
7777 */
7878 public SimpleQuery <T > endAt (Cursor value );
79-
79+
8080 /**
8181 * Sets the internal chunking and prefetching strategy within the low-level API. Affects
8282 * performance only; the result set will be the same.
83- *
83+ *
8484 * @param value must be >= 0
8585 */
8686 public SimpleQuery <T > chunk (int value );
87-
87+
8888 /**
8989 * <p>Sets the internal chunking and prefetching strategy within the low-level API to attempt to get all
9090 * results at once. Affects performance only; the result set will be the same.</p>
91- *
91+ *
9292 * <p>Same as chunk(Integer.MAX_VALUE).</p>
9393 */
9494 public SimpleQuery <T > chunkAll ();
95-
95+
96+ /**
97+ * Determines whether this is a SELECT DISTINCT query.
98+ */
99+ public SimpleQuery <T > distinct (boolean value );
100+
96101 /**
97102 * <p>This method forces Objectify to (or not to) hybridize the query into a keys-only fetch plus batch get.</p>
98- *
103+ *
99104 * <p>If Objectify knows you are fetching an entity type that can be cached, it automatically converts
100105 * queries into a "hybrid" of keys-only query followed by a batch fetch of the keys. This is cheaper (keys-only
101106 * results are 1/7th the price of a full fetch) and, if the cache hits, significantly faster. However,
102107 * there are some circumstances in which you may wish to force behavior one way or another:</p>
103- *
108+ *
104109 * <ul>
105110 * <li>Issuing a kindless query (which Objectify will not auto-hybridize) when you know a significant portion
106111 * of the result set is cacheable.</li>
@@ -110,50 +115,50 @@ public interface SimpleQuery<T> extends QueryExecute<T>
110115 * <li>Hybrid queries have a slightly different consistency model than normal queries. You may wish to
111116 * force hybridization off to ensure a weakly consistent query (see below).</li>
112117 * </ul>
113- *
118+ *
114119 * <p>For the most part, hybridization only affects the performance and cost of queries. However, it is possible
115120 * for hybridization to alter the content of the result set. In the HRD, queries
116121 * always have EVENTUAL consistency but get operations may have either STRONG or EVENTUAL consistency depending
117122 * on the read policy (see {@code Objectify.consistency()}. The keys-only query results will always be EVENTUAL and may
118123 * return data that has been deleted, but Objectify will exclude these results when the more-current batch get fails to return
119124 * data. So the count of the returned data may actually be less than the limit(), even if there are plenty of
120125 * actual results. {@code hybrid(false)} will prevent this behavior.</p>
121- *
126+ *
122127 * <p>Note that in hybrid queries, the chunk size defines the batch size.</p>
123128 */
124129 public SimpleQuery <T > hybrid (boolean force );
125-
130+
126131 /**
127132 * Switches to a keys-only query. Keys-only responses are billed as "minor datastore operations"
128133 * which are significantly cheaper (~7X) than fetching whole entities.
129134 */
130135 public QueryKeys <T > keys ();
131-
136+
132137 /**
133138 * <p>Count the total number of values in the result. <em>limit</em> and <em>offset</em> are obeyed.
134139 * This is somewhat faster than fetching, but the time still grows with the number of results.
135140 * The datastore actually walks through the result set and counts for you.</p>
136- *
141+ *
137142 * <p>Immediately executes the query; there is no async version of this method.</p>
138- *
143+ *
139144 * <p>WARNING: Each counted entity is billed as a "datastore minor operation". Counting large numbers
140145 * of entities can quickly create massive bills.</p>
141146 */
142147 public int count ();
143148
144149 /**
145150 * Gets the first entity in the result set. Obeys the offset value.
146- *
151+ *
147152 * @return an asynchronous Ref containing the first result. The Ref will hold null if the result set is empty.
148153 */
149154 public Ref <T > first ();
150-
155+
151156 /**
152157 * <p>Generates a string that consistently and uniquely specifies this query. There
153158 * is no way to convert this string back into a query and there is no guarantee that
154159 * the string will be consistent across versions of Objectify.</p>
155- *
156- * <p>In particular, this value is useful as a key for a simple memcache query cache.</p>
160+ *
161+ * <p>In particular, this value is useful as a key for a simple memcache query cache.</p>
157162 */
158163 public String toString ();
159164}
0 commit comments