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(DatastoreProvider datastoreProvider)
Deprecated.
Use Mapper#setDatastoreProvider(DatastoreProvider) instead
|
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.
|
EntityCache |
createEntityCache() |
<T> T |
fromDb(com.mongodb.DBObject dbObject,
T entity,
EntityCache cache) |
<T> T |
fromDBObject(Class<T> entityClass,
com.mongodb.DBObject dbObject,
EntityCache cache)
Converts a DBObject back to a type-safe java object (POJO)
|
Class<?> |
getClassFromCollection(String collection) |
String |
getCollectionName(Object object) |
Converters |
getConverters() |
DatastoreProvider |
getDatastoreProvider() |
Object |
getId(Object entity) |
Map<Class,Object> |
getInstanceCache() |
Collection<EntityInterceptor> |
getInterceptors()
Gets list of
EntityInterceptor s |
<T> Key<T> |
getKey(T entity) |
<T> Key<T> |
getKey(T entity,
String collection) |
<T> List<Key<T>> |
getKeysByManualRefs(Class<T> kindClass,
List<Object> refs)
Queries the server to check for each manual ref
|
<T> List<Key<T>> |
getKeysByRefs(List<com.mongodb.DBRef> refs)
Queries the server to check for each DBRef
|
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() |
LazyProxyFactory |
getProxyFactory() |
boolean |
isMapped(Class c) |
Object |
keyToManualRef(Key key) |
com.mongodb.DBRef |
keyToRef(Key key) |
<T> Key<T> |
manualRefToKey(Class<T> type,
Object id) |
<T> Key<T> |
manualRefToKey(String collection,
Object id) |
<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).
|
String |
updateCollection(Key key) |
void |
updateKeyInfo(Object entity,
com.mongodb.DBObject dbObj,
EntityCache cache)
Updates the @
Id fields. |
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)
@Deprecated public Mapper(DatastoreProvider datastoreProvider)
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 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 <T> T fromDBObject(Class<T> 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)
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 <T> T fromDb(com.mongodb.DBObject dbObject, T entity, EntityCache cache)
public Converters getConverters()
public EntityCache createEntityCache()
public <T> Key<T> refToKey(com.mongodb.DBRef ref)
public <T> List<Key<T>> getKeysByManualRefs(Class<T> kindClass, List<Object> refs)
public <T> List<Key<T>> getKeysByRefs(List<com.mongodb.DBRef> refs)
public com.mongodb.DBRef keyToRef(Key key)
public LazyProxyFactory getProxyFactory()
public DatastoreProvider getDatastoreProvider()
Copyright © 2016. All rights reserved.