Spring Data Document

org.springframework.data.document.mongodb.convert
Class MappingMongoConverter

java.lang.Object
  extended by org.springframework.data.document.mongodb.convert.MappingMongoConverter
All Implemented Interfaces:
InitializingBean, ApplicationContextAware, MongoConverter, MongoReader<Object>, MongoWriter<Object>

public class MappingMongoConverter
extends Object
implements MongoConverter, ApplicationContextAware, InitializingBean

MongoConverter that uses a MappingContext to do sophisticated mapping of domain objects to DBObject.

Author:
Jon Brisbin , Oliver Gierke

Nested Class Summary
protected  class MappingMongoConverter.PersistentPropertyWrapper
           
 
Field Summary
protected  ApplicationContext applicationContext
           
protected  GenericConversionService conversionService
           
protected  Map<Class<?>,Class<?>> customTypeMapping
           
protected  String defaultDatabase
           
protected static org.apache.commons.logging.Log log
           
protected  org.springframework.data.mapping.model.MappingContext mappingContext
           
protected  Mongo mongo
           
protected  SpelExpressionParser spelExpressionParser
           
protected  boolean useFieldAccessOnly
           
 
Constructor Summary
MappingMongoConverter(org.springframework.data.mapping.model.MappingContext mappingContext)
          Creates a new MappingMongoConverter with the given MappingContext.
 
Method Summary
 void afterPropertiesSet()
           
 ObjectId convertObjectId(Object id)
          Returns the ObjectId instance for the given id.
<T> T
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.
 String getDefaultDatabase()
           
 org.springframework.data.mapping.model.MappingContext getMappingContext()
           
 Mongo getMongo()
           
protected  Object getValueInternal(org.springframework.data.mapping.model.PersistentProperty prop, DBObject dbo, StandardEvaluationContext ctx, Value spelExpr)
           
 boolean isUseFieldAccessOnly()
           
<S> S
read(Class<S> clazz, DBObject dbo)
          Ready from the native MongoDB DBObject representation to an instance of the class T.
 void setApplicationContext(ApplicationContext applicationContext)
           
 void setConverters(List<Converter<?,?>> converters)
          Add custom Converter or ConverterFactory instances to be used that will take presidence over metadata driven conversion between of objects to/from DBObject
 void setDefaultDatabase(String defaultDatabase)
           
 void setMongo(Mongo mongo)
           
 void setUseFieldAccessOnly(boolean useFieldAccessOnly)
           
 void write(Object obj, DBObject dbo)
          Write the given object of type T to the native MongoDB object representation DBObject.
protected  void write(Object obj, DBObject dbo, org.springframework.data.mapping.model.PersistentEntity<?> entity)
           
protected  void writeMapInternal(Map<Object,Object> obj, DBObject dbo)
           
protected  void writePropertyInternal(org.springframework.data.mapping.model.PersistentProperty prop, Object obj, DBObject dbo)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

protected static final org.apache.commons.logging.Log log

conversionService

protected final GenericConversionService conversionService

customTypeMapping

protected final Map<Class<?>,Class<?>> customTypeMapping

mappingContext

protected final org.springframework.data.mapping.model.MappingContext mappingContext

spelExpressionParser

protected SpelExpressionParser spelExpressionParser

applicationContext

protected ApplicationContext applicationContext

useFieldAccessOnly

protected boolean useFieldAccessOnly

mongo

protected Mongo mongo

defaultDatabase

protected String defaultDatabase
Constructor Detail

MappingMongoConverter

public MappingMongoConverter(org.springframework.data.mapping.model.MappingContext mappingContext)
Creates a new MappingMongoConverter with the given MappingContext.

Parameters:
mappingContext -
Method Detail

setConverters

public void setConverters(List<Converter<?,?>> converters)
Add custom Converter or ConverterFactory instances to be used that will take presidence over metadata driven conversion between of objects to/from DBObject

Parameters:
converters -

getMappingContext

public org.springframework.data.mapping.model.MappingContext getMappingContext()

getMongo

public Mongo getMongo()

setMongo

public void setMongo(Mongo mongo)

getDefaultDatabase

public String getDefaultDatabase()

setDefaultDatabase

public void setDefaultDatabase(String defaultDatabase)

isUseFieldAccessOnly

public boolean isUseFieldAccessOnly()

setUseFieldAccessOnly

public void setUseFieldAccessOnly(boolean useFieldAccessOnly)

convertObjectId

public <T> T convertObjectId(ObjectId id,
                             Class<T> targetType)
Description copied from interface: MongoConverter
Converts the given ObjectId to the given target type.

Specified by:
convertObjectId in interface MongoConverter
Type Parameters:
T - the actual type to create
Parameters:
id - the source ObjectId
targetType - the target type to convert the ObjectId to
Returns:

convertObjectId

public ObjectId convertObjectId(Object id)
Description copied from interface: MongoConverter
Returns the ObjectId instance for the given id.

Specified by:
convertObjectId in interface MongoConverter
Returns:

read

public <S> S read(Class<S> clazz,
                  DBObject dbo)
Description copied from interface: MongoReader
Ready from the native MongoDB DBObject representation to an instance of the class T. The given type has to be the starting point for marshalling the 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.

Specified by:
read in interface MongoReader<Object>
Parameters:
clazz - the type of the return value
dbo - theDBObject
Returns:
the converted object

write

public void write(Object obj,
                  DBObject dbo)
Description copied from interface: MongoWriter
Write the given object of type T to the native MongoDB object representation DBObject.

Specified by:
write in interface MongoWriter<Object>
Parameters:
obj - The object to convert to a DBObject
dbo - The DBObject to use for writing.

write

protected void write(Object obj,
                     DBObject dbo,
                     org.springframework.data.mapping.model.PersistentEntity<?> entity)

setApplicationContext

public void setApplicationContext(ApplicationContext applicationContext)
                           throws BeansException
Specified by:
setApplicationContext in interface ApplicationContextAware
Throws:
BeansException

writePropertyInternal

protected void writePropertyInternal(org.springframework.data.mapping.model.PersistentProperty prop,
                                     Object obj,
                                     DBObject dbo)

writeMapInternal

protected void writeMapInternal(Map<Object,Object> obj,
                                DBObject dbo)

createDBRef

protected DBRef createDBRef(Object target,
                            DBRef dbref)

getValueInternal

protected Object getValueInternal(org.springframework.data.mapping.model.PersistentProperty prop,
                                  DBObject dbo,
                                  StandardEvaluationContext ctx,
                                  Value spelExpr)

findTypeToBeUsed

protected Class<?> findTypeToBeUsed(DBObject dbObject)
Returns the type to be used to convert the DBObject given to.

Parameters:
dbObject -
Returns:

afterPropertiesSet

public void afterPropertiesSet()
Specified by:
afterPropertiesSet in interface InitializingBean

Spring Data Document

Copyright © 2011. All Rights Reserved.