public abstract class BsonQuery extends Query
A base class for Query implementations that create BSON queries based on MongoDB query format. See https://docs.mongodb.com/manual/tutorial/query-documents/
| Modifiers | Name | Description |
|---|---|---|
protected interface |
BsonQuery.OperatorHandler |
Handles query operators when reading BSON |
protected interface |
BsonQuery.ProjectionHandler |
Handles a projection |
protected interface |
BsonQuery.QueryHandler |
Handles an individual criterion |
| Modifiers | Name | Description |
|---|---|---|
static java.lang.String |
AND_OPERATOR |
|
static java.lang.String |
AVERAGE_OPERATOR |
|
static org.bson.codecs.EncoderContext |
ENCODER_CONTEXT |
|
static java.lang.String |
EQ_OPERATOR |
|
static java.lang.String |
EXISTS_OPERATOR |
|
static java.lang.String |
GROUP_OPERATOR |
|
static java.lang.String |
GTE_OPERATOR |
|
static java.lang.String |
GT_OPERATOR |
|
static java.lang.String |
ID_REFERENCE_SUFFIX |
|
static java.lang.String |
IN_OPERATOR |
|
static java.lang.String |
LTE_OPERATOR |
|
static java.lang.String |
LT_OPERATOR |
|
static java.lang.String |
MATCH_OPERATOR |
|
static java.lang.String |
MAX_OPERATOR |
|
static java.lang.String |
MIN_OPERATOR |
|
static java.lang.String |
NE_OPERATOR |
|
static java.lang.String |
NIN_OPERATOR |
|
static java.lang.String |
NOR_OPERATOR |
|
static java.lang.String |
NOT_OPERATOR |
|
static java.lang.String |
OR_OPERATOR |
|
static java.lang.String |
PROJECT_OPERATOR |
|
static java.lang.String |
REGEX_OPERATOR |
|
static java.lang.String |
SIZE_OPERATOR |
|
static java.lang.String |
SORT_OPERATOR |
|
static java.lang.String |
SUM_OPERATOR |
|
protected static java.util.Set<java.lang.Class<? extends Criterion>> |
VALUE_VALIDATION_EXEMPT_CRITERIA |
Criterion types whose values are shapes or nested queries by design and are therefore not subject to validateCriterionValues(Criterion, PersistentEntity). |
static java.lang.String |
WHERE_OPERATOR |
|
protected static java.util.Map<java.lang.Class, ProjectionHandler> |
groupByProjectionHandlers |
|
protected static java.util.Map<java.lang.String, OperatorHandler> |
operatorHandlers |
|
protected static java.util.Map<java.lang.Class, ProjectionHandler> |
projectProjectionHandlers |
|
protected static java.util.Map<java.lang.Class, QueryHandler> |
queryHandlers |
| Fields inherited from class | Fields |
|---|---|
class Query |
criteria, entity, fetchStrategies, joinTypes, lockResult, max, offset, orderBy, projections, queryCache, session, uniqueResult |
| Constructor and description |
|---|
protected BsonQuery(Session session, PersistentEntity entity) |
protected BsonQuery(PersistentEntity entity) |
| Type Params | Return Type | Name and description |
|---|---|---|
|
public static org.bson.Document |
createBsonQuery(org.bson.codecs.configuration.CodecRegistry registry, PersistentEntity entity, java.util.List<Criterion> criteria)Creates a new query for the given registry, entity and criteria |
|
public static org.bson.Document |
createBsonQuery(org.bson.codecs.configuration.CodecRegistry registry, PersistentEntity entity, Junction junction)Creates a new query for the given registry, entity and criteria |
|
protected static java.util.List<java.lang.Object> |
getInListQueryValues(PersistentEntity entity, In in)Get the list of native values to use in the query. |
|
protected static org.bson.Document |
getOrCreatePropertyQuery(org.bson.Document query, java.lang.String propertyName) |
|
protected static java.lang.String |
getPropertyName(PersistentEntity entity, PropertyNameCriterion criterion) |
|
protected static java.lang.String |
getPropertyName(PersistentEntity entity, java.lang.String propertyName) |
|
public void |
handle(EmbeddedQueryEncoder queryEncoder, IdEquals criterion, org.bson.Document query, PersistentEntity entity) |
|
public void |
handle(EmbeddedQueryEncoder queryEncoder, Equals criterion, org.bson.Document query, PersistentEntity entity) |
|
public void |
handle(EmbeddedQueryEncoder queryEncoder, IsNull criterion, org.bson.Document query, PersistentEntity entity) |
|
public void |
handle(EmbeddedQueryEncoder queryEncoder, IsNotNull criterion, org.bson.Document query, PersistentEntity entity) |
|
public void |
handle(EmbeddedQueryEncoder queryEncoder, EqualsProperty criterion, org.bson.Document query, PersistentEntity entity) |
|
public void |
handle(EmbeddedQueryEncoder queryEncoder, NotEqualsProperty criterion, org.bson.Document query, PersistentEntity entity) |
|
public void |
handle(EmbeddedQueryEncoder queryEncoder, GreaterThanProperty criterion, org.bson.Document query, PersistentEntity entity) |
|
public void |
handle(EmbeddedQueryEncoder queryEncoder, LessThanProperty criterion, org.bson.Document query, PersistentEntity entity) |
|
public void |
handle(EmbeddedQueryEncoder queryEncoder, GreaterThanEqualsProperty criterion, org.bson.Document query, PersistentEntity entity) |
|
public void |
handle(EmbeddedQueryEncoder queryEncoder, LessThanEqualsProperty criterion, org.bson.Document query, PersistentEntity entity) |
|
public void |
handle(EmbeddedQueryEncoder queryEncoder, NotEquals criterion, org.bson.Document query, PersistentEntity entity) |
|
public void |
handle(EmbeddedQueryEncoder queryEncoder, Like like, org.bson.Document query, PersistentEntity entity) |
|
public void |
handle(EmbeddedQueryEncoder queryEncoder, ILike like, org.bson.Document query, PersistentEntity entity) |
|
public void |
handle(EmbeddedQueryEncoder queryEncoder, RLike like, org.bson.Document query, PersistentEntity entity) |
|
public void |
handle(EmbeddedQueryEncoder queryEncoder, In in, org.bson.Document query, PersistentEntity entity) |
|
public void |
handle(EmbeddedQueryEncoder queryEncoder, Between between, org.bson.Document query, PersistentEntity entity) |
|
public void |
handle(EmbeddedQueryEncoder queryEncoder, GreaterThan criterion, org.bson.Document query, PersistentEntity entity) |
|
public void |
handle(EmbeddedQueryEncoder queryEncoder, GreaterThanEquals criterion, org.bson.Document query, PersistentEntity entity) |
|
public void |
handle(EmbeddedQueryEncoder queryEncoder, LessThan criterion, org.bson.Document query, PersistentEntity entity) |
|
public void |
handle(EmbeddedQueryEncoder queryEncoder, LessThanEquals criterion, org.bson.Document query, PersistentEntity entity) |
|
public void |
handle(EmbeddedQueryEncoder queryEncoder, Conjunction criterion, org.bson.Document query, PersistentEntity entity) |
|
public void |
handle(EmbeddedQueryEncoder queryEncoder, Negation criteria, org.bson.Document query, PersistentEntity entity) |
|
public void |
handle(EmbeddedQueryEncoder queryEncoder, Disjunction criterion, org.bson.Document query, PersistentEntity entity) |
|
public void |
handle(EmbeddedQueryEncoder queryEncoder, SizeEquals criterion, org.bson.Document query, PersistentEntity entity) |
|
public void |
handle(EmbeddedQueryEncoder queryEncoder, SizeNotEquals criterion, org.bson.Document query, PersistentEntity entity) |
|
public void |
handle(EmbeddedQueryEncoder queryEncoder, SizeGreaterThan criterion, org.bson.Document query, PersistentEntity entity) |
|
public void |
handle(EmbeddedQueryEncoder queryEncoder, SizeLessThan criterion, org.bson.Document query, PersistentEntity entity) |
|
public void |
handle(EmbeddedQueryEncoder queryEncoder, SizeLessThanEquals criterion, org.bson.Document query, PersistentEntity entity) |
|
public void |
handle(EmbeddedQueryEncoder queryEncoder, SizeGreaterThanEquals criterion, org.bson.Document query, PersistentEntity entity) |
|
public void |
handle(Junction criteria, java.lang.String attributeName, org.bson.BsonReader queryReader) |
|
public void |
handle(Junction criteria, java.lang.String attributeName, org.bson.BsonReader queryReader) |
|
public void |
handle(Junction criteria, java.lang.String attributeName, org.bson.BsonReader queryReader) |
|
public void |
handle(Junction criteria, java.lang.String attributeName, org.bson.BsonReader queryReader) |
|
public void |
handle(Junction criteria, java.lang.String attributeName, org.bson.BsonReader queryReader) |
|
public void |
handle(Junction criteria, java.lang.String attributeName, org.bson.BsonReader queryReader) |
|
public void |
handle(Junction criteria, java.lang.String attributeName, org.bson.BsonReader queryReader) |
|
public void |
handle(Junction criteria, java.lang.String attributeName, org.bson.BsonReader queryReader) |
|
public void |
handle(Junction criteria, java.lang.String attributeName, org.bson.BsonReader queryReader) |
|
public void |
handle(Junction criteria, java.lang.String attributeName, org.bson.BsonReader queryReader) |
|
public void |
handle(Junction criteria, java.lang.String attributeName, org.bson.BsonReader queryReader) |
|
public void |
handle(Junction criteria, java.lang.String attributeName, org.bson.BsonReader queryReader) |
<T> |
public static DetachedCriteria<T> |
parse(java.lang.Class<T> type, org.bson.BsonReader queryReader)Parse a query from a BsonReader into a DetachedCriteria |
|
protected static void |
populateBsonQuery(EmbeddedQueryEncoder queryEncoder, org.bson.Document query, java.util.List<Criterion> criteria, PersistentEntity entity) |
|
protected static void |
populateBsonQuery(EmbeddedQueryEncoder queryEncoder, org.bson.Document query, Junction criteria, PersistentEntity entity) |
|
protected static java.lang.Object |
readBsonValue(org.bson.BsonReader queryReader, org.bson.BsonType bsonType) |
|
protected static java.lang.Object |
validateCriterionValue(PersistentEntity entity, java.lang.String propertyName, java.lang.Object value)Ensures a criterion value cannot be interpreted by MongoDB as a query operator expression. |
|
protected static void |
validateCriterionValues(Criterion criterion, PersistentEntity entity)Validates every value carried by a criterion before it is dispatched to a query handler or a CustomTypeMarshaller, recursing through junctions so that negated and nested criteria are covered as well. |
| Methods inherited from class | Name |
|---|---|
class Query |
add, add, allEq, and, between, cache, clone, conjunction, createQuery, disjunction, eq, executeQuery, fetchStrategy, firstResult, flushBeforeQuery, ge, getCriteria, getEntity, getOrderBy, getSession, gt, gte, idEq, ilike, in, isEmpty, isNotEmpty, isNotNull, isNull, join, join, le, like, list, lock, lock, lt, lte, max, maxResults, negation, offset, or, order, patternToRegex, projections, resolveIdIfEntity, rlike, select, setUniqueResult, singleResult |
Criterion types whose values are shapes or nested queries by design and are therefore not subject to validateCriterionValues(Criterion, PersistentEntity). Subclasses register their own exemptions here, the same way they register query handlers.
Creates a new query for the given registry, entity and criteria
registry - The registryentity - The entitycriteria - The criteriaCreates a new query for the given registry, entity and criteria
registry - The registryentity - The entityjunction - The junctionGet the list of native values to use in the query. This converts entities to ids and other types to their persisted types.
entity - The entityin - The criterionParse a query from a BsonReader into a DetachedCriteria
type - The entity typequeryReader - The query readerT - The entity concrete typeEnsures a criterion value cannot be interpreted by MongoDB as a query operator expression.
The MongoDB driver encodes any java.util.Map as a BSON subdocument, and MongoDB evaluates a
value document whose keys start with $ as an operator expression rather than as a
value. A map without such keys is a literal subdocument comparison on any property, so it is
passed through; a map carrying a $-prefixed key is rejected so that a criterion value
is always compared as a value. MongoDB only evaluates operators in the top level of a value document, so the
walk into nested maps, collections and arrays is belt-and-braces rather than a requirement;
it is bounded to MAX_CRITERION_VALUE_DEPTH levels, the limit MongoDB itself imposes
on document nesting, so that a self-referential value is reported as invalid rather than
overflowing the stack.
entity - The entity being queriedpropertyName - The name of the property the criterion applies tovalue - The criterion valueValidates every value carried by a criterion before it is dispatched to a query handler or a CustomTypeMarshaller, recursing through junctions so that negated and nested criteria are covered as well. Running once at this choke point, rather than inside individual handlers, means custom typed properties such as enums, whose criteria never reach a handler, and any handler added later are validated too.
criterion - The criterion about to be dispatchedentity - The entity being queried