Support default session getters

In which case, we don't store the session in the DAO, we always call the getter
This commit is contained in:
Stéphane Épardaud 2023-12-05 12:02:45 +01:00 committed by Gavin King
parent 1f3aed022c
commit ed29057315
1 changed files with 29 additions and 17 deletions

View File

@ -138,6 +138,11 @@ public class AnnotationMetaEntity extends AnnotationMeta {
*/ */
private String sessionType = Constants.ENTITY_MANAGER; private String sessionType = Constants.ENTITY_MANAGER;
/**
* The field or method call to obtain the session
*/
private String sessionGetter = "entityManager";
private final Map<String,String> memberTypes = new HashMap<>(); private final Map<String,String> memberTypes = new HashMap<>();
public AnnotationMetaEntity( public AnnotationMetaEntity(
@ -484,21 +489,28 @@ public class AnnotationMetaEntity extends AnnotationMeta {
final String sessionVariableName = getSessionVariableName( sessionType ); final String sessionVariableName = getSessionVariableName( sessionType );
final String name = method == null ? sessionVariableName : method.getSimpleName().toString(); final String name = method == null ? sessionVariableName : method.getSimpleName().toString();
final String typeName = element.getSimpleName().toString() + '_'; final String typeName = element.getSimpleName().toString() + '_';
putMember( name,
new RepositoryConstructor( if( method == null || !method.isDefault() ) {
this, putMember( name,
typeName, new RepositoryConstructor(
name, this,
sessionType, typeName,
sessionVariableName, name,
dataStore(), sessionType,
context.addInjectAnnotation(), sessionVariableName,
context.addNonnullAnnotation(), dataStore(),
method != null, context.addInjectAnnotation(),
jakartaDataRepository, context.addNonnullAnnotation(),
quarkusInjection method != null,
) jakartaDataRepository,
); quarkusInjection
)
);
}
else {
// use this getter to get the method, do not generate an injection point for its type
sessionGetter = method.getSimpleName() + "()";
}
return sessionType; return sessionType;
} }
@ -1088,14 +1100,14 @@ public class AnnotationMetaEntity extends AnnotationMeta {
return getSessionVariableName(sessionType); return getSessionVariableName(sessionType);
} }
private static String getSessionVariableName(String sessionType) { private String getSessionVariableName(String sessionType) {
switch (sessionType) { switch (sessionType) {
case HIB_SESSION: case HIB_SESSION:
case HIB_STATELESS_SESSION: case HIB_STATELESS_SESSION:
case MUTINY_SESSION: case MUTINY_SESSION:
return "session"; return "session";
default: default:
return "entityManager"; return sessionGetter;
} }
} }