mirror of
https://github.com/spring-projects/spring-data-elasticsearch.git
synced 2025-06-25 05:22:10 +00:00
DATAES-329 - Remove references to Assert single-arg methods.
Replace references to Assert single-arg methods with references to methods accepting the test object and message. Related ticket: SPR-15196.
This commit is contained in:
parent
85a95219a1
commit
242460df4c
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013 the original author or authors.
|
* Copyright 2013-2017 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@ -31,8 +31,8 @@ import org.springframework.util.Assert;
|
|||||||
*
|
*
|
||||||
* @author Rizwan Idrees
|
* @author Rizwan Idrees
|
||||||
* @author Mohsin Husen
|
* @author Mohsin Husen
|
||||||
|
* @author Mark Paluch
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public class MappingElasticsearchConverter implements ElasticsearchConverter, ApplicationContextAware {
|
public class MappingElasticsearchConverter implements ElasticsearchConverter, ApplicationContextAware {
|
||||||
|
|
||||||
private final MappingContext<? extends ElasticsearchPersistentEntity<?>, ElasticsearchPersistentProperty> mappingContext;
|
private final MappingContext<? extends ElasticsearchPersistentEntity<?>, ElasticsearchPersistentProperty> mappingContext;
|
||||||
@ -43,7 +43,9 @@ public class MappingElasticsearchConverter implements ElasticsearchConverter, Ap
|
|||||||
|
|
||||||
public MappingElasticsearchConverter(
|
public MappingElasticsearchConverter(
|
||||||
MappingContext<? extends ElasticsearchPersistentEntity<?>, ElasticsearchPersistentProperty> mappingContext) {
|
MappingContext<? extends ElasticsearchPersistentEntity<?>, ElasticsearchPersistentProperty> mappingContext) {
|
||||||
Assert.notNull(mappingContext);
|
|
||||||
|
Assert.notNull(mappingContext, "MappingContext must not be null!");
|
||||||
|
|
||||||
this.mappingContext = mappingContext;
|
this.mappingContext = mappingContext;
|
||||||
this.conversionService = new DefaultConversionService();
|
this.conversionService = new DefaultConversionService();
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013-2016 the original author or authors.
|
* Copyright 2013-2017 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@ -29,6 +29,7 @@ import org.springframework.util.Assert;
|
|||||||
*
|
*
|
||||||
* @author Rizwan Idrees
|
* @author Rizwan Idrees
|
||||||
* @author Mohsin Husen
|
* @author Mohsin Husen
|
||||||
|
* @author Mark Paluch
|
||||||
*/
|
*/
|
||||||
abstract class AbstractQuery implements Query {
|
abstract class AbstractQuery implements Query {
|
||||||
|
|
||||||
@ -55,7 +56,9 @@ abstract class AbstractQuery implements Query {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final <T extends Query> T setPageable(Pageable pageable) {
|
public final <T extends Query> T setPageable(Pageable pageable) {
|
||||||
Assert.notNull(pageable);
|
|
||||||
|
Assert.notNull(pageable, "Pageable must not be null!");
|
||||||
|
|
||||||
this.pageable = pageable;
|
this.pageable = pageable;
|
||||||
return (T) this.addSort(pageable.getSort());
|
return (T) this.addSort(pageable.getSort());
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013-2016 the original author or authors.
|
* Copyright 2013-2017 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@ -43,6 +43,7 @@ import org.springframework.util.Assert;
|
|||||||
* @author Mohsin Husen
|
* @author Mohsin Husen
|
||||||
* @author Ryan Henszey
|
* @author Ryan Henszey
|
||||||
* @author Kevin Leturc
|
* @author Kevin Leturc
|
||||||
|
* @author Mark Paluch
|
||||||
*/
|
*/
|
||||||
public abstract class AbstractElasticsearchRepository<T, ID extends Serializable> implements
|
public abstract class AbstractElasticsearchRepository<T, ID extends Serializable> implements
|
||||||
ElasticsearchRepository<T, ID> {
|
ElasticsearchRepository<T, ID> {
|
||||||
@ -56,14 +57,18 @@ public abstract class AbstractElasticsearchRepository<T, ID extends Serializable
|
|||||||
}
|
}
|
||||||
|
|
||||||
public AbstractElasticsearchRepository(ElasticsearchOperations elasticsearchOperations) {
|
public AbstractElasticsearchRepository(ElasticsearchOperations elasticsearchOperations) {
|
||||||
Assert.notNull(elasticsearchOperations);
|
|
||||||
|
Assert.notNull(elasticsearchOperations, "ElasticsearchOperations must not be null!");
|
||||||
|
|
||||||
this.setElasticsearchOperations(elasticsearchOperations);
|
this.setElasticsearchOperations(elasticsearchOperations);
|
||||||
}
|
}
|
||||||
|
|
||||||
public AbstractElasticsearchRepository(ElasticsearchEntityInformation<T, ID> metadata,
|
public AbstractElasticsearchRepository(ElasticsearchEntityInformation<T, ID> metadata,
|
||||||
ElasticsearchOperations elasticsearchOperations) {
|
ElasticsearchOperations elasticsearchOperations) {
|
||||||
this(elasticsearchOperations);
|
this(elasticsearchOperations);
|
||||||
Assert.notNull(metadata);
|
|
||||||
|
Assert.notNull(metadata, "ElasticsearchEntityInformation must not be null!");
|
||||||
|
|
||||||
this.entityInformation = metadata;
|
this.entityInformation = metadata;
|
||||||
setEntityClass(this.entityInformation.getJavaType());
|
setEntityClass(this.entityInformation.getJavaType());
|
||||||
try {
|
try {
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013-2014 the original author or authors.
|
* Copyright 2013-2017 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@ -28,6 +28,7 @@ import org.springframework.util.Assert;
|
|||||||
* @author Rizwan Idrees
|
* @author Rizwan Idrees
|
||||||
* @author Mohsin Husen
|
* @author Mohsin Husen
|
||||||
* @author Oliver Gierke
|
* @author Oliver Gierke
|
||||||
|
* @author Mark Paluch
|
||||||
*/
|
*/
|
||||||
public class ElasticsearchEntityInformationCreatorImpl implements ElasticsearchEntityInformationCreator {
|
public class ElasticsearchEntityInformationCreatorImpl implements ElasticsearchEntityInformationCreator {
|
||||||
|
|
||||||
@ -35,7 +36,9 @@ public class ElasticsearchEntityInformationCreatorImpl implements ElasticsearchE
|
|||||||
|
|
||||||
public ElasticsearchEntityInformationCreatorImpl(
|
public ElasticsearchEntityInformationCreatorImpl(
|
||||||
MappingContext<? extends ElasticsearchPersistentEntity<?>, ElasticsearchPersistentProperty> mappingContext) {
|
MappingContext<? extends ElasticsearchPersistentEntity<?>, ElasticsearchPersistentProperty> mappingContext) {
|
||||||
Assert.notNull(mappingContext);
|
|
||||||
|
Assert.notNull(mappingContext, "MappingContext must not be null!");
|
||||||
|
|
||||||
this.mappingContext = mappingContext;
|
this.mappingContext = mappingContext;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,115 +1,119 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013 the original author or authors.
|
* Copyright 2013-2017 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
* You may obtain a copy of the License at
|
* 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
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package org.springframework.data.elasticsearch.repository.support;
|
package org.springframework.data.elasticsearch.repository.support;
|
||||||
|
|
||||||
import static org.springframework.data.querydsl.QueryDslUtils.*;
|
import static org.springframework.data.querydsl.QueryDslUtils.*;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
|
|
||||||
import org.springframework.data.elasticsearch.core.ElasticsearchOperations;
|
import org.springframework.data.elasticsearch.core.ElasticsearchOperations;
|
||||||
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
|
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
|
||||||
import org.springframework.data.elasticsearch.repository.query.ElasticsearchPartQuery;
|
import org.springframework.data.elasticsearch.repository.query.ElasticsearchPartQuery;
|
||||||
import org.springframework.data.elasticsearch.repository.query.ElasticsearchQueryMethod;
|
import org.springframework.data.elasticsearch.repository.query.ElasticsearchQueryMethod;
|
||||||
import org.springframework.data.elasticsearch.repository.query.ElasticsearchStringQuery;
|
import org.springframework.data.elasticsearch.repository.query.ElasticsearchStringQuery;
|
||||||
import org.springframework.data.projection.ProjectionFactory;
|
import org.springframework.data.projection.ProjectionFactory;
|
||||||
import org.springframework.data.querydsl.QueryDslPredicateExecutor;
|
import org.springframework.data.querydsl.QueryDslPredicateExecutor;
|
||||||
import org.springframework.data.repository.core.NamedQueries;
|
import org.springframework.data.repository.core.NamedQueries;
|
||||||
import org.springframework.data.repository.core.RepositoryInformation;
|
import org.springframework.data.repository.core.RepositoryInformation;
|
||||||
import org.springframework.data.repository.core.RepositoryMetadata;
|
import org.springframework.data.repository.core.RepositoryMetadata;
|
||||||
import org.springframework.data.repository.core.support.RepositoryFactorySupport;
|
import org.springframework.data.repository.core.support.RepositoryFactorySupport;
|
||||||
import org.springframework.data.repository.query.QueryLookupStrategy;
|
import org.springframework.data.repository.query.QueryLookupStrategy;
|
||||||
import org.springframework.data.repository.query.RepositoryQuery;
|
import org.springframework.data.repository.query.RepositoryQuery;
|
||||||
import org.springframework.util.Assert;
|
import org.springframework.util.Assert;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Factory to create {@link ElasticsearchRepository}
|
* Factory to create {@link ElasticsearchRepository}
|
||||||
*
|
*
|
||||||
* @author Rizwan Idrees
|
* @author Rizwan Idrees
|
||||||
* @author Mohsin Husen
|
* @author Mohsin Husen
|
||||||
* @author Ryan Henszey
|
* @author Ryan Henszey
|
||||||
*/
|
* @author Gad Akuka
|
||||||
public class ElasticsearchRepositoryFactory extends RepositoryFactorySupport {
|
* @author Mark Paluch
|
||||||
|
*/
|
||||||
private final ElasticsearchOperations elasticsearchOperations;
|
public class ElasticsearchRepositoryFactory extends RepositoryFactorySupport {
|
||||||
private final ElasticsearchEntityInformationCreator entityInformationCreator;
|
|
||||||
|
private final ElasticsearchOperations elasticsearchOperations;
|
||||||
public ElasticsearchRepositoryFactory(ElasticsearchOperations elasticsearchOperations) {
|
private final ElasticsearchEntityInformationCreator entityInformationCreator;
|
||||||
Assert.notNull(elasticsearchOperations);
|
|
||||||
this.elasticsearchOperations = elasticsearchOperations;
|
public ElasticsearchRepositoryFactory(ElasticsearchOperations elasticsearchOperations) {
|
||||||
this.entityInformationCreator = new ElasticsearchEntityInformationCreatorImpl(elasticsearchOperations
|
|
||||||
.getElasticsearchConverter().getMappingContext());
|
Assert.notNull(elasticsearchOperations, "ElasticsearchOperations must not be null!");
|
||||||
}
|
|
||||||
|
this.elasticsearchOperations = elasticsearchOperations;
|
||||||
@Override
|
this.entityInformationCreator = new ElasticsearchEntityInformationCreatorImpl(elasticsearchOperations
|
||||||
public <T, ID extends Serializable> ElasticsearchEntityInformation<T, ID> getEntityInformation(Class<T> domainClass) {
|
.getElasticsearchConverter().getMappingContext());
|
||||||
return entityInformationCreator.getEntityInformation(domainClass);
|
}
|
||||||
}
|
|
||||||
|
@Override
|
||||||
@Override
|
public <T, ID extends Serializable> ElasticsearchEntityInformation<T, ID> getEntityInformation(Class<T> domainClass) {
|
||||||
@SuppressWarnings({"rawtypes", "unchecked"})
|
return entityInformationCreator.getEntityInformation(domainClass);
|
||||||
protected Object getTargetRepository(RepositoryInformation metadata) {
|
}
|
||||||
return getTargetRepositoryViaReflection(metadata,getEntityInformation(metadata.getDomainType()), elasticsearchOperations);
|
|
||||||
}
|
@Override
|
||||||
|
@SuppressWarnings({"rawtypes", "unchecked"})
|
||||||
@Override
|
protected Object getTargetRepository(RepositoryInformation metadata) {
|
||||||
protected Class<?> getRepositoryBaseClass(RepositoryMetadata metadata) {
|
return getTargetRepositoryViaReflection(metadata,getEntityInformation(metadata.getDomainType()), elasticsearchOperations);
|
||||||
if (isQueryDslRepository(metadata.getRepositoryInterface())) {
|
}
|
||||||
throw new IllegalArgumentException("QueryDsl Support has not been implemented yet.");
|
|
||||||
}
|
@Override
|
||||||
if (Integer.class.isAssignableFrom(metadata.getIdType())
|
protected Class<?> getRepositoryBaseClass(RepositoryMetadata metadata) {
|
||||||
|| Long.class.isAssignableFrom(metadata.getIdType())
|
if (isQueryDslRepository(metadata.getRepositoryInterface())) {
|
||||||
|| Double.class.isAssignableFrom(metadata.getIdType())) {
|
throw new IllegalArgumentException("QueryDsl Support has not been implemented yet.");
|
||||||
return NumberKeyedRepository.class;
|
}
|
||||||
} else if (metadata.getIdType() == String.class) {
|
if (Integer.class.isAssignableFrom(metadata.getIdType())
|
||||||
return SimpleElasticsearchRepository.class;
|
|| Long.class.isAssignableFrom(metadata.getIdType())
|
||||||
} else {
|
|| Double.class.isAssignableFrom(metadata.getIdType())) {
|
||||||
throw new IllegalArgumentException("Unsuppored ID type " + metadata.getIdType());
|
return NumberKeyedRepository.class;
|
||||||
}
|
} else if (metadata.getIdType() == String.class) {
|
||||||
}
|
return SimpleElasticsearchRepository.class;
|
||||||
|
} else {
|
||||||
private static boolean isQueryDslRepository(Class<?> repositoryInterface) {
|
throw new IllegalArgumentException("Unsuppored ID type " + metadata.getIdType());
|
||||||
return QUERY_DSL_PRESENT && QueryDslPredicateExecutor.class.isAssignableFrom(repositoryInterface);
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
private static boolean isQueryDslRepository(Class<?> repositoryInterface) {
|
||||||
protected QueryLookupStrategy getQueryLookupStrategy(QueryLookupStrategy.Key key) {
|
return QUERY_DSL_PRESENT && QueryDslPredicateExecutor.class.isAssignableFrom(repositoryInterface);
|
||||||
return new ElasticsearchQueryLookupStrategy();
|
}
|
||||||
}
|
|
||||||
|
@Override
|
||||||
private class ElasticsearchQueryLookupStrategy implements QueryLookupStrategy {
|
protected QueryLookupStrategy getQueryLookupStrategy(QueryLookupStrategy.Key key) {
|
||||||
|
return new ElasticsearchQueryLookupStrategy();
|
||||||
/*
|
}
|
||||||
* (non-Javadoc)
|
|
||||||
* @see org.springframework.data.repository.query.QueryLookupStrategy#resolveQuery(java.lang.reflect.Method, org.springframework.data.repository.core.RepositoryMetadata, org.springframework.data.projection.ProjectionFactory, org.springframework.data.repository.core.NamedQueries)
|
private class ElasticsearchQueryLookupStrategy implements QueryLookupStrategy {
|
||||||
*/
|
|
||||||
@Override
|
/*
|
||||||
public RepositoryQuery resolveQuery(Method method, RepositoryMetadata metadata, ProjectionFactory factory,
|
* (non-Javadoc)
|
||||||
NamedQueries namedQueries) {
|
* @see org.springframework.data.repository.query.QueryLookupStrategy#resolveQuery(java.lang.reflect.Method, org.springframework.data.repository.core.RepositoryMetadata, org.springframework.data.projection.ProjectionFactory, org.springframework.data.repository.core.NamedQueries)
|
||||||
|
*/
|
||||||
ElasticsearchQueryMethod queryMethod = new ElasticsearchQueryMethod(method, metadata, factory);
|
@Override
|
||||||
String namedQueryName = queryMethod.getNamedQueryName();
|
public RepositoryQuery resolveQuery(Method method, RepositoryMetadata metadata, ProjectionFactory factory,
|
||||||
|
NamedQueries namedQueries) {
|
||||||
if (namedQueries.hasQuery(namedQueryName)) {
|
|
||||||
String namedQuery = namedQueries.getQuery(namedQueryName);
|
ElasticsearchQueryMethod queryMethod = new ElasticsearchQueryMethod(method, metadata, factory);
|
||||||
return new ElasticsearchStringQuery(queryMethod, elasticsearchOperations, namedQuery);
|
String namedQueryName = queryMethod.getNamedQueryName();
|
||||||
} else if (queryMethod.hasAnnotatedQuery()) {
|
|
||||||
return new ElasticsearchStringQuery(queryMethod, elasticsearchOperations, queryMethod.getAnnotatedQuery());
|
if (namedQueries.hasQuery(namedQueryName)) {
|
||||||
}
|
String namedQuery = namedQueries.getQuery(namedQueryName);
|
||||||
return new ElasticsearchPartQuery(queryMethod, elasticsearchOperations);
|
return new ElasticsearchStringQuery(queryMethod, elasticsearchOperations, namedQuery);
|
||||||
}
|
} else if (queryMethod.hasAnnotatedQuery()) {
|
||||||
}
|
return new ElasticsearchStringQuery(queryMethod, elasticsearchOperations, queryMethod.getAnnotatedQuery());
|
||||||
}
|
}
|
||||||
|
return new ElasticsearchPartQuery(queryMethod, elasticsearchOperations);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013 the original author or authors.
|
* Copyright 2013-2017 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@ -29,6 +29,7 @@ import org.springframework.util.Assert;
|
|||||||
*
|
*
|
||||||
* @author Rizwan Idrees
|
* @author Rizwan Idrees
|
||||||
* @author Mohsin Husen
|
* @author Mohsin Husen
|
||||||
|
* @author Mark Paluch
|
||||||
*/
|
*/
|
||||||
public class ElasticsearchRepositoryFactoryBean<T extends Repository<S, ID>, S, ID extends Serializable> extends
|
public class ElasticsearchRepositoryFactoryBean<T extends Repository<S, ID>, S, ID extends Serializable> extends
|
||||||
RepositoryFactoryBeanSupport<T, S, ID> {
|
RepositoryFactoryBeanSupport<T, S, ID> {
|
||||||
@ -41,7 +42,9 @@ public class ElasticsearchRepositoryFactoryBean<T extends Repository<S, ID>, S,
|
|||||||
* @param operations the operations to set
|
* @param operations the operations to set
|
||||||
*/
|
*/
|
||||||
public void setElasticsearchOperations(ElasticsearchOperations operations) {
|
public void setElasticsearchOperations(ElasticsearchOperations operations) {
|
||||||
Assert.notNull(operations);
|
|
||||||
|
Assert.notNull(operations, "ElasticsearchOperations must not be null!");
|
||||||
|
|
||||||
setMappingContext(operations.getElasticsearchConverter().getMappingContext());
|
setMappingContext(operations.getElasticsearchConverter().getMappingContext());
|
||||||
this.operations = operations;
|
this.operations = operations;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user