DATAMONGO-1566 - Adapt API in MongoRepositoryFactoryBean.

Related tickets: DATACMNS-891.
This commit is contained in:
Oliver Gierke
2016-12-15 14:57:10 +01:00
parent c9c5fe62ca
commit 89a02bb822
5 changed files with 21 additions and 29 deletions

View File

@@ -30,13 +30,22 @@ import org.springframework.util.Assert;
*
* @author Oliver Gierke
*/
public class MongoRepositoryFactoryBean<T extends Repository<S, ID>, S, ID extends Serializable> extends
RepositoryFactoryBeanSupport<T, S, ID> {
public class MongoRepositoryFactoryBean<T extends Repository<S, ID>, S, ID extends Serializable>
extends RepositoryFactoryBeanSupport<T, S, ID> {
private MongoOperations operations;
private boolean createIndexesForQueryMethods = false;
private boolean mappingContextConfigured = false;
/**
* Creates a new {@link MongoRepositoryFactoryBean} for the given repository interface.
*
* @param repositoryInterface must not be {@literal null}.
*/
public MongoRepositoryFactoryBean(Class<? extends T> repositoryInterface) {
super(repositoryInterface);
}
/**
* Configures the {@link MongoOperations} to be used.
*

View File

@@ -97,9 +97,9 @@ public class PerformanceTests {
this.converter = new MappingMongoConverter(new DefaultDbRefResolver(mongoDbFactory), context);
this.operations = new MongoTemplate(new SimpleMongoDbFactory(this.mongo, DATABASE_NAME), converter);
MongoRepositoryFactoryBean<PersonRepository, Person, ObjectId> factory = new MongoRepositoryFactoryBean<PersonRepository, Person, ObjectId>();
MongoRepositoryFactoryBean<PersonRepository, Person, ObjectId> factory = new MongoRepositoryFactoryBean<PersonRepository, Person, ObjectId>(
PersonRepository.class);
factory.setMongoOperations(operations);
factory.setRepositoryInterface(PersonRepository.class);
factory.afterPropertiesSet();
this.repository = factory.getObject();
@@ -125,8 +125,8 @@ public class PerformanceTests {
@Test
public void plainConversion() throws InterruptedException {
Statistics statistics = new Statistics("Plain conversion of " + NUMBER_OF_PERSONS * 100
+ " persons - After %s iterations");
Statistics statistics = new Statistics(
"Plain conversion of " + NUMBER_OF_PERSONS * 100 + " persons - After %s iterations");
List<DBObject> dbObjects = getPersonDBObjects(NUMBER_OF_PERSONS * 100);
@@ -842,8 +842,8 @@ public class PerformanceTests {
*/
@Override
public String toString() {
return times.isEmpty() ? "" : String.format("%s, %s: %s", api, mode,
StringUtils.collectionToCommaDelimitedString(times)) + '\n';
return times.isEmpty() ? ""
: String.format("%s, %s: %s", api, mode, StringUtils.collectionToCommaDelimitedString(times)) + '\n';
}
}

View File

@@ -15,11 +15,6 @@
*/
package org.springframework.data.mongodb.repository.config;
import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.*;
import java.util.Arrays;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
@@ -59,15 +54,4 @@ public class MongoRepositoriesRegistrarIntegrationTests {
@Test
public void testConfiguration() {}
/**
* @see DATAMONGO-901
*/
@Test
public void registersTypePredictingPostProcessor() {
Iterable<String> beanNames = Arrays.asList(context.getBeanDefinitionNames());
assertThat(beanNames, hasItem(containsString("RepositoryFactoryBeanSupport_Predictor")));
}
}

View File

@@ -48,7 +48,7 @@ public class MongoRepositoryFactoryBeanUnitTests {
@SuppressWarnings("rawtypes")
public void addsIndexEnsuringQueryCreationListenerIfConfigured() {
MongoRepositoryFactoryBean factory = new MongoRepositoryFactoryBean();
MongoRepositoryFactoryBean factory = new MongoRepositoryFactoryBean(ContactRepository.class);
factory.setCreateIndexesForQueryMethods(true);
List<Object> listeners = getListenersFromFactory(factory);
@@ -60,7 +60,7 @@ public class MongoRepositoryFactoryBeanUnitTests {
@SuppressWarnings("rawtypes")
public void doesNotAddIndexEnsuringQueryCreationListenerByDefault() {
List<Object> listeners = getListenersFromFactory(new MongoRepositoryFactoryBean());
List<Object> listeners = getListenersFromFactory(new MongoRepositoryFactoryBean(ContactRepository.class));
assertThat(listeners.size(), is(1));
}
@@ -72,7 +72,6 @@ public class MongoRepositoryFactoryBeanUnitTests {
factoryBean.setLazyInit(true);
factoryBean.setMongoOperations(operations);
factoryBean.setRepositoryInterface(ContactRepository.class);
factoryBean.afterPropertiesSet();
RepositoryFactorySupport factory = factoryBean.createRepositoryFactory();

View File

@@ -17,8 +17,8 @@
</bean>
<bean class="org.springframework.data.mongodb.repository.support.MongoRepositoryFactoryBean">
<constructor-arg value="org.springframework.data.mongodb.repository.PersonRepository"/>
<property name="mongoOperations" ref="mongoTemplate"/>
<property name="repositoryInterface" value="org.springframework.data.mongodb.repository.PersonRepository"/>
<property name="namedQueries">
<bean class="org.springframework.data.repository.core.support.PropertiesBasedNamedQueries">
<constructor-arg>
@@ -34,5 +34,5 @@
<bean class="org.springframework.data.mongodb.repository.SampleEvaluationContextExtension"/>
</constructor-arg>
</bean>
</beans>