Skip to content

DATAMONGO-1291 Persistent entity introspection to obtain a document annotation through AnnotationUtils #323

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.expression.BeanFactoryAccessor;
import org.springframework.context.expression.BeanFactoryResolver;
import org.springframework.core.annotation.AnnotationUtils;
import org.springframework.data.annotation.Id;
import org.springframework.data.mapping.Association;
import org.springframework.data.mapping.AssociationHandler;
Expand Down Expand Up @@ -77,7 +78,7 @@ public BasicMongoPersistentEntity(TypeInformation<T> typeInformation) {
Class<?> rawType = typeInformation.getType();
String fallback = MongoCollectionUtils.getPreferredCollectionName(rawType);

Document document = rawType.getAnnotation(Document.class);
Document document = AnnotationUtils.findAnnotation(rawType, Document.class);

this.expression = detectExpression(document);
this.context = new StandardEvaluationContext();
Expand All @@ -96,6 +97,7 @@ public BasicMongoPersistentEntity(TypeInformation<T> typeInformation) {
* (non-Javadoc)
* @see org.springframework.context.ApplicationContextAware#setApplicationContext(org.springframework.context.ApplicationContext)
*/
@Override
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {

context.addPropertyAccessor(new BeanFactoryAccessor());
Expand All @@ -107,6 +109,7 @@ public void setApplicationContext(ApplicationContext applicationContext) throws
* (non-Javadoc)
* @see org.springframework.data.mongodb.core.mapping.MongoPersistentEntity#getCollection()
*/
@Override
public String getCollection() {
return expression == null ? collection : expression.getValue(context, String.class);
}
Expand Down Expand Up @@ -174,6 +177,7 @@ static enum MongoPersistentPropertyComparator implements Comparator<MongoPersist
* (non-Javadoc)
* @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
*/
@Override
public int compare(MongoPersistentProperty o1, MongoPersistentProperty o2) {

if (o1.getFieldOrder() == Integer.MAX_VALUE) {
Expand Down Expand Up @@ -278,10 +282,12 @@ private static class AssertFieldNameUniquenessHandler implements PropertyHandler

private final Map<String, MongoPersistentProperty> properties = new HashMap<String, MongoPersistentProperty>();

@Override
public void doWithPersistentProperty(MongoPersistentProperty persistentProperty) {
assertUniqueness(persistentProperty);
}

@Override
public void doWithAssociation(Association<MongoPersistentProperty> association) {
assertUniqueness(association.getInverse());
}
Expand Down Expand Up @@ -351,9 +357,9 @@ private static void assertPropertyType(MongoPersistentProperty persistentPropert
}
}

throw new MappingException(
String.format("Missmatching types for %s. Found %s expected one of %s.", persistentProperty.getField(),
persistentProperty.getActualType(), StringUtils.arrayToCommaDelimitedString(validMatches)));
throw new MappingException(String.format("Missmatching types for %s. Found %s expected one of %s.",
persistentProperty.getField(), persistentProperty.getActualType(),
StringUtils.arrayToCommaDelimitedString(validMatches)));
}
}
}