Package ai.platon.gora.mongodb.utils
Class BSONDecorator
java.lang.Object
ai.platon.gora.mongodb.utils.BSONDecorator
Utility class to build
Document used by MongoDB in an easy way by
directly specifying the fully qualified names of fields.- Author:
- Fabien Poulard fpoulard@dictanova.com
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionorg.bson.DocumentAccess the decoratedDocument.booleancontainsField(String fieldName) Check if the field passed in parameter exists or not.Access field as an object, no casting.getBoolean(String fieldName) Access field as a boolean.Access field as bytes.Access field as a date.List<org.bson.Document>Access field as a collection ofDocument.org.bson.DocumentgetDBObject(String fieldName) Access field as aDocument.Access field as a double.Access field as a int.Access field as a long.org.apache.avro.util.Utf8getUtf8String(String fieldName) Access field as a Utf8 string.voidSet field.
-
Constructor Details
-
BSONDecorator
public BSONDecorator(org.bson.Document obj)
-
-
Method Details
-
asDocument
public org.bson.Document asDocument()Access the decoratedDocument.- Returns:
- the decorated
Documentin its actual state
-
containsField
Check if the field passed in parameter exists or not. The field is passed as a fully qualified name that is the path to the field from the root of the document (for example: "field1" or "parent.child.field2").- Parameters:
fieldName- fully qualified name of the field- Returns:
- true if the field and all its parents exists in the decorated
Document, false otherwise
-
getDBObject
Access field as aDocument.- Parameters:
fieldName- fully qualified name of the field to be accessed- Returns:
- value of the field as a
Document
-
getDBList
Access field as a collection ofDocument.- Parameters:
fieldName- fully qualified name of the field to be accessed- Returns:
- value of the field as a collection of
Document
-
getBoolean
Access field as a boolean.- Parameters:
fieldName- fully qualified name of the field to be accessed- Returns:
- value of the field as a boolean
-
getDouble
Access field as a double.- Parameters:
fieldName- fully qualified name of the field to be accessed- Returns:
- value of the field as a double
-
getInt
Access field as a int.- Parameters:
fieldName- fully qualified name of the field to be accessed- Returns:
- value of the field as a double
-
getLong
Access field as a long.- Parameters:
fieldName- fully qualified name of the field to be accessed- Returns:
- value of the field as a double
-
getDate
Access field as a date.- Parameters:
fieldName- fully qualified name of the field to be accessed- Returns:
- value of the field as a date
-
getUtf8String
Access field as a Utf8 string.- Parameters:
fieldName- fully qualified name of the field to be accessed- Returns:
- value of the field as a
Utf8string
-
getBytes
Access field as bytes.- Parameters:
fieldName- fully qualified name of the field to be accessed- Returns:
- value of the field
-
get
Access field as an object, no casting.- Parameters:
fieldName- fully qualified name of the field to be accessed- Returns:
- value of the field
-
put
Set field. Create the intermediate levels if necessary asDocumentfields.- Parameters:
fieldName- fully qualified name of the field to be accessedvalue- value of the field
-