Class BSONDecorator

java.lang.Object
ai.platon.gora.mongodb.utils.BSONDecorator

public class BSONDecorator extends Object
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 Details

    • BSONDecorator

      public BSONDecorator(org.bson.Document obj)
  • Method Details

    • asDocument

      public org.bson.Document asDocument()
      Access the decorated Document.
      Returns:
      the decorated Document in its actual state
    • containsField

      public boolean containsField(String fieldName)
      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

      public org.bson.Document getDBObject(String fieldName)
      Access field as a Document.
      Parameters:
      fieldName - fully qualified name of the field to be accessed
      Returns:
      value of the field as a Document
    • getDBList

      public List<org.bson.Document> getDBList(String fieldName)
      Access field as a collection of Document.
      Parameters:
      fieldName - fully qualified name of the field to be accessed
      Returns:
      value of the field as a collection of Document
    • getBoolean

      public Boolean getBoolean(String fieldName)
      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

      public Double getDouble(String fieldName)
      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

      public Integer getInt(String fieldName)
      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

      public Long getLong(String fieldName)
      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

      public Date getDate(String fieldName)
      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

      public org.apache.avro.util.Utf8 getUtf8String(String fieldName)
      Access field as a Utf8 string.
      Parameters:
      fieldName - fully qualified name of the field to be accessed
      Returns:
      value of the field as a Utf8 string
    • getBytes

      public ByteBuffer getBytes(String fieldName)
      Access field as bytes.
      Parameters:
      fieldName - fully qualified name of the field to be accessed
      Returns:
      value of the field
    • get

      public Object get(String fieldName)
      Access field as an object, no casting.
      Parameters:
      fieldName - fully qualified name of the field to be accessed
      Returns:
      value of the field
    • put

      public void put(String fieldName, Object value)
      Set field. Create the intermediate levels if necessary as Document fields.
      Parameters:
      fieldName - fully qualified name of the field to be accessed
      value - value of the field