@@ -764,21 +764,26 @@ private void setupSession() {
764764 final ExecutableElement getter = findSessionGetter ( element );
765765 if ( getter != null ) {
766766 // Never make a DAO for Panache subtypes
767- if ( !isPanacheType ( element ) ) {
767+ if ( !isPanacheType ( element ) && ! isPanache2Type ( element ) ) {
768768 repository = true ;
769769 sessionType = addDaoConstructor ( getter );
770770 }
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
773773 sessionType = fullReturnType (getter );
774774 }
775+ else {
776+ // For Panache 2 repositories we want a repository
777+ repository = true ;
778+ sessionType = setupQuarkusDaoConstructor ( getter , element );
779+ }
775780 }
776781 else if ( element .getKind () == ElementKind .INTERFACE
777782 && !jakartaDataRepository
778- && ( context .usesQuarkusOrm () || context .usesQuarkusReactive () ) ) {
783+ && ( context .usesQuarkusOrm () || context .usesQuarkusReactive () || context . usesQuarkusPanache2 () ) ) {
779784 // 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
780785 repository = true ;
781- sessionType = setupQuarkusDaoConstructor ();
786+ sessionType = setupQuarkusDaoConstructor ( null , element );
782787 }
783788 if ( !repository && jakartaDataRepository ) {
784789 repository = true ;
@@ -878,6 +883,19 @@ private boolean isReactivePanacheType(TypeElement type) {
878883 || extendsClass ( type , PANACHE_REACTIVE_ENTITY_BASE );
879884 }
880885
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+
881899 /**
882900 * If there is a session getter method, we generate an instance
883901 * variable backing it, together with a constructor that initializes
@@ -915,10 +933,31 @@ private String addDaoConstructor(@Nullable ExecutableElement method) {
915933 /**
916934 * For Quarkus, we generate a constructor with injection for EntityManager in ORM,
917935 * 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
918938 */
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+ }
952+ else if (element != null
953+ && implementsInterface (element , PANACHE2_STATELESS_BLOCKING_REPOSITORY_BASE )) {
954+ name = "getStatelessSession" ;
955+ sessionType = HIB_STATELESS_SESSION ;
956+ }
957+ else { // good default
958+ name = "getSession" ;
959+ sessionType = HIB_SESSION ;
960+ }
922961 putMember ( name ,
923962 new RepositoryConstructor (
924963 this ,
@@ -934,13 +973,20 @@ private String setupQuarkusDaoConstructor() {
934973 true
935974 )
936975 );
937- return ENTITY_MANAGER ;
976+ return sessionType ;
938977 }
939978 else {
940979 importType ( Constants .QUARKUS_SESSION_OPERATIONS );
941980 // 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 ;
981+ if (element != null
982+ && implementsInterface (element , PANACHE2_STATELESS_REACTIVE_REPOSITORY_BASE )) {
983+ sessionGetter = "SessionOperations.getStatelessSession()" ;
984+ return UNI_MUTINY_STATELESS_SESSION ;
985+ }
986+ else {
987+ sessionGetter = "SessionOperations.getSession()" ;
988+ return Constants .UNI_MUTINY_SESSION ;
989+ }
944990 }
945991 }
946992
0 commit comments