Skip to content

Commit 9f42ec9

Browse files
authored
Enhance refresh policy handling.
Original Pull Request spring-projects#2725 Closes spring-projects#2722
1 parent 0b33d7f commit 9f42ec9

9 files changed

+344
-15
lines changed

src/main/antora/modules/ROOT/pages/elasticsearch/elasticsearch-new.adoc

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
* Enable MultiField annotation on property getter
1313
* Support nested sort option
1414
* Improved scripted und runtime field support
15+
* Improved refresh policy support
1516

1617
[[new-features.5-1-0]]
1718
== New in Spring Data Elasticsearch 5.1

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

+9-1
Original file line numberDiff line numberDiff line change
@@ -855,7 +855,7 @@ public SearchScrollHits<T> doWith(SearchDocumentResponse response) {
855855
}
856856
// endregion
857857

858-
// region routing
858+
// region customization
859859
private void setRoutingResolver(RoutingResolver routingResolver) {
860860

861861
Assert.notNull(routingResolver, "routingResolver must not be null");
@@ -873,5 +873,13 @@ public ElasticsearchOperations withRouting(RoutingResolver routingResolver) {
873873
return copy;
874874
}
875875

876+
@Override
877+
public ElasticsearchOperations withRefreshPolicy(@Nullable RefreshPolicy refreshPolicy) {
878+
879+
var copy = copy();
880+
copy.setRefreshPolicy(refreshPolicy);
881+
return copy;
882+
}
883+
876884
// endregion
877885
}

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

+9-1
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ public Mono<Void> logVersions() {
186186

187187
// endregion
188188

189-
// region routing
189+
// region customizations
190190
private void setRoutingResolver(RoutingResolver routingResolver) {
191191

192192
Assert.notNull(routingResolver, "routingResolver must not be null");
@@ -203,6 +203,14 @@ public ReactiveElasticsearchOperations withRouting(RoutingResolver routingResolv
203203
copy.setRoutingResolver(routingResolver);
204204
return copy;
205205
}
206+
207+
@Override
208+
public ReactiveElasticsearchOperations withRefreshPolicy(@Nullable RefreshPolicy refreshPolicy) {
209+
AbstractReactiveElasticsearchTemplate copy = copy();
210+
copy.setRefreshPolicy(refreshPolicy);
211+
return copy;
212+
}
213+
206214
// endregion
207215

208216
// region DocumentOperations

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

+11-4
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515
*/
1616
package org.springframework.data.elasticsearch.core;
1717

18-
import java.util.Objects;
19-
2018
import org.springframework.data.elasticsearch.core.cluster.ClusterOperations;
2119
import org.springframework.data.elasticsearch.core.convert.ElasticsearchConverter;
2220
import org.springframework.data.elasticsearch.core.mapping.IndexCoordinates;
@@ -91,15 +89,24 @@ default String convertId(@Nullable Object idValue) {
9189
}
9290
// endregion
9391

94-
// region routing
92+
// region customizations
9593
/**
9694
* Returns a copy of this instance with the same configuration, but that uses a different {@link RoutingResolver} to
9795
* obtain routing information.
9896
*
9997
* @param routingResolver the {@link RoutingResolver} value, must not be {@literal null}.
100-
* @return DocumentOperations instance
98+
* @return {@link ElasticsearchOperations} instance
10199
* @since 4.2
102100
*/
103101
ElasticsearchOperations withRouting(RoutingResolver routingResolver);
102+
103+
/**
104+
* Returns a copy of this instance with the same configuration, but that uses a different {@link RefreshPolicy}.
105+
*
106+
* @param refreshPolicy the {@link RefreshPolicy} value.
107+
* @return {@link ElasticsearchOperations} instance.
108+
* @since 5.2
109+
*/
110+
ElasticsearchOperations withRefreshPolicy(@Nullable RefreshPolicy refreshPolicy);
104111
// endregion
105112
}

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

+10-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public interface ReactiveElasticsearchOperations
7777
*/
7878
ReactiveClusterOperations cluster();
7979

80-
// region routing
80+
// region customizations
8181
/**
8282
* Returns a copy of this instance with the same configuration, but that uses a different {@link RoutingResolver} to
8383
* obtain routing information.
@@ -86,5 +86,14 @@ public interface ReactiveElasticsearchOperations
8686
* @return DocumentOperations instance
8787
*/
8888
ReactiveElasticsearchOperations withRouting(RoutingResolver routingResolver);
89+
90+
/**
91+
* Returns a copy of this instance with the same configuration, but that uses a different {@link RefreshPolicy}.
92+
*
93+
* @param refreshPolicy the {@link RefreshPolicy} value.
94+
* @return {@link ReactiveElasticsearchOperations} instance.
95+
* @since 5.2
96+
*/
97+
ReactiveElasticsearchOperations withRefreshPolicy(@Nullable RefreshPolicy refreshPolicy);
8998
// endregion
9099
}

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

+37
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
import org.springframework.data.domain.Page;
1919
import org.springframework.data.domain.Pageable;
20+
import org.springframework.data.elasticsearch.core.RefreshPolicy;
2021
import org.springframework.data.repository.CrudRepository;
2122
import org.springframework.data.repository.NoRepositoryBean;
2223
import org.springframework.data.repository.PagingAndSortingRepository;
@@ -31,6 +32,7 @@
3132
* @author Murali Chevuri
3233
* @author Peter-Josef Meisch
3334
*/
35+
@SuppressWarnings("unused")
3436
@NoRepositoryBean
3537
public interface ElasticsearchRepository<T, ID> extends PagingAndSortingRepository<T, ID>, CrudRepository<T, ID> {
3638

@@ -43,4 +45,39 @@ public interface ElasticsearchRepository<T, ID> extends PagingAndSortingReposito
4345
* @return
4446
*/
4547
Page<T> searchSimilar(T entity, @Nullable String[] fields, Pageable pageable);
48+
49+
/**
50+
* @since 5.2
51+
*/
52+
<S extends T> S save(S entity, @Nullable RefreshPolicy refreshPolicy);
53+
54+
/**
55+
* @since 5.2
56+
*/
57+
<S extends T> Iterable<S> saveAll(Iterable<S> entities, @Nullable RefreshPolicy refreshPolicy);
58+
59+
/**
60+
* @since 5.2
61+
*/
62+
void deleteById(ID id, @Nullable RefreshPolicy refreshPolicy);
63+
64+
/**
65+
* @since 5.2
66+
*/
67+
void delete(T entity, @Nullable RefreshPolicy refreshPolicy);
68+
69+
/**
70+
* @since 5.2
71+
*/
72+
void deleteAllById(Iterable<? extends ID> ids, @Nullable RefreshPolicy refreshPolicy);
73+
74+
/**
75+
* @since 5.2
76+
*/
77+
void deleteAll(Iterable<? extends T> entities, @Nullable RefreshPolicy refreshPolicy);
78+
79+
/**
80+
* @since 5.2
81+
*/
82+
void deleteAll(@Nullable RefreshPolicy refreshPolicy);
4683
}

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

+59-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* Copyright 2019-2023 the original author or authors.
33
*
4-
* Licensed under the Apache License, Version 2.0 (the "License");
4+
* Licensed under the Apache License, Version 2.0 (the "License", @Nullable RefreshPolicy refreshPolicy);
55
* you may not use this file except in compliance with the License.
66
* You may obtain a copy of the License at
77
*
@@ -15,16 +15,73 @@
1515
*/
1616
package org.springframework.data.elasticsearch.repository;
1717

18+
import reactor.core.publisher.Flux;
19+
import reactor.core.publisher.Mono;
20+
21+
import org.reactivestreams.Publisher;
22+
import org.springframework.data.elasticsearch.core.RefreshPolicy;
1823
import org.springframework.data.repository.NoRepositoryBean;
1924
import org.springframework.data.repository.reactive.ReactiveCrudRepository;
2025
import org.springframework.data.repository.reactive.ReactiveSortingRepository;
26+
import org.springframework.lang.Nullable;
2127

2228
/**
2329
* Elasticsearch specific {@link org.springframework.data.repository.Repository} interface with reactive support.
2430
*
2531
* @author Christoph Strobl
2632
* @since 3.2
2733
*/
34+
@SuppressWarnings("unused")
2835
@NoRepositoryBean
2936
public interface ReactiveElasticsearchRepository<T, ID>
30-
extends ReactiveSortingRepository<T, ID>, ReactiveCrudRepository<T, ID> {}
37+
extends ReactiveSortingRepository<T, ID>, ReactiveCrudRepository<T, ID> {
38+
/**
39+
* @since 5.2
40+
*/
41+
<S extends T> Mono<S> save(S entity, @Nullable RefreshPolicy refreshPolicy);
42+
43+
/**
44+
* @since 5.2
45+
*/
46+
<S extends T> Flux<S> saveAll(Iterable<S> entities, @Nullable RefreshPolicy refreshPolicy);
47+
48+
/**
49+
* @since 5.2
50+
*/
51+
<S extends T> Flux<S> saveAll(Publisher<S> entityStream, @Nullable RefreshPolicy refreshPolicy);
52+
53+
/**
54+
* @since 5.2
55+
*/
56+
Mono<Void> deleteById(ID id, @Nullable RefreshPolicy refreshPolicy);
57+
58+
/**
59+
* @since 5.2
60+
*/
61+
Mono<Void> deleteById(Publisher<ID> id, @Nullable RefreshPolicy refreshPolicy);
62+
63+
/**
64+
* @since 5.2
65+
*/
66+
Mono<Void> delete(T entity, @Nullable RefreshPolicy refreshPolicy);
67+
68+
/**
69+
* @since 5.2
70+
*/
71+
Mono<Void> deleteAllById(Iterable<? extends ID> ids, @Nullable RefreshPolicy refreshPolicy);
72+
73+
/**
74+
* @since 5.2
75+
*/
76+
Mono<Void> deleteAll(Iterable<? extends T> entities, @Nullable RefreshPolicy refreshPolicy);
77+
78+
/**
79+
* @since 5.2
80+
*/
81+
Mono<Void> deleteAll(Publisher<? extends T> entityStream, @Nullable RefreshPolicy refreshPolicy);
82+
83+
/**
84+
* @since 5.2
85+
*/
86+
Mono<Void> deleteAll(@Nullable RefreshPolicy refreshPolicy);
87+
}

0 commit comments

Comments
 (0)