public class Mapper extends Object
This is the heart of Morphia and takes care of mapping from/to POJOs/DBObjects
This class is thread-safe and keeps various "cached" data which should speed up processing.
Modifier and Type | Field and Description |
---|---|
static String |
CLASS_NAME_FIELDNAME
Special field used by morphia to support various possibly loading issues; will be replaced when discriminators are implemented to
support polymorphism
|
static String |
ID_KEY
The @
Id field name that is stored with mongodb. |
static String |
IGNORED_FIELDNAME
Special name that can never be used.
|
Constructor and Description |
---|
Mapper() |
Mapper(MapperOptions opts) |
Modifier and Type | Method and Description |
---|---|
void |
addInterceptor(EntityInterceptor ei)
Adds an
EntityInterceptor |
MappedClass |
addMappedClass(Class c)
Creates a MappedClass and validates it.
|
MappedClass |
addMappedClass(MappedClass mc)
Validates MappedClass and adds to internal cache.
|
EntityCache |
createEntityCache() |
Object |
fromDBObject(Class entityClass,
com.mongodb.DBObject dbObject,
EntityCache cache)
Converts a DBObject back to a type-safe java object (POJO)
|
Class<?> |
getClassFromKind(String kind) |
String |
getCollectionName(Object object) |
DefaultConverters |
getConverters() |
Object |
getId(Object entity) |
Collection<EntityInterceptor> |
getInterceptors()
Gets list of
EntityInterceptor s |
<T> Key<T> |
getKey(T entity) |
MappedClass |
getMappedClass(Object obj)
Gets the
MappedClass for the object (type). |
Collection<MappedClass> |
getMappedClasses()
Returns collection of MappedClasses
|
Map<String,MappedClass> |
getMCMap()
Returns map of MappedClasses by class name
|
MapperOptions |
getOptions() |
static boolean |
isCompatibleForOperator(Class<?> type,
FilterOperator op,
Object value) |
boolean |
isMapped(Class c) |
com.mongodb.DBRef |
keyToRef(Key key) |
<T> Key<T> |
refToKey(com.mongodb.DBRef ref) |
void |
setOptions(MapperOptions options) |
com.mongodb.DBObject |
toDBObject(Object entity)
Converts an entity (POJO) to a DBObject; A special field will be added to keep track of the class:
CLASS_NAME_FIELDNAME |
com.mongodb.DBObject |
toDBObject(Object entity,
Map<Object,com.mongodb.DBObject> involvedObjects)
Converts an entity (POJO) to a DBObject (for use with low-level driver); A special field will be added to keep track of the class:
CLASS_NAME_FIELDNAME |
Object |
toMongoObject(MappedField mf,
MappedClass mc,
Object value)
Converts a java object to a mongo-compatible object (possibly a DBObject for complex mappings).
|
void |
updateKeyInfo(Object entity,
com.mongodb.DBObject dbObj,
EntityCache cache)
Updates the @
Id fields. |
String |
updateKind(Key key) |
static MappedField |
validate(Class clazz,
Mapper mapper,
StringBuffer origProp,
FilterOperator op,
Object val,
boolean validateNames,
boolean validateTypes)
Validate the path, and value type, returning the mapped field for the field at the path
|
public static final String ID_KEY
Id
field name that is stored with mongodb.public static final String IGNORED_FIELDNAME
public static final String CLASS_NAME_FIELDNAME
public Mapper()
public Mapper(MapperOptions opts)
public void addInterceptor(EntityInterceptor ei)
Adds an EntityInterceptor
public Collection<EntityInterceptor> getInterceptors()
Gets list of EntityInterceptor
s
public MapperOptions getOptions()
public void setOptions(MapperOptions options)
public boolean isMapped(Class c)
public MappedClass addMappedClass(Class c)
public MappedClass addMappedClass(MappedClass mc)
public Collection<MappedClass> getMappedClasses()
public Map<String,MappedClass> getMCMap()
public MappedClass getMappedClass(Object obj)
Gets the MappedClass
for the object (type). If it isn't mapped, create a new class and cache it (without validating).
public void updateKeyInfo(Object entity, com.mongodb.DBObject dbObj, EntityCache cache)
Updates the @Id
fields.
entity
- The object to updatedbObj
- Value to update with; null means skippublic Object fromDBObject(Class entityClass, com.mongodb.DBObject dbObject, EntityCache cache)
entityClass
- The type to return, or use; can be overridden by the @see Mapper.CLASS_NAME_FIELDNAME in the DBObjectpublic Object toMongoObject(MappedField mf, MappedClass mc, Object value)
Converts a java object to a mongo-compatible object (possibly a DBObject for complex mappings). Very similar to toDBObject(java.lang.Object)
Used (mainly) by query/update operations
public <T> Key<T> getKey(T entity)
public com.mongodb.DBObject toDBObject(Object entity)
Converts an entity (POJO) to a DBObject; A special field will be added to keep track of the class: CLASS_NAME_FIELDNAME
entity
- The POJOpublic com.mongodb.DBObject toDBObject(Object entity, Map<Object,com.mongodb.DBObject> involvedObjects)
Converts an entity (POJO) to a DBObject (for use with low-level driver); A special field will be added to keep track of the class:
CLASS_NAME_FIELDNAME
entity
- The POJOinvolvedObjects
- A Map of (already converted) POJOspublic DefaultConverters getConverters()
public EntityCache createEntityCache()
public <T> Key<T> refToKey(com.mongodb.DBRef ref)
public com.mongodb.DBRef keyToRef(Key key)
public static MappedField validate(Class clazz, Mapper mapper, StringBuffer origProp, FilterOperator op, Object val, boolean validateNames, boolean validateTypes)
public static boolean isCompatibleForOperator(Class<?> type, FilterOperator op, Object value)
Copyright © 2013. All Rights Reserved.