Skip to content

Commit 64d332a

Browse files
SanneDavideD
authored andcommitted
Avoid recursive wrapping of ReactiveResultSetMappingProcessor
1 parent 5afc9ff commit 64d332a

File tree

2 files changed

+44
-10
lines changed

2 files changed

+44
-10
lines changed

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

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,7 @@ public ReactiveNamedObjectRepositoryImpl(NamedObjectRepository delegate) {
3232

3333
@Override
3434
public NamedSqmQueryMemento getSqmQueryMemento(String queryName) {
35-
NamedSqmQueryMemento sqmQueryMemento = delegate.getSqmQueryMemento( queryName );
36-
return sqmQueryMemento == null
37-
? null
38-
: new ReactiveNamedSqmQueryMemento( sqmQueryMemento );
35+
return wrap( delegate.getSqmQueryMemento( queryName ) );
3936
}
4037

4138
@Override
@@ -50,10 +47,7 @@ public void registerSqmQueryMemento(String name, NamedSqmQueryMemento descriptor
5047

5148
@Override
5249
public NamedNativeQueryMemento getNativeQueryMemento(String queryName) {
53-
NamedNativeQueryMemento nativeQueryMemento = delegate.getNativeQueryMemento( queryName );
54-
return nativeQueryMemento == null
55-
? null
56-
: new ReactiveNamedNativeQueryMemento( nativeQueryMemento );
50+
return wrap( delegate.getNativeQueryMemento( queryName ) );
5751
}
5852

5953
@Override
@@ -123,4 +117,31 @@ public void prepare(SessionFactoryImplementor sessionFactory, Metadata bootMetam
123117
public void close() {
124118
delegate.close();
125119
}
120+
121+
private static NamedSqmQueryMemento wrap(final NamedSqmQueryMemento sqmQueryMemento) {
122+
if ( sqmQueryMemento == null ) {
123+
return null;
124+
}
125+
//Avoid nested wrapping!
126+
else if ( sqmQueryMemento instanceof ReactiveNamedSqmQueryMemento ) {
127+
return sqmQueryMemento;
128+
}
129+
else {
130+
return new ReactiveNamedSqmQueryMemento( sqmQueryMemento );
131+
}
132+
}
133+
134+
private static NamedNativeQueryMemento wrap(final NamedNativeQueryMemento nativeQueryMemento) {
135+
if ( nativeQueryMemento == null ) {
136+
return null;
137+
}
138+
//Avoid nested wrapping!
139+
else if ( nativeQueryMemento instanceof ReactiveNamedNativeQueryMemento ) {
140+
return nativeQueryMemento;
141+
}
142+
else {
143+
return new ReactiveNamedNativeQueryMemento( nativeQueryMemento );
144+
}
145+
}
146+
126147
}

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

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,20 @@ public ReactiveResultSetMappingProcessor(ResultSetMapping resultSetMapping, Sess
1818

1919
@Override
2020
public ResultSetMapping generateResultMapping(boolean queryHadAliases) {
21-
ResultSetMapping resultSetMapping = super.generateResultMapping( queryHadAliases );
22-
return new ReactiveResultSetMapping( resultSetMapping );
21+
return wrap( super.generateResultMapping( queryHadAliases ) );
2322
}
23+
24+
private static ResultSetMapping wrap(final ResultSetMapping resultSetMapping) {
25+
if ( resultSetMapping == null ) {
26+
return null;
27+
}
28+
//Avoid nested wrapping!
29+
else if ( resultSetMapping instanceof ReactiveResultSetMapping ) {
30+
return resultSetMapping;
31+
}
32+
else {
33+
return new ReactiveResultSetMapping( resultSetMapping );
34+
}
35+
}
36+
2437
}

0 commit comments

Comments
 (0)