-
Notifications
You must be signed in to change notification settings - Fork 194
Add type-safe property paths overloads (#2126) #2128
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: AddFTS
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,6 +21,7 @@ | |
| import java.util.stream.Stream; | ||
|
|
||
| import org.springframework.dao.IncorrectResultSizeDataAccessException; | ||
| import org.springframework.data.core.TypedPropertyPath; | ||
| import org.springframework.data.couchbase.core.support.InCollection; | ||
| import org.springframework.data.couchbase.core.support.InScope; | ||
| import org.springframework.data.couchbase.core.support.WithSearchConsistency; | ||
|
|
@@ -167,6 +168,9 @@ interface FindBySearchWithSkip<T> extends FindBySearchWithLimit<T> { | |
|
|
||
| interface FindBySearchWithSort<T> extends FindBySearchWithSkip<T> { | ||
| FindBySearchWithSkip<T> withSort(SearchSort... sort); | ||
|
|
||
| <P> FindBySearchWithSkip<T> withSort(TypedPropertyPath<P, ?> property, | ||
| TypedPropertyPath<P, ?>... additionalProperties); | ||
| } | ||
|
|
||
| interface FindBySearchWithHighlight<T> extends FindBySearchWithSort<T> { | ||
|
|
@@ -175,6 +179,14 @@ interface FindBySearchWithHighlight<T> extends FindBySearchWithSort<T> { | |
| default FindBySearchWithSort<T> withHighlight(String... fields) { | ||
| return withHighlight(HighlightStyle.SERVER_DEFAULT, fields); | ||
| } | ||
|
|
||
| <P> FindBySearchWithSort<T> withHighlight(HighlightStyle style, TypedPropertyPath<P, ?> field, | ||
| TypedPropertyPath<P, ?>... additionalFields); | ||
|
|
||
| default <P> FindBySearchWithSort<T> withHighlight(TypedPropertyPath<P, ?> field, | ||
| TypedPropertyPath<P, ?>... additionalFields) { | ||
| return withHighlight(HighlightStyle.SERVER_DEFAULT, field, additionalFields); | ||
| } | ||
| } | ||
|
|
||
| interface FindBySearchWithFacets<T> extends FindBySearchWithHighlight<T> { | ||
|
|
@@ -183,6 +195,9 @@ interface FindBySearchWithFacets<T> extends FindBySearchWithHighlight<T> { | |
|
|
||
| interface FindBySearchWithFields<T> extends FindBySearchWithFacets<T> { | ||
| FindBySearchWithFacets<T> withFields(String... fields); | ||
|
|
||
| <P> FindBySearchWithFacets<T> withFields(TypedPropertyPath<P, ?> field, | ||
| TypedPropertyPath<P, ?>... additionalFields); | ||
|
Comment on lines
169
to
+200
|
||
| } | ||
|
|
||
| interface FindBySearchWithProjection<T> extends FindBySearchWithFields<T> { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,6 +19,7 @@ | |
| import java.util.Map; | ||
| import java.util.stream.Stream; | ||
|
|
||
| import org.springframework.data.core.TypedPropertyPath; | ||
| import org.springframework.data.couchbase.core.ReactiveFindBySearchOperationSupport.ReactiveFindBySearchSupport; | ||
| import org.springframework.data.couchbase.core.query.OptionsBuilder; | ||
| import org.springframework.util.Assert; | ||
|
|
@@ -186,8 +187,8 @@ public FindBySearchWithOptions<T> inCollection(final String collection) { | |
| @Override | ||
| public FindBySearchWithQuery<T> withOptions(final SearchOptions options) { | ||
| return new ExecutableFindBySearchSupport<>(template, domainType, returnType, indexName, searchRequest, | ||
| scanConsistency, scope, collection, options != null ? options : this.options, sort, | ||
| highlightStyle, highlightFields, facets, fields, limitSkip); | ||
| scanConsistency, scope, collection, options != null ? options : this.options, sort, highlightStyle, | ||
| highlightFields, facets, fields, limitSkip); | ||
| } | ||
|
|
||
| @Override | ||
|
|
@@ -215,11 +216,23 @@ public FindBySearchWithSkip<T> withSort(SearchSort... sort) { | |
| fields, limitSkip); | ||
| } | ||
|
|
||
| @Override | ||
| public <P> FindBySearchWithSkip<T> withSort(TypedPropertyPath<P, ?> property, | ||
| TypedPropertyPath<P, ?>... additionalProperties) { | ||
| return withSort(SearchPropertyPathSupport.toSearchSorts(template.getConverter(), property, additionalProperties)); | ||
| } | ||
|
Comment on lines
+219
to
+223
|
||
|
|
||
| @Override | ||
| public FindBySearchWithSort<T> withHighlight(HighlightStyle style, String... fields) { | ||
| return new ExecutableFindBySearchSupport<>(template, domainType, returnType, indexName, searchRequest, | ||
| scanConsistency, scope, collection, options, sort, style, fields, facets, | ||
| this.fields, limitSkip); | ||
| scanConsistency, scope, collection, options, sort, style, fields, facets, this.fields, limitSkip); | ||
| } | ||
|
|
||
| @Override | ||
| public <P> FindBySearchWithSort<T> withHighlight(HighlightStyle style, TypedPropertyPath<P, ?> field, | ||
| TypedPropertyPath<P, ?>... additionalFields) { | ||
| return withHighlight(style, | ||
| SearchPropertyPathSupport.getMappedFieldPaths(template.getConverter(), field, additionalFields)); | ||
| } | ||
|
|
||
| @Override | ||
|
|
@@ -235,5 +248,11 @@ public FindBySearchWithFacets<T> withFields(String... fields) { | |
| scanConsistency, scope, collection, options, sort, highlightStyle, highlightFields, facets, | ||
| fields, limitSkip); | ||
| } | ||
|
|
||
| @Override | ||
| public <P> FindBySearchWithFacets<T> withFields(TypedPropertyPath<P, ?> field, | ||
| TypedPropertyPath<P, ?>... additionalFields) { | ||
| return withFields(SearchPropertyPathSupport.getMappedFieldPaths(template.getConverter(), field, additionalFields)); | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,17 +19,20 @@ | |
| import com.couchbase.client.java.kv.MutateInOptions; | ||
| import com.couchbase.client.java.kv.PersistTo; | ||
| import com.couchbase.client.java.kv.ReplicateTo; | ||
| import org.springframework.data.core.TypedPropertyPath; | ||
| import org.springframework.data.couchbase.core.support.*; | ||
| import reactor.core.publisher.Flux; | ||
| import reactor.core.publisher.Mono; | ||
|
|
||
| import java.time.Duration; | ||
| import java.util.Arrays; | ||
| import java.util.Collection; | ||
|
|
||
| /** | ||
| * Mutate In Operations | ||
| * | ||
| * @author Tigran Babloyan | ||
| * @author Emilien Bevierre | ||
| * @since 5.1 | ||
| */ | ||
| public interface ExecutableMutateInByIdOperation { | ||
|
|
@@ -98,6 +101,42 @@ interface MutateInByIdWithPaths<T> extends TerminatingMutateInById<T>, WithMutat | |
| * By default the CAS value is not provided. | ||
| */ | ||
| MutateInByIdWithPaths<T> withCasProvided(); | ||
|
|
||
| /** | ||
| * Type-safe variant of {@link #withRemovePaths(String...)} using property paths. | ||
| * @since 6.1 | ||
| */ | ||
| @SuppressWarnings("unchecked") | ||
| default MutateInByIdWithPaths<T> withRemovePaths(TypedPropertyPath<T, ?>... removePaths) { | ||
| return withRemovePaths(Arrays.stream(removePaths).map(TypedPropertyPath::toDotPath).toArray(String[]::new)); | ||
| } | ||
|
|
||
| /** | ||
| * Type-safe variant of {@link #withInsertPaths(String...)} using property paths. | ||
| * @since 6.1 | ||
| */ | ||
| @SuppressWarnings("unchecked") | ||
| default MutateInByIdWithPaths<T> withInsertPaths(TypedPropertyPath<T, ?>... insertPaths) { | ||
| return withInsertPaths(Arrays.stream(insertPaths).map(TypedPropertyPath::toDotPath).toArray(String[]::new)); | ||
| } | ||
|
|
||
| /** | ||
| * Type-safe variant of {@link #withUpsertPaths(String...)} using property paths. | ||
| * @since 6.1 | ||
| */ | ||
| @SuppressWarnings("unchecked") | ||
| default MutateInByIdWithPaths<T> withUpsertPaths(TypedPropertyPath<T, ?>... upsertPaths) { | ||
| return withUpsertPaths(Arrays.stream(upsertPaths).map(TypedPropertyPath::toDotPath).toArray(String[]::new)); | ||
| } | ||
|
|
||
| /** | ||
| * Type-safe variant of {@link #withReplacePaths(String...)} using property paths. | ||
| * @since 6.1 | ||
| */ | ||
| @SuppressWarnings("unchecked") | ||
| default MutateInByIdWithPaths<T> withReplacePaths(TypedPropertyPath<T, ?>... replacePaths) { | ||
| return withReplacePaths(Arrays.stream(replacePaths).map(TypedPropertyPath::toDotPath).toArray(String[]::new)); | ||
| } | ||
|
Comment on lines
+105
to
+139
|
||
| } | ||
|
|
||
| /** | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,7 +18,10 @@ | |
| import reactor.core.publisher.Flux; | ||
| import reactor.core.publisher.Mono; | ||
|
|
||
| import java.util.Arrays; | ||
|
|
||
| import org.springframework.dao.IncorrectResultSizeDataAccessException; | ||
| import org.springframework.data.core.TypedPropertyPath; | ||
| import org.springframework.data.couchbase.core.query.Query; | ||
| import org.springframework.data.couchbase.core.query.QueryCriteriaDefinition; | ||
| import org.springframework.data.couchbase.core.support.InCollection; | ||
|
|
@@ -38,6 +41,7 @@ | |
| * | ||
| * @author Michael Nitschinger | ||
| * @author Michael Reiche | ||
| * @author Emilien Bevierre | ||
| */ | ||
| public interface ReactiveFindByQueryOperation { | ||
|
|
||
|
|
@@ -217,6 +221,17 @@ interface FindByQueryWithProjecting<T> extends FindByQueryWithProjection<T> { | |
| * @throws IllegalArgumentException if returnType is {@literal null}. | ||
| */ | ||
| FindByQueryWithProjection<T> project(String[] fields); | ||
|
|
||
| /** | ||
| * Type-safe variant of {@link #project(String[])} using property paths. | ||
| * | ||
| * @param fields the property paths to project. | ||
| * @since 6.1 | ||
| */ | ||
| @SuppressWarnings("unchecked") | ||
| default FindByQueryWithProjection<T> project(TypedPropertyPath<T, ?>... fields) { | ||
| return project(Arrays.stream(fields).map(TypedPropertyPath::toDotPath).toArray(String[]::new)); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -234,6 +249,17 @@ interface FindByQueryWithDistinct<T> extends FindByQueryWithProjecting<T>, WithD | |
| * @throws IllegalArgumentException if field is {@literal null}. | ||
| */ | ||
| FindByQueryWithProjection<T> distinct(String[] distinctFields); | ||
|
|
||
| /** | ||
| * Type-safe variant of {@link #distinct(String[])} using property paths. | ||
| * | ||
| * @param distinctFields the property paths for distinct fields. | ||
| * @since 6.1 | ||
| */ | ||
| @SuppressWarnings("unchecked") | ||
| default FindByQueryWithProjection<T> distinct(TypedPropertyPath<T, ?>... distinctFields) { | ||
| return distinct(Arrays.stream(distinctFields).map(TypedPropertyPath::toDotPath).toArray(String[]::new)); | ||
| } | ||
|
Comment on lines
225
to
+262
|
||
| } | ||
|
|
||
| /** | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
project(TypedPropertyPath...)anddistinct(TypedPropertyPath...)overloads useTypedPropertyPath<?, ?>..., which allows passing paths unrelated to the queried entity typeT. Consider changing them toTypedPropertyPath<T, ?>...so these overloads actually enforce type-safe paths for this fluent API.