Interface Document
Nitrite document are composed of key-value pairs. A key is always a String and value
can be anything including null.
Nitrite document supports nested documents as well. The key of a nested document is a String
separated by NitriteConfig.getFieldSeparator(). By default, Nitrite uses `.` as field separator.
This can be changed by setting NitriteConfig.fieldSeparator(String).
For example, if a document has a nested document
{ "a" : { "b" : 1 } }, then the value of inside the nested document can be retrieved by
calling get(String) with key a.b.
Below fields are reserved and cannot be used as key in a document.
- _id: The unique identifier of the document. If not provided,
Nitrite will generate a unique
NitriteIdfor the document during insertion. - _revision: The revision number of the document.
- _source: The source of the document.
- _modified: The last modified time of the document in milliseconds since epoch.
- Since:
- 1.0
- Author:
- Anindya Chatterjee
-
Method Summary
Modifier and TypeMethodDescriptionclone()Creates and returns a copy of this document.booleancontainsField(String field) Checks if a top level field or embedded field exists in the document.booleancontainsKey(String key) Checks if a top level key exists in the document.static DocumentCreates an empty document.static DocumentcreateDocument(String key, Object value) Creates a new document initialized with the given key/value pair.static DocumentcreateDocument(Map<String, Object> documentMap) Creates a new document initialized with the given map.Returns the value to which the specified key is associated with, or null if this document contains no mapping for the key.<T> TReturns the value of type<T>to which the specified key is associated, or null if this document contains no mapping for the key.Retrieves all fields (top level and embedded) associated with this document.getId()Return the nitrite id associated with this document.default LongGets last modified time of this document since epoch.default IntegerGets the document revision number.default StringGets the source of this document.booleanhasId()Checks if this document has a nitrite id.Merges a document in this document.Associates the specified value with the specified key in this document.voidRemoves the key and its value from the document.intsize()Returns the number of entries in the document.Methods inherited from interface java.lang.Iterable
forEach, iterator, spliterator
-
Method Details
-
createDocument
Creates an empty document.- Returns:
- the document
-
createDocument
Creates a new document initialized with the given key/value pair.- Parameters:
key- the keyvalue- the value- Returns:
- the document
-
createDocument
Creates a new document initialized with the given map.- Parameters:
documentMap- the map- Returns:
- the document
-
put
Associates the specified value with the specified key in this document.NOTE: An embedded field is also supported.
- Parameters:
key- the keyvalue- the value- Returns:
- the document
-
get
Returns the value to which the specified key is associated with, or null if this document contains no mapping for the key.- Parameters:
key- the key- Returns:
- the object
-
get
Returns the value of type<T>to which the specified key is associated, or null if this document contains no mapping for the key.NOTE: This method may not work for fields containing primitive types. Use
get(String)instead.- Type Parameters:
T- the type parameter- Parameters:
key- the keytype- the type- Returns:
- the value
-
getId
NitriteId getId()Return the nitrite id associated with this document.- Returns:
- the nitrite id
-
getFields
Retrieves all fields (top level and embedded) associated with this document.- Returns:
- the fields
-
hasId
boolean hasId()Checks if this document has a nitrite id.- Returns:
- the boolean
-
remove
Removes the key and its value from the document.- Parameters:
key- the key
-
clone
Document clone()Creates and returns a copy of this document.- Returns:
- document
-
size
int size()Returns the number of entries in the document.- Returns:
- the int
-
merge
Merges a document in this document.- Parameters:
update- the update- Returns:
- the document
-
containsKey
Checks if a top level key exists in the document.- Parameters:
key- the key- Returns:
- the boolean
-
containsField
Checks if a top level field or embedded field exists in the document.- Parameters:
field- the field- Returns:
- the boolean
-
getRevision
Gets the document revision number.- Returns:
- the revision
-
getSource
Gets the source of this document.- Returns:
- the source
-
getLastModifiedSinceEpoch
Gets last modified time of this document since epoch.- Returns:
- the last modified since epoch
-