public class MappingMongoConverter extends AbstractMongoConverter implements ApplicationContextAware
MongoConverter
that uses a MappingContext
to do sophisticated mapping of domain objects to
DBObject
.Modifier and Type | Field and Description |
---|---|
protected ApplicationContext |
applicationContext |
protected QueryMapper |
idMapper |
protected static org.slf4j.Logger |
log |
protected String |
mapKeyDotReplacement |
protected org.springframework.data.mapping.context.MappingContext<? extends MongoPersistentEntity<?>,MongoPersistentProperty> |
mappingContext |
protected MongoDbFactory |
mongoDbFactory |
protected SpelExpressionParser |
spelExpressionParser |
protected MongoTypeMapper |
typeMapper |
protected boolean |
useFieldAccessOnly |
conversions, conversionService, instantiators
Constructor and Description |
---|
MappingMongoConverter(MongoDbFactory mongoDbFactory,
org.springframework.data.mapping.context.MappingContext<? extends MongoPersistentEntity<?>,MongoPersistentProperty> mappingContext)
|
Modifier and Type | Method and Description |
---|---|
protected void |
addCustomTypeKeyIfNecessary(org.springframework.data.util.TypeInformation<?> type,
Object value,
DBObject dbObject)
Adds custom type information to the given
DBObject if necessary. |
Object |
convertToMongoType(Object obj)
Converts the given object into one Mongo will be able to store natively.
|
protected DBObject |
createCollection(Collection<?> collection,
MongoPersistentProperty property)
Writes the given
Collection using the given MongoPersistentProperty information. |
protected DBRef |
createDBRef(Object target,
DBRef dbref) |
org.springframework.data.mapping.context.MappingContext<? extends MongoPersistentEntity<?>,MongoPersistentProperty> |
getMappingContext() |
protected Object |
getValueInternal(MongoPersistentProperty prop,
DBObject dbo,
org.springframework.data.mapping.model.SpELExpressionEvaluator eval,
Object parent) |
BasicDBList |
maybeConvertList(Iterable<?> source) |
protected String |
potentiallyEscapeMapKey(String source)
Potentially replaces dots in the given map key with the configured map key replacement if configured or aborts
conversion if none is configured.
|
protected String |
potentiallyUnescapeMapKey(String source)
Translates the map key replacements in the given key just read with a dot in case a map key replacement has been
configured.
|
<S> S |
read(Class<S> clazz,
DBObject dbo) |
protected <S> S |
read(org.springframework.data.util.TypeInformation<S> type,
DBObject dbo) |
protected <S> S |
read(org.springframework.data.util.TypeInformation<S> type,
DBObject dbo,
Object parent) |
protected Map<Object,Object> |
readMap(org.springframework.data.util.TypeInformation<?> type,
DBObject dbObject,
Object parent)
|
void |
setApplicationContext(ApplicationContext applicationContext) |
void |
setMapKeyDotReplacement(String mapKeyDotReplacement)
Configure the characters dots potentially contained in a
Map shall be replaced with. |
void |
setTypeMapper(MongoTypeMapper typeMapper)
Configures the
MongoTypeMapper to be used to add type information to DBObject s created by the
converter and how to lookup type information from DBObject s when reading them. |
void |
setUseFieldAccessOnly(boolean useFieldAccessOnly)
Configures whether to use field access only for entity mapping.
|
DBRef |
toDBRef(Object object,
MongoPersistentProperty referingProperty)
Creates a
DBRef to refer to the given object. |
protected <T> List<?> |
unwrapList(BasicDBList dbList,
org.springframework.data.util.TypeInformation<T> targetType) |
void |
write(Object obj,
DBObject dbo)
Root entry method into write conversion.
|
protected void |
writeInternal(Object obj,
DBObject dbo,
MongoPersistentEntity<?> entity) |
protected void |
writeInternal(Object obj,
DBObject dbo,
org.springframework.data.util.TypeInformation<?> typeHint)
Internal write conversion method which should be used for nested invocations.
|
protected DBObject |
writeMapInternal(Map<Object,Object> obj,
DBObject dbo,
org.springframework.data.util.TypeInformation<?> propertyType)
|
protected void |
writePropertyInternal(Object obj,
DBObject dbo,
MongoPersistentProperty prop) |
afterPropertiesSet, getConversionService, setCustomConversions, setInstantiators
protected static final org.slf4j.Logger log
protected final org.springframework.data.mapping.context.MappingContext<? extends MongoPersistentEntity<?>,MongoPersistentProperty> mappingContext
protected final SpelExpressionParser spelExpressionParser
protected final MongoDbFactory mongoDbFactory
protected final QueryMapper idMapper
protected ApplicationContext applicationContext
protected boolean useFieldAccessOnly
protected MongoTypeMapper typeMapper
protected String mapKeyDotReplacement
public MappingMongoConverter(MongoDbFactory mongoDbFactory, org.springframework.data.mapping.context.MappingContext<? extends MongoPersistentEntity<?>,MongoPersistentProperty> mappingContext)
mongoDbFactory
- must not be null.mappingContext
- must not be null.public void setTypeMapper(MongoTypeMapper typeMapper)
MongoTypeMapper
to be used to add type information to DBObject
s created by the
converter and how to lookup type information from DBObject
s when reading them. Uses a
DefaultMongoTypeMapper
by default. Setting this to null will reset the TypeMapper
to the
default one.typeMapper
- the typeMapper to setpublic void setMapKeyDotReplacement(String mapKeyDotReplacement)
Map
shall be replaced with. By default we don't do
any translation but rather reject a Map
with keys containing dots causing the conversion for the entire
object to fail. If further customization of the translation is needed, have a look at
potentiallyEscapeMapKey(String)
as well as potentiallyUnescapeMapKey(String)
.mapKeyDotReplacement
- the mapKeyDotReplacement to setpublic org.springframework.data.mapping.context.MappingContext<? extends MongoPersistentEntity<?>,MongoPersistentProperty> getMappingContext()
getMappingContext
in interface org.springframework.data.convert.EntityConverter<MongoPersistentEntity<?>,MongoPersistentProperty,Object,DBObject>
public void setUseFieldAccessOnly(boolean useFieldAccessOnly)
MongoConverter
to not go through getters or setters even if they are present for getting and setting
property values.useFieldAccessOnly
- public void setApplicationContext(ApplicationContext applicationContext) throws BeansException
setApplicationContext
in interface ApplicationContextAware
BeansException
protected <S> S read(org.springframework.data.util.TypeInformation<S> type, DBObject dbo)
protected <S> S read(org.springframework.data.util.TypeInformation<S> type, DBObject dbo, Object parent)
public DBRef toDBRef(Object object, MongoPersistentProperty referingProperty)
MongoWriter
DBRef
to refer to the given object.toDBRef
in interface MongoWriter<Object>
object
- the object to create a DBRef
to link to. The object's type has to carry an id attribute.referingProperty
- the client-side property referring to the object which might carry additional metadata for
the DBRef
object to create. Can be null.public void write(Object obj, DBObject dbo)
DBObject
. Shouldn't be called for
nested conversions.protected void writeInternal(Object obj, DBObject dbo, org.springframework.data.util.TypeInformation<?> typeHint)
obj
- dbo
- protected void writeInternal(Object obj, DBObject dbo, MongoPersistentEntity<?> entity)
protected void writePropertyInternal(Object obj, DBObject dbo, MongoPersistentProperty prop)
protected DBObject createCollection(Collection<?> collection, MongoPersistentProperty property)
Collection
using the given MongoPersistentProperty
information.collection
- must not be null.property
- must not be null.protected DBObject writeMapInternal(Map<Object,Object> obj, DBObject dbo, org.springframework.data.util.TypeInformation<?> propertyType)
obj
- must not be null.dbo
- must not be null.propertyType
- must not be null.protected String potentiallyEscapeMapKey(String source)
source
- setMapKeyDotReplacement(String)
protected String potentiallyUnescapeMapKey(String source)
source
- protected 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
- must not be null.dbObject
- must not be null.protected Object getValueInternal(MongoPersistentProperty prop, DBObject dbo, org.springframework.data.mapping.model.SpELExpressionEvaluator eval, Object parent)
protected Map<Object,Object> readMap(org.springframework.data.util.TypeInformation<?> type, DBObject dbObject, Object parent)
protected <T> List<?> unwrapList(BasicDBList dbList, org.springframework.data.util.TypeInformation<T> targetType)
public Object convertToMongoType(Object obj)
MongoWriter
convertToMongoType
in interface MongoWriter<Object>
public BasicDBList maybeConvertList(Iterable<?> source)
Copyright © 2012. All Rights Reserved.