Package com.mongodb
Class ReflectionDBObject
- java.lang.Object
-
- com.mongodb.ReflectionDBObject
-
- All Implemented Interfaces:
DBObject,BSONObject
public abstract class ReflectionDBObject extends java.lang.Object implements DBObject
This class enables to map simple Class fields to a BSON object fields
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classReflectionDBObject.JavaWrapperRepresents a wrapper around the DBObject to interface with the Class fields
-
Constructor Summary
Constructors Constructor Description ReflectionDBObject()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description booleancontainsField(java.lang.String fieldName)Checks if this object contains a field with the given name.booleancontainsKey(java.lang.String key)Deprecated.java.lang.Objectget(java.lang.String key)Gets a field from this object by a given name.java.lang.Objectget_id()Gets the _idstatic ReflectionDBObject.JavaWrappergetWrapper(java.lang.Class c)Returns an existing Wrapper instance associated with a class, or creates a new one.static ReflectionDBObject.JavaWrappergetWrapperIfReflectionObject(java.lang.Class c)Returns the wrapper if this object can be assigned from this class.booleanisPartialObject()WhetherDBObject.markAsPartialObject()was ever called only matters if you are going to upsert and do not want to risk losing fields.java.util.Set<java.lang.String>keySet()Returns this object's fields' namesvoidmarkAsPartialObject()ReflectionDBObjects can't be partial.java.lang.Objectput(java.lang.String key, java.lang.Object v)Sets a name/value pair in this object.voidputAll(java.util.Map m)Sets all key/value pairs from a map into this objectvoidputAll(BSONObject o)Sets all key/value pairs from an object into this objectjava.lang.ObjectremoveField(java.lang.String key)This operation is not supported.voidset_id(java.lang.Object id)Sets the _idjava.util.MaptoMap()Returns a map representing this BSONObject.
-
-
-
Method Detail
-
get
@Nullable public java.lang.Object get(java.lang.String key)
Description copied from interface:BSONObjectGets a field from this object by a given name.- Specified by:
getin interfaceBSONObject- Parameters:
key- The name of the field fetch- Returns:
- The field, if found
-
keySet
public java.util.Set<java.lang.String> keySet()
Description copied from interface:BSONObjectReturns this object's fields' names- Specified by:
keySetin interfaceBSONObject- Returns:
- The names of the fields in this object
-
containsKey
@Deprecated public boolean containsKey(java.lang.String key)
Deprecated.Description copied from interface:BSONObjectDeprecated- Specified by:
containsKeyin interfaceBSONObject- Parameters:
key- the key to check- Returns:
- True if the key is present
-
containsField
public boolean containsField(java.lang.String fieldName)
Description copied from interface:BSONObjectChecks if this object contains a field with the given name.- Specified by:
containsFieldin interfaceBSONObject- Parameters:
fieldName- Field name for which to check- Returns:
- True if the field is present
-
put
public java.lang.Object put(java.lang.String key, java.lang.Object v)Description copied from interface:BSONObjectSets a name/value pair in this object.- Specified by:
putin interfaceBSONObject- Parameters:
key- Name to setv- Corresponding value- Returns:
- the previous value associated with key, or null if there was no mapping for key. (A null return can also indicate that the map previously associated null with key.)
-
putAll
public void putAll(java.util.Map m)
Description copied from interface:BSONObjectSets all key/value pairs from a map into this object- Specified by:
putAllin interfaceBSONObject- Parameters:
m- the map
-
putAll
public void putAll(BSONObject o)
Description copied from interface:BSONObjectSets all key/value pairs from an object into this object- Specified by:
putAllin interfaceBSONObject- Parameters:
o- the object
-
get_id
public java.lang.Object get_id()
Gets the _id- Returns:
- the _id of this document
-
set_id
public void set_id(java.lang.Object id)
Sets the _id- Parameters:
id- the unique identifier for this DBObject
-
isPartialObject
public boolean isPartialObject()
Description copied from interface:DBObjectWhetherDBObject.markAsPartialObject()was ever called only matters if you are going to upsert and do not want to risk losing fields.- Specified by:
isPartialObjectin interfaceDBObject- Returns:
- true if this has been marked as a partial object
-
toMap
public java.util.Map toMap()
Description copied from interface:BSONObjectReturns a map representing this BSONObject.- Specified by:
toMapin interfaceBSONObject- Returns:
- the map
-
markAsPartialObject
public void markAsPartialObject()
ReflectionDBObjects can't be partial. This operation is not supported.- Specified by:
markAsPartialObjectin interfaceDBObject- Throws:
java.lang.RuntimeException- ReflectionDBObjects can't be partial
-
removeField
public java.lang.Object removeField(java.lang.String key)
This operation is not supported.- Specified by:
removeFieldin interfaceBSONObject- Parameters:
key- The name of the field to remove- Returns:
- The value removed from this object
- Throws:
java.lang.UnsupportedOperationException- can't remove from a ReflectionDBObject
-
getWrapperIfReflectionObject
@Nullable public static ReflectionDBObject.JavaWrapper getWrapperIfReflectionObject(java.lang.Class c)
Returns the wrapper if this object can be assigned from this class.- Parameters:
c- the class to be wrapped- Returns:
- the wrapper
-
getWrapper
public static ReflectionDBObject.JavaWrapper getWrapper(java.lang.Class c)
Returns an existing Wrapper instance associated with a class, or creates a new one.- Parameters:
c- the class to be wrapped- Returns:
- the wrapped
-
-