public class QueryMapper extends Object
Modifier and Type | Class and Description |
---|---|
protected static class |
QueryMapper.Field
Value object to represent a field and its meta-information.
|
protected static class |
QueryMapper.MetadataBackedField
Extension of
DocumentField to be backed with mapping metadata. |
Constructor and Description |
---|
QueryMapper(MongoConverter converter)
Creates a new
QueryMapper with the given MongoConverter . |
Modifier and Type | Method and Description |
---|---|
protected Object |
convertAssociation(Object source,
MongoPersistentProperty property)
Converts the given source assuming it's actually an association to another object.
|
protected Object |
convertAssociation(Object source,
QueryMapper.Field field) |
Object |
convertId(Object id)
Converts the given raw id value into either
ObjectId or String . |
protected Object |
convertSimpleOrDBObject(Object source,
MongoPersistentEntity<?> entity)
Retriggers mapping if the given source is a
DBObject or simply invokes the |
protected Map.Entry<String,Object> |
createMapEntry(QueryMapper.Field field,
Object value)
Creates a new
Map.Entry for the given QueryMapper.Field with the given value. |
protected QueryMapper.Field |
createPropertyField(MongoPersistentEntity<?> entity,
String key,
MappingContext<? extends MongoPersistentEntity<?>,MongoPersistentProperty> mappingContext) |
protected Object |
delegateConvertToMongoType(Object source,
MongoPersistentEntity<?> entity)
Converts the given source Object to a mongo type with the type information of the original source type omitted.
|
protected com.mongodb.DBObject |
getMappedKeyword(QueryMapper.Field property,
org.springframework.data.mongodb.core.convert.QueryMapper.Keyword keyword)
Returns the mapped keyword considered defining a criteria for the given property.
|
protected com.mongodb.DBObject |
getMappedKeyword(org.springframework.data.mongodb.core.convert.QueryMapper.Keyword keyword,
MongoPersistentEntity<?> entity)
Returns the given
DBObject representing a keyword by mapping the keyword's value. |
com.mongodb.DBObject |
getMappedObject(com.mongodb.DBObject query,
MongoPersistentEntity<?> entity)
Replaces the property keys used in the given
DBObject with the appropriate keys by using the
PersistentEntity metadata. |
protected Map.Entry<String,Object> |
getMappedObjectForField(QueryMapper.Field field,
Object rawValue)
Extracts the mapped object value for given field out of rawValue taking nested
Keyword s into account |
protected Object |
getMappedValue(QueryMapper.Field documentField,
Object value)
Returns the mapped value for the given source object assuming it's a value for the given
MongoPersistentProperty . |
protected boolean |
isAssociationConversionNecessary(QueryMapper.Field documentField,
Object value)
Returns whether the given
QueryMapper.Field represents an association reference that together with the given value
requires conversion to a DBRef object. |
protected boolean |
isDBObject(Object value)
Checks whether the given value is a
DBObject . |
protected boolean |
isKeyword(String candidate)
Returns whether the given
String is a MongoDB keyword. |
protected boolean |
isNestedKeyword(Object candidate)
Returns whether the given
Object is a keyword, i.e. if it's a DBObject with a keyword key. |
public QueryMapper(MongoConverter converter)
QueryMapper
with the given MongoConverter
.converter
- must not be null.public com.mongodb.DBObject getMappedObject(com.mongodb.DBObject query, MongoPersistentEntity<?> entity)
DBObject
with the appropriate keys by using the
PersistentEntity
metadata.query
- must not be null.entity
- can be null.protected Map.Entry<String,Object> getMappedObjectForField(QueryMapper.Field field, Object rawValue)
Keyword
s into accountfield
- rawValue
- protected QueryMapper.Field createPropertyField(MongoPersistentEntity<?> entity, String key, MappingContext<? extends MongoPersistentEntity<?>,MongoPersistentProperty> mappingContext)
entity
- key
- mappingContext
- protected com.mongodb.DBObject getMappedKeyword(org.springframework.data.mongodb.core.convert.QueryMapper.Keyword keyword, MongoPersistentEntity<?> entity)
DBObject
representing a keyword by mapping the keyword's value.keyword
- the DBObject
representing a keyword (e.g. $ne : …
)entity
- protected com.mongodb.DBObject getMappedKeyword(QueryMapper.Field property, org.springframework.data.mongodb.core.convert.QueryMapper.Keyword keyword)
property
- keyword
- protected Object getMappedValue(QueryMapper.Field documentField, Object value)
MongoPersistentProperty
.value
- the source object to be mappedproperty
- the property the value is a value fornewKey
- the key the value will be bound to eventuallyprotected boolean isAssociationConversionNecessary(QueryMapper.Field documentField, Object value)
QueryMapper.Field
represents an association reference that together with the given value
requires conversion to a DBRef
object. We check whether the
type of the given value is compatible with the type of the given document field in order to deal with potential
query field exclusions, since MongoDB uses the int
0 as an indicator for an excluded field.documentField
- must not be null.value
- protected Object convertSimpleOrDBObject(Object source, MongoPersistentEntity<?> entity)
DBObject
or simply invokes thesource
- entity
- protected Object delegateConvertToMongoType(Object source, MongoPersistentEntity<?> entity)
source
- entity
- protected Object convertAssociation(Object source, QueryMapper.Field field)
protected Object convertAssociation(Object source, MongoPersistentProperty property)
source
- property
- protected final boolean isDBObject(Object value)
DBObject
.value
- can be null.protected final Map.Entry<String,Object> createMapEntry(QueryMapper.Field field, Object value)
Map.Entry
for the given QueryMapper.Field
with the given value.field
- must not be null.value
- can be null.public Object convertId(Object id)
ObjectId
or String
.id
- protected boolean isNestedKeyword(Object candidate)
Object
is a keyword, i.e. if it's a DBObject
with a keyword key.candidate
- Copyright © 2011-2014–2014 Pivotal Software, Inc.. All rights reserved.