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.Fields 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()
Documentpublic DocumentEditor with(Map<String,Object> changedFields)
Documentpublic Document with(String fieldName, Object value)
Documentpublic DocumentEditor with(Document.ValueTransformer transformer)
DocumentDocument.ValueTransformer.public Document withVariablesReplaced(Properties properties)
DocumentVariables 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 except
Note 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 Documentproperties - the properties keyed by variable nameDocument.withVariablesReplacedWithSystemProperties(),
Document.with(ValueTransformer),
SchemaLibrary.convertValues(Document, String)public Document withVariablesReplacedWithSystemProperties()
DocumentVariables 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 except
Note 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 DocumentDocument.withVariablesReplaced(Properties),
Document.with(ValueTransformer),
SchemaLibrary.convertValues(Document, String)public Document unwrap()
EditableDocumentunwrap in interface EditableDocumentpublic MutableDocument asMutableDocument()
public Object get(String name)
Documentpublic Boolean getBoolean(String name)
DocumentgetBoolean in interface Documentname - The name of the pairpublic boolean getBoolean(String name, boolean defaultValue)
DocumentgetBoolean in interface Documentname - 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)
EditableDocumentputAll in interface EditableDocumentobject - the object containing the name/value pairs to be set on this objectpublic void putAll(Map<? extends String,? extends Object> map)
EditableDocumentputAll in interface EditableDocumentmap - the map containing the name/value pairs to be set on this objectpublic void merge(Document other)
EditableDocumentConsider 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 EditableDocumentother - the other document whose values should be mergedpublic Object remove(String name)
EditableDocumentremove in interface EditableDocumentname - The name of the fieldpublic Integer getInteger(String name)
DocumentgetInteger in interface Documentname - The name of the pairpublic int getInteger(String name, int defaultValue)
DocumentgetInteger in interface Documentname - 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)
Documentpublic long getLong(String name, long defaultValue)
DocumentgetLong in interface Documentname - 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)
Documentpublic double getDouble(String name, double defaultValue)
Documentpublic Number getNumber(String name)
Documentpublic Number getNumber(String name, Number defaultValue)
Documentpublic String getString(String name)
DocumentSymbol.public String getString(String name, String defaultValue)
DocumentSymbol.public EditableArray getArray(String name)
EditableDocumentgetArray in interface DocumentgetArray in interface EditableDocumentname - The name of the pairpublic EditableArray getOrCreateArray(String name)
EditableDocumentgetOrCreateArray in interface EditableDocumentname - The name of the pairpublic EditableDocument getDocument(String name)
EditableDocumentgetDocument in interface DocumentgetDocument in interface EditableDocumentname - The name of the pairpublic EditableDocument getOrCreateDocument(String name)
EditableDocumentgetOrCreateDocument in interface EditableDocumentname - The name of the pairpublic boolean isNull(String name)
Documentthis.get(name) instanceof Null;
isNull in interface Documentname - 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)
DocumentNull.matches(this.get(name));
isNullOrMissing in interface Documentname - 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)
DocumentMaxKey value in this document for the given field name.public MinKey getMinKey(String name)
DocumentMinKey value in this document for the given field name.public Code getCode(String name)
DocumentCode value in this document for the given field name.public CodeWithScope getCodeWithScope(String name)
DocumentCodeWithScope value in this document for the given field name.getCodeWithScope in interface Documentname - The name of the pairCodeWithScope field value, if found, or null if there is no such pair or if the value is not a
CodeWithScopepublic ObjectId getObjectId(String name)
DocumentObjectId value in this document for the given field name.getObjectId in interface Documentname - The name of the pairObjectId field value, if found, or null if there is no such pair or if the value is not a
ObjectIdpublic Binary getBinary(String name)
DocumentBinary value in this document for the given field name.public Symbol getSymbol(String name)
DocumentSymbol value in this document for the given field name.public Pattern getPattern(String name)
DocumentPattern value in this document for the given field name.getPattern in interface Documentname - The name of the pairPattern field value, if found, or null if there is no such pair or if the value is not a
Patternpublic UUID getUuid(String name)
DocumentUUID value in this document for the given field name.public UUID getUuid(String name, UUID defaultValue)
DocumentUUID value in this document for the given field name.getUuid in interface Documentname - 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)
DocumentBson.Type constant that describes the type of value for the given field name.public Map<String,? extends Object> toMap()
Documentpublic Iterable<Document.Field> fields()
DocumentDocument.Fields in this object.public boolean containsField(String name)
DocumentcontainsField in interface Documentname - The name of the pair for which to checkpublic boolean containsAll(Document document)
DocumentcontainsAll in interface Documentdocument - The document with the fields that should be in this documentpublic Set<String> keySet()
Documentpublic int size()
Documentpublic boolean isEmpty()
Documentpublic void removeAll()
EditableDocumentremoveAll in interface EditableDocumentpublic EditableDocument set(String name, Object value)
EditableDocumentset in interface EditableDocumentname - The name of the fieldvalue - the new value for the fieldpublic EditableDocument setBoolean(String name, boolean value)
EditableDocumentsetBoolean in interface EditableDocumentname - The name of the fieldvalue - the new value for the fieldpublic EditableDocument setNumber(String name, int value)
EditableDocumentsetNumber in interface EditableDocumentname - The name of the fieldvalue - the new value for the fieldpublic EditableDocument setNumber(String name, long value)
EditableDocumentsetNumber in interface EditableDocumentname - The name of the fieldvalue - the new value for the fieldpublic EditableDocument setNumber(String name, float value)
EditableDocumentsetNumber in interface EditableDocumentname - The name of the fieldvalue - the new value for the fieldpublic EditableDocument setNumber(String name, double value)
EditableDocumentsetNumber in interface EditableDocumentname - The name of the fieldvalue - the new value for the fieldpublic EditableDocument setString(String name, String value)
EditableDocumentsetString in interface EditableDocumentname - The name of the fieldvalue - the new value for the fieldpublic EditableDocument setSymbol(String name, String value)
EditableDocumentSymbol 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 EditableDocumentname - The name of the fieldvalue - the new value for the fieldEditableDocument.setString(String, String)public EditableDocument setDocument(String name)
EditableDocumentsetDocument in interface EditableDocumentname - The name of the fieldpublic EditableDocument setDocument(String name, Document document)
EditableDocumentsetDocument in interface EditableDocumentname - The name of the fielddocument - the documentdocument.public EditableArray setArray(String name)
EditableDocumentsetArray in interface EditableDocumentname - The name of the fieldpublic EditableArray setArray(String name, Array array)
EditableDocumentsetArray in interface EditableDocumentname - The name of the fieldarray - the arrayarray.public EditableArray setArray(String name, Object... values)
EditableDocumentsetArray in interface EditableDocumentname - The name of the fieldvalues - the (valid) values for the arrayarray.public EditableDocument setDate(String name, Date value)
EditableDocumentsetDate in interface EditableDocumentname - The name of the fieldvalue - the new value for the fieldpublic EditableDocument setDate(String name, String isoDate) throws ParseException
EditableDocumentyyyy-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 EditableDocumentname - 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)
EditableDocumentTimestamp 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 EditableDocumentname - 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)
EditableDocumentObjectId 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 EditableDocumentname - 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)
EditableDocumentObjectId 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 EditableDocumentname - 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)
EditableDocumentObjectId 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 EditableDocumentname - 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)
EditableDocumentPattern 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 EditableDocumentname - The name of the fieldpattern - the regular expression pattern stringEditableDocument.setRegularExpression(String, String, int)public EditableDocument setRegularExpression(String name, String pattern, int flags)
EditableDocumentPattern 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 EditableDocumentname - 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_LINESEditableDocument.setRegularExpression(String, String)public EditableDocument setNull(String name)
EditableDocumentNull 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 EditableDocumentname - 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 EditableDocumentname - 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)
EditableDocumentUUID. 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 EditableDocumentname - The name of the fielduuid - the UUID valuepublic EditableDocument setCode(String name, String code, boolean includeScope)
EditableDocumentCode 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 EditableDocumentname - 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)
EditableDocumentCode 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 EditableDocumentname - 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.