Skip to content

Commit 16ebc09

Browse files
committed
HSEARCH-3319 Add context type
1 parent 11f4b48 commit 16ebc09

File tree

377 files changed

+2249
-1952
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

377 files changed

+2249
-1952
lines changed

backend/elasticsearch/src/main/java/org/hibernate/search/backend/elasticsearch/ElasticsearchExtension.java

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -60,21 +60,23 @@
6060
*
6161
* @see #get()
6262
*/
63-
public final class ElasticsearchExtension<H, R, E, LOS>
64-
implements SearchQueryDslExtension<ElasticsearchSearchQuerySelectStep<R, E, LOS>, R, E, LOS>,
63+
public final class ElasticsearchExtension<SR, H, R, E, LOS>
64+
implements SearchQueryDslExtension<SR, ElasticsearchSearchQuerySelectStep<SR, R, E, LOS>, R, E, LOS>,
6565
SearchQueryExtension<ElasticsearchSearchQuery<H>, H>,
66-
SearchPredicateFactoryExtension<ElasticsearchSearchPredicateFactory>,
67-
SearchSortFactoryExtension<ElasticsearchSearchSortFactory>,
68-
SearchProjectionFactoryExtension<ElasticsearchSearchProjectionFactory<R, E>, R, E>,
69-
SearchAggregationFactoryExtension<ElasticsearchSearchAggregationFactory>,
66+
SearchPredicateFactoryExtension<SR, ElasticsearchSearchPredicateFactory<SR>>,
67+
SearchSortFactoryExtension<SR, ElasticsearchSearchSortFactory<SR>>,
68+
SearchProjectionFactoryExtension<SR, ElasticsearchSearchProjectionFactory<SR, R, E>, R, E>,
69+
SearchAggregationFactoryExtension<SR, ElasticsearchSearchAggregationFactory<SR>>,
7070
IndexFieldTypeFactoryExtension<ElasticsearchIndexFieldTypeFactory>,
7171
SchemaExportExtension<ElasticsearchIndexSchemaExport> {
7272

73-
private static final ElasticsearchExtension<Object, Object, Object, Object> INSTANCE = new ElasticsearchExtension<>();
73+
private static final ElasticsearchExtension<Object, Object, Object, Object, Object> INSTANCE =
74+
new ElasticsearchExtension<>();
7475

7576
/**
7677
* Get the extension with generic parameters automatically set as appropriate for the context in which it's used.
7778
*
79+
* @param <SR> Scope root type.
7880
* @param <H> The type of query hits.
7981
* Users should not have to care about this, as the parameter will automatically take the appropriate value when calling
8082
* {@code .extension( ElasticsearchExtension.get() )}.
@@ -90,8 +92,8 @@ public final class ElasticsearchExtension<H, R, E, LOS>
9092
* @return The extension.
9193
*/
9294
@SuppressWarnings("unchecked") // The instance works for any H, R, E and LOS
93-
public static <H, R, E, LOS> ElasticsearchExtension<H, R, E, LOS> get() {
94-
return (ElasticsearchExtension<H, R, E, LOS>) INSTANCE;
95+
public static <SR, H, R, E, LOS> ElasticsearchExtension<SR, H, R, E, LOS> get() {
96+
return (ElasticsearchExtension<SR, H, R, E, LOS>) INSTANCE;
9597
}
9698

9799
private ElasticsearchExtension() {
@@ -102,8 +104,8 @@ private ElasticsearchExtension() {
102104
* {@inheritDoc}
103105
*/
104106
@Override
105-
public Optional<ElasticsearchSearchQuerySelectStep<R, E, LOS>> extendOptional(
106-
SearchQuerySelectStep<?, R, E, LOS, ?, ?> original,
107+
public Optional<ElasticsearchSearchQuerySelectStep<SR, R, E, LOS>> extendOptional(
108+
SearchQuerySelectStep<SR, ?, R, E, LOS, ?, ?> original,
107109
SearchQueryIndexScope<?> scope,
108110
BackendSessionContext sessionContext,
109111
SearchLoadingContextBuilder<E, LOS> loadingContextBuilder) {
@@ -135,9 +137,9 @@ public Optional<ElasticsearchSearchQuery<H>> extendOptional(SearchQuery<H> origi
135137
* {@inheritDoc}
136138
*/
137139
@Override
138-
public Optional<ElasticsearchSearchPredicateFactory> extendOptional(SearchPredicateFactory original) {
140+
public Optional<ElasticsearchSearchPredicateFactory<SR>> extendOptional(SearchPredicateFactory<SR> original) {
139141
if ( original instanceof ElasticsearchSearchPredicateFactory ) {
140-
return Optional.of( (ElasticsearchSearchPredicateFactory) original );
142+
return Optional.of( (ElasticsearchSearchPredicateFactory<SR>) original );
141143
}
142144
else {
143145
return Optional.empty();
@@ -148,10 +150,10 @@ public Optional<ElasticsearchSearchPredicateFactory> extendOptional(SearchPredic
148150
* {@inheritDoc}
149151
*/
150152
@Override
151-
public Optional<ElasticsearchSearchSortFactory> extendOptional(
152-
SearchSortFactory original) {
153+
public Optional<ElasticsearchSearchSortFactory<SR>> extendOptional(
154+
SearchSortFactory<SR> original) {
153155
if ( original instanceof ElasticsearchSearchSortFactory ) {
154-
return Optional.of( (ElasticsearchSearchSortFactory) original );
156+
return Optional.of( (ElasticsearchSearchSortFactory<SR>) original );
155157
}
156158
else {
157159
return Optional.empty();
@@ -162,9 +164,9 @@ public Optional<ElasticsearchSearchSortFactory> extendOptional(
162164
* {@inheritDoc}
163165
*/
164166
@Override
165-
public Optional<ElasticsearchSearchProjectionFactory<R, E>> extendOptional(SearchProjectionFactory<R, E> original) {
167+
public Optional<ElasticsearchSearchProjectionFactory<SR, R, E>> extendOptional(SearchProjectionFactory<SR, R, E> original) {
166168
if ( original instanceof ElasticsearchSearchProjectionFactory ) {
167-
return Optional.of( (ElasticsearchSearchProjectionFactory<R, E>) original );
169+
return Optional.of( (ElasticsearchSearchProjectionFactory<SR, R, E>) original );
168170
}
169171
else {
170172
return Optional.empty();
@@ -175,10 +177,10 @@ public Optional<ElasticsearchSearchProjectionFactory<R, E>> extendOptional(Searc
175177
* {@inheritDoc}
176178
*/
177179
@Override
178-
public Optional<ElasticsearchSearchAggregationFactory> extendOptional(
179-
SearchAggregationFactory original) {
180+
public Optional<ElasticsearchSearchAggregationFactory<SR>> extendOptional(
181+
SearchAggregationFactory<SR> original) {
180182
if ( original instanceof ElasticsearchSearchAggregationFactory ) {
181-
return Optional.of( (ElasticsearchSearchAggregationFactory) original );
183+
return Optional.of( (ElasticsearchSearchAggregationFactory<SR>) original );
182184
}
183185
else {
184186
return Optional.empty();

backend/elasticsearch/src/main/java/org/hibernate/search/backend/elasticsearch/scope/model/impl/ElasticsearchSearchIndexScopeImpl.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -171,24 +171,25 @@ public <P> ElasticsearchSearchQueryBuilder<P> select(BackendSessionContext sessi
171171
}
172172

173173
@Override
174-
public ElasticsearchSearchPredicateFactory predicateFactory() {
175-
return new ElasticsearchSearchPredicateFactoryImpl( SearchPredicateDslContext.root( this ) );
174+
public <SR> ElasticsearchSearchPredicateFactory<SR> predicateFactory() {
175+
return new ElasticsearchSearchPredicateFactoryImpl<SR>( SearchPredicateDslContext.root( this ) );
176176
}
177177

178178
@Override
179-
public ElasticsearchSearchSortFactory sortFactory() {
180-
return new ElasticsearchSearchSortFactoryImpl( SearchSortDslContext
179+
public <SR> ElasticsearchSearchSortFactory<SR> sortFactory() {
180+
return new ElasticsearchSearchSortFactoryImpl<SR>( SearchSortDslContext
181181
.root( this, ElasticsearchSearchSortFactoryImpl::new, predicateFactory() ) );
182182
}
183183

184184
@Override
185-
public <R, E> ElasticsearchSearchProjectionFactory<R, E> projectionFactory() {
185+
public <SR, R, E> ElasticsearchSearchProjectionFactory<SR, R, E> projectionFactory() {
186186
return new ElasticsearchSearchProjectionFactoryImpl<>( SearchProjectionDslContext.root( this ) );
187187
}
188188

189189
@Override
190-
public ElasticsearchSearchAggregationFactory aggregationFactory() {
191-
return new ElasticsearchSearchAggregationFactoryImpl( SearchAggregationDslContext.root( this, predicateFactory() ) );
190+
public <SR> ElasticsearchSearchAggregationFactory<SR> aggregationFactory() {
191+
return new ElasticsearchSearchAggregationFactoryImpl<SR>(
192+
SearchAggregationDslContext.root( this, predicateFactory() ) );
192193
}
193194

194195
@Override

backend/elasticsearch/src/main/java/org/hibernate/search/backend/elasticsearch/search/aggregation/dsl/ElasticsearchSearchAggregationFactory.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,11 @@
1010

1111
import com.google.gson.JsonObject;
1212

13-
public interface ElasticsearchSearchAggregationFactory
14-
extends ExtendedSearchAggregationFactory<ElasticsearchSearchAggregationFactory, ElasticsearchSearchPredicateFactory> {
13+
public interface ElasticsearchSearchAggregationFactory<SR>
14+
extends
15+
ExtendedSearchAggregationFactory<SR,
16+
ElasticsearchSearchAggregationFactory<SR>,
17+
ElasticsearchSearchPredicateFactory<SR>> {
1518

1619
/**
1720
* Create an aggregation from JSON.

backend/elasticsearch/src/main/java/org/hibernate/search/backend/elasticsearch/search/aggregation/dsl/impl/ElasticsearchSearchAggregationFactoryImpl.java

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,24 @@
1313

1414
import com.google.gson.JsonObject;
1515

16-
public class ElasticsearchSearchAggregationFactoryImpl
16+
public class ElasticsearchSearchAggregationFactoryImpl<SR>
1717
extends AbstractSearchAggregationFactory<
18-
ElasticsearchSearchAggregationFactory,
18+
SR,
19+
ElasticsearchSearchAggregationFactory<SR>,
1920
ElasticsearchSearchAggregationIndexScope<?>,
20-
ElasticsearchSearchPredicateFactory>
21-
implements ElasticsearchSearchAggregationFactory {
21+
ElasticsearchSearchPredicateFactory<SR>>
22+
implements ElasticsearchSearchAggregationFactory<SR> {
2223

2324
public ElasticsearchSearchAggregationFactoryImpl(
24-
SearchAggregationDslContext<ElasticsearchSearchAggregationIndexScope<?>,
25-
ElasticsearchSearchPredicateFactory> dslContext) {
25+
SearchAggregationDslContext<SR,
26+
ElasticsearchSearchAggregationIndexScope<?>,
27+
ElasticsearchSearchPredicateFactory<SR>> dslContext) {
2628
super( dslContext );
2729
}
2830

2931
@Override
30-
public ElasticsearchSearchAggregationFactory withRoot(String objectFieldPath) {
31-
return new ElasticsearchSearchAggregationFactoryImpl( dslContext.rescope(
32+
public ElasticsearchSearchAggregationFactory<SR> withRoot(String objectFieldPath) {
33+
return new ElasticsearchSearchAggregationFactoryImpl<SR>( dslContext.rescope(
3234
dslContext.scope().withRoot( objectFieldPath ),
3335
dslContext.predicateFactory().withRoot( objectFieldPath ) ) );
3436
}

backend/elasticsearch/src/main/java/org/hibernate/search/backend/elasticsearch/search/predicate/dsl/ElasticsearchSearchPredicateFactory.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,11 @@
1111

1212
/**
1313
* A factory for search predicates with some Elasticsearch-specific methods.
14+
*
15+
* @param <SR> Scope root type.
1416
*/
15-
public interface ElasticsearchSearchPredicateFactory
16-
extends ExtendedSearchPredicateFactory<ElasticsearchSearchPredicateFactory> {
17+
public interface ElasticsearchSearchPredicateFactory<SR>
18+
extends ExtendedSearchPredicateFactory<SR, ElasticsearchSearchPredicateFactory<SR>> {
1719

1820
/**
1921
* Create a predicate from JSON.

backend/elasticsearch/src/main/java/org/hibernate/search/backend/elasticsearch/search/predicate/dsl/impl/ElasticsearchSearchPredicateFactoryImpl.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,21 @@
1313

1414
import com.google.gson.JsonObject;
1515

16-
public class ElasticsearchSearchPredicateFactoryImpl
16+
public class ElasticsearchSearchPredicateFactoryImpl<SR>
1717
extends AbstractSearchPredicateFactory<
18-
ElasticsearchSearchPredicateFactory,
18+
SR,
19+
ElasticsearchSearchPredicateFactory<SR>,
1920
ElasticsearchSearchPredicateIndexScope<?>>
20-
implements ElasticsearchSearchPredicateFactory {
21+
implements ElasticsearchSearchPredicateFactory<SR> {
2122

2223
public ElasticsearchSearchPredicateFactoryImpl(
2324
SearchPredicateDslContext<ElasticsearchSearchPredicateIndexScope<?>> dslContext) {
2425
super( dslContext );
2526
}
2627

2728
@Override
28-
public ElasticsearchSearchPredicateFactory withRoot(String objectFieldPath) {
29-
return new ElasticsearchSearchPredicateFactoryImpl( dslContext.rescope(
29+
public ElasticsearchSearchPredicateFactory<SR> withRoot(String objectFieldPath) {
30+
return new ElasticsearchSearchPredicateFactoryImpl<SR>( dslContext.rescope(
3031
dslContext.scope().withRoot( objectFieldPath ) ) );
3132
}
3233

backend/elasticsearch/src/main/java/org/hibernate/search/backend/elasticsearch/search/predicate/impl/ElasticsearchNamedPredicate.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ private static class Builder extends AbstractBuilder implements NamedPredicateBu
7171
private final PredicateDefinition definition;
7272
private final String predicateName;
7373
private final ElasticsearchSearchIndexCompositeNodeContext field;
74-
private SearchPredicateFactory factory;
74+
private SearchPredicateFactory<?> factory;
7575
private final Map<String, Object> params = new LinkedHashMap<>();
7676

7777
Builder(PredicateDefinition definition, String predicateName,
@@ -84,7 +84,7 @@ private static class Builder extends AbstractBuilder implements NamedPredicateBu
8484
}
8585

8686
@Override
87-
public void factory(SearchPredicateFactory factory) {
87+
public void factory(SearchPredicateFactory<?> factory) {
8888
this.factory = factory;
8989
}
9090

@@ -95,8 +95,9 @@ public void param(String name, Object value) {
9595

9696
@Override
9797
public SearchPredicate build() {
98-
NamedValuesBasedPredicateDefinitionContext ctx = new NamedValuesBasedPredicateDefinitionContext( factory, params,
99-
name -> QueryLog.INSTANCE.paramNotDefined( name, predicateName, field.eventContext() ) );
98+
NamedValuesBasedPredicateDefinitionContext<?> ctx =
99+
new NamedValuesBasedPredicateDefinitionContext<>( factory, params,
100+
name -> QueryLog.INSTANCE.paramNotDefined( name, predicateName, field.eventContext() ) );
100101

101102
ElasticsearchSearchPredicate providedPredicate = ElasticsearchSearchPredicate.from(
102103
scope, definition.create( ctx ) );

backend/elasticsearch/src/main/java/org/hibernate/search/backend/elasticsearch/search/projection/dsl/ElasticsearchSearchProjectionFactory.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,13 @@
1313
/**
1414
* A factory for search projections with some Elasticsearch-specific methods.
1515
*
16+
* @param <SR> Scope root type.
1617
* @param <R> The type of entity references.
1718
* @param <E> The type of entities.
1819
* @see SearchProjectionFactory
1920
*/
20-
public interface ElasticsearchSearchProjectionFactory<R, E>
21-
extends ExtendedSearchProjectionFactory<ElasticsearchSearchProjectionFactory<R, E>, R, E> {
21+
public interface ElasticsearchSearchProjectionFactory<SR, R, E>
22+
extends ExtendedSearchProjectionFactory<SR, ElasticsearchSearchProjectionFactory<SR, R, E>, R, E> {
2223

2324
/**
2425
* Project to a {@link JsonObject} representing the document as stored in Elasticsearch.

backend/elasticsearch/src/main/java/org/hibernate/search/backend/elasticsearch/search/projection/dsl/impl/ElasticsearchSearchProjectionFactoryImpl.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,22 @@
1313

1414
import com.google.gson.JsonObject;
1515

16-
public class ElasticsearchSearchProjectionFactoryImpl<R, E>
16+
public class ElasticsearchSearchProjectionFactoryImpl<SR, R, E>
1717
extends AbstractSearchProjectionFactory<
18-
ElasticsearchSearchProjectionFactory<R, E>,
18+
SR,
19+
ElasticsearchSearchProjectionFactory<SR, R, E>,
1920
ElasticsearchSearchProjectionIndexScope<?>,
2021
R,
2122
E>
22-
implements ElasticsearchSearchProjectionFactory<R, E> {
23+
implements ElasticsearchSearchProjectionFactory<SR, R, E> {
2324

2425
public ElasticsearchSearchProjectionFactoryImpl(
2526
SearchProjectionDslContext<ElasticsearchSearchProjectionIndexScope<?>> dslContext) {
2627
super( dslContext );
2728
}
2829

2930
@Override
30-
public ElasticsearchSearchProjectionFactory<R, E> withRoot(String objectFieldPath) {
31+
public ElasticsearchSearchProjectionFactory<SR, R, E> withRoot(String objectFieldPath) {
3132
return new ElasticsearchSearchProjectionFactoryImpl<>( dslContext.rescope(
3233
dslContext.scope().withRoot( objectFieldPath ) ) );
3334
}

backend/elasticsearch/src/main/java/org/hibernate/search/backend/elasticsearch/search/query/dsl/ElasticsearchSearchQueryOptionsStep.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,14 @@
1212
import org.hibernate.search.engine.search.query.dsl.SearchQueryOptionsStep;
1313
import org.hibernate.search.util.common.annotation.Incubating;
1414

15-
public interface ElasticsearchSearchQueryOptionsStep<H, LOS>
15+
public interface ElasticsearchSearchQueryOptionsStep<SR, H, LOS>
1616
extends SearchQueryOptionsStep<
17-
ElasticsearchSearchQueryOptionsStep<H, LOS>,
17+
SR,
18+
ElasticsearchSearchQueryOptionsStep<SR, H, LOS>,
1819
H,
1920
LOS,
20-
ElasticsearchSearchSortFactory,
21-
ElasticsearchSearchAggregationFactory>,
21+
ElasticsearchSearchSortFactory<SR>,
22+
ElasticsearchSearchAggregationFactory<SR>>,
2223
ElasticsearchSearchFetchable<H> {
2324

2425
/**
@@ -34,7 +35,7 @@ public interface ElasticsearchSearchQueryOptionsStep<H, LOS>
3435
* @return {@code this}, for method chaining.
3536
*/
3637
@Incubating
37-
ElasticsearchSearchQueryOptionsStep<H, LOS> requestTransformer(ElasticsearchSearchRequestTransformer transformer);
38+
ElasticsearchSearchQueryOptionsStep<SR, H, LOS> requestTransformer(ElasticsearchSearchRequestTransformer transformer);
3839

3940
@Override
4041
ElasticsearchSearchQuery<H> toQuery();

0 commit comments

Comments
 (0)