Browse Source

DATADOC-40 - Repositories now pick up collection name from mapping metadata if available.

We also pick up the ID attribute to be used to determine isNew(…) if the RepositoryFactoryBean gets a MappingContext injected. Collection name of mapping defaults to the simple class name.
pull/1/head
Oliver Gierke 15 years ago
parent
commit
d69b890a70
  1. 20
      spring-data-mongodb/src/main/java/org/springframework/data/document/mongodb/mapping/MongoPersistentEntity.java
  2. 80
      spring-data-mongodb/src/main/java/org/springframework/data/document/mongodb/repository/MappingMongoEntityInformation.java
  3. 87
      spring-data-mongodb/src/main/java/org/springframework/data/document/mongodb/repository/MongoEntityInformation.java
  4. 5
      spring-data-mongodb/src/main/java/org/springframework/data/document/mongodb/repository/MongoQueryMethod.java
  5. 55
      spring-data-mongodb/src/main/java/org/springframework/data/document/mongodb/repository/MongoRepositoryFactoryBean.java
  6. 2
      spring-data-mongodb/src/main/java/org/springframework/data/document/mongodb/repository/QueryDslMongoRepository.java
  7. 111
      spring-data-mongodb/src/main/java/org/springframework/data/document/mongodb/repository/SimpleMongoEntityInformation.java
  8. 2
      spring-data-mongodb/src/main/java/org/springframework/data/document/mongodb/repository/SimpleMongoRepository.java
  9. 26
      spring-data-mongodb/src/test/java/org/springframework/data/document/mongodb/repository/MongoRepositoryFactoryUnitTests.java
  10. 10
      spring-data-mongodb/src/test/java/org/springframework/data/document/mongodb/repository/SimpleMongoEntityInformationUnitTests.java
  11. 9
      spring-data-mongodb/src/test/java/org/springframework/data/document/mongodb/repository/StringBasedMongoQueryUnitTests.java
  12. 5
      spring-data-mongodb/src/test/resources/infrastructure.xml
  13. 13
      spring-data-mongodb/src/test/resources/org/springframework/data/document/mongodb/repository/PersonRepositoryIntegrationTests-context.xml

20
spring-data-mongodb/src/main/java/org/springframework/data/document/mongodb/mapping/MongoPersistentEntity.java

@ -18,24 +18,42 @@ package org.springframework.data.document.mongodb.mapping; @@ -18,24 +18,42 @@ package org.springframework.data.document.mongodb.mapping;
import org.springframework.data.mapping.BasicPersistentEntity;
import org.springframework.data.mapping.model.MappingContext;
import org.springframework.data.mapping.model.PersistentEntity;
import org.springframework.data.util.TypeInformation;
/**
* Mongo specific {@link PersistentEntity} implementation that adds Mongo specific meta-data such as the collection name
* and the like.
*
* @author Jon Brisbin <jbrisbin@vmware.com>
* @author Oliver Gierke
*/
public class MongoPersistentEntity<T> extends BasicPersistentEntity<T> {
protected String collection;
/**
* Creates a new {@link MongoPersistentEntity} with the given {@link MappingContext} and {@link TypeInformation}. Will
* default the collection name to the entities simple type name.
*
* @param mappingContext
* @param typeInformation
*/
public MongoPersistentEntity(MappingContext mappingContext, TypeInformation typeInformation) {
super(mappingContext, typeInformation);
this.collection = typeInformation.getType().getSimpleName();
}
/**
* Returns the collection the entity should be stored in.
*
* @return
*/
public String getCollection() {
return collection;
}
public void setCollection(String collection) {
this.collection = collection;
}

80
spring-data-mongodb/src/main/java/org/springframework/data/document/mongodb/repository/MappingMongoEntityInformation.java

@ -0,0 +1,80 @@ @@ -0,0 +1,80 @@
/*
* Copyright (c) 2011 by the original author(s).
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.document.mongodb.repository;
import java.io.Serializable;
import org.springframework.data.document.mongodb.mapping.MongoPersistentEntity;
import org.springframework.data.mapping.MappingBeanHelper;
import org.springframework.data.mapping.model.PersistentProperty;
import org.springframework.data.repository.support.AbstractEntityInformation;
/**
* {@link MongoEntityInformation} implementation using a {@link MongoPersistentEntity} instance to lookup the necessary
* information.
*
* @author Oliver Gierke
*/
public class MappingMongoEntityInformation<T, ID extends Serializable> extends AbstractEntityInformation<T, ID>
implements MongoEntityInformation<T, ID> {
private final MongoPersistentEntity<T> entityMetadata;
/**
* Creates a new {@link MappingMongoEntityInformation} for the given {@link MongoPersistentEntity}.
*
* @param domainClass
* @param entity
*/
public MappingMongoEntityInformation(MongoPersistentEntity<T> entity) {
super(entity.getType());
this.entityMetadata = entity;
}
/* (non-Javadoc)
* @see org.springframework.data.repository.support.EntityInformation#getId(java.lang.Object)
*/
public ID getId(T entity) {
PersistentProperty idProperty = entityMetadata.getIdProperty();
try {
return (ID) MappingBeanHelper.getProperty(entity, idProperty, idProperty.getType(), false);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
/* (non-Javadoc)
* @see org.springframework.data.repository.support.EntityInformation#getIdType()
*/
public Class<ID> getIdType() {
return (Class<ID>) entityMetadata.getIdProperty().getType();
}
/* (non-Javadoc)
* @see org.springframework.data.document.mongodb.repository.MongoEntityInformation#getCollectionName()
*/
public String getCollectionName() {
return entityMetadata.getCollection();
}
/* (non-Javadoc)
* @see org.springframework.data.document.mongodb.repository.MongoEntityInformation#getIdAttribute()
*/
public String getIdAttribute() {
return "_id";
}
}

87
spring-data-mongodb/src/main/java/org/springframework/data/document/mongodb/repository/MongoEntityInformation.java

@ -1,11 +1,11 @@ @@ -1,11 +1,11 @@
/*
* Copyright (c) 2011 by the original author(s).
* Copyright 2011 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@ -16,100 +16,27 @@ @@ -16,100 +16,27 @@
package org.springframework.data.document.mongodb.repository;
import java.io.Serializable;
import java.lang.reflect.Field;
import java.util.Arrays;
import java.util.List;
import org.springframework.data.repository.support.AbstractEntityInformation;
import org.springframework.util.ReflectionUtils;
import org.springframework.util.StringUtils;
import org.springframework.data.repository.support.EntityInformation;
/**
* Expects the domain class to contain a field with a name out of the following
* {@value #FIELD_NAMES}.
* Mongo specific {@link EntityInformation}.
*
* @author Oliver Gierke
*/
class MongoEntityInformation<T extends Object, ID extends Serializable> extends AbstractEntityInformation<T, ID> {
private static final List<String> FIELD_NAMES = Arrays.asList("ID", "id", "_id");
private Field field;
/**
* Creates a new {@link MongoEntityInformation}.
*
* @param domainClass
*/
public MongoEntityInformation(Class<T> domainClass) {
super(domainClass);
for (String name : FIELD_NAMES) {
Field candidate = ReflectionUtils.findField(domainClass, name);
if (candidate != null) {
ReflectionUtils.makeAccessible(candidate);
this.field = candidate;
break;
}
}
if (this.field == null) {
throw new IllegalArgumentException(String.format(
"Given domain class %s does not contain an id property!",
domainClass.getName()));
}
}
interface MongoEntityInformation<T, ID extends Serializable> extends EntityInformation<T, ID> {
/**
* Returns the name of the collection the entity shall be persisted to.
*
* @return
*/
public String getCollectionName() {
return StringUtils.uncapitalize(getJavaType().getSimpleName());
}
String getCollectionName();
/**
* Returns the attribute that the id will be persisted to.
*
* @return
*/
public String getIdAttribute() {
return "_id";
}
/*
* (non-Javadoc)
*
* @see
* org.springframework.data.repository.support.IdAware#getId(java.lang.Object
* )
*/
@SuppressWarnings("unchecked")
public ID getId(Object entity) {
return (ID) ReflectionUtils.getField(field, entity);
}
/*
* (non-Javadoc)
*
* @see
* org.springframework.data.repository.support.EntityInformation#getIdType()
*/
@SuppressWarnings("unchecked")
public Class<ID> getIdType() {
return (Class<ID>) field.getType();
}
String getIdAttribute();
}

5
spring-data-mongodb/src/main/java/org/springframework/data/document/mongodb/repository/MongoQueryMethod.java

@ -18,6 +18,7 @@ package org.springframework.data.document.mongodb.repository; @@ -18,6 +18,7 @@ package org.springframework.data.document.mongodb.repository;
import java.lang.reflect.Method;
import org.springframework.core.annotation.AnnotationUtils;
import org.springframework.data.document.mongodb.repository.MongoRepositoryFactoryBean.EntityInformationCreator;
import org.springframework.data.repository.query.QueryMethod;
import org.springframework.data.repository.util.ClassUtils;
import org.springframework.util.StringUtils;
@ -39,10 +40,10 @@ class MongoQueryMethod extends QueryMethod { @@ -39,10 +40,10 @@ class MongoQueryMethod extends QueryMethod {
* @param method
*/
@SuppressWarnings({ "rawtypes", "unchecked" })
public MongoQueryMethod(Method method, Class<?> domainClass) {
public MongoQueryMethod(Method method, EntityInformationCreator entityInformationCreator) {
super(method);
this.method = method;
this.entityInformation = new MongoEntityInformation(ClassUtils.getReturnedDomainClass(method));
this.entityInformation = entityInformationCreator.getEntityInformation(ClassUtils.getReturnedDomainClass(method));
}
/**

55
spring-data-mongodb/src/main/java/org/springframework/data/document/mongodb/repository/MongoRepositoryFactoryBean.java

@ -23,9 +23,12 @@ import org.slf4j.LoggerFactory; @@ -23,9 +23,12 @@ import org.slf4j.LoggerFactory;
import org.springframework.data.document.mongodb.MongoOperations;
import org.springframework.data.document.mongodb.MongoPropertyDescriptors.MongoPropertyDescriptor;
import org.springframework.data.document.mongodb.MongoTemplate;
import org.springframework.data.document.mongodb.mapping.MongoPersistentEntity;
import org.springframework.data.document.mongodb.query.Index;
import org.springframework.data.document.mongodb.query.Order;
import org.springframework.data.domain.Sort;
import org.springframework.data.mapping.model.MappingContext;
import org.springframework.data.mapping.model.PersistentEntity;
import org.springframework.data.repository.query.QueryLookupStrategy;
import org.springframework.data.repository.query.QueryLookupStrategy.Key;
import org.springframework.data.repository.query.RepositoryQuery;
@ -47,6 +50,7 @@ public class MongoRepositoryFactoryBean<T extends MongoRepository<S, ID>, S, ID @@ -47,6 +50,7 @@ public class MongoRepositoryFactoryBean<T extends MongoRepository<S, ID>, S, ID
RepositoryFactoryBeanSupport<T, S, ID> {
private MongoTemplate template;
private MappingContext mappingContext;
/**
* Configures the {@link MongoTemplate} to be used.
@ -58,6 +62,15 @@ public class MongoRepositoryFactoryBean<T extends MongoRepository<S, ID>, S, ID @@ -58,6 +62,15 @@ public class MongoRepositoryFactoryBean<T extends MongoRepository<S, ID>, S, ID
this.template = template;
}
/**
* Sets the {@link MappingContext} used with the underlying {@link MongoTemplate}.
*
* @param mappingContext the mappingContext to set
*/
public void setMappingContext(MappingContext mappingContext) {
this.mappingContext = mappingContext;
}
/*
* (non-Javadoc)
@ -69,7 +82,7 @@ public class MongoRepositoryFactoryBean<T extends MongoRepository<S, ID>, S, ID @@ -69,7 +82,7 @@ public class MongoRepositoryFactoryBean<T extends MongoRepository<S, ID>, S, ID
@Override
protected RepositoryFactorySupport createRepositoryFactory() {
MongoRepositoryFactory factory = new MongoRepositoryFactory(template);
MongoRepositoryFactory factory = new MongoRepositoryFactory(template, mappingContext);
factory.addQueryCreationListener(new IndexEnsuringQueryCreationListener(template));
return factory;
}
@ -99,15 +112,19 @@ public class MongoRepositoryFactoryBean<T extends MongoRepository<S, ID>, S, ID @@ -99,15 +112,19 @@ public class MongoRepositoryFactoryBean<T extends MongoRepository<S, ID>, S, ID
"com.mysema.query.types.Predicate", MongoRepositoryFactory.class.getClassLoader());
private final MongoTemplate template;
private final EntityInformationCreator entityInformationCreator;
/**
* Creates a new {@link MongoRepositoryFactory} fwith the given {@link MongoTemplate}.
* Creates a new {@link MongoRepositoryFactory} with the given {@link MongoTemplate} and {@link MappingContext}.
*
* @param template
* @param template must not be {@literal null}
* @param mappingContext
*/
public MongoRepositoryFactory(MongoTemplate template) {
public MongoRepositoryFactory(MongoTemplate template, MappingContext mappingContext) {
Assert.notNull(template);
this.template = template;
this.entityInformationCreator = new EntityInformationCreator(mappingContext);
}
/*
@ -180,7 +197,7 @@ public class MongoRepositoryFactoryBean<T extends MongoRepository<S, ID>, S, ID @@ -180,7 +197,7 @@ public class MongoRepositoryFactoryBean<T extends MongoRepository<S, ID>, S, ID
*/
public RepositoryQuery resolveQuery(Method method, Class<?> domainClass) {
MongoQueryMethod queryMethod = new MongoQueryMethod(method, domainClass);
MongoQueryMethod queryMethod = new MongoQueryMethod(method, entityInformationCreator);
if (queryMethod.hasAnnotatedQuery()) {
return new StringBasedMongoQuery(queryMethod, template);
@ -219,7 +236,33 @@ public class MongoRepositoryFactoryBean<T extends MongoRepository<S, ID>, S, ID @@ -219,7 +236,33 @@ public class MongoRepositoryFactoryBean<T extends MongoRepository<S, ID>, S, ID
@Override
public <T, ID extends Serializable> MongoEntityInformation<T, ID> getEntityInformation(Class<T> domainClass) {
return new MongoEntityInformation<T, ID>(domainClass);
return entityInformationCreator.getEntityInformation(domainClass);
}
}
/**
* Simple wrapper to to create {@link MongoEntityInformation} instances based on a {@link MappingContext}.
*
* @author Oliver Gierke
*/
static class EntityInformationCreator {
private final MappingContext mappingContext;
public EntityInformationCreator(MappingContext mappingContext) {
this.mappingContext = mappingContext;
}
public <T, ID extends Serializable> MongoEntityInformation<T, ID> getEntityInformation(Class<T> domainClass) {
if (null == mappingContext) {
return new SimpleMongoEntityInformation<T, ID>(domainClass);
}
PersistentEntity<T> persistentEntity = mappingContext.getPersistentEntity(domainClass);
if (persistentEntity == null) {
persistentEntity = mappingContext.addPersistentEntity(domainClass);
}
return new MappingMongoEntityInformation<T, ID>((MongoPersistentEntity<T>) persistentEntity);
}
}

2
spring-data-mongodb/src/main/java/org/springframework/data/document/mongodb/repository/QueryDslMongoRepository.java

@ -76,7 +76,7 @@ public class QueryDslMongoRepository<T, ID extends Serializable> extends @@ -76,7 +76,7 @@ public class QueryDslMongoRepository<T, ID extends Serializable> extends
/**
* Creates a new {@link QueryDslMongoRepository} for the given domain class,
* Creates a new {@link QueryDslMongoRepository} for the given {@link MongoEntityInformation},
* {@link MongoTemplate} and {@link EntityPathResolver}.
*
* @param entityInformation

111
spring-data-mongodb/src/main/java/org/springframework/data/document/mongodb/repository/SimpleMongoEntityInformation.java

@ -0,0 +1,111 @@ @@ -0,0 +1,111 @@
/*
* Copyright (c) 2011 by the original author(s).
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.document.mongodb.repository;
import java.io.Serializable;
import java.lang.reflect.Field;
import java.util.Arrays;
import java.util.List;
import org.springframework.data.repository.support.AbstractEntityInformation;
import org.springframework.util.ReflectionUtils;
import org.springframework.util.StringUtils;
/**
* Expects the domain class to contain a field with a name out of the following
* {@value #FIELD_NAMES}.
*
* @author Oliver Gierke
*/
class SimpleMongoEntityInformation<T extends Object, ID extends Serializable> extends AbstractEntityInformation<T, ID> implements MongoEntityInformation<T, ID> {
private static final List<String> FIELD_NAMES = Arrays.asList("ID", "id", "_id");
private Field field;
/**
* Creates a new {@link SimpleMongoEntityInformation}.
*
* @param domainClass
*/
public SimpleMongoEntityInformation(Class<T> domainClass) {
super(domainClass);
for (String name : FIELD_NAMES) {
Field candidate = ReflectionUtils.findField(domainClass, name);
if (candidate != null) {
ReflectionUtils.makeAccessible(candidate);
this.field = candidate;
break;
}
}
if (this.field == null) {
throw new IllegalArgumentException(String.format(
"Given domain class %s does not contain an id property!",
domainClass.getName()));
}
}
/* (non-Javadoc)
* @see org.springframework.data.document.mongodb.repository.MongoEntityInformation#getCollectionName()
*/
public String getCollectionName() {
return StringUtils.uncapitalize(getJavaType().getSimpleName());
}
/* (non-Javadoc)
* @see org.springframework.data.document.mongodb.repository.MongoEntityInformation#getIdAttribute()
*/
public String getIdAttribute() {
return "_id";
}
/*
* (non-Javadoc)
*
* @see
* org.springframework.data.repository.support.IdAware#getId(java.lang.Object
* )
*/
@SuppressWarnings("unchecked")
public ID getId(Object entity) {
return (ID) ReflectionUtils.getField(field, entity);
}
/*
* (non-Javadoc)
*
* @see
* org.springframework.data.repository.support.EntityInformation#getIdType()
*/
@SuppressWarnings("unchecked")
public Class<ID> getIdType() {
return (Class<ID>) field.getType();
}
}

2
spring-data-mongodb/src/main/java/org/springframework/data/document/mongodb/repository/SimpleMongoRepository.java

@ -45,7 +45,7 @@ public class SimpleMongoRepository<T, ID extends Serializable> implements Paging @@ -45,7 +45,7 @@ public class SimpleMongoRepository<T, ID extends Serializable> implements Paging
private final MongoEntityInformation<T, ID> entityInformation;
/**
* Creates a ew {@link SimpleMongoRepository} for the given {@link MongoInformation} and {@link MongoTemplate}.
* Creates a ew {@link SimpleMongoRepository} for the given {@link MongoEntityInformation} and {@link MongoTemplate}.
*
* @param metadata
* @param template

26
spring-data-mongodb/src/test/java/org/springframework/data/document/mongodb/repository/MongoRepositoryFactoryUnitTests.java

@ -15,12 +15,19 @@ @@ -15,12 +15,19 @@
*/
package org.springframework.data.document.mongodb.repository;
import static org.junit.Assert.*;
import static org.mockito.Mockito.*;
import java.io.Serializable;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import org.springframework.data.document.mongodb.MongoTemplate;
import org.springframework.data.document.mongodb.mapping.MongoPersistentEntity;
import org.springframework.data.document.mongodb.repository.MongoRepositoryFactoryBean.MongoRepositoryFactory;
import org.springframework.data.mapping.model.MappingContext;
/**
* Unit test for {@link MongoRepositoryFactory}.
@ -33,11 +40,28 @@ public class MongoRepositoryFactoryUnitTests { @@ -33,11 +40,28 @@ public class MongoRepositoryFactoryUnitTests {
@Mock
MongoTemplate template;
@Mock
MappingContext mappingContext;
@Mock
MongoPersistentEntity<Person> entity;
@Test(expected = IllegalArgumentException.class)
public void rejectsInvalidIdType() throws Exception {
MongoRepositoryFactory factory = new MongoRepositoryFactory(template);
MongoRepositoryFactory factory = new MongoRepositoryFactory(template, null);
factory.getRepository(SampleRepository.class);
}
@Test
public void usesMappingMongoEntityInformationIfMappingContextSet() {
when(mappingContext.getPersistentEntity(Person.class)).thenReturn(entity);
when(entity.getType()).thenReturn(Person.class);
MongoRepositoryFactory factory = new MongoRepositoryFactory(template, mappingContext);
MongoEntityInformation<Person,Serializable> entityInformation = factory.getEntityInformation(Person.class);
assertTrue(entityInformation instanceof MappingMongoEntityInformation);
}
private interface SampleRepository extends MongoRepository<Person, Long> {

10
spring-data-mongodb/src/test/java/org/springframework/data/document/mongodb/repository/MongoEntityMetadataUnitTests.java → spring-data-mongodb/src/test/java/org/springframework/data/document/mongodb/repository/SimpleMongoEntityInformationUnitTests.java

@ -22,17 +22,17 @@ import org.junit.Test; @@ -22,17 +22,17 @@ import org.junit.Test;
/**
* Unit test for {@link MongoEntityInformation}.
* Unit test for {@link SimpleMongoEntityInformation}.
*
* @author Oliver Gierke
*/
public class MongoEntityMetadataUnitTests {
public class SimpleMongoEntityInformationUnitTests {
@Test
public void findsIdField() throws Exception {
MongoEntityInformation<Person, Long> isNewAware =
new MongoEntityInformation<Person, Long>(Person.class);
SimpleMongoEntityInformation<Person, Long> isNewAware =
new SimpleMongoEntityInformation<Person, Long>(Person.class);
Person person = new Person();
assertThat(isNewAware.isNew(person), is(true));
@ -44,7 +44,7 @@ public class MongoEntityMetadataUnitTests { @@ -44,7 +44,7 @@ public class MongoEntityMetadataUnitTests {
@Test(expected = IllegalArgumentException.class)
public void rejectsClassIfNoIdField() throws Exception {
new MongoEntityInformation<InvalidPerson, Long>(InvalidPerson.class);
new SimpleMongoEntityInformation<InvalidPerson, Long>(InvalidPerson.class);
}
class Person {

9
spring-data-mongodb/src/test/java/org/springframework/data/document/mongodb/repository/StringBasedMongoQueryUnitTests.java

@ -15,9 +15,9 @@ @@ -15,9 +15,9 @@
*/
package org.springframework.data.document.mongodb.repository;
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertThat;
import static org.mockito.Mockito.when;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
import static org.mockito.Mockito.*;
import java.lang.reflect.Method;
@ -30,6 +30,7 @@ import org.springframework.data.document.mongodb.MongoTemplate; @@ -30,6 +30,7 @@ import org.springframework.data.document.mongodb.MongoTemplate;
import org.springframework.data.document.mongodb.convert.MongoConverter;
import org.springframework.data.document.mongodb.convert.SimpleMongoConverter;
import org.springframework.data.document.mongodb.query.BasicQuery;
import org.springframework.data.document.mongodb.repository.MongoRepositoryFactoryBean.EntityInformationCreator;
/**
* Unit tests for {@link StringBasedMongoQuery}.
@ -52,7 +53,7 @@ public class StringBasedMongoQueryUnitTests { @@ -52,7 +53,7 @@ public class StringBasedMongoQueryUnitTests {
public void testname() throws Exception {
Method method = SampleRepository.class.getMethod("findByLastname", String.class);
MongoQueryMethod queryMethod = new MongoQueryMethod(method, Person.class);
MongoQueryMethod queryMethod = new MongoQueryMethod(method, new EntityInformationCreator(null));
StringBasedMongoQuery mongoQuery = new StringBasedMongoQuery(queryMethod, template);
ConvertingParameterAccessor accesor = StubParameterAccessor.getAccessor(converter, "Matthews");

5
spring-data-mongodb/src/test/resources/infrastructure.xml

@ -12,8 +12,9 @@ @@ -12,8 +12,9 @@
<constructor-arg ref="mongo"/>
<constructor-arg value="database"/>
<property name="defaultCollectionName" value="springdata"/>
<property name="mongoConverter" ref="mongoConverter" />
</bean>
<bean class="org.springframework.data.document.mongodb.MongoExceptionTranslator"/>
<bean id="mongoConverter" class="org.springframework.data.document.mongodb.convert.SimpleMongoConverter" />
</beans>

13
spring-data-mongodb/src/test/resources/org/springframework/data/document/mongodb/repository/PersonRepositoryIntegrationTests-context.xml

@ -7,7 +7,20 @@ @@ -7,7 +7,20 @@
<bean class="org.springframework.data.document.mongodb.repository.MongoRepositoryFactoryBean">
<property name="template" ref="mongoTemplate"/>
<property name="mappingContext" ref="mappingContext" />
<property name="repositoryInterface" value="org.springframework.data.document.mongodb.repository.PersonRepository"/>
</bean>
<bean id="mappingContext" class="org.springframework.data.mapping.BasicMappingContext">
<property name="mappingConfigurationBuilder">
<bean class="org.springframework.data.document.mongodb.mapping.MongoMappingConfigurationBuilder">
<constructor-arg ref="mongoTemplate" />
</bean>
</property>
</bean>
<bean id="mongoConverter" class="org.springframework.data.document.mongodb.convert.MappingMongoConverter">
<constructor-arg ref="mappingContext" />
</bean>
</beans>

Loading…
Cancel
Save