public class QueryBuilder extends Object implements DocumentAssignable
Document
s.
As an example:
import static
com.allanbank.mongodb.builder.QueryBuilder.and
import staticcom.allanbank.mongodb.builder.QueryBuilder.or
import staticcom.allanbank.mongodb.builder.QueryBuilder.not
import staticcom.allanbank.mongodb.builder.QueryBuilder.where
Document query = or( where("f").greaterThan(23).lessThan(42).and("g").lessThan(3), and( where("f").greaterThanOrEqualTo(42), not( where("g").lessThan(3) ) ) );
Constructor and Description |
---|
QueryBuilder()
Creates a new QueryBuilder.
|
Modifier and Type | Method and Description |
---|---|
static Document |
and(DocumentAssignable... criteria)
Creates a single document that is the conjunction of the criteria
provided.
|
Document |
asDocument()
Converts the object into a document.
|
Document |
build()
Construct the final query document.
|
QueryBuilder |
comment(String comment)
Adds a comment to the query builder.
|
static Document |
nor(DocumentAssignable... criteria)
Creates a single document that is the disjunction of the criteria
provided.
|
static Document |
not(DocumentAssignable... criteria)
Negate a set of criteria.
|
static Document |
or(DocumentAssignable... criteria)
Creates a single document that is the disjunction of the criteria
provided.
|
void |
reset()
Clears the builder's conditions.
|
QueryBuilder |
text(String textSearchExpression)
Adds a text query to the query builder.
|
QueryBuilder |
text(String textSearchExpression,
String language)
Adds a text query to the query builder.
|
static ConditionBuilder |
where(String field)
Start a criteria for a single conjunctions.
|
ConditionBuilder |
whereField(String fieldName)
Returns a builder for the constraints on a single field.
|
QueryBuilder |
whereJavaScript(String javaScript)
Adds an ad-hoc JavaScript condition to the query.
|
public static Document and(DocumentAssignable... criteria)
criteria
- The criteria to create a conjunction of.public static Document nor(DocumentAssignable... criteria)
criteria
- The criteria to create a disjunction of.public static Document not(DocumentAssignable... criteria)
criteria
- The criteria to negate. These will normally be
ConditionBuilder
s or Document
s.public static Document or(DocumentAssignable... criteria)
criteria
- The criteria to create a disjunction of.public static ConditionBuilder where(String field)
field
- The field to start the criteria against.ConditionBuilder
for constructing the conditions.public Document asDocument()
Returns the result of build()
.
asDocument
in interface DocumentAssignable
build()
public Document build()
public QueryBuilder comment(String comment)
Only a single comment(java.lang.String)
can be used. Calling multiple
comment(...) methods overwrites previous values.
comment
- The query's comment.public void reset()
public QueryBuilder text(String textSearchExpression)
Only a single text(java.lang.String)
condition can be used. Calling multiple
text(...) methods overwrites previous values.
textSearchExpression
- The text search expression.public QueryBuilder text(String textSearchExpression, String language)
Only a single text(java.lang.String)
condition can be used. Calling multiple
text(...) methods overwrites previous values.
textSearchExpression
- The text search expression.language
- The language of the text search expression.public ConditionBuilder whereField(String fieldName)
fieldName
- The name of the field to constrain.ConditionBuilder
for creation of the conditions of the
field.public QueryBuilder whereJavaScript(String javaScript)
javaScript
- The javaScript condition to add.Copyright © 2011–2014 Allanbank Consulting, Inc.. All rights reserved.