Skip to content

Commit cee493a

Browse files
committed
DATAES-162 - Adapt to changes in Spring Data Commons.
Tweaked method signatures in ElasticsearchRepositoryFactory after some signature changes in Spring Data Commons. Use newly introduced getTragetRepositoryViaReflection(…) to obtain the repository instance via the super class. Added repositoryBaseClass() attribute to @EnableMongoRepositories. Related tickets: DATACMNS-542
1 parent fa99671 commit cee493a

File tree

2 files changed

+20
-23
lines changed

2 files changed

+20
-23
lines changed

src/main/java/org/springframework/data/elasticsearch/repository/config/EnableElasticsearchRepositories.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import org.springframework.context.annotation.Import;
2222
import org.springframework.data.elasticsearch.core.ElasticsearchTemplate;
2323
import org.springframework.data.elasticsearch.repository.support.ElasticsearchRepositoryFactoryBean;
24+
import org.springframework.data.repository.config.DefaultRepositoryBaseClass;
2425
import org.springframework.data.repository.query.QueryLookupStrategy.Key;
2526

2627
/**
@@ -103,6 +104,13 @@
103104
*/
104105
Class<?> repositoryFactoryBeanClass() default ElasticsearchRepositoryFactoryBean.class;
105106

107+
/**
108+
* Configure the repository base class to be used to create repository proxies for this particular configuration.
109+
*
110+
* @return
111+
*/
112+
Class<?> repositoryBaseClass() default DefaultRepositoryBaseClass.class;
113+
106114
// Elasticsearch specific configuration
107115

108116
/**

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

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import org.springframework.data.elasticsearch.repository.query.ElasticsearchStringQuery;
2828
import org.springframework.data.querydsl.QueryDslPredicateExecutor;
2929
import org.springframework.data.repository.core.NamedQueries;
30+
import org.springframework.data.repository.core.RepositoryInformation;
3031
import org.springframework.data.repository.core.RepositoryMetadata;
3132
import org.springframework.data.repository.core.support.RepositoryFactorySupport;
3233
import org.springframework.data.repository.query.QueryLookupStrategy;
@@ -59,36 +60,24 @@ public <T, ID extends Serializable> ElasticsearchEntityInformation<T, ID> getEnt
5960

6061
@Override
6162
@SuppressWarnings({"rawtypes", "unchecked"})
62-
protected Object getTargetRepository(RepositoryMetadata metadata) {
63-
64-
ElasticsearchEntityInformation<?, ?> entityInformation = getEntityInformation(metadata.getDomainType());
65-
66-
AbstractElasticsearchRepository repository;
67-
68-
// Probably a better way to store and look these up.
69-
if (Integer.class.isAssignableFrom(entityInformation.getIdType())
70-
|| Long.class.isAssignableFrom(entityInformation.getIdType())
71-
|| Double.class.isAssignableFrom(entityInformation.getIdType())) {
72-
// logger.debug("Using NumberKeyedRepository for " + metadata.getRepositoryInterface());
73-
repository = new NumberKeyedRepository(getEntityInformation(metadata.getDomainType()), elasticsearchOperations);
74-
} else if (entityInformation.getIdType() == String.class) {
75-
// logger.debug("Using SimpleElasticsearchRepository for " + metadata.getRepositoryInterface());
76-
repository = new SimpleElasticsearchRepository(getEntityInformation(metadata.getDomainType()),
77-
elasticsearchOperations);
78-
} else {
79-
throw new IllegalArgumentException("Unsuppored ID type " + entityInformation.getIdType());
80-
}
81-
repository.setEntityClass(metadata.getDomainType());
82-
83-
return repository;
63+
protected Object getTargetRepository(RepositoryInformation metadata) {
64+
return getTargetRepositoryViaReflection(metadata,getEntityInformation(metadata.getDomainType()), elasticsearchOperations);
8465
}
8566

8667
@Override
8768
protected Class<?> getRepositoryBaseClass(RepositoryMetadata metadata) {
8869
if (isQueryDslRepository(metadata.getRepositoryInterface())) {
8970
throw new IllegalArgumentException("QueryDsl Support has not been implemented yet.");
9071
}
91-
return SimpleElasticsearchRepository.class;
72+
if (Integer.class.isAssignableFrom(metadata.getIdType())
73+
|| Long.class.isAssignableFrom(metadata.getIdType())
74+
|| Double.class.isAssignableFrom(metadata.getIdType())) {
75+
return NumberKeyedRepository.class;
76+
} else if (metadata.getIdType() == String.class) {
77+
return SimpleElasticsearchRepository.class;
78+
} else {
79+
throw new IllegalArgumentException("Unsuppored ID type " + metadata.getIdType());
80+
}
9281
}
9382

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

0 commit comments

Comments
 (0)