Skip to content

Commit 5ff6238

Browse files
committed
DATAES-521 - Remove id-type specific repository implementations.
1 parent 3abc3ab commit 5ff6238

File tree

7 files changed

+22
-125
lines changed

7 files changed

+22
-125
lines changed

src/main/java/org/springframework/data/elasticsearch/repository/ElasticsearchCrudRepository.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2013-2014 the original author or authors.
2+
* Copyright 2013-2018 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -15,8 +15,6 @@
1515
*/
1616
package org.springframework.data.elasticsearch.repository;
1717

18-
import java.io.Serializable;
19-
2018
import org.springframework.data.repository.NoRepositoryBean;
2119
import org.springframework.data.repository.PagingAndSortingRepository;
2220

@@ -26,8 +24,9 @@
2624
* @author Rizwan Idrees
2725
* @author Mohsin Husen
2826
* @author Oliver Gierke
27+
* @author Sascha Woo
2928
*/
3029
@NoRepositoryBean
31-
public interface ElasticsearchCrudRepository<T, ID extends Serializable> extends PagingAndSortingRepository<T, ID> {
30+
public interface ElasticsearchCrudRepository<T, ID> extends PagingAndSortingRepository<T, ID> {
3231

3332
}

src/main/java/org/springframework/data/elasticsearch/repository/ElasticsearchRepository.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2013-2016 the original author or authors.
2+
* Copyright 2013-2018 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -15,8 +15,6 @@
1515
*/
1616
package org.springframework.data.elasticsearch.repository;
1717

18-
import java.io.Serializable;
19-
2018
import org.elasticsearch.index.query.QueryBuilder;
2119
import org.springframework.data.domain.Page;
2220
import org.springframework.data.domain.Pageable;
@@ -28,9 +26,10 @@
2826
* @param <ID>
2927
* @author Rizwan Idrees
3028
* @author Mohsin Husen
29+
* @author Sascha Woo
3130
*/
3231
@NoRepositoryBean
33-
public interface ElasticsearchRepository<T, ID extends Serializable> extends ElasticsearchCrudRepository<T, ID> {
32+
public interface ElasticsearchRepository<T, ID> extends ElasticsearchCrudRepository<T, ID> {
3433

3534
<S extends T> S index(S entity);
3635

src/main/java/org/springframework/data/elasticsearch/repository/support/AbstractElasticsearchRepository.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2013-2017 the original author or authors.
2+
* Copyright 2013-2018 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -17,7 +17,6 @@
1717

1818
import static org.elasticsearch.index.query.QueryBuilders.*;
1919

20-
import java.io.Serializable;
2120
import java.lang.reflect.ParameterizedType;
2221
import java.lang.reflect.Type;
2322
import java.util.ArrayList;
@@ -56,8 +55,9 @@
5655
* @author Mark Paluch
5756
* @author Christoph Strobl
5857
* @author Michael Wirth
58+
* @author Sascha Woo
5959
*/
60-
public abstract class AbstractElasticsearchRepository<T, ID extends Serializable>
60+
public abstract class AbstractElasticsearchRepository<T, ID>
6161
implements ElasticsearchRepository<T, ID> {
6262

6363
static final Logger LOGGER = LoggerFactory.getLogger(AbstractElasticsearchRepository.class);

src/main/java/org/springframework/data/elasticsearch/repository/support/ElasticsearchRepositoryFactory.java

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2013-2017 the original author or authors.
2+
* Copyright 2013-2018 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -19,7 +19,6 @@
1919

2020
import java.lang.reflect.Method;
2121
import java.util.Optional;
22-
import java.util.UUID;
2322

2423
import org.springframework.data.elasticsearch.core.ElasticsearchOperations;
2524
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
@@ -36,7 +35,6 @@
3635
import org.springframework.data.repository.query.QueryLookupStrategy.Key;
3736
import org.springframework.data.repository.query.QueryMethodEvaluationContextProvider;
3837
import org.springframework.data.repository.query.RepositoryQuery;
39-
import org.springframework.data.spel.EvaluationContextProvider;
4038
import org.springframework.util.Assert;
4139

4240
/**
@@ -48,6 +46,7 @@
4846
* @author Gad Akuka
4947
* @author Mark Paluch
5048
* @author Christoph Strobl
49+
* @author Sascha Woo
5150
*/
5251
public class ElasticsearchRepositoryFactory extends RepositoryFactorySupport {
5352

@@ -69,7 +68,6 @@ public <T, ID> ElasticsearchEntityInformation<T, ID> getEntityInformation(Class<
6968
}
7069

7170
@Override
72-
@SuppressWarnings({ "rawtypes", "unchecked" })
7371
protected Object getTargetRepository(RepositoryInformation metadata) {
7472
return getTargetRepositoryViaReflection(metadata, getEntityInformation(metadata.getDomainType()),
7573
elasticsearchOperations);
@@ -80,16 +78,8 @@ protected Class<?> getRepositoryBaseClass(RepositoryMetadata metadata) {
8078
if (isQueryDslRepository(metadata.getRepositoryInterface())) {
8179
throw new IllegalArgumentException("QueryDsl Support has not been implemented yet.");
8280
}
83-
if (Integer.class.isAssignableFrom(metadata.getIdType()) || Long.class.isAssignableFrom(metadata.getIdType())
84-
|| Double.class.isAssignableFrom(metadata.getIdType())) {
85-
return NumberKeyedRepository.class;
86-
} else if (metadata.getIdType() == String.class) {
87-
return SimpleElasticsearchRepository.class;
88-
} else if (metadata.getIdType() == UUID.class) {
89-
return UUIDElasticsearchRepository.class;
90-
} else {
91-
throw new IllegalArgumentException("Unsupported ID type " + metadata.getIdType());
92-
}
81+
82+
return SimpleElasticsearchRepository.class;
9383
}
9484

9585
private static boolean isQueryDslRepository(Class<?> repositoryInterface) {

src/main/java/org/springframework/data/elasticsearch/repository/support/NumberKeyedRepository.java

Lines changed: 0 additions & 47 deletions
This file was deleted.

src/main/java/org/springframework/data/elasticsearch/repository/support/SimpleElasticsearchRepository.java

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2013 the original author or authors.
2+
* Copyright 2013-2018 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -15,6 +15,8 @@
1515
*/
1616
package org.springframework.data.elasticsearch.repository.support;
1717

18+
import java.util.Objects;
19+
1820
import org.springframework.data.elasticsearch.core.ElasticsearchOperations;
1921

2022
/**
@@ -24,15 +26,16 @@
2426
* @author Rizwan Idrees
2527
* @author Mohsin Husen
2628
* @author Ryan Henszey
29+
* @author Sascha Woo
2730
*/
28-
public class SimpleElasticsearchRepository<T> extends AbstractElasticsearchRepository<T, String> {
31+
public class SimpleElasticsearchRepository<T, ID> extends AbstractElasticsearchRepository<T, ID> {
2932

3033
public SimpleElasticsearchRepository() {
3134
super();
3235
}
3336

34-
public SimpleElasticsearchRepository(ElasticsearchEntityInformation<T, String> metadata,
35-
ElasticsearchOperations elasticsearchOperations) {
37+
public SimpleElasticsearchRepository(ElasticsearchEntityInformation<T, ID> metadata,
38+
ElasticsearchOperations elasticsearchOperations) {
3639
super(metadata, elasticsearchOperations);
3740
}
3841

@@ -41,7 +44,7 @@ public SimpleElasticsearchRepository(ElasticsearchOperations elasticsearchOperat
4144
}
4245

4346
@Override
44-
protected String stringIdRepresentation(String id) {
45-
return id;
47+
protected String stringIdRepresentation(ID id) {
48+
return Objects.toString(id, null);
4649
}
4750
}

src/main/java/org/springframework/data/elasticsearch/repository/support/UUIDElasticsearchRepository.java

Lines changed: 0 additions & 47 deletions
This file was deleted.

0 commit comments

Comments
 (0)