Skip to content

Commit

Permalink
Support default session getters
Browse files Browse the repository at this point in the history
In which case, we don't store the session in the DAO, we always call the getter
  • Loading branch information
FroMage authored and gavinking committed Mar 1, 2024
1 parent 1f3aed0 commit ed29057
Showing 1 changed file with 29 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,11 @@ public class AnnotationMetaEntity extends AnnotationMeta {
*/
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<>();

public AnnotationMetaEntity(
Expand Down Expand Up @@ -484,21 +489,28 @@ private String addDaoConstructor(@Nullable ExecutableElement method) {
final String sessionVariableName = getSessionVariableName( sessionType );
final String name = method == null ? sessionVariableName : method.getSimpleName().toString();
final String typeName = element.getSimpleName().toString() + '_';
putMember( name,
new RepositoryConstructor(
this,
typeName,
name,
sessionType,
sessionVariableName,
dataStore(),
context.addInjectAnnotation(),
context.addNonnullAnnotation(),
method != null,
jakartaDataRepository,
quarkusInjection
)
);

if( method == null || !method.isDefault() ) {
putMember( name,
new RepositoryConstructor(
this,
typeName,
name,
sessionType,
sessionVariableName,
dataStore(),
context.addInjectAnnotation(),
context.addNonnullAnnotation(),
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;
}

Expand Down Expand Up @@ -1088,14 +1100,14 @@ protected String getSessionVariableName() {
return getSessionVariableName(sessionType);
}

private static String getSessionVariableName(String sessionType) {
private String getSessionVariableName(String sessionType) {
switch (sessionType) {
case HIB_SESSION:
case HIB_STATELESS_SESSION:
case MUTINY_SESSION:
return "session";
default:
return "entityManager";
return sessionGetter;
}
}

Expand Down

0 comments on commit ed29057

Please sign in to comment.