public interface EditableDocument extends Document
Document.Field, Document.ValueTransformer
Modifier and Type | Method and Description |
---|---|
EditableArray |
getArray(String name)
Get the existing array 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.
|
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.
|
void |
merge(Document other)
Merges the supplied document onto this document.
|
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 . |
Document |
unwrap()
Unwrap this editor to obtain the potentially wrapped document.
|
clone, containsAll, containsField, fields, get, getBinary, getBoolean, getBoolean, getCode, getCodeWithScope, getDouble, getDouble, getInteger, getInteger, getLong, getLong, getMaxKey, getMinKey, getNumber, getNumber, getObjectId, getPattern, getString, getString, getSymbol, getType, getUuid, getUuid, isEmpty, isNull, isNullOrMissing, keySet, size, toMap, with, with, with, withVariablesReplaced, withVariablesReplacedWithSystemProperties
Document unwrap()
Object remove(String name)
name
- The name of the fieldvoid removeAll()
void putAll(Document object)
object
- the object containing the name/value pairs to be set on this objectvoid putAll(Map<? extends String,? extends Object> map)
map
- the map containing the name/value pairs to be set on this objectvoid merge(Document other)
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" } }
other
- the other document whose values should be mergedEditableDocument set(String name, Object value)
name
- The name of the fieldvalue
- the new value for the fieldEditableDocument setBoolean(String name, boolean value)
name
- The name of the fieldvalue
- the new value for the fieldEditableDocument setNumber(String name, int value)
name
- The name of the fieldvalue
- the new value for the fieldEditableDocument setNumber(String name, long value)
name
- The name of the fieldvalue
- the new value for the fieldEditableDocument setNumber(String name, float value)
name
- The name of the fieldvalue
- the new value for the fieldEditableDocument setNumber(String name, double value)
name
- The name of the fieldvalue
- the new value for the fieldEditableDocument setString(String name, String value)
name
- The name of the fieldvalue
- the new value for the fieldEditableDocument setSymbol(String name, String value)
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.name
- The name of the fieldvalue
- the new value for the fieldsetString(String, String)
EditableDocument setDocument(String name)
name
- The name of the fieldEditableDocument setDocument(String name, Document document)
name
- The name of the fielddocument
- the documentdocument
.EditableDocument getDocument(String name)
getDocument
in interface Document
name
- The name of the pairEditableDocument getOrCreateDocument(String name)
name
- The name of the pairEditableArray setArray(String name)
name
- The name of the fieldEditableArray setArray(String name, Array array)
name
- The name of the fieldarray
- the arrayarray
.EditableArray setArray(String name, Object... values)
name
- The name of the fieldvalues
- the (valid) values for the arrayarray
.EditableArray getArray(String name)
EditableArray getOrCreateArray(String name)
name
- The name of the pairEditableDocument setDate(String name, Date value)
name
- The name of the fieldvalue
- the new value for the fieldEditableDocument setDate(String name, String isoDate) throws ParseException
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 charactersname
- The name of the fieldisoDate
- the new value for the fieldParseException
- if the supplied value could not be parsed into a valid dateEditableDocument setTimestamp(String name, int timeInSeconds, int increment)
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.name
- The name of the fieldtimeInSeconds
- the time in seconds for the new Timestampincrement
- the time increment for the new TimestampsetDate(String, Date)
EditableDocument setObjectId(String name, String hex)
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" }
name
- The name of the fieldhex
- the hexadecimal binary value for the ObjectIdsetObjectId(String, byte[])
,
setObjectId(String, int, int, int, int)
EditableDocument setObjectId(String name, byte[] bytes)
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" }
name
- The name of the fieldbytes
- the 12-byte value for the ObjectIdsetObjectId(String, String)
,
setObjectId(String, int, int, int, int)
EditableDocument setObjectId(String name, int time, int machine, int process, int inc)
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" }
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/runtimesetObjectId(String, String)
,
setObjectId(String, byte[])
EditableDocument setRegularExpression(String name, String pattern)
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.
name
- The name of the fieldpattern
- the regular expression pattern stringsetRegularExpression(String, String, int)
EditableDocument setRegularExpression(String name, String pattern, int flags)
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.
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
setRegularExpression(String, String)
EditableDocument setNull(String name)
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.name
- The name of the fieldDocument.isNull(String)
,
Document.isNullOrMissing(String)
EditableDocument setBinary(String name, byte type, byte[] data)
{ "$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.
EditableDocument setUuid(String name, UUID uuid)
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.
name
- The name of the fielduuid
- the UUID valueEditableDocument setCode(String name, String code, boolean includeScope)
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.
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 methodssetCode(String, String, Document)
EditableDocument setCode(String name, String code, Document scope)
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.
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 nullsetCode(String, String, boolean)
Copyright © 2008-2014 JBoss, a division of Red Hat. All Rights Reserved.