@@ -764,21 +764,26 @@ private void setupSession() {
764
764
final ExecutableElement getter = findSessionGetter ( element );
765
765
if ( getter != null ) {
766
766
// Never make a DAO for Panache subtypes
767
- if ( !isPanacheType ( element ) ) {
767
+ if ( !isPanacheType ( element ) && ! isPanache2Type ( element ) ) {
768
768
repository = true ;
769
769
sessionType = addDaoConstructor ( getter );
770
770
}
771
- else {
772
- // For Panache subtypes, we look at the session type, but no DAO, we want static methods
771
+ else if ( ! isPanache2Repository ( element ) && ! isPanache2Type ( element ) ) {
772
+ // For Panache 1 subtypes, we look at the session type, but no DAO, we want static methods
773
773
sessionType = fullReturnType (getter );
774
774
}
775
+ else {
776
+ // For Panache 2 repositories we want a repository
777
+ repository = true ;
778
+ sessionType = setupQuarkusDaoConstructor ( getter , element );
779
+ }
775
780
}
776
781
else if ( element .getKind () == ElementKind .INTERFACE
777
782
&& !jakartaDataRepository
778
- && ( context .usesQuarkusOrm () || context .usesQuarkusReactive () ) ) {
783
+ && ( context .usesQuarkusOrm () || context .usesQuarkusReactive () || context . usesQuarkusPanache2 () ) ) {
779
784
// if we don't have a getter, and not a JD repository, but we're in Quarkus, we know how to find the default sessions
780
785
repository = true ;
781
- sessionType = setupQuarkusDaoConstructor ();
786
+ sessionType = setupQuarkusDaoConstructor ( null , element );
782
787
}
783
788
if ( !repository && jakartaDataRepository ) {
784
789
repository = true ;
@@ -878,6 +883,19 @@ private boolean isReactivePanacheType(TypeElement type) {
878
883
|| extendsClass ( type , PANACHE_REACTIVE_ENTITY_BASE );
879
884
}
880
885
886
+ private boolean isPanache2Type (TypeElement type ) {
887
+ return implementsInterface ( type , PANACHE2_ENTITY_MARKER )
888
+ || isPanache2Repository ( type );
889
+ }
890
+
891
+ private boolean isPanache2Repository (TypeElement type ) {
892
+ return implementsInterface ( type , PANACHE2_MANAGED_BLOCKING_REPOSITORY_BASE )
893
+ || implementsInterface ( type , PANACHE2_STATELESS_BLOCKING_REPOSITORY_BASE )
894
+ || implementsInterface ( type , PANACHE2_MANAGED_REACTIVE_REPOSITORY_BASE )
895
+ || implementsInterface ( type , PANACHE2_STATELESS_REACTIVE_REPOSITORY_BASE )
896
+ ;
897
+ }
898
+
881
899
/**
882
900
* If there is a session getter method, we generate an instance
883
901
* variable backing it, together with a constructor that initializes
@@ -915,10 +933,29 @@ private String addDaoConstructor(@Nullable ExecutableElement method) {
915
933
/**
916
934
* For Quarkus, we generate a constructor with injection for EntityManager in ORM,
917
935
* and in HR, we define the static session getter.
936
+ * For Panache 2, we can use the element to figure out what kind of session we want since this
937
+ * is for repositories
918
938
*/
919
- private String setupQuarkusDaoConstructor () {
920
- if ( context .usesQuarkusOrm () ) {
921
- String name = "getEntityManager" ;
939
+ private String setupQuarkusDaoConstructor (@ Nullable ExecutableElement getter , @ Nullable TypeElement element ) {
940
+ if ( context .usesQuarkusOrm ()
941
+ || (context .usesQuarkusPanache2 ()
942
+ && element != null
943
+ && (implementsInterface (element , PANACHE2_MANAGED_BLOCKING_REPOSITORY_BASE )
944
+ || implementsInterface (element , PANACHE2_STATELESS_BLOCKING_REPOSITORY_BASE )))
945
+ ) {
946
+ String name ;
947
+ String sessionType ;
948
+ if ( getter != null ) {
949
+ name = getter .getSimpleName ().toString ();
950
+ sessionType = fullReturnType (getter );
951
+ } else if (element != null
952
+ && implementsInterface (element , PANACHE2_STATELESS_BLOCKING_REPOSITORY_BASE )) {
953
+ name = "getStatelessSession" ;
954
+ sessionType = HIB_STATELESS_SESSION ;
955
+ } else { // good default
956
+ name = "getSession" ;
957
+ sessionType = HIB_SESSION ;
958
+ }
922
959
putMember ( name ,
923
960
new RepositoryConstructor (
924
961
this ,
@@ -934,13 +971,19 @@ private String setupQuarkusDaoConstructor() {
934
971
true
935
972
)
936
973
);
937
- return ENTITY_MANAGER ;
974
+ return sessionType ;
938
975
}
939
976
else {
940
977
importType ( Constants .QUARKUS_SESSION_OPERATIONS );
941
978
// use this getter to get the method, do not generate an injection point for its type
942
- sessionGetter = "SessionOperations.getSession()" ;
943
- return Constants .UNI_MUTINY_SESSION ;
979
+ if (element != null
980
+ && implementsInterface (element , PANACHE2_STATELESS_REACTIVE_REPOSITORY_BASE )) {
981
+ sessionGetter = "SessionOperations.getStatelessSession()" ;
982
+ return UNI_MUTINY_STATELESS_SESSION ;
983
+ } else {
984
+ sessionGetter = "SessionOperations.getSession()" ;
985
+ return Constants .UNI_MUTINY_SESSION ;
986
+ }
944
987
}
945
988
}
946
989
0 commit comments