Skip to content

Commit 9acac16

Browse files
FroMagegavinking
authored andcommitted
[HHH-19586] For Panache 2 repositories, look for any annotated method returning a Uni to decide for reactive session
1 parent 6bca02f commit 9acac16

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
@@ -1052,12 +1052,32 @@ private String addDaoConstructor(@Nullable ExecutableElement method) {
10521052
* is for repositories
10531053
*/
10541054
private String setupQuarkusDaoConstructor(@Nullable ExecutableElement getter, @Nullable TypeElement element) {
1055-
if ( context.usesQuarkusOrm()
1056-
|| (context.usesQuarkusPanache2()
1057-
&& element != null
1058-
&& (implementsInterface(element, PANACHE2_MANAGED_BLOCKING_REPOSITORY_BASE)
1059-
|| implementsInterface(element, PANACHE2_STATELESS_BLOCKING_REPOSITORY_BASE)))
1055+
boolean favorBlocking = context.usesQuarkusOrm()
1056+
|| (context.usesQuarkusPanache2()
1057+
&& element != null
1058+
&& (implementsInterface(element, PANACHE2_MANAGED_BLOCKING_REPOSITORY_BASE)
1059+
|| implementsInterface(element, PANACHE2_STATELESS_BLOCKING_REPOSITORY_BASE)));
1060+
if ( context.usesQuarkusPanache2()
1061+
&& element != null
1062+
&& !implementsInterface(element, PANACHE2_MANAGED_BLOCKING_REPOSITORY_BASE)
1063+
&& !implementsInterface(element, PANACHE2_STATELESS_BLOCKING_REPOSITORY_BASE)
1064+
&& !implementsInterface(element, PANACHE2_MANAGED_REACTIVE_REPOSITORY_BASE)
1065+
&& !implementsInterface(element, PANACHE2_STATELESS_REACTIVE_REPOSITORY_BASE)
1066+
// FIXME: add other default for JD repos?
10601067
) {
1068+
// look for any annotated method, see if they return a Uni
1069+
final List<ExecutableElement> methodsOfClass =
1070+
methodsIn( context.getAllMembers( element ) );
1071+
for ( ExecutableElement method : methodsOfClass ) {
1072+
// trust the first method, no need to look for them all
1073+
if ( containsAnnotation( method, HQL, SQL, JD_QUERY, FIND, JD_FIND ) ) {
1074+
favorBlocking = !isUni( method.getReturnType() );
1075+
break;
1076+
}
1077+
}
1078+
}
1079+
// FIXME: probably go in this branch if we have a getter too?
1080+
if ( favorBlocking ) {
10611081
String name;
10621082
String sessionType;
10631083
if ( getter != null ) {
@@ -1627,6 +1647,15 @@ private static TypeMirror ununi(TypeMirror returnType) {
16271647
return returnType;
16281648
}
16291649

1650+
private static boolean isUni (TypeMirror returnType){
1651+
if ( returnType.getKind() == TypeKind.DECLARED ) {
1652+
final DeclaredType declaredType = (DeclaredType) returnType;
1653+
final TypeElement typeElement = (TypeElement) declaredType.asElement();
1654+
return typeElement.getQualifiedName().contentEquals( Constants.UNI );
1655+
}
1656+
return false;
1657+
}
1658+
16301659
private static boolean isLegalRawResultType(String containerTypeName) {
16311660
return LEGAL_RAW_RESULT_TYPES.contains( containerTypeName );
16321661
}

0 commit comments

Comments
 (0)