Package org.mongojack
Class DBUpdate.Builder
- java.lang.Object
-
- org.mongojack.DBUpdate.Builder
-
- All Implemented Interfaces:
org.bson.conversions.Bson
,InitializationRequiredForTransformation
- Enclosing class:
- DBUpdate
public static class DBUpdate.Builder extends Object implements org.bson.conversions.Bson, InitializationRequiredForTransformation
The builder
-
-
Constructor Summary
Constructors Constructor Description Builder()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description DBUpdate.Builder
addOperation(String modifier, String field, UpdateOperationValue value)
Add an operation to the updateDBUpdate.Builder
addRawOperation(String op, String field, Object value)
Add a raw operation.DBUpdate.Builder
addToSet(String field, Object value)
Add the given value to the array value if it doesn't already exist in the specified field atomicallyDBUpdate.Builder
addToSet(String field, Object... values)
Add the given values to the array value if they don't already exist in the specified field atomicallyDBUpdate.Builder
addToSet(String field, List<?> values)
Add the given values to the array value if they don't already exist in the specified field atomicallyDBUpdate.Builder
bit(String field, String operation, int value)
Perform a bit operation on the given fieldDBUpdate.Builder
bit(String field, String operation1, int value1, String operation2, int value2)
Perform two bit operations on the given fieldDBUpdate.Builder
bitwiseAnd(String field, int value)
Perform a bitwise and on the given fieldDBUpdate.Builder
bitwiseOr(String field, int value)
Perform a bitwise or on the given fieldDBUpdate.Builder
inc(String field)
Increment the given field atomically by oneDBUpdate.Builder
inc(String field, int by)
Increment the given field atomically by the given valuevoid
initialize(com.fasterxml.jackson.databind.ObjectMapper objectMapper, com.fasterxml.jackson.databind.JavaType type, JacksonCodecRegistry codecRegistry)
boolean
isEmpty()
Checks if the update is emptyDBUpdate.Builder
popFirst(String field)
Remove the first value from the array specified by field atomicallyDBUpdate.Builder
popLast(String field)
Remove the last value from the array specified by field atomicallyDBUpdate.Builder
pull(String field, Object value)
Remove all occurances of value from the array at fieldDBUpdate.Builder
pullAll(String field, Object... values)
Remove all occurances of the values from the array at fieldDBUpdate.Builder
pullAll(String field, List<?> values)
Remove all occurances of the values from the array at fieldDBUpdate.Builder
push(String field, Object value)
Add the given value to the array value at the specified field atomicallyDBUpdate.Builder
pushAll(String field, Object... values)
Add all of the given values to the array value at the specified field atomicallyDBUpdate.Builder
pushAll(String field, List<?> values)
Add all of the given values to the array value at the specified field atomicallyDBUpdate.Builder
rename(String oldFieldName, String newFieldName)
Rename the given field to the new field nameDBUpdate.Builder
set(String field, Object value)
Set the given field (can be multiple levels deep) to the given value atomically<TDocument>
org.bson.BsonDocumenttoBsonDocument(Class<TDocument> tDocumentClass, org.bson.codecs.configuration.CodecRegistry codecRegistry)
DBUpdate.Builder
unset(String field)
Unset the given field atomically
-
-
-
Method Detail
-
inc
public DBUpdate.Builder inc(String field)
Increment the given field atomically by one- Parameters:
field
- The field to increment- Returns:
- this object
-
inc
public DBUpdate.Builder inc(String field, int by)
Increment the given field atomically by the given value- Parameters:
field
- The field to incrementby
- The value to increment by- Returns:
- this object
-
set
public DBUpdate.Builder set(String field, Object value)
Set the given field (can be multiple levels deep) to the given value atomically- Parameters:
field
- The field to setvalue
- The value to set it to- Returns:
- this object
-
unset
public DBUpdate.Builder unset(String field)
Unset the given field atomically- Parameters:
field
- The field to unset- Returns:
- this object
-
push
public DBUpdate.Builder push(String field, Object value)
Add the given value to the array value at the specified field atomically- Parameters:
field
- The field to add the value tovalue
- The value to add- Returns:
- this object
-
pushAll
public DBUpdate.Builder pushAll(String field, Object... values)
Add all of the given values to the array value at the specified field atomically- Parameters:
field
- The field to add the values tovalues
- The values to add- Returns:
- this object
-
pushAll
public DBUpdate.Builder pushAll(String field, List<?> values)
Add all of the given values to the array value at the specified field atomically- Parameters:
field
- The field to add the values tovalues
- The values to add- Returns:
- this object
-
addToSet
public DBUpdate.Builder addToSet(String field, Object value)
Add the given value to the array value if it doesn't already exist in the specified field atomically- Parameters:
field
- The field to add the value tovalue
- The value to add- Returns:
- this object
-
addToSet
public DBUpdate.Builder addToSet(String field, Object... values)
Add the given values to the array value if they don't already exist in the specified field atomically- Parameters:
field
- The field to add the values tovalues
- The values to add- Returns:
- this object
-
addToSet
public DBUpdate.Builder addToSet(String field, List<?> values)
Add the given values to the array value if they don't already exist in the specified field atomically- Parameters:
field
- The field to add the values tovalues
- The values to add- Returns:
- this object
-
popFirst
public DBUpdate.Builder popFirst(String field)
Remove the first value from the array specified by field atomically- Parameters:
field
- The field to remove the value from- Returns:
- this object
-
popLast
public DBUpdate.Builder popLast(String field)
Remove the last value from the array specified by field atomically- Parameters:
field
- The field to remove the value from- Returns:
- this object
-
pull
public DBUpdate.Builder pull(String field, Object value)
Remove all occurances of value from the array at field- Parameters:
field
- The field to remove the value fromvalue
- The value to remove. This may be another query.- Returns:
- this object
-
pullAll
public DBUpdate.Builder pullAll(String field, Object... values)
Remove all occurances of the values from the array at field- Parameters:
field
- The field to remove the values fromvalues
- The values to remove- Returns:
- this object
-
pullAll
public DBUpdate.Builder pullAll(String field, List<?> values)
Remove all occurances of the values from the array at field- Parameters:
field
- The field to remove the values fromvalues
- The values to remove- Returns:
- this object
-
rename
public DBUpdate.Builder rename(String oldFieldName, String newFieldName)
Rename the given field to the new field name- Parameters:
oldFieldName
- The old field namenewFieldName
- The new field name- Returns:
- this object
-
bit
public DBUpdate.Builder bit(String field, String operation, int value)
Perform a bit operation on the given field- Parameters:
field
- The field to perform the operation onoperation
- The operation to performvalue
- The value- Returns:
- this object
-
bit
public DBUpdate.Builder bit(String field, String operation1, int value1, String operation2, int value2)
Perform two bit operations on the given field- Parameters:
field
- The field to perform the operations onoperation1
- The first operation to performvalue1
- The first valueoperation2
- The second operation to performvalue2
- The second value- Returns:
- this object
-
bitwiseAnd
public DBUpdate.Builder bitwiseAnd(String field, int value)
Perform a bitwise and on the given field- Parameters:
field
- The field to perform the and onvalue
- The value- Returns:
- this object
-
bitwiseOr
public DBUpdate.Builder bitwiseOr(String field, int value)
Perform a bitwise or on the given field- Parameters:
field
- The field to perform the or onvalue
- The value- Returns:
- this object
-
addRawOperation
public DBUpdate.Builder addRawOperation(String op, String field, Object value)
Add a raw operation. This may be useful in case of MongoDB adding new features that aren't yet available through this interface, or if something has been left out. Note that no serialisation will be attempted of the values.- Parameters:
op
- The operationfield
- The field to set the value onvalue
- The value to set- Returns:
- this object
-
addOperation
public DBUpdate.Builder addOperation(String modifier, String field, UpdateOperationValue value)
Add an operation to the update- Parameters:
modifier
- The modifier of the operationfield
- The field to setvalue
- The value to modify it with.- Returns:
- this object
-
isEmpty
public boolean isEmpty()
Checks if the update is empty- Returns:
- true if the update is empty
-
toBsonDocument
public <TDocument> org.bson.BsonDocument toBsonDocument(Class<TDocument> tDocumentClass, org.bson.codecs.configuration.CodecRegistry codecRegistry)
- Specified by:
toBsonDocument
in interfaceorg.bson.conversions.Bson
-
initialize
public void initialize(com.fasterxml.jackson.databind.ObjectMapper objectMapper, com.fasterxml.jackson.databind.JavaType type, JacksonCodecRegistry codecRegistry)
- Specified by:
initialize
in interfaceInitializationRequiredForTransformation
-
-