com.mongodb
Class ReflectionDBObject

java.lang.Object
  extended by com.mongodb.ReflectionDBObject
All Implemented Interfaces:
DBObject, BSONObject

public abstract class ReflectionDBObject
extends Object
implements DBObject

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


Nested Class Summary
static class ReflectionDBObject.JavaWrapper
          Represents a wrapper around the DBObject to interface with the Class fields
 
Constructor Summary
ReflectionDBObject()
           
 
Method Summary
 boolean containsField(String s)
          Checks if this object contains a field with the given name.
 boolean containsKey(String s)
          Deprecated.  
 Object get_id()
          Gets the _id
 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
 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(BSONObject o)
          Sets all key/value pairs from an object into this object
 void putAll(Map m)
          Sets all key/value pairs from a map 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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ReflectionDBObject

public ReflectionDBObject()
Method Detail

get

public Object get(String key)
Description copied from interface: BSONObject
Gets a field from this object by a given name.

Specified by:
get in interface BSONObject
Parameters:
key - The name of the field fetch
Returns:
The field, if found

keySet

public Set<String> keySet()
Description copied from interface: BSONObject
Returns this object's fields' names

Specified by:
keySet in interface BSONObject
Returns:
The names of the fields in this object

containsKey

@Deprecated
public boolean containsKey(String s)
Deprecated. 

Description copied from interface: BSONObject
Deprecated

Specified by:
containsKey in interface BSONObject
Returns:
True if the key is present

containsField

public boolean containsField(String s)
Description copied from interface: BSONObject
Checks if this object contains a field with the given name.

Specified by:
containsField in interface BSONObject
Parameters:
s - Field name for which to check
Returns:
True if the field is present

put

public Object put(String key,
                  Object v)
Description copied from interface: BSONObject
Sets a name/value pair in this object.

Specified by:
put in interface BSONObject
Parameters:
key - Name to set
v - Corresponding value
Returns:
v

putAll

public void putAll(Map m)
Description copied from interface: BSONObject
Sets all key/value pairs from a map into this object

Specified by:
putAll in interface BSONObject
Parameters:
m - the map

putAll

public void putAll(BSONObject o)
Description copied from interface: BSONObject
Sets all key/value pairs from an object into this object

Specified by:
putAll in interface BSONObject
Parameters:
o - the object

get_id

public Object get_id()
Gets the _id

Returns:

set_id

public void set_id(Object id)
Sets the _id

Parameters:
id -

isPartialObject

public boolean isPartialObject()
Description copied from interface: DBObject
whether markAsPartialObject was ever called only matters if you are going to upsert and do not want to risk losing fields

Specified by:
isPartialObject in interface DBObject

toMap

public Map toMap()
Description copied from interface: BSONObject
Returns a map representing this BSONObject.

Specified by:
toMap in interface BSONObject
Returns:
the map

markAsPartialObject

public void markAsPartialObject()
ReflectionDBObjects can't be partial

Specified by:
markAsPartialObject in interface DBObject

removeField

public Object removeField(String key)
can't remove from a ReflectionDBObject

Specified by:
removeField in interface BSONObject
Parameters:
key -
Returns:

getWrapperIfReflectionObject

public static ReflectionDBObject.JavaWrapper getWrapperIfReflectionObject(Class c)
Returns the wrapper if this object can be assigned from this class

Parameters:
c -
Returns:

getWrapper

public static ReflectionDBObject.JavaWrapper getWrapper(Class c)
Returns an existing Wrapper instance associated with a class, or creates a new one.

Parameters:
c -
Returns: