net.vz.mongodb.jackson
Class DBQuery

java.lang.Object
  extended by net.vz.mongodb.jackson.DBQuery

public class DBQuery
extends Object

Builder for MongoDB queries.

The primary way in which this case is used is by calling the below methods on DBCursor, which is an instance if the Builder. The static methods on this class may be used when passing in expressions to and(), or() etc.

Any values that are not basic objects (numbers, Strings, booleans, collections etc) that are passed in are attempted to be serialised using Jackson.

Caution needs to be taken when querying entries that are objectIds. The mapper is at this stage unaware whether a field is stored as an ObjectId or not, so you must pass in any values that are stored as ObjectId as type ObjectId.

Since:
1.2
Author:
James Roper

Nested Class Summary
static class DBQuery.AbstractBuilder<Q extends DBQuery.AbstractBuilder>
           
static class DBQuery.Query
          This is a query builder that is also a valid query that can be passed to MongoDB
 
Constructor Summary
DBQuery()
           
 
Method Summary
static DBQuery.Query all(String field, Collection<?> values)
          The array field contains all of the given values
static DBQuery.Query all(String field, Object... values)
          The array field contains all of the given values
static DBQuery.Query and(DBQuery.Query... expressions)
          All of the given expressions match
static DBQuery.Query elemMatch(String field, DBQuery.Query query)
          An element in the given array field matches the given query
static DBQuery.Query exists(String field)
          The given field exists
static DBQuery.Query greaterThan(String field, Object value)
          The field is greater than the given value
static DBQuery.Query greaterThanEquals(String field, Object value)
          The field is greater than or equal to the given value
static DBQuery.Query in(String field, Collection<?> values)
          The field is in the given set of values
static DBQuery.Query in(String field, Object... values)
          The field is in the given set of values
static DBQuery.Query is(String field, Object value)
          The field is equal to the given value
static DBQuery.Query lessThan(String field, Object value)
          The field is less than the given value
static DBQuery.Query lessThanEquals(String field, Object value)
          The field is less than or equal to the given value
static DBQuery.Query mod(String field, Number mod, Number value)
          The field, modulo the given mod argument, is equal to the value
static DBQuery.Query nor(DBQuery.Query... expressions)
          None of the given expressions match
static DBQuery.Query notEquals(String field, Object value)
          The field is not equal to the given value
static DBQuery.Query notExists(String field)
          The given field doesn't exist
static DBQuery.Query notIn(String field, Collection<?> values)
          The field is not in the given set of values
static DBQuery.Query notIn(String field, Object... values)
          The field is not in the given set of values
static DBQuery.Query or(DBQuery.Query... expressions)
          One of the given expressions matches
static DBQuery.Query regex(String field, Pattern regex)
          The given field matches the regular expression
static DBQuery.Query size(String field, int size)
          The array field is of the given size
static DBQuery.Query where(String code)
          Execute the given JavaScript code as part of the query
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DBQuery

public DBQuery()
Method Detail

is

public static DBQuery.Query is(String field,
                               Object value)
The field is equal to the given value

Parameters:
field - The field to compare
value - The value to compare to
Returns:
the query

lessThan

public static DBQuery.Query lessThan(String field,
                                     Object value)
The field is less than the given value

Parameters:
field - The field to compare
value - The value to compare to
Returns:
the query

lessThanEquals

public static DBQuery.Query lessThanEquals(String field,
                                           Object value)
The field is less than or equal to the given value

Parameters:
field - The field to compare
value - The value to compare to
Returns:
the query

greaterThan

public static DBQuery.Query greaterThan(String field,
                                        Object value)
The field is greater than the given value

Parameters:
field - The field to compare
value - The value to compare to
Returns:
the query

greaterThanEquals

public static DBQuery.Query greaterThanEquals(String field,
                                              Object value)
The field is greater than or equal to the given value

Parameters:
field - The field to compare
value - The value to compare to
Returns:
the query

notEquals

public static DBQuery.Query notEquals(String field,
                                      Object value)
The field is not equal to the given value

Parameters:
field - The field to compare
value - The value to compare to
Returns:
the query

in

public static DBQuery.Query in(String field,
                               Object... values)
The field is in the given set of values

Parameters:
field - The field to compare
values - The value to compare to
Returns:
the query

in

public static DBQuery.Query in(String field,
                               Collection<?> values)
The field is in the given set of values

Parameters:
field - The field to compare
values - The value to compare to
Returns:
the query

notIn

public static DBQuery.Query notIn(String field,
                                  Object... values)
The field is not in the given set of values

Parameters:
field - The field to compare
values - The value to compare to
Returns:
the query

notIn

public static DBQuery.Query notIn(String field,
                                  Collection<?> values)
The field is not in the given set of values

Parameters:
field - The field to compare
values - The value to compare to
Returns:
the query

mod

public static DBQuery.Query mod(String field,
                                Number mod,
                                Number value)
The field, modulo the given mod argument, is equal to the value

Parameters:
field - The field to compare
mod - The modulo
value - The value to compare to
Returns:
the query

all

public static DBQuery.Query all(String field,
                                Collection<?> values)
The array field contains all of the given values

Parameters:
field - The field to compare
values - The values to compare to
Returns:
the query

all

public static DBQuery.Query all(String field,
                                Object... values)
The array field contains all of the given values

Parameters:
field - The field to compare
values - The values to compare to
Returns:
the query

size

public static DBQuery.Query size(String field,
                                 int size)
The array field is of the given size

Parameters:
field - The field to compare
size - The value to compare
Returns:
the query

exists

public static DBQuery.Query exists(String field)
The given field exists

Parameters:
field - The field to check
Returns:
the query

notExists

public static DBQuery.Query notExists(String field)
The given field doesn't exist

Parameters:
field - The field to check
Returns:
the query

or

public static DBQuery.Query or(DBQuery.Query... expressions)
One of the given expressions matches

Parameters:
expressions - The expressions to test
Returns:
the query

and

public static DBQuery.Query and(DBQuery.Query... expressions)
All of the given expressions match

Parameters:
expressions - The expressions to test
Returns:
the query

nor

public static DBQuery.Query nor(DBQuery.Query... expressions)
None of the given expressions match

Parameters:
expressions - The expressions to test
Returns:
the query

regex

public static DBQuery.Query regex(String field,
                                  Pattern regex)
The given field matches the regular expression

Parameters:
field - The field to comare
regex - The regular expression to match with
Returns:
the query

elemMatch

public static DBQuery.Query elemMatch(String field,
                                      DBQuery.Query query)
An element in the given array field matches the given query

Parameters:
field - the array field
query - The query to attempt to match against the elements of the array field
Returns:
the query

where

public static DBQuery.Query where(String code)
Execute the given JavaScript code as part of the query

Parameters:
code - the JavaScript code
Returns:
the query


Copyright © 2011-2012 VZ Netzwerke. All Rights Reserved.