public abstract class

ReflectionDBObject

extends Object
implements DBObject
java.lang.Object
   ↳ com.mongodb.ReflectionDBObject

Class Overview

This class enables to map simple Class fields to a BSON object fields

Summary

Nested Classes
class ReflectionDBObject.JavaWrapper Represents a wrapper around the DBObject to interface with the Class fields  
Public Constructors
ReflectionDBObject()
Public Methods
boolean containsField(String s)
Checks if this object contains a field with the given name.
boolean containsKey(String s)
This method is deprecated. No replacement.
Object get(String key)
Gets a field from this object by a given name.
static ReflectionDBObject.JavaWrapper getWrapper(Class c)
Returns an existing Wrapper instance associated with a class, or creates a new one.
static ReflectionDBObject.JavaWrapper getWrapperIfReflectionObject(Class c)
Returns the wrapper if this object can be assigned from this class
Object get_id()
Gets the _id
boolean isPartialObject()
whether markAsPartialObject was ever called only matters if you are going to upsert and do not want to risk losing fields
Set<String> keySet()
Returns this object's fields' names
void markAsPartialObject()
ReflectionDBObjects can't be partial
Object put(String key, Object v)
Sets a name/value pair in this object.
void putAll(Map m)
Sets all key/value pairs from a map into this object
void putAll(BSONObject o)
Sets all key/value pairs from an object into this object
Object removeField(String key)
can't remove from a ReflectionDBObject
void set_id(Object id)
Sets the _id
Map toMap()
Returns a map representing this BSONObject.
[Expand]
Inherited Methods
From class java.lang.Object
From interface com.mongodb.DBObject
From interface org.bson.BSONObject

Public Constructors

public ReflectionDBObject ()

Public Methods

public boolean containsField (String s)

Checks if this object contains a field with the given name.

Parameters
s Field name for which to check
Returns
  • True if the field is present

public boolean containsKey (String s)

This method is deprecated.
No replacement.

Deprecated

Returns
  • True if the key is present

public Object get (String key)

Gets a field from this object by a given name.

Parameters
key The name of the field fetch
Returns
  • The field, if found

public static ReflectionDBObject.JavaWrapper getWrapper (Class c)

Returns an existing Wrapper instance associated with a class, or creates a new one.

public static ReflectionDBObject.JavaWrapper getWrapperIfReflectionObject (Class c)

Returns the wrapper if this object can be assigned from this class

public Object get_id ()

Gets the _id

public boolean isPartialObject ()

whether markAsPartialObject was ever called only matters if you are going to upsert and do not want to risk losing fields

public Set<String> keySet ()

Returns this object's fields' names

Returns
  • The names of the fields in this object

public void markAsPartialObject ()

ReflectionDBObjects can't be partial

public Object put (String key, Object v)

Sets a name/value pair in this object.

Parameters
key Name to set
v Corresponding value
Returns
  • v

public void putAll (Map m)

Sets all key/value pairs from a map into this object

Parameters
m the map

public void putAll (BSONObject o)

Sets all key/value pairs from an object into this object

Parameters
o the object

public Object removeField (String key)

can't remove from a ReflectionDBObject

Parameters
key The name of the field to remove
Returns
  • The value removed from this object

public void set_id (Object id)

Sets the _id

public Map toMap ()

Returns a map representing this BSONObject.

Returns
  • the map