|
Spring Data Document | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.springframework.data.document.mongodb.convert.AbstractMongoConverter org.springframework.data.document.mongodb.convert.MappingMongoConverter
public class MappingMongoConverter
MongoConverter
that uses a MappingContext
to do sophisticated mapping of domain objects to
DBObject
.
Field Summary | |
---|---|
protected ApplicationContext |
applicationContext
|
static String |
CUSTOM_TYPE_KEY
|
protected static org.apache.commons.logging.Log |
log
|
protected org.springframework.data.mapping.model.MappingContext<? extends MongoPersistentEntity<?>,MongoPersistentProperty> |
mappingContext
|
protected MongoDbFactory |
mongoDbFactory
|
protected SpelExpressionParser |
spelExpressionParser
|
protected boolean |
useFieldAccessOnly
|
Fields inherited from class org.springframework.data.document.mongodb.convert.AbstractMongoConverter |
---|
conversionService |
Constructor Summary | |
---|---|
MappingMongoConverter(MongoDbFactory mongoDbFactory,
org.springframework.data.mapping.model.MappingContext<? extends MongoPersistentEntity<?>,MongoPersistentProperty> mappingContext)
Creates a new MappingMongoConverter given the new MongoDbFactory and MappingContext . |
Method Summary | ||
---|---|---|
void |
addCustomTypeKeyIfNecessary(org.springframework.data.util.TypeInformation<?> type,
Object value,
DBObject dbObject)
Adds custom type information to the given DBObject if necessary. |
|
ObjectId |
convertObjectId(Object id)
Returns the ObjectId instance for the given id. |
|
|
convertObjectId(ObjectId id,
Class<T> targetType)
Converts the given ObjectId to the given target type. |
|
protected DBRef |
createDBRef(Object target,
DBRef dbref)
|
|
protected Class<?> |
findTypeToBeUsed(DBObject dbObject)
Returns the type to be used to convert the DBObject given to. |
|
org.springframework.data.mapping.model.MappingContext<? extends MongoPersistentEntity<?>,MongoPersistentProperty> |
getMappingContext()
|
|
protected Object |
getValueInternal(MongoPersistentProperty prop,
DBObject dbo,
StandardEvaluationContext ctx,
String spelExpr)
|
|
org.springframework.data.util.TypeInformation<?> |
getValueType(org.springframework.data.util.TypeInformation<?> type)
Returns the type type information of the actual value to be stored. |
|
boolean |
isUseFieldAccessOnly()
|
|
|
read(Class<S> clazz,
DBObject dbo)
Ready from the native MongoDB DBObject representation to an instance of the class T. |
|
protected
|
read(org.springframework.data.util.TypeInformation<S> type,
DBObject dbo)
|
|
void |
setApplicationContext(ApplicationContext applicationContext)
|
|
void |
setMongoDbFactory(MongoDbFactory mongoDbFactory)
|
|
void |
setUseFieldAccessOnly(boolean useFieldAccessOnly)
|
|
protected
|
unwrapList(BasicDBList dbList,
org.springframework.data.util.TypeInformation<T> targetType)
|
|
void |
write(Object obj,
DBObject dbo)
Root entry method into write conversion. |
|
protected DBObject |
writeCollectionInternal(MongoPersistentProperty property,
Object obj)
|
|
protected void |
writeInternal(Object obj,
DBObject dbo)
Internal write conversion method which should be used for nested invocations. |
|
protected void |
writeInternal(Object obj,
DBObject dbo,
MongoPersistentEntity<?> entity)
|
|
protected void |
writeMapInternal(Map<Object,Object> obj,
DBObject dbo,
org.springframework.data.util.TypeInformation<?> propertyType)
|
|
protected void |
writePropertyInternal(MongoPersistentProperty prop,
Object obj,
DBObject dbo)
|
Methods inherited from class org.springframework.data.document.mongodb.convert.AbstractMongoConverter |
---|
afterPropertiesSet, getConversionService, getCustomTarget, maybeConvertArray, maybeConvertList, maybeConvertObject, setCustomConverters |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final String CUSTOM_TYPE_KEY
protected static final org.apache.commons.logging.Log log
protected final org.springframework.data.mapping.model.MappingContext<? extends MongoPersistentEntity<?>,MongoPersistentProperty> mappingContext
protected final SpelExpressionParser spelExpressionParser
protected ApplicationContext applicationContext
protected boolean useFieldAccessOnly
protected MongoDbFactory mongoDbFactory
Constructor Detail |
---|
public MappingMongoConverter(MongoDbFactory mongoDbFactory, org.springframework.data.mapping.model.MappingContext<? extends MongoPersistentEntity<?>,MongoPersistentProperty> mappingContext)
MappingMongoConverter
given the new MongoDbFactory
and MappingContext
.
mongoDbFactory
- mappingContext
- Method Detail |
---|
public org.springframework.data.mapping.model.MappingContext<? extends MongoPersistentEntity<?>,MongoPersistentProperty> getMappingContext()
getMappingContext
in interface MongoConverter
public void setMongoDbFactory(MongoDbFactory mongoDbFactory)
public boolean isUseFieldAccessOnly()
public void setUseFieldAccessOnly(boolean useFieldAccessOnly)
public <T> T convertObjectId(ObjectId id, Class<T> targetType)
MongoConverter
ObjectId
to the given target type.
convertObjectId
in interface MongoConverter
T
- the actual type to createid
- the source ObjectId
targetType
- the target type to convert the ObjectId
to
public ObjectId convertObjectId(Object id)
MongoConverter
ObjectId
instance for the given id.
convertObjectId
in interface MongoConverter
public <S> S read(Class<S> clazz, DBObject dbo)
MongoReader
DBObject
into it. So in case there's no real valid data inside
DBObject
for the given type, just return an empty instance of the given type.
read
in interface MongoReader<Object>
clazz
- the type of the return valuedbo
- theDBObject
protected <S> S read(org.springframework.data.util.TypeInformation<S> type, DBObject dbo)
public void write(Object obj, DBObject dbo)
DBObject
. Shouldn't be called for
nested conversions.
write
in interface MongoWriter<Object>
obj
- The object to convert to a DBObjectdbo
- The DBObject to use for writing.MongoWriter.write(java.lang.Object, com.mongodb.DBObject)
protected void writeInternal(Object obj, DBObject dbo)
obj
- dbo
- protected void writeInternal(Object obj, DBObject dbo, MongoPersistentEntity<?> entity)
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException
setApplicationContext
in interface ApplicationContextAware
BeansException
protected void writePropertyInternal(MongoPersistentProperty prop, Object obj, DBObject dbo)
protected DBObject writeCollectionInternal(MongoPersistentProperty property, Object obj)
protected void writeMapInternal(Map<Object,Object> obj, DBObject dbo, org.springframework.data.util.TypeInformation<?> propertyType)
public void addCustomTypeKeyIfNecessary(org.springframework.data.util.TypeInformation<?> type, Object value, DBObject dbObject)
DBObject
if necessary. That is if the value is not the same as
the one given. This is usually the case if you store a subtype of the actual declared type of the property.
type
- value
- dbObject
- public org.springframework.data.util.TypeInformation<?> getValueType(org.springframework.data.util.TypeInformation<?> type)
type
-
protected DBRef createDBRef(Object target, DBRef dbref)
protected Object getValueInternal(MongoPersistentProperty prop, DBObject dbo, StandardEvaluationContext ctx, String spelExpr)
protected Class<?> findTypeToBeUsed(DBObject dbObject)
DBObject
or the type hint found can't be converted into a Class
as the type might not
be available.
dbObject
-
DBObject
into or null if there's no type
found.protected <T> List<?> unwrapList(BasicDBList dbList, org.springframework.data.util.TypeInformation<T> targetType)
|
Spring Data Document | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |