From 5ff623839928b6da00e55b2e73e77c3d46e69c9b Mon Sep 17 00:00:00 2001 From: xhaggi Date: Tue, 18 Dec 2018 13:44:38 +0100 Subject: [PATCH] DATAES-521 - Remove id-type specific repository implementations. --- .../ElasticsearchCrudRepository.java | 7 ++- .../repository/ElasticsearchRepository.java | 7 ++- .../AbstractElasticsearchRepository.java | 6 +-- .../ElasticsearchRepositoryFactory.java | 18 ++----- .../support/NumberKeyedRepository.java | 47 ------------------- .../SimpleElasticsearchRepository.java | 15 +++--- .../support/UUIDElasticsearchRepository.java | 47 ------------------- 7 files changed, 22 insertions(+), 125 deletions(-) delete mode 100644 src/main/java/org/springframework/data/elasticsearch/repository/support/NumberKeyedRepository.java delete mode 100644 src/main/java/org/springframework/data/elasticsearch/repository/support/UUIDElasticsearchRepository.java diff --git a/src/main/java/org/springframework/data/elasticsearch/repository/ElasticsearchCrudRepository.java b/src/main/java/org/springframework/data/elasticsearch/repository/ElasticsearchCrudRepository.java index cd74a985f..19f70fdda 100644 --- a/src/main/java/org/springframework/data/elasticsearch/repository/ElasticsearchCrudRepository.java +++ b/src/main/java/org/springframework/data/elasticsearch/repository/ElasticsearchCrudRepository.java @@ -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 extends PagingAndSortingRepository { +public interface ElasticsearchCrudRepository extends PagingAndSortingRepository { } diff --git a/src/main/java/org/springframework/data/elasticsearch/repository/ElasticsearchRepository.java b/src/main/java/org/springframework/data/elasticsearch/repository/ElasticsearchRepository.java index a349058a6..1fd9ab55a 100644 --- a/src/main/java/org/springframework/data/elasticsearch/repository/ElasticsearchRepository.java +++ b/src/main/java/org/springframework/data/elasticsearch/repository/ElasticsearchRepository.java @@ -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 * @author Rizwan Idrees * @author Mohsin Husen + * @author Sascha Woo */ @NoRepositoryBean -public interface ElasticsearchRepository extends ElasticsearchCrudRepository { +public interface ElasticsearchRepository extends ElasticsearchCrudRepository { S index(S entity); diff --git a/src/main/java/org/springframework/data/elasticsearch/repository/support/AbstractElasticsearchRepository.java b/src/main/java/org/springframework/data/elasticsearch/repository/support/AbstractElasticsearchRepository.java index 92d0ae0c5..e51de0e15 100644 --- a/src/main/java/org/springframework/data/elasticsearch/repository/support/AbstractElasticsearchRepository.java +++ b/src/main/java/org/springframework/data/elasticsearch/repository/support/AbstractElasticsearchRepository.java @@ -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 +public abstract class AbstractElasticsearchRepository implements ElasticsearchRepository { static final Logger LOGGER = LoggerFactory.getLogger(AbstractElasticsearchRepository.class); diff --git a/src/main/java/org/springframework/data/elasticsearch/repository/support/ElasticsearchRepositoryFactory.java b/src/main/java/org/springframework/data/elasticsearch/repository/support/ElasticsearchRepositoryFactory.java index f1fe5bf33..ddc5861af 100644 --- a/src/main/java/org/springframework/data/elasticsearch/repository/support/ElasticsearchRepositoryFactory.java +++ b/src/main/java/org/springframework/data/elasticsearch/repository/support/ElasticsearchRepositoryFactory.java @@ -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) { diff --git a/src/main/java/org/springframework/data/elasticsearch/repository/support/NumberKeyedRepository.java b/src/main/java/org/springframework/data/elasticsearch/repository/support/NumberKeyedRepository.java deleted file mode 100644 index a386f5660..000000000 --- a/src/main/java/org/springframework/data/elasticsearch/repository/support/NumberKeyedRepository.java +++ /dev/null @@ -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 extends AbstractElasticsearchRepository { - - public NumberKeyedRepository() { - super(); - } - - public NumberKeyedRepository(ElasticsearchEntityInformation metadata, - ElasticsearchOperations elasticsearchOperations) { - super(metadata, elasticsearchOperations); - } - - public NumberKeyedRepository(ElasticsearchOperations elasticsearchOperations) { - super(elasticsearchOperations); - } - - @Override - protected String stringIdRepresentation(ID id) { - return String.valueOf(id); - } -} diff --git a/src/main/java/org/springframework/data/elasticsearch/repository/support/SimpleElasticsearchRepository.java b/src/main/java/org/springframework/data/elasticsearch/repository/support/SimpleElasticsearchRepository.java index 25472b605..1e3eb5064 100644 --- a/src/main/java/org/springframework/data/elasticsearch/repository/support/SimpleElasticsearchRepository.java +++ b/src/main/java/org/springframework/data/elasticsearch/repository/support/SimpleElasticsearchRepository.java @@ -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 extends AbstractElasticsearchRepository { +public class SimpleElasticsearchRepository extends AbstractElasticsearchRepository { public SimpleElasticsearchRepository() { super(); } - public SimpleElasticsearchRepository(ElasticsearchEntityInformation metadata, - ElasticsearchOperations elasticsearchOperations) { + public SimpleElasticsearchRepository(ElasticsearchEntityInformation metadata, + ElasticsearchOperations elasticsearchOperations) { super(metadata, elasticsearchOperations); } @@ -41,7 +44,7 @@ public class SimpleElasticsearchRepository extends AbstractElasticsearchRepos } @Override - protected String stringIdRepresentation(String id) { - return id; + protected String stringIdRepresentation(ID id) { + return Objects.toString(id, null); } } diff --git a/src/main/java/org/springframework/data/elasticsearch/repository/support/UUIDElasticsearchRepository.java b/src/main/java/org/springframework/data/elasticsearch/repository/support/UUIDElasticsearchRepository.java deleted file mode 100644 index ee08dd970..000000000 --- a/src/main/java/org/springframework/data/elasticsearch/repository/support/UUIDElasticsearchRepository.java +++ /dev/null @@ -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 extends AbstractElasticsearchRepository { - - public UUIDElasticsearchRepository() { - super(); - } - - public UUIDElasticsearchRepository(ElasticsearchEntityInformation metadata, - ElasticsearchOperations elasticsearchOperations) { - super(metadata, elasticsearchOperations); - } - - public UUIDElasticsearchRepository(ElasticsearchOperations elasticsearchOperations) { - super(elasticsearchOperations); - } - - @Override - protected String stringIdRepresentation(UUID id) { - return (id != null) ? id.toString() : null; - } -}