Skip to content

Commit 035c558

Browse files
committed
DATAES-631 - refactoring.
1 parent 6eab0e1 commit 035c558

File tree

4 files changed

+18
-19
lines changed

4 files changed

+18
-19
lines changed

src/main/java/org/springframework/data/elasticsearch/core/AbstractElasticsearchTemplate.java

+9
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@
33
import org.slf4j.Logger;
44
import org.slf4j.LoggerFactory;
55
import org.springframework.data.elasticsearch.ElasticsearchException;
6+
import org.springframework.data.elasticsearch.annotations.Document;
67
import org.springframework.data.elasticsearch.annotations.Mapping;
78
import org.springframework.data.elasticsearch.core.convert.ElasticsearchConverter;
89
import org.springframework.data.elasticsearch.core.convert.MappingElasticsearchConverter;
910
import org.springframework.data.elasticsearch.core.index.MappingBuilder;
11+
import org.springframework.data.elasticsearch.core.mapping.ElasticsearchPersistentEntity;
1012
import org.springframework.data.elasticsearch.core.mapping.SimpleElasticsearchMappingContext;
1113
import org.springframework.util.Assert;
1214
import org.springframework.util.StringUtils;
@@ -69,4 +71,11 @@ protected String buildMapping(Class<?> clazz) {
6971
public ElasticsearchConverter getElasticsearchConverter() {
7072
return elasticsearchConverter;
7173
}
74+
75+
@Override
76+
public ElasticsearchPersistentEntity getPersistentEntityFor(Class clazz) {
77+
Assert.isTrue(clazz.isAnnotationPresent(Document.class), "Unable to identify index name. " + clazz.getSimpleName()
78+
+ " is not a Document. Make sure the document class is annotated with @Document(indexName=\"foo\")");
79+
return elasticsearchConverter.getMappingContext().getRequiredPersistentEntity(clazz);
80+
}
7281
}

src/main/java/org/springframework/data/elasticsearch/core/ElasticsearchOperations.java

+9-5
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
import org.springframework.data.elasticsearch.core.query.*;
2828
import org.springframework.data.util.CloseableIterator;
2929
import org.springframework.lang.Nullable;
30-
import org.springframework.util.Assert;
3130

3231
/**
3332
* ElasticsearchOperations
@@ -182,7 +181,7 @@ public interface ElasticsearchOperations {
182181
* @param clazz
183182
* @return the first matching object
184183
*/
185-
default <T> T queryForObject(CriteriaQuery query, Class<T> clazz){
184+
default <T> T queryForObject(CriteriaQuery query, Class<T> clazz) {
186185
List<T> content = queryForPage(query, clazz).getContent();
187186
return content.isEmpty() ? null : content.get(0);
188187
}
@@ -416,10 +415,10 @@ default void bulkUpdate(List<UpdateQuery> queries, IndexCoordinates index) {
416415
void bulkUpdate(List<UpdateQuery> queries, BulkOptions bulkOptions, IndexCoordinates index);
417416

418417
/**
419-
* Delete the one object with provided id
418+
* Delete the one object with provided id.
420419
*
421-
* @param id
422-
* @param index
420+
* @param id the document ot delete
421+
* @param index the index from which to delete
423422
* @return documentId of the document deleted
424423
*/
425424
String delete(String id, IndexCoordinates index);
@@ -570,6 +569,11 @@ default <T> void refresh(Class<T> clazz) {
570569
*/
571570
RequestFactory getRequestFactory();
572571

572+
/**
573+
* @param clazz
574+
* @return the IndexCoordinates defined on the entity.
575+
* @since 4.0
576+
*/
573577
default IndexCoordinates getIndexCoordinatesFor(Class<?> clazz) {
574578
ElasticsearchPersistentEntity entity = getPersistentEntityFor(clazz);
575579
return IndexCoordinates.of(entity.getIndexName(), entity.getIndexType());

src/main/java/org/springframework/data/elasticsearch/core/ElasticsearchRestTemplate.java

-7
Original file line numberDiff line numberDiff line change
@@ -1281,13 +1281,6 @@ private ElasticsearchPersistentEntity<?> getPersistentEntity(@Nullable Class<?>
12811281
return clazz != null ? elasticsearchConverter.getMappingContext().getPersistentEntity(clazz) : null;
12821282
}
12831283

1284-
@Override
1285-
public ElasticsearchPersistentEntity getPersistentEntityFor(Class clazz) {
1286-
Assert.isTrue(clazz.isAnnotationPresent(Document.class), "Unable to identify index name. " + clazz.getSimpleName()
1287-
+ " is not a Document. Make sure the document class is annotated with @Document(indexName=\"foo\")");
1288-
return elasticsearchConverter.getMappingContext().getRequiredPersistentEntity(clazz);
1289-
}
1290-
12911284
private String getPersistentEntityId(Object entity) {
12921285

12931286
ElasticsearchPersistentEntity<?> persistentEntity = getPersistentEntityFor(entity.getClass());

src/main/java/org/springframework/data/elasticsearch/core/ElasticsearchTemplate.java

-7
Original file line numberDiff line numberDiff line change
@@ -1012,13 +1012,6 @@ private ElasticsearchPersistentEntity<?> getPersistentEntity(@Nullable Class<?>
10121012
return clazz != null ? elasticsearchConverter.getMappingContext().getPersistentEntity(clazz) : null;
10131013
}
10141014

1015-
@Override
1016-
public ElasticsearchPersistentEntity getPersistentEntityFor(Class clazz) {
1017-
Assert.isTrue(clazz.isAnnotationPresent(Document.class), "Unable to identify index name. " + clazz.getSimpleName()
1018-
+ " is not a Document. Make sure the document class is annotated with @Document(indexName=\"foo\")");
1019-
return elasticsearchConverter.getMappingContext().getRequiredPersistentEntity(clazz);
1020-
}
1021-
10221015
private String getPersistentEntityId(Object entity) {
10231016

10241017
ElasticsearchPersistentEntity<?> persistentEntity = getPersistentEntityFor(entity.getClass());

0 commit comments

Comments
 (0)