|
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.mongodb.core.convert.AbstractMongoConverter org.springframework.data.mongodb.core.convert.MappingMongoConverter
public class MappingMongoConverter
MongoConverter
that uses a MappingContext
to do sophisticated mapping of domain objects to
DBObject
.
Field Summary | |
---|---|
protected ApplicationContext |
applicationContext
|
protected static org.apache.commons.logging.Log |
log
|
protected org.springframework.data.mapping.context.MappingContext<? extends MongoPersistentEntity<?>,MongoPersistentProperty> |
mappingContext
|
protected MongoDbFactory |
mongoDbFactory
|
protected SpelExpressionParser |
spelExpressionParser
|
protected TypeMapper |
typeMapper
|
protected boolean |
useFieldAccessOnly
|
Fields inherited from class org.springframework.data.mongodb.core.convert.AbstractMongoConverter |
---|
conversions, conversionService |
Constructor Summary | |
---|---|
MappingMongoConverter(MongoDbFactory mongoDbFactory,
org.springframework.data.mapping.context.MappingContext<? extends MongoPersistentEntity<?>,MongoPersistentProperty> mappingContext)
Creates a new MappingMongoConverter given the new MongoDbFactory and MappingContext . |
Method Summary | ||
---|---|---|
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)
|
|
protected org.springframework.data.util.TypeInformation<?> |
findTypeToBeUsed(DBObject dbObject)
Returns the type to be used to convert the DBObject given to. |
|
org.springframework.data.mapping.context.MappingContext<? extends MongoPersistentEntity<?>,MongoPersistentProperty> |
getMappingContext()
Returns the underlying MappingContext used by the converter. |
|
TypeMapper |
getTypeMapper()
Returns the TypeMapper . |
|
protected Object |
getValueInternal(MongoPersistentProperty prop,
DBObject dbo,
StandardEvaluationContext ctx,
String spelExpr)
|
|
Object[] |
maybeConvertArray(Object[] src)
|
|
BasicDBList |
maybeConvertList(BasicDBList dbl)
|
|
|
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)
|
|
protected Map<Object,Object> |
readMap(org.springframework.data.util.TypeInformation<?> type,
DBObject dbObject)
Reads the given DBObject into a Map . will recursively resolve nested Map s as well. |
|
void |
setApplicationContext(ApplicationContext applicationContext)
|
|
void |
setTypeMapper(TypeMapper typeMapper)
Configures the TypeMapper 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. |
|
protected
|
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)
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(Object obj,
DBObject dbo,
MongoPersistentProperty prop)
|
Methods inherited from class org.springframework.data.mongodb.core.convert.AbstractMongoConverter |
---|
afterPropertiesSet, getConversionService, setCustomConversions |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected static final org.apache.commons.logging.Log log
protected final org.springframework.data.mapping.context.MappingContext<? extends MongoPersistentEntity<?>,MongoPersistentProperty> mappingContext
protected final SpelExpressionParser spelExpressionParser
protected final MongoDbFactory mongoDbFactory
protected ApplicationContext applicationContext
protected boolean useFieldAccessOnly
protected TypeMapper typeMapper
Constructor Detail |
---|
public MappingMongoConverter(MongoDbFactory mongoDbFactory, org.springframework.data.mapping.context.MappingContext<? extends MongoPersistentEntity<?>,MongoPersistentProperty> mappingContext)
MappingMongoConverter
given the new MongoDbFactory
and MappingContext
.
mongoDbFactory
- must not be null.mappingContext
- must not be null.Method Detail |
---|
public void setTypeMapper(TypeMapper typeMapper)
TypeMapper
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 DefaultTypeMapper
by
default. Setting this to null will reset the TypeMapper
to the default one.
typeMapper
- the typeMapper to setpublic TypeMapper getTypeMapper()
TypeMapperProvider
TypeMapper
.
getTypeMapper
in interface TypeMapperProvider
TypeMapper
or null if none available.public org.springframework.data.mapping.context.MappingContext<? extends MongoPersistentEntity<?>,MongoPersistentProperty> getMappingContext()
MongoConverter
MappingContext
used by the converter.
getMappingContext
in interface MongoConverter
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
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 value. Will never be null.dbo
- the DBObject
to convert into a domain object. Might be null.
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.org.springframework.data.mongodb.core.core.convert.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)
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 void writeMapInternal(Map<Object,Object> obj, DBObject dbo, org.springframework.data.util.TypeInformation<?> propertyType)
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 DBRef createDBRef(Object target, DBRef dbref)
protected Object getValueInternal(MongoPersistentProperty prop, DBObject dbo, StandardEvaluationContext ctx, String spelExpr)
protected Map<Object,Object> readMap(org.springframework.data.util.TypeInformation<?> type, DBObject dbObject)
DBObject
into a Map
. will recursively resolve nested Map
s as well.
type
- the Map
TypeInformation
to be used to unmarshall this DBObject
.dbObject
-
protected org.springframework.data.util.TypeInformation<?> 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)
public Object convertToMongoType(Object obj)
MongoWriter
convertToMongoType
in interface MongoWriter<Object>
public Object[] maybeConvertArray(Object[] src)
public BasicDBList maybeConvertList(BasicDBList dbl)
|
Spring Data Document | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |