Skip to content

Commit 06a6ca2

Browse files
gavinkingDavideD
authored andcommitted
simplify some code in query hierarchy + squash some warnings
1 parent 70878ea commit 06a6ca2

File tree

11 files changed

+63
-86
lines changed

11 files changed

+63
-86
lines changed

hibernate-reactive-core/src/main/java/org/hibernate/reactive/mutiny/impl/MutinyQueryImpl.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
import org.hibernate.CacheMode;
1616
import org.hibernate.FlushMode;
1717
import org.hibernate.LockMode;
18-
import org.hibernate.graph.RootGraph;
18+
import org.hibernate.graph.GraphSemantic;
19+
import org.hibernate.graph.spi.RootGraphImplementor;
1920
import org.hibernate.reactive.mutiny.Mutiny.Query;
2021
import org.hibernate.reactive.query.ReactiveQuery;
2122

@@ -66,7 +67,7 @@ public Query<R> setLockMode(LockMode lockMode) {
6667

6768
@Override
6869
public Query<R> setPlan(EntityGraph<R> entityGraph) {
69-
delegate.applyFetchGraph( (RootGraph<?>) entityGraph );
70+
delegate.applyGraph( (RootGraphImplementor<?>) entityGraph, GraphSemantic.FETCH );
7071
return this;
7172
}
7273

hibernate-reactive-core/src/main/java/org/hibernate/reactive/mutiny/impl/MutinySelectionQueryImpl.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
import org.hibernate.CacheMode;
1616
import org.hibernate.FlushMode;
1717
import org.hibernate.LockMode;
18-
import org.hibernate.graph.RootGraph;
18+
import org.hibernate.graph.GraphSemantic;
19+
import org.hibernate.graph.spi.RootGraphImplementor;
1920
import org.hibernate.reactive.mutiny.Mutiny.SelectionQuery;
2021
import org.hibernate.reactive.query.ReactiveQuery;
2122

@@ -65,7 +66,7 @@ public SelectionQuery<R> setLockMode(LockMode lockMode) {
6566

6667
@Override
6768
public SelectionQuery<R> setPlan(EntityGraph<R> entityGraph) {
68-
delegate.applyFetchGraph( (RootGraph<?>) entityGraph );
69+
delegate.applyGraph( (RootGraphImplementor<?>) entityGraph, GraphSemantic.FETCH );
6970
return this;
7071
}
7172

hibernate-reactive-core/src/main/java/org/hibernate/reactive/query/ReactiveQuery.java

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515
import org.hibernate.FlushMode;
1616
import org.hibernate.LockMode;
1717
import org.hibernate.LockOptions;
18-
import org.hibernate.graph.GraphSemantic;
19-
import org.hibernate.graph.RootGraph;
2018
import org.hibernate.query.BindableType;
2119
import org.hibernate.query.ParameterMetadata;
2220
import org.hibernate.query.QueryParameter;
@@ -37,20 +35,6 @@
3735
public interface ReactiveQuery<R> extends ReactiveSelectionQuery<R>, ReactiveMutationQuery<R> {
3836
String getQueryString();
3937

40-
@Override
41-
ReactiveQuery<R> applyGraph(RootGraph<?> graph, GraphSemantic semantic);
42-
43-
@Override
44-
default ReactiveQuery<R> applyFetchGraph(RootGraph<?> graph) {
45-
return applyGraph( graph, GraphSemantic.FETCH );
46-
}
47-
48-
@Override
49-
@SuppressWarnings("UnusedDeclaration")
50-
default ReactiveQuery<R> applyLoadGraph(RootGraph<?> graph) {
51-
return applyGraph( graph, GraphSemantic.LOAD );
52-
}
53-
5438
String getComment();
5539

5640
ReactiveQuery<R> setComment(String comment);

hibernate-reactive-core/src/main/java/org/hibernate/reactive/query/ReactiveSelectionQuery.java

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
import org.hibernate.LockMode;
2020
import org.hibernate.LockOptions;
2121
import org.hibernate.graph.GraphSemantic;
22-
import org.hibernate.graph.RootGraph;
22+
import org.hibernate.graph.spi.RootGraphImplementor;
2323
import org.hibernate.query.BindableType;
2424
import org.hibernate.query.CommonQueryContract;
2525
import org.hibernate.query.QueryParameter;
@@ -119,16 +119,7 @@ default CompletionStage<List<R>> getReactiveResultList() {
119119

120120
ReactiveSelectionQuery<R> setFollowOnLocking(boolean enable);
121121

122-
ReactiveSelectionQuery<R> applyGraph(RootGraph<?> graph, GraphSemantic semantic);
123-
124-
default ReactiveSelectionQuery<R> applyFetchGraph(RootGraph<?> graph) {
125-
return applyGraph( graph, GraphSemantic.FETCH );
126-
}
127-
128-
@SuppressWarnings("UnusedDeclaration")
129-
default ReactiveSelectionQuery<R> applyLoadGraph(RootGraph<?> graph) {
130-
return applyGraph( graph, GraphSemantic.LOAD );
131-
}
122+
void applyGraph(RootGraphImplementor<?> graph, GraphSemantic semantic);
132123

133124
@Override
134125
ReactiveSelectionQuery<R> setParameter(String name, Object value);

hibernate-reactive-core/src/main/java/org/hibernate/reactive/query/sql/internal/ReactiveNativeQueryImpl.java

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import org.hibernate.engine.spi.SharedSessionContractImplementor;
2626
import org.hibernate.graph.GraphSemantic;
2727
import org.hibernate.graph.RootGraph;
28+
import org.hibernate.graph.spi.RootGraphImplementor;
2829
import org.hibernate.internal.AbstractSharedSessionContract;
2930
import org.hibernate.metamodel.model.domain.BasicDomainType;
3031
import org.hibernate.query.BindableType;
@@ -229,13 +230,13 @@ public ReactiveNativeQueryImpl<R> addScalar(String columnAlias) {
229230
}
230231

231232
@Override
232-
public ReactiveNativeQueryImpl<R> addScalar(String columnAlias, @SuppressWarnings("rawtypes") BasicDomainType type) {
233+
public ReactiveNativeQueryImpl<R> addScalar(String columnAlias, BasicDomainType type) {
233234
super.addScalar( columnAlias, type );
234235
return this;
235236
}
236237

237238
@Override
238-
public ReactiveNativeQueryImpl<R> addScalar(String columnAlias, @SuppressWarnings("rawtypes") Class javaType) {
239+
public ReactiveNativeQueryImpl<R> addScalar(String columnAlias, Class javaType) {
239240
super.addScalar( columnAlias, javaType );
240241
return this;
241242
}
@@ -277,7 +278,7 @@ public <O, J> ReactiveNativeQueryImpl<R> addScalar(String columnAlias, Class<O>
277278
}
278279

279280
@Override
280-
public ReactiveNativeQueryImpl<R> addAttributeResult(String columnAlias, @SuppressWarnings("rawtypes") Class entityJavaType, String attributePath) {
281+
public ReactiveNativeQueryImpl<R> addAttributeResult(String columnAlias, Class entityJavaType, String attributePath) {
281282
super.addAttributeResult( columnAlias, entityJavaType, attributePath );
282283
return this;
283284
}
@@ -289,7 +290,7 @@ public ReactiveNativeQueryImpl<R> addAttributeResult(String columnAlias, String
289290
}
290291

291292
@Override
292-
public ReactiveNativeQueryImpl<R> addAttributeResult(String columnAlias, @SuppressWarnings("rawtypes") SingularAttribute attribute) {
293+
public ReactiveNativeQueryImpl<R> addAttributeResult(String columnAlias, SingularAttribute attribute) {
293294
super.addAttributeResult( columnAlias, attribute );
294295
return this;
295296
}
@@ -312,19 +313,19 @@ public ReactiveNativeQueryImpl<R> addEntity(String tableAlias, String entityName
312313
return this;
313314
}
314315
@Override
315-
public ReactiveNativeQueryImpl<R> addEntity(@SuppressWarnings("rawtypes") Class entityType) {
316+
public ReactiveNativeQueryImpl<R> addEntity(Class entityType) {
316317
super.addEntity( entityType );
317318
return this;
318319
}
319320

320321
@Override
321-
public ReactiveNativeQueryImpl<R> addEntity(String tableAlias, @SuppressWarnings("rawtypes") Class entityType) {
322+
public ReactiveNativeQueryImpl<R> addEntity(String tableAlias, Class entityType) {
322323
super.addEntity( tableAlias, entityType );
323324
return this;
324325
}
325326

326327
@Override
327-
public ReactiveNativeQueryImpl<R> addEntity(String tableAlias, @SuppressWarnings("rawtypes") Class entityClass, LockMode lockMode) {
328+
public ReactiveNativeQueryImpl<R> addEntity(String tableAlias, Class entityClass, LockMode lockMode) {
328329
super.addEntity( tableAlias, entityClass, lockMode );
329330
return this;
330331
}
@@ -360,7 +361,7 @@ public ReactiveNativeQueryImpl<R> addSynchronizedEntityName(String entityName) {
360361
}
361362

362363
@Override
363-
public ReactiveNativeQueryImpl<R> addSynchronizedEntityClass(@SuppressWarnings("rawtypes") Class entityClass) {
364+
public ReactiveNativeQueryImpl<R> addSynchronizedEntityClass(Class entityClass) {
364365
super.addSynchronizedEntityClass( entityClass );
365366
return this;
366367
}
@@ -375,7 +376,7 @@ public ReactiveNativeQueryImpl<R> applyLoadGraph(RootGraph graph) {
375376
return this;
376377
}
377378

378-
@Override
379+
@Override @Deprecated
379380
public ReactiveNativeQueryImpl<R> setAliasSpecificLockMode(String alias, LockMode lockMode) {
380381
super.setAliasSpecificLockMode( alias, lockMode );
381382
return this;
@@ -622,7 +623,7 @@ public ReactiveNativeQueryImpl<R> setParameter(Parameter<Calendar> param, Calend
622623
}
623624

624625
@Override
625-
public ReactiveNativeQueryImpl<R> setParameterList(String name, @SuppressWarnings("rawtypes") Collection values) {
626+
public ReactiveNativeQueryImpl<R> setParameterList(String name, Collection values) {
626627
super.setParameterList( name, values );
627628
return this;
628629
}
@@ -658,7 +659,7 @@ public <P> ReactiveNativeQueryImpl<R> setParameterList(String name, P[] values,
658659
}
659660

660661
@Override
661-
public ReactiveNativeQueryImpl<R> setParameterList(int position, @SuppressWarnings("rawtypes") Collection values) {
662+
public ReactiveNativeQueryImpl<R> setParameterList(int position, Collection values) {
662663
super.setParameterList( position, values );
663664
return this;
664665
}
@@ -736,8 +737,13 @@ public ReactiveNativeQueryImpl<R> setProperties(Object bean) {
736737
}
737738

738739
@Override
739-
public ReactiveNativeQueryImpl<R> setProperties(@SuppressWarnings("rawtypes") Map bean) {
740+
public ReactiveNativeQueryImpl<R> setProperties(Map bean) {
740741
super.setProperties( bean );
741742
return this;
742743
}
744+
745+
@Override
746+
public void applyGraph(RootGraphImplementor<?> graph, GraphSemantic semantic) {
747+
super.applyGraph( graph, semantic );
748+
}
743749
}

hibernate-reactive-core/src/main/java/org/hibernate/reactive/query/sql/spi/ReactiveNamedSqmQueryMemento.java

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -44,21 +44,27 @@ public <T> SqmQueryImplementor<T> toQuery(SharedSessionContractImplementor sessi
4444
public <T> SqmQueryImplementor<T> toQuery(SharedSessionContractImplementor session, Class<T> resultType) {
4545
// A bit of a hack, I'm sure that if we have a better look at this we can avoid the instanceof
4646
if ( delegate instanceof NamedHqlQueryMementoImpl ) {
47-
return new ReactiveQuerySqmImpl<T>( (NamedHqlQueryMementoImpl) delegate, resultType, session );
47+
return new ReactiveQuerySqmImpl<>( (NamedHqlQueryMementoImpl) delegate, resultType, session );
4848
}
49-
if ( delegate instanceof NamedHqlQueryMementoImpl ) {
50-
return new ReactiveQuerySqmImpl<T>( (NamedCriteriaQueryMementoImpl) delegate, resultType, session );
49+
if ( delegate instanceof NamedCriteriaQueryMementoImpl ) {
50+
return new ReactiveQuerySqmImpl<>( (NamedCriteriaQueryMementoImpl) delegate, resultType, session );
51+
}
52+
else {
53+
throw new UnsupportedOperationException( "NamedSqmQueryMemento not recognized: " + delegate.getClass() );
5154
}
52-
53-
throw new UnsupportedOperationException( "NamedSqmQueryMemento not recognized: " + delegate.getClass() );
5455
}
5556

5657
@Override
5758
public <T> SqmSelectionQuery<T> toSelectionQuery(Class<T> resultType, SharedSessionContractImplementor session) {
58-
SqmSelectionQuery<T> selectionQuery = delegate.toSelectionQuery( resultType, session );
59-
return selectionQuery == null
60-
? null
61-
: new ReactiveSqmSelectionQueryImpl<>( (SqmSelectStatement) selectionQuery.getSqmStatement(), resultType, session );
59+
final SqmSelectionQuery<T> selectionQuery = delegate.toSelectionQuery( resultType, session );
60+
if ( selectionQuery == null ) {
61+
return null;
62+
}
63+
else {
64+
@SuppressWarnings("unchecked")
65+
final SqmSelectStatement<T> statement = (SqmSelectStatement<T>) selectionQuery.getSqmStatement();
66+
return new ReactiveSqmSelectionQueryImpl<>( statement, resultType, session );
67+
}
6268
}
6369

6470
@Override
@@ -67,7 +73,7 @@ public String getHqlString() {
6773
}
6874

6975
@Override
70-
public SqmStatement getSqmStatement() {
76+
public SqmStatement<?> getSqmStatement() {
7177
return delegate.getSqmStatement();
7278
}
7379

hibernate-reactive-core/src/main/java/org/hibernate/reactive/query/sqm/iternal/ReactiveQuerySqmImpl.java

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import org.hibernate.engine.spi.SharedSessionContractImplementor;
2626
import org.hibernate.graph.GraphSemantic;
2727
import org.hibernate.graph.RootGraph;
28+
import org.hibernate.graph.spi.RootGraphImplementor;
2829
import org.hibernate.id.BulkInsertionCapableIdentifierGenerator;
2930
import org.hibernate.id.IdentifierGenerator;
3031
import org.hibernate.id.OptimizableGenerator;
@@ -234,16 +235,16 @@ private ReactiveSelectQueryPlan<R> resolveSelectReactiveQueryPlan() {
234235
}
235236

236237
private ReactiveSelectQueryPlan<R> buildSelectQueryPlan() {
237-
final SqmSelectStatement<R>[] concreteSqmStatements = QuerySplitter
238-
.split( (SqmSelectStatement<R>) getSqmStatement(), getSession().getFactory() );
238+
final SqmSelectStatement<R>[] concreteSqmStatements =
239+
QuerySplitter.split( (SqmSelectStatement<R>) getSqmStatement(), getSession().getFactory() );
239240

240241
return concreteSqmStatements.length > 1
241242
? buildAggregatedSelectQueryPlan( concreteSqmStatements )
242243
: buildConcreteSelectQueryPlan( concreteSqmStatements[0], getResultType(), getQueryOptions() );
243244
}
244245

245246
private ReactiveSelectQueryPlan<R> buildAggregatedSelectQueryPlan(SqmSelectStatement<?>[] concreteSqmStatements) {
246-
//noinspection unchecked
247+
@SuppressWarnings("unchecked")
247248
final ReactiveSelectQueryPlan<R>[] aggregatedQueryPlans = new ReactiveSelectQueryPlan[ concreteSqmStatements.length ];
248249

249250
// todo (6.0) : we want to make sure that certain thing (ResultListTransformer, etc) only get applied at the aggregator-level
@@ -470,7 +471,7 @@ public ReactiveQuerySqmImpl<R> setResultListTransformer(ResultListTransformer tr
470471
return this;
471472
}
472473

473-
@Override
474+
@Override @Deprecated
474475
public <T> ReactiveQuerySqmImpl<T> setResultTransformer(ResultTransformer<T> transformer) {
475476
throw new UnsupportedOperationException();
476477
}
@@ -509,7 +510,7 @@ public ReactiveQuerySqmImpl<R> setLockMode(LockModeType lockMode) {
509510
// covariance
510511

511512

512-
@Override
513+
@Override @Deprecated
513514
public ReactiveQuerySqmImpl<R> setAliasSpecificLockMode(String alias, LockMode lockMode) {
514515
super.setAliasSpecificLockMode( alias, lockMode );
515516
return this;
@@ -826,4 +827,9 @@ public ReactiveQuerySqmImpl<R> setFollowOnLocking(boolean enable) {
826827
super.setFollowOnLocking( enable );
827828
return this;
828829
}
830+
831+
@Override
832+
public void applyGraph(RootGraphImplementor<?> graph, GraphSemantic semantic) {
833+
super.applyGraph( graph, semantic );
834+
}
829835
}

hibernate-reactive-core/src/main/java/org/hibernate/reactive/query/sqm/iternal/ReactiveSqmSelectionQueryImpl.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import org.hibernate.LockMode;
2424
import org.hibernate.engine.spi.SharedSessionContractImplementor;
2525
import org.hibernate.graph.GraphSemantic;
26-
import org.hibernate.graph.RootGraph;
2726
import org.hibernate.graph.spi.RootGraphImplementor;
2827
import org.hibernate.internal.util.collections.IdentitySet;
2928
import org.hibernate.query.BindableType;
@@ -39,7 +38,6 @@
3938
import org.hibernate.query.spi.QueryOptions;
4039
import org.hibernate.query.sqm.internal.SqmSelectionQueryImpl;
4140
import org.hibernate.query.sqm.tree.select.SqmSelectStatement;
42-
import org.hibernate.reactive.query.ReactiveSelectionQuery;
4341
import org.hibernate.reactive.query.spi.ReactiveAbstractSelectionQuery;
4442
import org.hibernate.reactive.query.sqm.ReactiveSqmSelectionQuery;
4543

@@ -86,7 +84,7 @@ public ReactiveSqmSelectionQueryImpl(
8684
}
8785

8886
public ReactiveSqmSelectionQueryImpl(
89-
SqmSelectStatement criteria,
87+
SqmSelectStatement<R> criteria,
9088
Class<R> expectedResultType,
9189
SharedSessionContractImplementor session) {
9290
super( criteria, expectedResultType, session );
@@ -605,8 +603,7 @@ public ReactiveSqmSelectionQueryImpl<R> setProperties(Object bean) {
605603
}
606604

607605
@Override
608-
public ReactiveSelectionQuery<R> applyGraph(RootGraph<?> graph, GraphSemantic semantic) {
609-
getQueryOptions().applyGraph( (RootGraphImplementor<?>) graph, semantic );
610-
return this;
606+
public void applyGraph(RootGraphImplementor<?> graph, GraphSemantic semantic) {
607+
getQueryOptions().applyGraph( graph, semantic );
611608
}
612609
}

hibernate-reactive-core/src/main/java/org/hibernate/reactive/session/ReactiveSqmQueryImplementor.java

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616
import org.hibernate.Incubating;
1717
import org.hibernate.LockMode;
1818
import org.hibernate.LockOptions;
19-
import org.hibernate.graph.GraphSemantic;
20-
import org.hibernate.graph.RootGraph;
2119
import org.hibernate.query.BindableType;
2220
import org.hibernate.query.QueryParameter;
2321
import org.hibernate.query.ResultListTransformer;
@@ -59,21 +57,6 @@ public interface ReactiveSqmQueryImplementor<R> extends ReactiveQueryImplementor
5957

6058
ReactiveSqmQueryImplementor<R> setReadOnly(boolean readOnly);
6159

62-
@Override
63-
ReactiveSqmQueryImplementor<R> applyGraph(RootGraph<?> graph, GraphSemantic semantic);
64-
65-
@Override
66-
default ReactiveSqmQueryImplementor<R> applyFetchGraph(RootGraph<?> graph) {
67-
ReactiveQueryImplementor.super.applyFetchGraph( graph );
68-
return this;
69-
}
70-
71-
@Override
72-
default ReactiveSqmQueryImplementor<R> applyLoadGraph(RootGraph<?> graph) {
73-
ReactiveQueryImplementor.super.applyLoadGraph( graph );
74-
return this;
75-
}
76-
7760
@Override
7861
ReactiveSqmQueryImplementor<R> setComment(String comment);
7962

@@ -90,7 +73,7 @@ default ReactiveSqmQueryImplementor<R> applyLoadGraph(RootGraph<?> graph) {
9073
<T> ReactiveSqmQueryImplementor<T> setTupleTransformer(TupleTransformer<T> transformer);
9174

9275
@Override
93-
ReactiveSqmQueryImplementor<R> setResultListTransformer(ResultListTransformer transformer);
76+
ReactiveSqmQueryImplementor<R> setResultListTransformer(ResultListTransformer<R> transformer);
9477

9578

9679
@Override

0 commit comments

Comments
 (0)