Skip to content

Commit ca66595

Browse files
committed
[HHH-19586] For Panache 2 repositories, look for any annotated method returning a Uni to decide for reactive session
1 parent 1799b43 commit ca66595

File tree

1 file changed

+34
-5
lines changed

1 file changed

+34
-5
lines changed

tooling/metamodel-generator/src/main/java/org/hibernate/processor/annotation/AnnotationMetaEntity.java

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1037,12 +1037,32 @@ private String addDaoConstructor(@Nullable ExecutableElement method) {
10371037
* is for repositories
10381038
*/
10391039
private String setupQuarkusDaoConstructor(@Nullable ExecutableElement getter, @Nullable TypeElement element) {
1040-
if ( context.usesQuarkusOrm()
1041-
|| (context.usesQuarkusPanache2()
1042-
&& element != null
1043-
&& (implementsInterface(element, PANACHE2_MANAGED_BLOCKING_REPOSITORY_BASE)
1044-
|| implementsInterface(element, PANACHE2_STATELESS_BLOCKING_REPOSITORY_BASE)))
1040+
boolean favorBlocking = context.usesQuarkusOrm()
1041+
|| (context.usesQuarkusPanache2()
1042+
&& element != null
1043+
&& (implementsInterface(element, PANACHE2_MANAGED_BLOCKING_REPOSITORY_BASE)
1044+
|| implementsInterface(element, PANACHE2_STATELESS_BLOCKING_REPOSITORY_BASE)));
1045+
if ( context.usesQuarkusPanache2()
1046+
&& element != null
1047+
&& !implementsInterface(element, PANACHE2_MANAGED_BLOCKING_REPOSITORY_BASE)
1048+
&& !implementsInterface(element, PANACHE2_STATELESS_BLOCKING_REPOSITORY_BASE)
1049+
&& !implementsInterface(element, PANACHE2_MANAGED_REACTIVE_REPOSITORY_BASE)
1050+
&& !implementsInterface(element, PANACHE2_STATELESS_REACTIVE_REPOSITORY_BASE)
1051+
// FIXME: add other default for JD repos?
10451052
) {
1053+
// look for any annotated method, see if they return a Uni
1054+
final List<ExecutableElement> methodsOfClass =
1055+
methodsIn( context.getAllMembers( element ) );
1056+
for ( ExecutableElement method : methodsOfClass ) {
1057+
// trust the first method, no need to look for them all
1058+
if ( containsAnnotation( method, HQL, SQL, JD_QUERY, FIND, JD_FIND ) ) {
1059+
favorBlocking = !isUni( method.getReturnType() );
1060+
break;
1061+
}
1062+
}
1063+
}
1064+
// FIXME: probably go in this branch if we have a getter too?
1065+
if ( favorBlocking ) {
10461066
String name;
10471067
String sessionType;
10481068
if ( getter != null ) {
@@ -1598,6 +1618,15 @@ private static TypeMirror ununi(TypeMirror returnType) {
15981618
return returnType;
15991619
}
16001620

1621+
private static boolean isUni (TypeMirror returnType){
1622+
if ( returnType.getKind() == TypeKind.DECLARED ) {
1623+
final DeclaredType declaredType = (DeclaredType) returnType;
1624+
final TypeElement typeElement = (TypeElement) declaredType.asElement();
1625+
return typeElement.getQualifiedName().contentEquals( Constants.UNI );
1626+
}
1627+
return false;
1628+
}
1629+
16011630
private static boolean isLegalRawResultType(String containerTypeName) {
16021631
return LEGAL_RAW_RESULT_TYPES.contains( containerTypeName );
16031632
}

0 commit comments

Comments
 (0)