All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.jmkgreen.morphia.query.Query Maven / Gradle / Ivy

The newest version!
package com.github.jmkgreen.morphia.query;

import com.mongodb.ReadPreference;
import org.bson.types.CodeWScope;

/**
 * @author Scott Hernandez
 */
public interface Query extends QueryResults, Cloneable {
    /**
     * 

Create a filter based on the specified condition and value. *

* Note: Property is in the form of "name op" ("age >"). *

* Valid operators are ["=", "==","!=", "<>", ">", "<", ">=", "<=", "in", "nin", "all", "size", "exists"] *

*

Examples:

*

*

    *
  • {@code filter("yearsOfOperation >", 5)}
  • *
  • {@code filter("rooms.maxBeds >=", 2)}
  • *
  • {@code filter("rooms.bathrooms exists", 1)}
  • *
  • {@code filter("stars in", new Long[]{3, 4}) //3 and 4 stars (midrange?)}
  • *
  • {@code filter("age >=", age)}
  • *
  • {@code filter("age =", age)}
  • *
  • {@code filter("age", age)} (if no operator, = is assumed)
  • *
  • {@code filter("age !=", age)}
  • *
  • {@code filter("age in", ageList)}
  • *
  • {@code filter("customers.loyaltyYears in", yearsList)}
  • *
*

*

You can filter on id properties if this query is * restricted to a Class. */ Query filter(String condition, Object value); /** * Fluent query interface: {@code createQuery(Ent.class).field("count").greaterThan(7)...} */ FieldEnd> field(String field); /** * Criteria builder interface */ FieldEnd criteria(String field); CriteriaContainer and(Criteria... criteria); CriteriaContainer or(Criteria... criteria); /** * Limit the query using this javascript block; only one per query */ Query where(String js); /** * Limit the query using this javascript block; only one per query */ Query where(CodeWScope js); /** *

Sorts based on a property (defines return order). Examples:

*

*

    *
  • {@code order("age")}
  • *
  • {@code order("-age")} (descending order)
  • *
  • {@code order("age, date")}
  • *
  • {@code order("age,-date")} (age ascending, date descending)
  • *
*/ Query order(String condition); /** * Limit the fetched result set to a certain number of values. * * @param value must be >= 0. A value of 0 indicates no limit. */ Query limit(int value); /** * Batch-size of the fetched result (cursor). * * @param value must be >= 0. A value of 0 indicates the server default. */ Query batchSize(int value); /** * Starts the query results at a particular zero-based offset. * * @param value must be >= 0 */ Query offset(int value); @Deprecated Query skip(int value); /** * Turns on validation (for all calls made after); by default validation is on */ Query enableValidation(); /** * Turns off validation (for all calls made after) */ Query disableValidation(); /** * Hints as to which index should be used. */ Query hintIndex(String idxName); /** * Limits the fields retrieved */ Query retrievedFields(boolean include, String... fields); /** * Limits the fields retrieved to those of the query type -- dangerous with interfaces and abstract classes */ Query retrieveKnownFields(); /** * Enabled snapshotted mode where duplicate results * (which may be updated during the lifetime of the cursor) * will not be returned. Not compatible with order/sort and hint. * */ Query enableSnapshotMode(); /** * Disable snapshotted mode (default mode). This will be faster * but changes made during the cursor may cause duplicates. * */ Query disableSnapshotMode(); /** * Route query to non-primary node */ Query queryNonPrimary(); /** * Route query to primary node */ Query queryPrimaryOnly(); /** * Route query ReadPreference */ Query useReadPreference(ReadPreference readPref); /** * Disables cursor timeout on server. */ Query disableCursorTimeout(); /** * Enables cursor timeout on server. */ Query enableCursorTimeout(); /** *

Generates a string that consistently and uniquely specifies this query. There * is no way to convert this string back into a query and there is no guarantee that * the string will be consistent across versions.

*

*

In particular, this value is useful as a key for a simple memcache query cache.

*/ String toString(); Class getEntityClass(); Query clone(); }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy