|
|
|
|
@ -52,7 +52,7 @@ import com.mongodb.DBRef;
@@ -52,7 +52,7 @@ import com.mongodb.DBRef;
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* A helper class to encapsulate any modifications of a Query object before it gets submitted to the database. |
|
|
|
|
* |
|
|
|
|
* |
|
|
|
|
* @author Jon Brisbin |
|
|
|
|
* @author Oliver Gierke |
|
|
|
|
* @author Patryk Wasik |
|
|
|
|
@ -77,7 +77,7 @@ public class QueryMapper {
@@ -77,7 +77,7 @@ public class QueryMapper {
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Creates a new {@link QueryMapper} with the given {@link MongoConverter}. |
|
|
|
|
* |
|
|
|
|
* |
|
|
|
|
* @param converter must not be {@literal null}. |
|
|
|
|
*/ |
|
|
|
|
public QueryMapper(MongoConverter converter) { |
|
|
|
|
@ -93,7 +93,7 @@ public class QueryMapper {
@@ -93,7 +93,7 @@ public class QueryMapper {
|
|
|
|
|
/** |
|
|
|
|
* Replaces the property keys used in the given {@link DBObject} with the appropriate keys by using the |
|
|
|
|
* {@link PersistentEntity} metadata. |
|
|
|
|
* |
|
|
|
|
* |
|
|
|
|
* @param query must not be {@literal null}. |
|
|
|
|
* @param entity can be {@literal null}. |
|
|
|
|
* @return |
|
|
|
|
@ -146,7 +146,7 @@ public class QueryMapper {
@@ -146,7 +146,7 @@ public class QueryMapper {
|
|
|
|
|
/** |
|
|
|
|
* Maps fields used for sorting to the {@link MongoPersistentEntity}s properties. <br /> |
|
|
|
|
* Also converts properties to their {@code $meta} representation if present. |
|
|
|
|
* |
|
|
|
|
* |
|
|
|
|
* @param sortObject |
|
|
|
|
* @param entity |
|
|
|
|
* @return |
|
|
|
|
@ -166,7 +166,7 @@ public class QueryMapper {
@@ -166,7 +166,7 @@ public class QueryMapper {
|
|
|
|
|
/** |
|
|
|
|
* Maps fields to retrieve to the {@link MongoPersistentEntity}s properties. <br /> |
|
|
|
|
* Also onverts and potentially adds missing property {@code $meta} representation. |
|
|
|
|
* |
|
|
|
|
* |
|
|
|
|
* @param fieldsObject |
|
|
|
|
* @param entity |
|
|
|
|
* @return |
|
|
|
|
@ -200,7 +200,7 @@ public class QueryMapper {
@@ -200,7 +200,7 @@ public class QueryMapper {
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Extracts the mapped object value for given field out of rawValue taking nested {@link Keyword}s into account |
|
|
|
|
* |
|
|
|
|
* |
|
|
|
|
* @param field |
|
|
|
|
* @param rawValue |
|
|
|
|
* @return |
|
|
|
|
@ -233,7 +233,7 @@ public class QueryMapper {
@@ -233,7 +233,7 @@ public class QueryMapper {
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Returns the given {@link DBObject} representing a keyword by mapping the keyword's value. |
|
|
|
|
* |
|
|
|
|
* |
|
|
|
|
* @param keyword the {@link DBObject} representing a keyword (e.g. {@code $ne : … } ) |
|
|
|
|
* @param entity |
|
|
|
|
* @return |
|
|
|
|
@ -263,7 +263,7 @@ public class QueryMapper {
@@ -263,7 +263,7 @@ public class QueryMapper {
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Returns the mapped keyword considered defining a criteria for the given property. |
|
|
|
|
* |
|
|
|
|
* |
|
|
|
|
* @param property |
|
|
|
|
* @param keyword |
|
|
|
|
* @return |
|
|
|
|
@ -282,7 +282,7 @@ public class QueryMapper {
@@ -282,7 +282,7 @@ public class QueryMapper {
|
|
|
|
|
/** |
|
|
|
|
* Returns the mapped value for the given source object assuming it's a value for the given |
|
|
|
|
* {@link MongoPersistentProperty}. |
|
|
|
|
* |
|
|
|
|
* |
|
|
|
|
* @param value the source object to be mapped |
|
|
|
|
* @param property the property the value is a value for |
|
|
|
|
* @param newKey the key the value will be bound to eventually |
|
|
|
|
@ -332,7 +332,7 @@ public class QueryMapper {
@@ -332,7 +332,7 @@ public class QueryMapper {
|
|
|
|
|
* requires conversion to a {@link org.springframework.data.mongodb.core.mapping.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 {@code int} {@literal 0} as an indicator for an excluded field. |
|
|
|
|
* |
|
|
|
|
* |
|
|
|
|
* @param documentField must not be {@literal null}. |
|
|
|
|
* @param value |
|
|
|
|
* @return |
|
|
|
|
@ -363,7 +363,7 @@ public class QueryMapper {
@@ -363,7 +363,7 @@ public class QueryMapper {
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Retriggers mapping if the given source is a {@link DBObject} or simply invokes the |
|
|
|
|
* |
|
|
|
|
* |
|
|
|
|
* @param source |
|
|
|
|
* @param entity |
|
|
|
|
* @return |
|
|
|
|
@ -384,7 +384,7 @@ public class QueryMapper {
@@ -384,7 +384,7 @@ public class QueryMapper {
|
|
|
|
|
/** |
|
|
|
|
* Converts the given source Object to a mongo type with the type information of the original source type omitted. |
|
|
|
|
* Subclasses may overwrite this method to retain the type information of the source type on the resulting mongo type. |
|
|
|
|
* |
|
|
|
|
* |
|
|
|
|
* @param source |
|
|
|
|
* @param entity |
|
|
|
|
* @return the converted mongo type or null if source is null |
|
|
|
|
@ -399,7 +399,7 @@ public class QueryMapper {
@@ -399,7 +399,7 @@ public class QueryMapper {
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Converts the given source assuming it's actually an association to another object. |
|
|
|
|
* |
|
|
|
|
* |
|
|
|
|
* @param source |
|
|
|
|
* @param property |
|
|
|
|
* @return |
|
|
|
|
@ -438,7 +438,7 @@ public class QueryMapper {
@@ -438,7 +438,7 @@ public class QueryMapper {
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Checks whether the given value is a {@link DBObject}. |
|
|
|
|
* |
|
|
|
|
* |
|
|
|
|
* @param value can be {@literal null}. |
|
|
|
|
* @return |
|
|
|
|
*/ |
|
|
|
|
@ -448,7 +448,7 @@ public class QueryMapper {
@@ -448,7 +448,7 @@ public class QueryMapper {
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Creates a new {@link Entry} for the given {@link Field} with the given value. |
|
|
|
|
* |
|
|
|
|
* |
|
|
|
|
* @param field must not be {@literal null}. |
|
|
|
|
* @param value can be {@literal null}. |
|
|
|
|
* @return |
|
|
|
|
@ -459,7 +459,7 @@ public class QueryMapper {
@@ -459,7 +459,7 @@ public class QueryMapper {
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Creates a new {@link Entry} with the given key and value. |
|
|
|
|
* |
|
|
|
|
* |
|
|
|
|
* @param key must not be {@literal null} or empty. |
|
|
|
|
* @param value can be {@literal null} |
|
|
|
|
* @return |
|
|
|
|
@ -481,7 +481,7 @@ public class QueryMapper {
@@ -481,7 +481,7 @@ public class QueryMapper {
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Converts the given raw id value into either {@link ObjectId} or {@link String}. |
|
|
|
|
* |
|
|
|
|
* |
|
|
|
|
* @param id |
|
|
|
|
* @return |
|
|
|
|
*/ |
|
|
|
|
@ -505,7 +505,7 @@ public class QueryMapper {
@@ -505,7 +505,7 @@ public class QueryMapper {
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Returns whether the given {@link Object} is a keyword, i.e. if it's a {@link DBObject} with a keyword key. |
|
|
|
|
* |
|
|
|
|
* |
|
|
|
|
* @param candidate |
|
|
|
|
* @return |
|
|
|
|
*/ |
|
|
|
|
@ -528,7 +528,7 @@ public class QueryMapper {
@@ -528,7 +528,7 @@ public class QueryMapper {
|
|
|
|
|
/** |
|
|
|
|
* Returns whether the given {@link String} is a MongoDB keyword. The default implementation will check against the |
|
|
|
|
* set of registered keywords returned by {@link #getKeywords()}. |
|
|
|
|
* |
|
|
|
|
* |
|
|
|
|
* @param candidate |
|
|
|
|
* @return |
|
|
|
|
*/ |
|
|
|
|
@ -538,7 +538,7 @@ public class QueryMapper {
@@ -538,7 +538,7 @@ public class QueryMapper {
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Value object to capture a query keyword representation. |
|
|
|
|
* |
|
|
|
|
* |
|
|
|
|
* @author Oliver Gierke |
|
|
|
|
*/ |
|
|
|
|
static class Keyword { |
|
|
|
|
@ -564,7 +564,7 @@ public class QueryMapper {
@@ -564,7 +564,7 @@ public class QueryMapper {
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Returns whether the current keyword is the {@code $exists} keyword. |
|
|
|
|
* |
|
|
|
|
* |
|
|
|
|
* @return |
|
|
|
|
*/ |
|
|
|
|
public boolean isExists() { |
|
|
|
|
@ -577,7 +577,7 @@ public class QueryMapper {
@@ -577,7 +577,7 @@ public class QueryMapper {
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Returns whether the current keyword is the {@code $geometry} keyword. |
|
|
|
|
* |
|
|
|
|
* |
|
|
|
|
* @return |
|
|
|
|
* @since 1.8 |
|
|
|
|
*/ |
|
|
|
|
@ -587,7 +587,7 @@ public class QueryMapper {
@@ -587,7 +587,7 @@ public class QueryMapper {
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Returns wheter the current keyword indicates a sample object. |
|
|
|
|
* |
|
|
|
|
* |
|
|
|
|
* @return |
|
|
|
|
* @since 1.8 |
|
|
|
|
*/ |
|
|
|
|
@ -611,7 +611,7 @@ public class QueryMapper {
@@ -611,7 +611,7 @@ public class QueryMapper {
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Value object to represent a field and its meta-information. |
|
|
|
|
* |
|
|
|
|
* |
|
|
|
|
* @author Oliver Gierke |
|
|
|
|
*/ |
|
|
|
|
protected static class Field { |
|
|
|
|
@ -622,7 +622,7 @@ public class QueryMapper {
@@ -622,7 +622,7 @@ public class QueryMapper {
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Creates a new {@link DocumentField} without meta-information but the given name. |
|
|
|
|
* |
|
|
|
|
* |
|
|
|
|
* @param name must not be {@literal null} or empty. |
|
|
|
|
*/ |
|
|
|
|
public Field(String name) { |
|
|
|
|
@ -633,7 +633,7 @@ public class QueryMapper {
@@ -633,7 +633,7 @@ public class QueryMapper {
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Returns a new {@link DocumentField} with the given name. |
|
|
|
|
* |
|
|
|
|
* |
|
|
|
|
* @param name must not be {@literal null} or empty. |
|
|
|
|
* @return |
|
|
|
|
*/ |
|
|
|
|
@ -643,7 +643,7 @@ public class QueryMapper {
@@ -643,7 +643,7 @@ public class QueryMapper {
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Returns whether the current field is the id field. |
|
|
|
|
* |
|
|
|
|
* |
|
|
|
|
* @return |
|
|
|
|
*/ |
|
|
|
|
public boolean isIdField() { |
|
|
|
|
@ -654,7 +654,7 @@ public class QueryMapper {
@@ -654,7 +654,7 @@ public class QueryMapper {
|
|
|
|
|
* Returns the underlying {@link MongoPersistentProperty} backing the field. For path traversals this will be the |
|
|
|
|
* property that represents the value to handle. This means it'll be the leaf property for plain paths or the |
|
|
|
|
* association property in case we refer to an association somewhere in the path. |
|
|
|
|
* |
|
|
|
|
* |
|
|
|
|
* @return |
|
|
|
|
*/ |
|
|
|
|
public MongoPersistentProperty getProperty() { |
|
|
|
|
@ -663,7 +663,7 @@ public class QueryMapper {
@@ -663,7 +663,7 @@ public class QueryMapper {
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Returns the {@link MongoPersistentEntity} that field is conatined in. |
|
|
|
|
* |
|
|
|
|
* |
|
|
|
|
* @return |
|
|
|
|
*/ |
|
|
|
|
public MongoPersistentEntity<?> getPropertyEntity() { |
|
|
|
|
@ -672,7 +672,7 @@ public class QueryMapper {
@@ -672,7 +672,7 @@ public class QueryMapper {
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Returns whether the field represents an association. |
|
|
|
|
* |
|
|
|
|
* |
|
|
|
|
* @return |
|
|
|
|
*/ |
|
|
|
|
public boolean isAssociation() { |
|
|
|
|
@ -681,7 +681,7 @@ public class QueryMapper {
@@ -681,7 +681,7 @@ public class QueryMapper {
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Returns the key to be used in the mapped document eventually. |
|
|
|
|
* |
|
|
|
|
* |
|
|
|
|
* @return |
|
|
|
|
*/ |
|
|
|
|
public String getMappedKey() { |
|
|
|
|
@ -690,7 +690,7 @@ public class QueryMapper {
@@ -690,7 +690,7 @@ public class QueryMapper {
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Returns whether the field references an association in case it refers to a nested field. |
|
|
|
|
* |
|
|
|
|
* |
|
|
|
|
* @return |
|
|
|
|
*/ |
|
|
|
|
public boolean containsAssociation() { |
|
|
|
|
@ -708,7 +708,7 @@ public class QueryMapper {
@@ -708,7 +708,7 @@ public class QueryMapper {
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Extension of {@link DocumentField} to be backed with mapping metadata. |
|
|
|
|
* |
|
|
|
|
* |
|
|
|
|
* @author Oliver Gierke |
|
|
|
|
* @author Thomas Darimont |
|
|
|
|
*/ |
|
|
|
|
@ -725,7 +725,7 @@ public class QueryMapper {
@@ -725,7 +725,7 @@ public class QueryMapper {
|
|
|
|
|
/** |
|
|
|
|
* Creates a new {@link MetadataBackedField} with the given name, {@link MongoPersistentEntity} and |
|
|
|
|
* {@link MappingContext}. |
|
|
|
|
* |
|
|
|
|
* |
|
|
|
|
* @param name must not be {@literal null} or empty. |
|
|
|
|
* @param entity must not be {@literal null}. |
|
|
|
|
* @param context must not be {@literal null}. |
|
|
|
|
@ -738,7 +738,7 @@ public class QueryMapper {
@@ -738,7 +738,7 @@ public class QueryMapper {
|
|
|
|
|
/** |
|
|
|
|
* Creates a new {@link MetadataBackedField} with the given name, {@link MongoPersistentEntity} and |
|
|
|
|
* {@link MappingContext} with the given {@link MongoPersistentProperty}. |
|
|
|
|
* |
|
|
|
|
* |
|
|
|
|
* @param name must not be {@literal null} or empty. |
|
|
|
|
* @param entity must not be {@literal null}. |
|
|
|
|
* @param context must not be {@literal null}. |
|
|
|
|
@ -788,7 +788,7 @@ public class QueryMapper {
@@ -788,7 +788,7 @@ public class QueryMapper {
|
|
|
|
|
return DEFAULT_ID_NAMES.contains(name); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/* |
|
|
|
|
/* |
|
|
|
|
* (non-Javadoc) |
|
|
|
|
* @see org.springframework.data.mongodb.core.convert.QueryMapper.Field#getProperty() |
|
|
|
|
*/ |
|
|
|
|
@ -797,7 +797,7 @@ public class QueryMapper {
@@ -797,7 +797,7 @@ public class QueryMapper {
|
|
|
|
|
return association == null ? property : association.getInverse(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/* |
|
|
|
|
/* |
|
|
|
|
* (non-Javadoc) |
|
|
|
|
* @see org.springframework.data.mongodb.core.convert.QueryMapper.Field#getEntity() |
|
|
|
|
*/ |
|
|
|
|
@ -807,7 +807,7 @@ public class QueryMapper {
@@ -807,7 +807,7 @@ public class QueryMapper {
|
|
|
|
|
return property == null ? null : mappingContext.getPersistentEntity(property); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/* |
|
|
|
|
/* |
|
|
|
|
* (non-Javadoc) |
|
|
|
|
* @see org.springframework.data.mongodb.core.convert.QueryMapper.Field#isAssociation() |
|
|
|
|
*/ |
|
|
|
|
@ -816,7 +816,7 @@ public class QueryMapper {
@@ -816,7 +816,7 @@ public class QueryMapper {
|
|
|
|
|
return association != null; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/* |
|
|
|
|
/* |
|
|
|
|
* (non-Javadoc) |
|
|
|
|
* @see org.springframework.data.mongodb.core.convert.QueryMapper.Field#getAssociation() |
|
|
|
|
*/ |
|
|
|
|
@ -827,7 +827,7 @@ public class QueryMapper {
@@ -827,7 +827,7 @@ public class QueryMapper {
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Finds the association property in the {@link PersistentPropertyPath}. |
|
|
|
|
* |
|
|
|
|
* |
|
|
|
|
* @return |
|
|
|
|
*/ |
|
|
|
|
private final Association<MongoPersistentProperty> findAssociation() { |
|
|
|
|
@ -858,7 +858,7 @@ public class QueryMapper {
@@ -858,7 +858,7 @@ public class QueryMapper {
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Returns the {@link PersistentPropertyPath} for the given <code>pathExpression</code>. |
|
|
|
|
* |
|
|
|
|
* |
|
|
|
|
* @param pathExpression |
|
|
|
|
* @return |
|
|
|
|
*/ |
|
|
|
|
@ -895,7 +895,7 @@ public class QueryMapper {
@@ -895,7 +895,7 @@ public class QueryMapper {
|
|
|
|
|
/** |
|
|
|
|
* Return the {@link Converter} to be used to created the mapped key. Default implementation will use |
|
|
|
|
* {@link PropertyToFieldNameConverter}. |
|
|
|
|
* |
|
|
|
|
* |
|
|
|
|
* @return |
|
|
|
|
*/ |
|
|
|
|
protected Converter<MongoPersistentProperty, String> getPropertyConverter() { |
|
|
|
|
@ -905,7 +905,7 @@ public class QueryMapper {
@@ -905,7 +905,7 @@ public class QueryMapper {
|
|
|
|
|
/** |
|
|
|
|
* Return the {@link Converter} to use for creating the mapped key of an association. Default implementation is |
|
|
|
|
* {@link AssociationConverter}. |
|
|
|
|
* |
|
|
|
|
* |
|
|
|
|
* @return |
|
|
|
|
* @since 1.7 |
|
|
|
|
*/ |
|
|
|
|
@ -935,7 +935,7 @@ public class QueryMapper {
@@ -935,7 +935,7 @@ public class QueryMapper {
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/* |
|
|
|
|
/* |
|
|
|
|
* (non-Javadoc) |
|
|
|
|
* @see org.springframework.data.mongodb.core.convert.QueryMapper.Field#getTypeHint() |
|
|
|
|
*/ |
|
|
|
|
@ -972,7 +972,7 @@ public class QueryMapper {
@@ -972,7 +972,7 @@ public class QueryMapper {
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Maps the property name while retaining potential positional operator {@literal $}. |
|
|
|
|
* |
|
|
|
|
* |
|
|
|
|
* @param property |
|
|
|
|
* @return |
|
|
|
|
*/ |
|
|
|
|
@ -1014,7 +1014,7 @@ public class QueryMapper {
@@ -1014,7 +1014,7 @@ public class QueryMapper {
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Converter to skip all properties after an association property was rendered. |
|
|
|
|
* |
|
|
|
|
* |
|
|
|
|
* @author Oliver Gierke |
|
|
|
|
*/ |
|
|
|
|
protected static class AssociationConverter implements Converter<MongoPersistentProperty, String> { |
|
|
|
|
@ -1024,7 +1024,7 @@ public class QueryMapper {
@@ -1024,7 +1024,7 @@ public class QueryMapper {
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Creates a new {@link AssociationConverter} for the given {@link Association}. |
|
|
|
|
* |
|
|
|
|
* |
|
|
|
|
* @param association must not be {@literal null}. |
|
|
|
|
*/ |
|
|
|
|
public AssociationConverter(Association<MongoPersistentProperty> association) { |
|
|
|
|
@ -1033,7 +1033,7 @@ public class QueryMapper {
@@ -1033,7 +1033,7 @@ public class QueryMapper {
|
|
|
|
|
this.property = association.getInverse(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/* |
|
|
|
|
/* |
|
|
|
|
* (non-Javadoc) |
|
|
|
|
* @see org.springframework.core.convert.converter.Converter#convert(java.lang.Object) |
|
|
|
|
*/ |
|
|
|
|
|