public class DocumentEditor extends Object implements EditableDocument
Document.Field, Document.ValueTransformer
Modifier and Type | Field and Description |
---|---|
protected DocumentValueFactory |
factory |
Constructor and Description |
---|
DocumentEditor(MutableDocument document)
Return the document that was edited.
|
DocumentEditor(MutableDocument document,
DocumentValueFactory factory)
Return the document that was edited.
|
Modifier and Type | Method and Description |
---|---|
MutableDocument |
asMutableDocument() |
DocumentEditor |
clone()
Obtain a clone of this document.
|
boolean |
containsAll(Document document)
Checks if this object contains all of the fields in the supplied document.
|
boolean |
containsField(String name)
Checks if this object contains a field with the given name.
|
protected EditableArray |
createEditableArray(MutableArray array,
String fieldName,
DocumentValueFactory factory) |
protected EditableDocument |
createEditableDocument(MutableDocument document,
String fieldName,
DocumentValueFactory factory) |
protected void |
doSetAllValues(Document values)
The method that does the actual setting for all of the
putAll(Document) method. |
protected void |
doSetAllValues(Map<? extends String,? extends Object> values)
The method that does the actual setting for all of the
putAll(Map) method. |
protected Object |
doSetValue(String name,
Object value)
The method that does the actual setting for all of the
set... |
protected Object |
doSetValueIfAbsent(String name,
Object value)
The method that does the actual setting for all of the
set... |
protected EditableDocument |
editable(Document doc,
String fieldName) |
protected EditableArray |
editable(List<?> array,
String fieldName) |
Iterable<Document.Field> |
fields()
Obtain an iterator over the
Document.Field s in this object. |
Object |
get(String name)
Gets the value in this document for the given field name.
|
EditableArray |
getArray(String name)
Get the existing array value in this document for the given field name.
|
Binary |
getBinary(String name)
Get the
Binary value in this document for the given field name. |
Boolean |
getBoolean(String name)
Get the boolean value in this document for the given field name.
|
boolean |
getBoolean(String name,
boolean defaultValue)
Get the boolean value in this document for the given field name.
|
Code |
getCode(String name)
Get the
Code value in this document for the given field name. |
CodeWithScope |
getCodeWithScope(String name)
Get the
CodeWithScope value in this document for the given field name. |
EditableDocument |
getDocument(String name)
Get the existing document value in this document for the given field name.
|
Double |
getDouble(String name)
Get the double value in this document for the given field name.
|
double |
getDouble(String name,
double defaultValue)
Get the double value in this document for the given field name.
|
Integer |
getInteger(String name)
Get the integer value in this document for the given field name.
|
int |
getInteger(String name,
int defaultValue)
Get the integer value in this document for the given field name.
|
Long |
getLong(String name)
Get the integer value in this document for the given field name.
|
long |
getLong(String name,
long defaultValue)
Get the long value in this document for the given field name.
|
MaxKey |
getMaxKey(String name)
Get the
MaxKey value in this document for the given field name. |
MinKey |
getMinKey(String name)
Get the
MinKey value in this document for the given field name. |
Number |
getNumber(String name)
Get the number value in this document for the given field name.
|
Number |
getNumber(String name,
Number defaultValue)
Get the number value in this document for the given field name.
|
ObjectId |
getObjectId(String name)
Get the
ObjectId value in this document for the given field name. |
EditableArray |
getOrCreateArray(String name)
Get the existing array value in this document for the given field name, or create a new array if there is no existing array
at this field.
|
EditableDocument |
getOrCreateDocument(String name)
Get the existing document value in this document for the given field name, or create a new document if there is no existing
document at this field.
|
Pattern |
getPattern(String name)
Get the
Pattern value in this document for the given field name. |
String |
getString(String name)
Get the string value in this document for the given field name.
|
String |
getString(String name,
String defaultValue)
Get the string value in this document for the given field name.
|
Symbol |
getSymbol(String name)
Get the
Symbol value in this document for the given field name. |
int |
getType(String name)
Get the
Bson.Type constant that describes the type of value for the given field name. |
UUID |
getUuid(String name)
Get the
UUID value in this document for the given field name. |
UUID |
getUuid(String name,
UUID defaultValue)
Get the
UUID value in this document for the given field name. |
boolean |
isEmpty()
Return whether this document contains no fields and is therefore empty.
|
boolean |
isNull(String name)
Determine whether this object has a pair with the given the name and the value is null.
|
boolean |
isNullOrMissing(String name)
Determine whether this object has a pair with the given the name and the value is null, or if this object has no field with
the given name.
|
Set<String> |
keySet()
Returns this object's fields' names
|
void |
merge(Document other)
Merges the supplied document onto this document.
|
Object |
put(String name,
Object value) |
void |
putAll(Document object)
Sets on this object all name/value pairs from the supplied object.
|
void |
putAll(Map<? extends String,? extends Object> map)
Sets on this object all key/value pairs from the supplied map.
|
Object |
remove(String name)
Remove the field with the supplied name, and return the value.
|
void |
removeAll()
Remove all fields from this document.
|
EditableDocument |
set(String name,
Object value)
Set the value for the field with the given name to the supplied value.
|
EditableArray |
setArray(String name)
Set the value for the field with the given name to be a new, empty array.
|
EditableArray |
setArray(String name,
Array array)
Set the value for the field with the given name to be the supplied array.
|
EditableArray |
setArray(String name,
Object... values)
Set the value for the field with the given name to be the supplied array.
|
EditableDocument |
setBinary(String name,
byte type,
byte[] data)
Set the value for the field with the given name to be a binary value.
|
EditableDocument |
setBoolean(String name,
boolean value)
Set the value for the field with the given name to the supplied boolean value.
|
EditableDocument |
setCode(String name,
String code,
boolean includeScope)
Set the value for the field with the given name to be a
Code or CodeWithScope . |
EditableDocument |
setCode(String name,
String code,
Document scope)
Set the value for the field with the given name to be a
Code or CodeWithScope . |
EditableDocument |
setDate(String name,
Date value)
Set the value for the field with the given name to the supplied date value.
|
EditableDocument |
setDate(String name,
String isoDate)
Set the value for the field with the given name to the date value parsed from the ISO-8601 date representation.
|
EditableDocument |
setDocument(String name)
Set the value for the field with the given name to be a new, empty Document.
|
EditableDocument |
setDocument(String name,
Document document)
Set the value for the field with the given name to be the supplied Document.
|
EditableDocument |
setNull(String name)
Set the value for the field with the given name to be a null value.
|
EditableDocument |
setNumber(String name,
double value)
Set the value for the field with the given name to the supplied double value.
|
EditableDocument |
setNumber(String name,
float value)
Set the value for the field with the given name to the supplied float value.
|
EditableDocument |
setNumber(String name,
int value)
Set the value for the field with the given name to the supplied integer value.
|
EditableDocument |
setNumber(String name,
long value)
Set the value for the field with the given name to the supplied long value.
|
EditableDocument |
setObjectId(String name,
byte[] bytes)
Set the value for the field with the given name to an
ObjectId created from the supplied 12-byte binary value. |
EditableDocument |
setObjectId(String name,
int time,
int machine,
int process,
int inc)
Set the value for the field with the given name to an
ObjectId created from the supplied hexadecimal binary value. |
EditableDocument |
setObjectId(String name,
String hex)
Set the value for the field with the given name to an
ObjectId created from the supplied hexadecimal binary value. |
EditableDocument |
setRegularExpression(String name,
String pattern)
Set the value for the field with the given name to the supplied regular expression.
|
EditableDocument |
setRegularExpression(String name,
String pattern,
int flags)
Set the value for the field with the given name to the supplied regular expression.
|
EditableDocument |
setString(String name,
String value)
Set the value for the field with the given name to the supplied string value.
|
EditableDocument |
setSymbol(String name,
String value)
Set the value for the field with the given name to a
Symbol created from the supplied string value. |
EditableDocument |
setTimestamp(String name,
int timeInSeconds,
int increment)
Set the value for the field with the given name to a
Timestamp with the supplied time in seconds and increment. |
EditableDocument |
setUuid(String name,
UUID uuid)
Set the value for the field with the given name to be a
UUID . |
int |
size()
Return the number of name-value pairs in this object.
|
Map<String,? extends Object> |
toMap()
Returns a map representing this BSONObject.
|
String |
toString() |
Document |
unwrap()
Unwrap this editor to obtain the potentially wrapped document.
|
DocumentEditor |
with(Document.ValueTransformer transformer)
Obtain a clone of this document, but with the field values transformed using the supplied
Document.ValueTransformer . |
DocumentEditor |
with(Map<String,Object> changedFields)
Obtain a clone of this document, but with the supplied fields replaced.
|
Document |
with(String fieldName,
Object value)
Obtain a clone of this document, but with the supplied fields replaced.
|
Document |
withVariablesReplaced(Properties properties)
Obtain a clone of this document, but with all variables in string field values replaced with the referenced values from the
supplied properties.
|
Document |
withVariablesReplacedWithSystemProperties()
Obtain a clone of this document, but with all variables in string field values replaced with the referenced values from the
System properties.
|
protected final DocumentValueFactory factory
public DocumentEditor(MutableDocument document)
document
- the document to be editedpublic DocumentEditor(MutableDocument document, DocumentValueFactory factory)
document
- the document to be editedfactory
- the factory that should be used to create value objectspublic DocumentEditor clone()
Document
public DocumentEditor with(Map<String,Object> changedFields)
Document
public Document with(String fieldName, Object value)
Document
public DocumentEditor with(Document.ValueTransformer transformer)
Document
Document.ValueTransformer
.public Document withVariablesReplaced(Properties properties)
Document
Variables may appear anywhere within a string value, and multiple variables can be used within the same value. Variables take the form:
variable := '${' variableNames [ ':' defaultValue ] '}' variableNames := variableName [ ',' variableNames ] variableName := /* any characters except ',' and ':' and '}' defaultValue := /* any characters exceptNote that variableName is the name used to look up the
Properties
property.
Notice that the syntax supports multiple variables. The logic will process the variables from let to right,
until an existing System property is found. And at that point, it will stop and will not attempt to find values for the
other variables.
withVariablesReplaced
in interface Document
properties
- the properties keyed by variable nameDocument.withVariablesReplacedWithSystemProperties()
,
Document.with(ValueTransformer)
,
SchemaLibrary.convertValues(Document, String)
public Document withVariablesReplacedWithSystemProperties()
Document
Variables may appear anywhere within a string value, and multiple variables can be used within the same value. Variables take the form:
variable := '${' variableNames [ ':' defaultValue ] '}' variableNames := variableName [ ',' variableNames ] variableName := /* any characters except ',' and ':' and '}' defaultValue := /* any characters exceptNote that variableName is the name used to look up a System property via
System.getProperty(String)
.
Notice that the syntax supports multiple variables. The logic will process the variables from let to right,
until an existing System property is found. And at that point, it will stop and will not attempt to find values for the
other variables.
Because only string values can contain variables, the resulting values are left as strings. This may not be valid according
to the document's JSON Schema, so see SchemaLibrary.convertValues(Document, String)
to convert the string values
after variable substitution into the expected non-string types.
withVariablesReplacedWithSystemProperties
in interface Document
Document.withVariablesReplaced(Properties)
,
Document.with(ValueTransformer)
,
SchemaLibrary.convertValues(Document, String)
public Document unwrap()
EditableDocument
unwrap
in interface EditableDocument
public MutableDocument asMutableDocument()
public Object get(String name)
Document
public Boolean getBoolean(String name)
Document
getBoolean
in interface Document
name
- The name of the pairpublic boolean getBoolean(String name, boolean defaultValue)
Document
getBoolean
in interface Document
name
- The name of the pairdefaultValue
- the default value to return if there is no such pair or if the value is not a booleandefaultValue
if there is no such pair or if the value is not a
booleanpublic void putAll(Document object)
EditableDocument
putAll
in interface EditableDocument
object
- the object containing the name/value pairs to be set on this objectpublic void putAll(Map<? extends String,? extends Object> map)
EditableDocument
putAll
in interface EditableDocument
map
- the map containing the name/value pairs to be set on this objectpublic void merge(Document other)
EditableDocument
Consider the following example. If this document contains:
{ "firstName" : "Jane", "lastName" : "Smith", "address" : { "street" : "Main Street", "city" : "Springfield" }, "phone" : "(800)555-1212" }and another document 'other' contains:
{ "lastName" : "Doe", "address" : { "city" : "Memphis", "zip" : 12345 }, "phone" : { "home" : "(800)555-1212" } }then merging 'other' onto the first will result in the first being modified to contain:
{ "firstName" : "Jane", "lastName" : "Doe", "address" : { "street" : "Main Street", "city" : "Memphis", "zip" : 12345 }, "phone" : { "home" : "(800)555-1212" } }
merge
in interface EditableDocument
other
- the other document whose values should be mergedpublic Object remove(String name)
EditableDocument
remove
in interface EditableDocument
name
- The name of the fieldpublic Integer getInteger(String name)
Document
getInteger
in interface Document
name
- The name of the pairpublic int getInteger(String name, int defaultValue)
Document
getInteger
in interface Document
name
- The name of the pairdefaultValue
- the default value to return if there is no such pair or if the value is not a integerdefaultValue
if there is no such pair or if the value is not a
integerpublic Long getLong(String name)
Document
public long getLong(String name, long defaultValue)
Document
getLong
in interface Document
name
- The name of the pairdefaultValue
- the default value to return if there is no such pair or if the value is not a long valuedefaultValue
if there is no such pair or if the value is not a long
valuepublic Double getDouble(String name)
Document
public double getDouble(String name, double defaultValue)
Document
public Number getNumber(String name)
Document
public Number getNumber(String name, Number defaultValue)
Document
public String getString(String name)
Document
Symbol
.public String getString(String name, String defaultValue)
Document
Symbol
.public EditableArray getArray(String name)
EditableDocument
getArray
in interface Document
getArray
in interface EditableDocument
name
- The name of the pairpublic EditableArray getOrCreateArray(String name)
EditableDocument
getOrCreateArray
in interface EditableDocument
name
- The name of the pairpublic EditableDocument getDocument(String name)
EditableDocument
getDocument
in interface Document
getDocument
in interface EditableDocument
name
- The name of the pairpublic EditableDocument getOrCreateDocument(String name)
EditableDocument
getOrCreateDocument
in interface EditableDocument
name
- The name of the pairpublic boolean isNull(String name)
Document
this.get(name) instanceof Null;
isNull
in interface Document
name
- The name of the pairtrue
if the field has been set to a Null
value, or false otherwiseDocument.isNullOrMissing(String)
public boolean isNullOrMissing(String name)
Document
Null.matches(this.get(name));
isNullOrMissing
in interface Document
name
- The name of the pairtrue
if the field value for the name is null or if there is no such field.Document.isNull(String)
public MaxKey getMaxKey(String name)
Document
MaxKey
value in this document for the given field name.public MinKey getMinKey(String name)
Document
MinKey
value in this document for the given field name.public Code getCode(String name)
Document
Code
value in this document for the given field name.public CodeWithScope getCodeWithScope(String name)
Document
CodeWithScope
value in this document for the given field name.getCodeWithScope
in interface Document
name
- The name of the pairCodeWithScope
field value, if found, or null if there is no such pair or if the value is not a
CodeWithScope
public ObjectId getObjectId(String name)
Document
ObjectId
value in this document for the given field name.getObjectId
in interface Document
name
- The name of the pairObjectId
field value, if found, or null if there is no such pair or if the value is not a
ObjectId
public Binary getBinary(String name)
Document
Binary
value in this document for the given field name.public Symbol getSymbol(String name)
Document
Symbol
value in this document for the given field name.public Pattern getPattern(String name)
Document
Pattern
value in this document for the given field name.getPattern
in interface Document
name
- The name of the pairPattern
field value, if found, or null if there is no such pair or if the value is not a
Pattern
public UUID getUuid(String name)
Document
UUID
value in this document for the given field name.public UUID getUuid(String name, UUID defaultValue)
Document
UUID
value in this document for the given field name.getUuid
in interface Document
name
- The name of the pairdefaultValue
- the default value to return if there is no such pair or if the value is not a stringUUID
field value if found, or defaultValue
if there is no such pair or if the value is not
a UUID (or a string that is convertable from a UUID)public int getType(String name)
Document
Bson.Type
constant that describes the type of value for the given field name.public Map<String,? extends Object> toMap()
Document
public Iterable<Document.Field> fields()
Document
Document.Field
s in this object.public boolean containsField(String name)
Document
containsField
in interface Document
name
- The name of the pair for which to checkpublic boolean containsAll(Document document)
Document
containsAll
in interface Document
document
- The document with the fields that should be in this documentpublic Set<String> keySet()
Document
public int size()
Document
public boolean isEmpty()
Document
public void removeAll()
EditableDocument
removeAll
in interface EditableDocument
public EditableDocument set(String name, Object value)
EditableDocument
set
in interface EditableDocument
name
- The name of the fieldvalue
- the new value for the fieldpublic EditableDocument setBoolean(String name, boolean value)
EditableDocument
setBoolean
in interface EditableDocument
name
- The name of the fieldvalue
- the new value for the fieldpublic EditableDocument setNumber(String name, int value)
EditableDocument
setNumber
in interface EditableDocument
name
- The name of the fieldvalue
- the new value for the fieldpublic EditableDocument setNumber(String name, long value)
EditableDocument
setNumber
in interface EditableDocument
name
- The name of the fieldvalue
- the new value for the fieldpublic EditableDocument setNumber(String name, float value)
EditableDocument
setNumber
in interface EditableDocument
name
- The name of the fieldvalue
- the new value for the fieldpublic EditableDocument setNumber(String name, double value)
EditableDocument
setNumber
in interface EditableDocument
name
- The name of the fieldvalue
- the new value for the fieldpublic EditableDocument setString(String name, String value)
EditableDocument
setString
in interface EditableDocument
name
- The name of the fieldvalue
- the new value for the fieldpublic EditableDocument setSymbol(String name, String value)
EditableDocument
Symbol
created from the supplied string value. Symbols are
defined in the BSON specification as being similar to a string but which exists for those languages that have a specific
symbol type. Symbols are serialized to JSON as a normal string.setSymbol
in interface EditableDocument
name
- The name of the fieldvalue
- the new value for the fieldEditableDocument.setString(String, String)
public EditableDocument setDocument(String name)
EditableDocument
setDocument
in interface EditableDocument
name
- The name of the fieldpublic EditableDocument setDocument(String name, Document document)
EditableDocument
setDocument
in interface EditableDocument
name
- The name of the fielddocument
- the documentdocument
.public EditableArray setArray(String name)
EditableDocument
setArray
in interface EditableDocument
name
- The name of the fieldpublic EditableArray setArray(String name, Array array)
EditableDocument
setArray
in interface EditableDocument
name
- The name of the fieldarray
- the arrayarray
.public EditableArray setArray(String name, Object... values)
EditableDocument
setArray
in interface EditableDocument
name
- The name of the fieldvalues
- the (valid) values for the arrayarray
.public EditableDocument setDate(String name, Date value)
EditableDocument
setDate
in interface EditableDocument
name
- The name of the fieldvalue
- the new value for the fieldpublic EditableDocument setDate(String name, String isoDate) throws ParseException
EditableDocument
yyyy-MM-ddTHH:mm:ss
" where "T
" is a literal
characteryyyy-MM-ddTHH:mm:ssZ
" where "T
" and "
Z
" are literal charactersyyyy-MM-ddTHH:mm:ssGMT+00:00
" where "
T
", and "GMT
" are literal characterssetDate
in interface EditableDocument
name
- The name of the fieldisoDate
- the new value for the fieldParseException
- if the supplied value could not be parsed into a valid datepublic EditableDocument setTimestamp(String name, int timeInSeconds, int increment)
EditableDocument
Timestamp
with the supplied time in seconds and increment.
Note that Date
values are recommended for most purposes, as they are better suited to most applications'
representations of time instants.setTimestamp
in interface EditableDocument
name
- The name of the fieldtimeInSeconds
- the time in seconds for the new Timestampincrement
- the time increment for the new TimestampEditableDocument.setDate(String, Date)
public EditableDocument setObjectId(String name, String hex)
EditableDocument
ObjectId
created from the supplied hexadecimal binary value.
Object IDs are defined by the BSON specification as 12-byte binary values designed to have a reasonably high probability of
being unique when allocated. Since there is no explicit way to represent these in a JSON document, each ObjectId value is
serialized in a JSON document as a nested document of the form:
{ "$oid" : "12bytesOfIdInBase16" }When nested documents of this form are read by this library's
JSON reader
, nested documents of this form will
be converted to an ObjectId value.
For example, an ObjectId with time value of "1310745823", machine value of "1", process value of "2", and increment value of "3" would be written as
{ "$oid" : "4e2064df0000010002000003" }
setObjectId
in interface EditableDocument
name
- The name of the fieldhex
- the hexadecimal binary value for the ObjectIdEditableDocument.setObjectId(String, byte[])
,
EditableDocument.setObjectId(String, int, int, int, int)
public EditableDocument setObjectId(String name, byte[] bytes)
EditableDocument
ObjectId
created from the supplied 12-byte binary value.
Object IDs are defined by the BSON specification as 12-byte binary values designed to have a reasonably high probability of
being unique when allocated. Since there is no explicit way to represent these in a JSON document, each ObjectId value is
serialized in a JSON document as a nested document of the form:
{ "$oid" : "12bytesOfIdInBase16" }When nested documents of this form are read by this library's
JSON reader
, nested documents of this form will
be converted to an ObjectId value.
For example, an ObjectId with time value of "1310745823", machine value of "1", process value of "2", and increment value of "3" would be written as
{ "$oid" : "4e2064df0000010002000003" }
setObjectId
in interface EditableDocument
name
- The name of the fieldbytes
- the 12-byte value for the ObjectIdEditableDocument.setObjectId(String, String)
,
EditableDocument.setObjectId(String, int, int, int, int)
public EditableDocument setObjectId(String name, int time, int machine, int process, int inc)
EditableDocument
ObjectId
created from the supplied hexadecimal binary value.
Object IDs are defined by the BSON specification as 12-byte binary values designed to have a reasonably high probability of
being unique when allocated. Since there is no explicit way to represent these in a JSON document, each ObjectId value is
serialized in a JSON document as a nested document of the form:
{ "$oid" : "12bytesOfIdInBase16" }When nested documents of this form are read by this library's
JSON reader
, nested documents of this form will
be converted to an ObjectId value.
For example, an ObjectId with time value of "1310745823", machine value of "1", process value of "2", and increment value of "3" would be written as
{ "$oid" : "4e2064df0000010002000003" }
setObjectId
in interface EditableDocument
name
- The name of the fieldtime
- the Unix-style timestamp, which is a signed integer representing the number of seconds before or after January
1st 1970 (UTC)machine
- the first three bytes of the (md5) hash of the machine host name, or of the mac/network address, or the
virtual machine idprocess
- the 2 bytes of the process id (or thread id) of the process generating the object idinc
- an ever incrementing value, or a random number if a counter can't be used in the language/runtimeEditableDocument.setObjectId(String, String)
,
EditableDocument.setObjectId(String, byte[])
public EditableDocument setRegularExpression(String name, String pattern)
EditableDocument
Pattern
instances, and are stored natively in BSON as regular expressions. However,
when serialized to JSON, regular expressions are written as nested documents of the form:
{ "$regex" : "pattern" }where "pattern" is the regular expression pattern.
When nested documents of this form are read by this library's JSON reader
, nested documents of this form will
be converted to a regular expression value.
setRegularExpression
in interface EditableDocument
name
- The name of the fieldpattern
- the regular expression pattern stringEditableDocument.setRegularExpression(String, String, int)
public EditableDocument setRegularExpression(String name, String pattern, int flags)
EditableDocument
Pattern
instances, and are stored natively in BSON as regular expressions. However,
when serialized to JSON, regular expressions are written as nested documents of the form:
{ "$regex" : "pattern", "$options" : "flags" }where "pattern" is the regular expression pattern, and "flags" is a string representation of the regular expression options.
When nested documents of this form are read by this library's JSON reader
, nested documents of this form will
be converted to a regular expression value.
setRegularExpression
in interface EditableDocument
name
- The name of the fieldpattern
- the regular expression pattern stringflags
- the bitwise-anded Pattern
options: Pattern.CANON_EQ
, Pattern.CASE_INSENSITIVE
,
Pattern.CASE_INSENSITIVE
, Pattern.COMMENTS
, Pattern.DOTALL
, Pattern.LITERAL
,
Pattern.MULTILINE
, Pattern.UNICODE_CASE
, and Pattern.UNIX_LINES
EditableDocument.setRegularExpression(String, String)
public EditableDocument setNull(String name)
EditableDocument
Null
is used for the value in the in-memory representation. The Document.isNull(String)
methods can be used to
determine if a field has been set to null, or Document.isNullOrMissing(String)
if the field has not be set or if it has
been set to null.setNull
in interface EditableDocument
name
- The name of the fieldDocument.isNull(String)
,
Document.isNullOrMissing(String)
public EditableDocument setBinary(String name, byte type, byte[] data)
EditableDocument
{ "$type" : typeAsInt, "$base64" : "bytesInBase64" }where "typeAsInt" is the integer representation of the
BSON type
, and "bytesInBase64" is
the Base64 encoding of the actual Binary bytes
.
When nested documents of this form are read by this library's JSON reader
, nested documents of this form will
be converted to Binary value.
setBinary
in interface EditableDocument
name
- The name of the fieldtype
- one of the BSON type
constants denoting the type of the Binary
valuedata
- the bytes for the Binary
valuepublic EditableDocument setUuid(String name, UUID uuid)
EditableDocument
UUID
. JSON does not formally support binary values, and so
such values will be encoded using a nested document of the form:
{ "$uuid" : "string-form-of-uuid" }where "string-form-of-uuid" is the UUID's
string representation
When nested documents of this form are read by this library's JSON reader
, nested documents of this form will
be converted to UUID value.
setUuid
in interface EditableDocument
name
- The name of the fielduuid
- the UUID valuepublic EditableDocument setCode(String name, String code, boolean includeScope)
EditableDocument
Code
or CodeWithScope
. JSON does not formally
support such values, and so when written to JSON they will be encoded using a nested document of the form:
{ "$code" : "code" }or, if there is a scope document
{ "$code" : "code", "$scope" : scope document }where "code" is the
Code
's JavaScript code
and scopeDocument is the nested
document representing the scope
in which the JavaScript code should be evaluated.
When nested documents of this form are read by this library's JSON reader
, nested documents of this form will
be converted to Code
or CodeWithScope
value.
Note that when includeScope
is true
, the returned EditableDocument
can be used to
populate the scope document.
setCode
in interface EditableDocument
name
- The name of the fieldcode
- the codeincludeScope
- true if the code should include a scope (and if this method should return an EditableDocument
for this scope document), or false otherwiseincludeScope
is true
, then the EditableDocument
for the scope; otherwise, this
document to allow for chaining methodsEditableDocument.setCode(String, String, Document)
public EditableDocument setCode(String name, String code, Document scope)
EditableDocument
Code
or CodeWithScope
. JSON does not formally
support such values, and so when written to JSON they will be encoded using a nested document of the form:
{ "$code" : "code" }or, if there is a scope document
{ "$code" : "code", "$scope" : scope document }where "code" is the
Code
's JavaScript code
and scopeDocument is the nested
document representing the scope
in which the JavaScript code should be evaluated.
When nested documents of this form are read by this library's JSON reader
, nested documents of this form will
be converted to Code
or CodeWithScope
value.
setCode
in interface EditableDocument
name
- The name of the fieldcode
- the codescope
- the scope in which the JavaScript code should be evaulated, or null if there is no scopeEditableDocument
for the scope, or null if the scope
reference is nullEditableDocument.setCode(String, String, boolean)
protected Object doSetValue(String name, Object value)
set...
methods. This method may be overridden by
subclasses when additional work needs to be performed during the set operations.name
- the name of the field being setvalue
- the new valueprotected Object doSetValueIfAbsent(String name, Object value)
set...
methods. This method may be overridden by
subclasses when additional work needs to be performed during the set operations.name
- the name of the field being setvalue
- the new valueprotected void doSetAllValues(Document values)
putAll(Document)
method. This method may be overridden by
subclasses when additional work needs to be performed during this operation.values
- the document containing the fields to be addedprotected void doSetAllValues(Map<? extends String,? extends Object> values)
putAll(Map)
method. This method may be overridden by
subclasses when additional work needs to be performed during this operation.values
- the map containing the fields to be addedprotected EditableDocument editable(Document doc, String fieldName)
protected EditableArray editable(List<?> array, String fieldName)
protected EditableDocument createEditableDocument(MutableDocument document, String fieldName, DocumentValueFactory factory)
protected EditableArray createEditableArray(MutableArray array, String fieldName, DocumentValueFactory factory)
Copyright © 2008-2014 JBoss, a division of Red Hat. All Rights Reserved.