DATAJDBC-155 - Polishing.

Update Javadoc, assert state, default nullable properties in afterPropertiesSets and add tests.

Original pull request: #54.
This commit is contained in:
Christoph Strobl
2018-03-27 13:11:52 +02:00
parent aaae9a5f5c
commit db2b44db63
3 changed files with 63 additions and 13 deletions

View File

@@ -30,13 +30,15 @@ import org.springframework.data.repository.core.RepositoryMetadata;
import org.springframework.data.repository.core.support.RepositoryFactorySupport;
import org.springframework.data.repository.query.EvaluationContextProvider;
import org.springframework.data.repository.query.QueryLookupStrategy;
import org.springframework.util.Assert;
/**
* Creates repository implementation based on JDBC.
*
* @author Jens Schauder
* @author Greg Turnquist
* @since 2.0
* @author Christoph Strobl
* @since 1.0
*/
public class JdbcRepositoryFactory extends RepositoryFactorySupport {
@@ -89,7 +91,12 @@ public class JdbcRepositoryFactory extends RepositoryFactorySupport {
return Optional.of(new JdbcQueryLookupStrategy(evaluationContextProvider, context, accessStrategy, rowMapperMap));
}
/**
* @param rowMapperMap must not be {@literal null} consider {@link RowMapperMap#EMPTY} instead.
*/
public void setRowMapperMap(RowMapperMap rowMapperMap) {
Assert.notNull(rowMapperMap, "RowMapperMap must not be null!");
this.rowMapperMap = rowMapperMap;
}
}

View File

@@ -36,7 +36,8 @@ import org.springframework.util.Assert;
*
* @author Jens Schauder
* @author Greg Turnquist
* @since 2.0
* @author Christoph Strobl
* @since 1.0
*/
public class JdbcRepositoryFactoryBean<T extends Repository<S, ID>, S, ID extends Serializable> //
extends TransactionalRepositoryFactoryBeanSupport<T, S, ID> implements ApplicationEventPublisherAware {
@@ -67,10 +68,7 @@ public class JdbcRepositoryFactoryBean<T extends Repository<S, ID>, S, ID extend
JdbcRepositoryFactory jdbcRepositoryFactory = new JdbcRepositoryFactory(publisher, mappingContext,
dataAccessStrategy);
if (rowMapperMap != null) {
jdbcRepositoryFactory.setRowMapperMap(rowMapperMap);
}
jdbcRepositoryFactory.setRowMapperMap(rowMapperMap);
return jdbcRepositoryFactory;
}
@@ -82,11 +80,18 @@ public class JdbcRepositoryFactoryBean<T extends Repository<S, ID>, S, ID extend
this.mappingContext = mappingContext;
}
/**
* @param dataAccessStrategy can be {@literal null}.
*/
@Autowired(required = false)
public void setDataAccessStrategy(DataAccessStrategy dataAccessStrategy) {
this.dataAccessStrategy = dataAccessStrategy;
}
/**
* @param rowMapperMap can be {@literal null}. {@link #afterPropertiesSet()} defaults to {@link RowMapperMap#EMPTY} if
* {@literal null}.
*/
@Autowired(required = false)
public void setRowMapperMap(RowMapperMap rowMapperMap) {
this.rowMapperMap = rowMapperMap;
@@ -95,7 +100,7 @@ public class JdbcRepositoryFactoryBean<T extends Repository<S, ID>, S, ID extend
@Override
public void afterPropertiesSet() {
Assert.notNull(this.mappingContext, "MappingContext must not be null!");
Assert.state(this.mappingContext != null, "MappingContext is required and must not be null!");
if (dataAccessStrategy == null) {
@@ -104,6 +109,10 @@ public class JdbcRepositoryFactoryBean<T extends Repository<S, ID>, S, ID extend
mappingContext);
}
if (rowMapperMap == null) {
rowMapperMap = RowMapperMap.EMPTY;
}
super.afterPropertiesSet();
}
}