DATAKV-123 - Introduced dedicated KeyValueRepositoryFactoryBean.createRepositoryFactory(…).

We now expose a dedicated method for implementors to use to create the repository factory instance based on the configuration of the factory.

Added unit tests to make sure the factory bean fails fast if it's configured improperly.

Original Pull Request: #17
This commit is contained in:
Oliver Gierke
2016-01-26 12:42:02 +01:00
committed by Christoph Strobl
parent 40fe2addac
commit 874b2bc880
2 changed files with 170 additions and 3 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2014 the original author or authors.
* Copyright 2014-2016 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.
@@ -19,16 +19,19 @@ import java.io.Serializable;
import org.springframework.data.keyvalue.core.KeyValueOperations;
import org.springframework.data.keyvalue.repository.KeyValueRepository;
import org.springframework.data.keyvalue.repository.config.QueryCreatorType;
import org.springframework.data.mapping.context.MappingContext;
import org.springframework.data.repository.Repository;
import org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport;
import org.springframework.data.repository.core.support.RepositoryFactorySupport;
import org.springframework.data.repository.query.parser.AbstractQueryCreator;
import org.springframework.util.Assert;
/**
* {@link org.springframework.beans.factory.FactoryBean} to create {@link KeyValueRepository}.
*
* @author Christoph Strobl
* @author Oliver Gierke
*/
public class KeyValueRepositoryFactoryBean<T extends Repository<S, ID>, S, ID extends Serializable> extends
RepositoryFactoryBeanSupport<T, S, ID> {
@@ -36,7 +39,15 @@ public class KeyValueRepositoryFactoryBean<T extends Repository<S, ID>, S, ID ex
private KeyValueOperations operations;
private Class<? extends AbstractQueryCreator<?, ?>> queryCreator;
/**
* Configures the {@link KeyValueOperations} to be used for the repositories.
*
* @param operations must not be {@literal null}.
*/
public void setKeyValueOperations(KeyValueOperations operations) {
Assert.notNull(operations, "KeyValueOperations must not be null!");
this.operations = operations;
}
@@ -49,7 +60,15 @@ public class KeyValueRepositoryFactoryBean<T extends Repository<S, ID>, S, ID ex
super.setMappingContext(mappingContext);
}
/**
* Configures the {@link QueryCreatorType} to be used.
*
* @param queryCreator must not be {@literal null}.
*/
public void setQueryCreator(Class<? extends AbstractQueryCreator<?, ?>> queryCreator) {
Assert.notNull(queryCreator, "Query creator type must not be null!");
this.queryCreator = queryCreator;
}
@@ -58,8 +77,22 @@ public class KeyValueRepositoryFactoryBean<T extends Repository<S, ID>, S, ID ex
* @see org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport#createRepositoryFactory()
*/
@Override
protected RepositoryFactorySupport createRepositoryFactory() {
return new KeyValueRepositoryFactory(this.operations, this.queryCreator);
protected final RepositoryFactorySupport createRepositoryFactory() {
return createRepositoryFactory(operations, queryCreator);
}
/**
* Create the repository factory to be used to create repositories.
*
* @param operations will never be {@literal null}.
* @param queryCreator will never be {@literal null}.
* @return must not be {@literal null}.
* @since 1.1
*/
protected KeyValueRepositoryFactory createRepositoryFactory(KeyValueOperations operations,
Class<? extends AbstractQueryCreator<?, ?>> queryCreator) {
return new KeyValueRepositoryFactory(operations, queryCreator);
}
/*
@@ -68,6 +101,10 @@ public class KeyValueRepositoryFactoryBean<T extends Repository<S, ID>, S, ID ex
*/
@Override
public void afterPropertiesSet() {
Assert.notNull(operations, "KeyValueOperations must not be null!");
Assert.notNull(queryCreator, "Query creator type must not be null!");
super.afterPropertiesSet();
}
}