DATAES-521 - Remove id-type specific repository implementations.

This commit is contained in:
xhaggi 2018-12-18 13:44:38 +01:00
parent 3abc3ab13b
commit 5ff6238399
7 changed files with 22 additions and 125 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright 2013-2014 the original author or authors.
* Copyright 2013-2018 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.
@ -15,8 +15,6 @@
*/
package org.springframework.data.elasticsearch.repository;
import java.io.Serializable;
import org.springframework.data.repository.NoRepositoryBean;
import org.springframework.data.repository.PagingAndSortingRepository;
@ -26,8 +24,9 @@ import org.springframework.data.repository.PagingAndSortingRepository;
* @author Rizwan Idrees
* @author Mohsin Husen
* @author Oliver Gierke
* @author Sascha Woo
*/
@NoRepositoryBean
public interface ElasticsearchCrudRepository<T, ID extends Serializable> extends PagingAndSortingRepository<T, ID> {
public interface ElasticsearchCrudRepository<T, ID> extends PagingAndSortingRepository<T, ID> {
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2013-2016 the original author or authors.
* Copyright 2013-2018 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.
@ -15,8 +15,6 @@
*/
package org.springframework.data.elasticsearch.repository;
import java.io.Serializable;
import org.elasticsearch.index.query.QueryBuilder;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
@ -28,9 +26,10 @@ import org.springframework.data.repository.NoRepositoryBean;
* @param <ID>
* @author Rizwan Idrees
* @author Mohsin Husen
* @author Sascha Woo
*/
@NoRepositoryBean
public interface ElasticsearchRepository<T, ID extends Serializable> extends ElasticsearchCrudRepository<T, ID> {
public interface ElasticsearchRepository<T, ID> extends ElasticsearchCrudRepository<T, ID> {
<S extends T> S index(S entity);

View File

@ -1,5 +1,5 @@
/*
* Copyright 2013-2017 the original author or authors.
* Copyright 2013-2018 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.
@ -17,7 +17,6 @@ package org.springframework.data.elasticsearch.repository.support;
import static org.elasticsearch.index.query.QueryBuilders.*;
import java.io.Serializable;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.ArrayList;
@ -56,8 +55,9 @@ import org.springframework.util.Assert;
* @author Mark Paluch
* @author Christoph Strobl
* @author Michael Wirth
* @author Sascha Woo
*/
public abstract class AbstractElasticsearchRepository<T, ID extends Serializable>
public abstract class AbstractElasticsearchRepository<T, ID>
implements ElasticsearchRepository<T, ID> {
static final Logger LOGGER = LoggerFactory.getLogger(AbstractElasticsearchRepository.class);

View File

@ -1,5 +1,5 @@
/*
* Copyright 2013-2017 the original author or authors.
* Copyright 2013-2018 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,7 +19,6 @@ import static org.springframework.data.querydsl.QuerydslUtils.*;
import java.lang.reflect.Method;
import java.util.Optional;
import java.util.UUID;
import org.springframework.data.elasticsearch.core.ElasticsearchOperations;
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
@ -36,7 +35,6 @@ import org.springframework.data.repository.query.QueryLookupStrategy;
import org.springframework.data.repository.query.QueryLookupStrategy.Key;
import org.springframework.data.repository.query.QueryMethodEvaluationContextProvider;
import org.springframework.data.repository.query.RepositoryQuery;
import org.springframework.data.spel.EvaluationContextProvider;
import org.springframework.util.Assert;
/**
@ -48,6 +46,7 @@ import org.springframework.util.Assert;
* @author Gad Akuka
* @author Mark Paluch
* @author Christoph Strobl
* @author Sascha Woo
*/
public class ElasticsearchRepositoryFactory extends RepositoryFactorySupport {
@ -69,7 +68,6 @@ public class ElasticsearchRepositoryFactory extends RepositoryFactorySupport {
}
@Override
@SuppressWarnings({ "rawtypes", "unchecked" })
protected Object getTargetRepository(RepositoryInformation metadata) {
return getTargetRepositoryViaReflection(metadata, getEntityInformation(metadata.getDomainType()),
elasticsearchOperations);
@ -80,16 +78,8 @@ public class ElasticsearchRepositoryFactory extends RepositoryFactorySupport {
if (isQueryDslRepository(metadata.getRepositoryInterface())) {
throw new IllegalArgumentException("QueryDsl Support has not been implemented yet.");
}
if (Integer.class.isAssignableFrom(metadata.getIdType()) || Long.class.isAssignableFrom(metadata.getIdType())
|| Double.class.isAssignableFrom(metadata.getIdType())) {
return NumberKeyedRepository.class;
} else if (metadata.getIdType() == String.class) {
return SimpleElasticsearchRepository.class;
} else if (metadata.getIdType() == UUID.class) {
return UUIDElasticsearchRepository.class;
} else {
throw new IllegalArgumentException("Unsupported ID type " + metadata.getIdType());
}
return SimpleElasticsearchRepository.class;
}
private static boolean isQueryDslRepository(Class<?> repositoryInterface) {

View File

@ -1,47 +0,0 @@
/*
* Copyright 2013 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
*
* 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.elasticsearch.repository.support;
import org.springframework.data.elasticsearch.core.ElasticsearchOperations;
/**
* Elasticsearch specific repository implementation. Likely to be used as target within
* {@link ElasticsearchRepositoryFactory}
*
* @author Rizwan Idrees
* @author Mohsin Husen
* @author Ryan Henszey
*/
public class NumberKeyedRepository<T, ID extends Number> extends AbstractElasticsearchRepository<T, ID> {
public NumberKeyedRepository() {
super();
}
public NumberKeyedRepository(ElasticsearchEntityInformation<T, ID> metadata,
ElasticsearchOperations elasticsearchOperations) {
super(metadata, elasticsearchOperations);
}
public NumberKeyedRepository(ElasticsearchOperations elasticsearchOperations) {
super(elasticsearchOperations);
}
@Override
protected String stringIdRepresentation(ID id) {
return String.valueOf(id);
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2013 the original author or authors.
* Copyright 2013-2018 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.
@ -15,6 +15,8 @@
*/
package org.springframework.data.elasticsearch.repository.support;
import java.util.Objects;
import org.springframework.data.elasticsearch.core.ElasticsearchOperations;
/**
@ -24,15 +26,16 @@ import org.springframework.data.elasticsearch.core.ElasticsearchOperations;
* @author Rizwan Idrees
* @author Mohsin Husen
* @author Ryan Henszey
* @author Sascha Woo
*/
public class SimpleElasticsearchRepository<T> extends AbstractElasticsearchRepository<T, String> {
public class SimpleElasticsearchRepository<T, ID> extends AbstractElasticsearchRepository<T, ID> {
public SimpleElasticsearchRepository() {
super();
}
public SimpleElasticsearchRepository(ElasticsearchEntityInformation<T, String> metadata,
ElasticsearchOperations elasticsearchOperations) {
public SimpleElasticsearchRepository(ElasticsearchEntityInformation<T, ID> metadata,
ElasticsearchOperations elasticsearchOperations) {
super(metadata, elasticsearchOperations);
}
@ -41,7 +44,7 @@ public class SimpleElasticsearchRepository<T> extends AbstractElasticsearchRepos
}
@Override
protected String stringIdRepresentation(String id) {
return id;
protected String stringIdRepresentation(ID id) {
return Objects.toString(id, null);
}
}

View File

@ -1,47 +0,0 @@
/*
* Copyright 2013 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
*
* 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.elasticsearch.repository.support;
import java.util.UUID;
import org.springframework.data.elasticsearch.core.ElasticsearchOperations;
/**
* Elasticsearch specific repository implementation. Likely to be used as target within
* {@link ElasticsearchRepositoryFactory}
*
* @author Gad Akuka
*/
public class UUIDElasticsearchRepository<T> extends AbstractElasticsearchRepository<T, UUID> {
public UUIDElasticsearchRepository() {
super();
}
public UUIDElasticsearchRepository(ElasticsearchEntityInformation<T, UUID> metadata,
ElasticsearchOperations elasticsearchOperations) {
super(metadata, elasticsearchOperations);
}
public UUIDElasticsearchRepository(ElasticsearchOperations elasticsearchOperations) {
super(elasticsearchOperations);
}
@Override
protected String stringIdRepresentation(UUID id) {
return (id != null) ? id.toString() : null;
}
}