retain type use annotation in return types and simplify code
Signed-off-by: Gavin King <gavin@hibernate.org>
This commit is contained in:
parent
4c1285b609
commit
ec8cdd9dbb
|
@ -33,9 +33,10 @@ public abstract class AbstractCriteriaMethod extends AbstractFinderMethod {
|
||||||
boolean addNonnullAnnotation,
|
boolean addNonnullAnnotation,
|
||||||
boolean convertToDataExceptions,
|
boolean convertToDataExceptions,
|
||||||
List<Boolean> multivalued,
|
List<Boolean> multivalued,
|
||||||
List<Boolean> paramPatterns) {
|
List<Boolean> paramPatterns,
|
||||||
|
String fullReturnType) {
|
||||||
super(annotationMetaEntity, method, methodName, entity, belongsToDao, sessionType, sessionName, fetchProfiles,
|
super(annotationMetaEntity, method, methodName, entity, belongsToDao, sessionType, sessionName, fetchProfiles,
|
||||||
paramNames, paramTypes, orderBys, addNonnullAnnotation, convertToDataExceptions);
|
paramNames, paramTypes, orderBys, addNonnullAnnotation, convertToDataExceptions, fullReturnType);
|
||||||
this.multivalued = multivalued;
|
this.multivalued = multivalued;
|
||||||
this.paramPatterns = paramPatterns;
|
this.paramPatterns = paramPatterns;
|
||||||
}
|
}
|
||||||
|
@ -46,7 +47,7 @@ public abstract class AbstractCriteriaMethod extends AbstractFinderMethod {
|
||||||
final StringBuilder declaration = new StringBuilder();
|
final StringBuilder declaration = new StringBuilder();
|
||||||
comment( declaration );
|
comment( declaration );
|
||||||
modifiers( declaration );
|
modifiers( declaration );
|
||||||
preamble( declaration, returnType(), paramTypes );
|
preamble( declaration, paramTypes );
|
||||||
chainSession( declaration );
|
chainSession( declaration );
|
||||||
nullChecks( paramTypes, declaration );
|
nullChecks( paramTypes, declaration );
|
||||||
createBuilder(declaration);
|
createBuilder(declaration);
|
||||||
|
@ -64,7 +65,7 @@ public abstract class AbstractCriteriaMethod extends AbstractFinderMethod {
|
||||||
|
|
||||||
abstract String createCriteriaMethod();
|
abstract String createCriteriaMethod();
|
||||||
|
|
||||||
abstract String returnType();
|
// abstract String returnType();
|
||||||
|
|
||||||
abstract String createQueryMethod();
|
abstract String createQueryMethod();
|
||||||
|
|
||||||
|
|
|
@ -13,7 +13,6 @@ import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
|
||||||
import static org.hibernate.processor.util.Constants.HIB_SESSION;
|
import static org.hibernate.processor.util.Constants.HIB_SESSION;
|
||||||
import static org.hibernate.processor.util.Constants.UNI;
|
|
||||||
import static org.hibernate.processor.util.StringUtil.getUpperUnderscoreCaseFromLowerCamelCase;
|
import static org.hibernate.processor.util.StringUtil.getUpperUnderscoreCaseFromLowerCamelCase;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -36,14 +35,16 @@ public abstract class AbstractFinderMethod extends AbstractQueryMethod {
|
||||||
List<String> paramTypes,
|
List<String> paramTypes,
|
||||||
List<OrderBy> orderBys,
|
List<OrderBy> orderBys,
|
||||||
boolean addNonnullAnnotation,
|
boolean addNonnullAnnotation,
|
||||||
boolean convertToDataExceptions) {
|
boolean convertToDataExceptions,
|
||||||
|
String fullReturnType) {
|
||||||
super( annotationMetaEntity, method,
|
super( annotationMetaEntity, method,
|
||||||
methodName,
|
methodName,
|
||||||
paramNames, paramTypes, entity,
|
paramNames, paramTypes, entity,
|
||||||
sessionType, sessionName,
|
sessionType, sessionName,
|
||||||
belongsToDao, orderBys,
|
belongsToDao, orderBys,
|
||||||
addNonnullAnnotation,
|
addNonnullAnnotation,
|
||||||
convertToDataExceptions );
|
convertToDataExceptions,
|
||||||
|
fullReturnType );
|
||||||
this.entity = entity;
|
this.entity = entity;
|
||||||
this.fetchProfiles = fetchProfiles;
|
this.fetchProfiles = fetchProfiles;
|
||||||
}
|
}
|
||||||
|
@ -173,16 +174,6 @@ public abstract class AbstractFinderMethod extends AbstractQueryMethod {
|
||||||
return unwrapped;
|
return unwrapped;
|
||||||
}
|
}
|
||||||
|
|
||||||
void preamble(StringBuilder declaration) {
|
|
||||||
modifiers( declaration );
|
|
||||||
entityType( declaration );
|
|
||||||
declaration
|
|
||||||
.append(" ")
|
|
||||||
.append(methodName);
|
|
||||||
parameters( paramTypes, declaration ) ;
|
|
||||||
declaration.append(" {\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
void tryReturn(StringBuilder declaration) {
|
void tryReturn(StringBuilder declaration) {
|
||||||
if (dataRepository) {
|
if (dataRepository) {
|
||||||
declaration
|
declaration
|
||||||
|
@ -193,19 +184,19 @@ public abstract class AbstractFinderMethod extends AbstractQueryMethod {
|
||||||
.append(sessionName);
|
.append(sessionName);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void entityType(StringBuilder declaration) {
|
// private void returnType(StringBuilder declaration) {
|
||||||
if ( isReactive() ) {
|
// if ( isReactive() ) {
|
||||||
declaration
|
// declaration
|
||||||
.append(annotationMetaEntity.importType(UNI))
|
// .append(annotationMetaEntity.importType(UNI))
|
||||||
.append('<');
|
// .append('<');
|
||||||
}
|
// }
|
||||||
declaration
|
// declaration
|
||||||
.append(annotationMetaEntity.importType(entity));
|
// .append(annotationMetaEntity.importType(entity));
|
||||||
if ( isReactive() ) {
|
// if ( isReactive() ) {
|
||||||
declaration
|
// declaration
|
||||||
.append('>');
|
// .append('>');
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
void modifiers(StringBuilder declaration) {
|
void modifiers(StringBuilder declaration) {
|
||||||
declaration
|
declaration
|
||||||
|
|
|
@ -49,6 +49,7 @@ public abstract class AbstractQueryMethod extends AbstractAnnotatedMethod {
|
||||||
final List<OrderBy> orderBys;
|
final List<OrderBy> orderBys;
|
||||||
final boolean addNonnullAnnotation;
|
final boolean addNonnullAnnotation;
|
||||||
final boolean dataRepository;
|
final boolean dataRepository;
|
||||||
|
final String fullReturnType;
|
||||||
|
|
||||||
AbstractQueryMethod(
|
AbstractQueryMethod(
|
||||||
AnnotationMetaEntity annotationMetaEntity,
|
AnnotationMetaEntity annotationMetaEntity,
|
||||||
|
@ -61,7 +62,8 @@ public abstract class AbstractQueryMethod extends AbstractAnnotatedMethod {
|
||||||
boolean belongsToDao,
|
boolean belongsToDao,
|
||||||
List<OrderBy> orderBys,
|
List<OrderBy> orderBys,
|
||||||
boolean addNonnullAnnotation,
|
boolean addNonnullAnnotation,
|
||||||
boolean dataRepository) {
|
boolean dataRepository,
|
||||||
|
String fullReturnType) {
|
||||||
super(annotationMetaEntity, method, sessionName, sessionType);
|
super(annotationMetaEntity, method, sessionName, sessionType);
|
||||||
this.methodName = methodName;
|
this.methodName = methodName;
|
||||||
this.paramNames = paramNames;
|
this.paramNames = paramNames;
|
||||||
|
@ -71,6 +73,7 @@ public abstract class AbstractQueryMethod extends AbstractAnnotatedMethod {
|
||||||
this.orderBys = orderBys;
|
this.orderBys = orderBys;
|
||||||
this.addNonnullAnnotation = addNonnullAnnotation;
|
this.addNonnullAnnotation = addNonnullAnnotation;
|
||||||
this.dataRepository = dataRepository;
|
this.dataRepository = dataRepository;
|
||||||
|
this.fullReturnType = fullReturnType;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -107,9 +110,9 @@ public abstract class AbstractQueryMethod extends AbstractAnnotatedMethod {
|
||||||
return type.endsWith("...") ? stripped + "..." : stripped;
|
return type.endsWith("...") ? stripped + "..." : stripped;
|
||||||
}
|
}
|
||||||
|
|
||||||
void preamble(StringBuilder declaration, String returnType, List<String> paramTypes) {
|
void preamble(StringBuilder declaration, List<String> paramTypes) {
|
||||||
declaration
|
declaration
|
||||||
.append(returnType)
|
.append(annotationMetaEntity.importType(fullReturnType))
|
||||||
.append(" ")
|
.append(" ")
|
||||||
.append(methodName);
|
.append(methodName);
|
||||||
parameters( paramTypes, declaration );
|
parameters( paramTypes, declaration );
|
||||||
|
|
|
@ -593,7 +593,7 @@ public class AnnotationMetaEntity extends AnnotationMeta {
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// For Panache subtypes, we look at the session type, but no DAO, we want static methods
|
// For Panache subtypes, we look at the session type, but no DAO, we want static methods
|
||||||
sessionType = getter.getReturnType().toString();
|
sessionType = fullReturnType(getter);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if ( element.getKind() == ElementKind.INTERFACE
|
else if ( element.getKind() == ElementKind.INTERFACE
|
||||||
|
@ -702,7 +702,7 @@ public class AnnotationMetaEntity extends AnnotationMeta {
|
||||||
* it.
|
* it.
|
||||||
*/
|
*/
|
||||||
private String addDaoConstructor(@Nullable ExecutableElement method) {
|
private String addDaoConstructor(@Nullable ExecutableElement method) {
|
||||||
final String sessionType = method == null ? this.sessionType : method.getReturnType().toString();
|
final String sessionType = method == null ? this.sessionType : fullReturnType(method);
|
||||||
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();
|
||||||
|
|
||||||
|
@ -1110,10 +1110,7 @@ public class AnnotationMetaEntity extends AnnotationMeta {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addQueryMethod(ExecutableElement method) {
|
private void addQueryMethod(ExecutableElement method) {
|
||||||
final ExecutableType methodType =
|
final TypeMirror returnType = memberMethodType(method).getReturnType();
|
||||||
(ExecutableType) context.getTypeUtils()
|
|
||||||
.asMemberOf((DeclaredType) element.asType(), method);
|
|
||||||
final TypeMirror returnType = methodType.getReturnType();
|
|
||||||
final TypeKind kind = returnType.getKind();
|
final TypeKind kind = returnType.getKind();
|
||||||
if ( kind == TypeKind.VOID || kind == TypeKind.ARRAY || kind.isPrimitive() ) {
|
if ( kind == TypeKind.VOID || kind == TypeKind.ARRAY || kind.isPrimitive() ) {
|
||||||
addQueryMethod( method, returnType, null );
|
addQueryMethod( method, returnType, null );
|
||||||
|
@ -1562,7 +1559,8 @@ public class AnnotationMetaEntity extends AnnotationMeta {
|
||||||
enabledFetchProfiles( method ),
|
enabledFetchProfiles( method ),
|
||||||
orderByList( method, entity ),
|
orderByList( method, entity ),
|
||||||
context.addNonnullAnnotation(),
|
context.addNonnullAnnotation(),
|
||||||
jakartaDataRepository
|
jakartaDataRepository,
|
||||||
|
fullReturnType(method)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -1608,7 +1606,6 @@ public class AnnotationMetaEntity extends AnnotationMeta {
|
||||||
this, method,
|
this, method,
|
||||||
methodName,
|
methodName,
|
||||||
entity.getQualifiedName().toString(),
|
entity.getQualifiedName().toString(),
|
||||||
returnType.toString(),
|
|
||||||
paramNames,
|
paramNames,
|
||||||
paramTypes,
|
paramTypes,
|
||||||
parameterNullability(method, entity),
|
parameterNullability(method, entity),
|
||||||
|
@ -1618,7 +1615,8 @@ public class AnnotationMetaEntity extends AnnotationMeta {
|
||||||
sessionType[0],
|
sessionType[0],
|
||||||
sessionType[1],
|
sessionType[1],
|
||||||
context.addNonnullAnnotation(),
|
context.addNonnullAnnotation(),
|
||||||
jakartaDataRepository
|
jakartaDataRepository,
|
||||||
|
fullReturnType(method)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -1806,7 +1804,8 @@ public class AnnotationMetaEntity extends AnnotationMeta {
|
||||||
sessionType[1],
|
sessionType[1],
|
||||||
enabledFetchProfiles( method ),
|
enabledFetchProfiles( method ),
|
||||||
context.addNonnullAnnotation(),
|
context.addNonnullAnnotation(),
|
||||||
jakartaDataRepository
|
jakartaDataRepository,
|
||||||
|
fullReturnType(method)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -1829,7 +1828,8 @@ public class AnnotationMetaEntity extends AnnotationMeta {
|
||||||
enabledFetchProfiles( method ),
|
enabledFetchProfiles( method ),
|
||||||
orderByList( method, entity ),
|
orderByList( method, entity ),
|
||||||
context.addNonnullAnnotation(),
|
context.addNonnullAnnotation(),
|
||||||
jakartaDataRepository
|
jakartaDataRepository,
|
||||||
|
fullReturnType(method)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -1862,7 +1862,8 @@ public class AnnotationMetaEntity extends AnnotationMeta {
|
||||||
sessionType[1],
|
sessionType[1],
|
||||||
profiles,
|
profiles,
|
||||||
context.addNonnullAnnotation(),
|
context.addNonnullAnnotation(),
|
||||||
jakartaDataRepository
|
jakartaDataRepository,
|
||||||
|
fullReturnType(method)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
break;
|
break;
|
||||||
|
@ -1880,7 +1881,8 @@ public class AnnotationMetaEntity extends AnnotationMeta {
|
||||||
sessionType[1],
|
sessionType[1],
|
||||||
profiles,
|
profiles,
|
||||||
context.addNonnullAnnotation(),
|
context.addNonnullAnnotation(),
|
||||||
jakartaDataRepository
|
jakartaDataRepository,
|
||||||
|
fullReturnType(method)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
break;
|
break;
|
||||||
|
@ -1907,7 +1909,8 @@ public class AnnotationMetaEntity extends AnnotationMeta {
|
||||||
profiles,
|
profiles,
|
||||||
orderByList( method, entity ),
|
orderByList( method, entity ),
|
||||||
context.addNonnullAnnotation(),
|
context.addNonnullAnnotation(),
|
||||||
jakartaDataRepository
|
jakartaDataRepository,
|
||||||
|
fullReturnType(method)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
break;
|
break;
|
||||||
|
@ -2265,11 +2268,16 @@ public class AnnotationMetaEntity extends AnnotationMeta {
|
||||||
sessionType[1],
|
sessionType[1],
|
||||||
orderBys,
|
orderBys,
|
||||||
context.addNonnullAnnotation(),
|
context.addNonnullAnnotation(),
|
||||||
jakartaDataRepository
|
jakartaDataRepository,
|
||||||
|
fullReturnType(method)
|
||||||
);
|
);
|
||||||
putMember( attribute.getPropertyName() + paramTypes, attribute );
|
putMember( attribute.getPropertyName() + paramTypes, attribute );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String fullReturnType(ExecutableElement method) {
|
||||||
|
return typeAsString( memberMethodType(method).getReturnType() );
|
||||||
|
}
|
||||||
|
|
||||||
private static String returnTypeClass(TypeMirror returnType) {
|
private static String returnTypeClass(TypeMirror returnType) {
|
||||||
switch (returnType.getKind()) {
|
switch (returnType.getKind()) {
|
||||||
case DECLARED:
|
case DECLARED:
|
||||||
|
@ -2468,7 +2476,7 @@ public class AnnotationMetaEntity extends AnnotationMeta {
|
||||||
}
|
}
|
||||||
if ( reactive ) {
|
if ( reactive ) {
|
||||||
// for reactive calls, don't use the returnType param, which has been ununi-ed, we want to check the full one
|
// for reactive calls, don't use the returnType param, which has been ununi-ed, we want to check the full one
|
||||||
final String returnTypeName = method.getReturnType().toString();
|
final String returnTypeName = fullReturnType(method);
|
||||||
return returnTypeName.equals( UNI_VOID )
|
return returnTypeName.equals( UNI_VOID )
|
||||||
|| returnTypeName.equals( UNI_BOOLEAN )
|
|| returnTypeName.equals( UNI_BOOLEAN )
|
||||||
|| returnTypeName.equals( UNI_INTEGER );
|
|| returnTypeName.equals( UNI_INTEGER );
|
||||||
|
@ -2824,10 +2832,7 @@ public class AnnotationMetaEntity extends AnnotationMeta {
|
||||||
private TypeMirror parameterType(VariableElement parameter) {
|
private TypeMirror parameterType(VariableElement parameter) {
|
||||||
final ExecutableElement method =
|
final ExecutableElement method =
|
||||||
(ExecutableElement) parameter.getEnclosingElement();
|
(ExecutableElement) parameter.getEnclosingElement();
|
||||||
final ExecutableType methodType =
|
final TypeMirror type = memberMethodType(method).getParameterTypes()
|
||||||
(ExecutableType) context.getTypeUtils()
|
|
||||||
.asMemberOf((DeclaredType) element.asType(), method);
|
|
||||||
final TypeMirror type = methodType.getParameterTypes()
|
|
||||||
.get( method.getParameters().indexOf(parameter) );
|
.get( method.getParameters().indexOf(parameter) );
|
||||||
switch ( type.getKind() ) {
|
switch ( type.getKind() ) {
|
||||||
case TYPEVAR:
|
case TYPEVAR:
|
||||||
|
@ -2844,6 +2849,11 @@ public class AnnotationMetaEntity extends AnnotationMeta {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private ExecutableType memberMethodType(ExecutableElement method) {
|
||||||
|
return (ExecutableType) context.getTypeUtils()
|
||||||
|
.asMemberOf((DeclaredType) element.asType(), method);
|
||||||
|
}
|
||||||
|
|
||||||
private static List<Boolean> parameterPatterns(ExecutableElement method) {
|
private static List<Boolean> parameterPatterns(ExecutableElement method) {
|
||||||
return method.getParameters().stream()
|
return method.getParameters().stream()
|
||||||
.map(param -> hasAnnotation(param, PATTERN))
|
.map(param -> hasAnnotation(param, PATTERN))
|
||||||
|
|
|
@ -17,12 +17,11 @@ import static java.util.Collections.emptyList;
|
||||||
public class CriteriaDeleteMethod extends AbstractCriteriaMethod {
|
public class CriteriaDeleteMethod extends AbstractCriteriaMethod {
|
||||||
|
|
||||||
private final List<Boolean> paramNullability;
|
private final List<Boolean> paramNullability;
|
||||||
private final String returnType;
|
|
||||||
|
|
||||||
CriteriaDeleteMethod(
|
CriteriaDeleteMethod(
|
||||||
AnnotationMetaEntity annotationMetaEntity,
|
AnnotationMetaEntity annotationMetaEntity,
|
||||||
ExecutableElement method,
|
ExecutableElement method,
|
||||||
String methodName, String entity, String returnType,
|
String methodName, String entity,
|
||||||
List<String> paramNames,
|
List<String> paramNames,
|
||||||
List<String> paramTypes,
|
List<String> paramTypes,
|
||||||
List<Boolean> paramNullability,
|
List<Boolean> paramNullability,
|
||||||
|
@ -32,11 +31,12 @@ public class CriteriaDeleteMethod extends AbstractCriteriaMethod {
|
||||||
String sessionType,
|
String sessionType,
|
||||||
String sessionName,
|
String sessionName,
|
||||||
boolean addNonnullAnnotation,
|
boolean addNonnullAnnotation,
|
||||||
boolean dataRepository) {
|
boolean dataRepository,
|
||||||
|
String fullReturnType) {
|
||||||
super( annotationMetaEntity, method, methodName, entity, belongsToDao, sessionType, sessionName, emptyList(),
|
super( annotationMetaEntity, method, methodName, entity, belongsToDao, sessionType, sessionName, emptyList(),
|
||||||
paramNames, paramTypes, emptyList(), addNonnullAnnotation, dataRepository, multivalued, paramPatterns );
|
paramNames, paramTypes, emptyList(), addNonnullAnnotation, dataRepository, multivalued, paramPatterns,
|
||||||
|
fullReturnType);
|
||||||
this.paramNullability = paramNullability;
|
this.paramNullability = paramNullability;
|
||||||
this.returnType = returnType;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -49,10 +49,10 @@ public class CriteriaDeleteMethod extends AbstractCriteriaMethod {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
// @Override
|
||||||
String returnType() {
|
// String returnType() {
|
||||||
return returnType;
|
// return returnType;
|
||||||
}
|
// }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
void executeQuery(StringBuilder declaration, List<String> paramTypes) {
|
void executeQuery(StringBuilder declaration, List<String> paramTypes) {
|
||||||
|
@ -64,7 +64,7 @@ public class CriteriaDeleteMethod extends AbstractCriteriaMethod {
|
||||||
void tryReturn(StringBuilder declaration) {
|
void tryReturn(StringBuilder declaration) {
|
||||||
declaration
|
declaration
|
||||||
.append("\n\ttry {\n\t\t");
|
.append("\n\ttry {\n\t\t");
|
||||||
if ( !"void".equals(returnType) ) {
|
if ( !"void".equals(fullReturnType) ) {
|
||||||
declaration
|
declaration
|
||||||
.append("return ");
|
.append("return ");
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,8 +7,6 @@
|
||||||
package org.hibernate.processor.annotation;
|
package org.hibernate.processor.annotation;
|
||||||
|
|
||||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
import org.hibernate.AssertionFailure;
|
|
||||||
import org.hibernate.processor.util.Constants;
|
|
||||||
|
|
||||||
import javax.lang.model.element.ExecutableElement;
|
import javax.lang.model.element.ExecutableElement;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -36,9 +34,11 @@ public class CriteriaFinderMethod extends AbstractCriteriaMethod {
|
||||||
List<String> fetchProfiles,
|
List<String> fetchProfiles,
|
||||||
List<OrderBy> orderBys,
|
List<OrderBy> orderBys,
|
||||||
boolean addNonnullAnnotation,
|
boolean addNonnullAnnotation,
|
||||||
boolean dataRepository) {
|
boolean dataRepository,
|
||||||
|
String fullReturnType) {
|
||||||
super( annotationMetaEntity, method, methodName, entity, belongsToDao, sessionType, sessionName, fetchProfiles,
|
super( annotationMetaEntity, method, methodName, entity, belongsToDao, sessionType, sessionName, fetchProfiles,
|
||||||
paramNames, paramTypes, orderBys, addNonnullAnnotation, dataRepository, multivalued, paramPatterns );
|
paramNames, paramTypes, orderBys, addNonnullAnnotation, dataRepository, multivalued, paramPatterns,
|
||||||
|
fullReturnType);
|
||||||
this.containerType = containerType;
|
this.containerType = containerType;
|
||||||
this.paramNullability = paramNullability;
|
this.paramNullability = paramNullability;
|
||||||
}
|
}
|
||||||
|
@ -100,31 +100,31 @@ public class CriteriaFinderMethod extends AbstractCriteriaMethod {
|
||||||
return "createQuery";
|
return "createQuery";
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
// @Override
|
||||||
String returnType() {
|
// String returnType() {
|
||||||
final StringBuilder type = new StringBuilder();
|
// final StringBuilder type = new StringBuilder();
|
||||||
if ( "[]".equals(containerType) ) {
|
// if ( "[]".equals(containerType) ) {
|
||||||
if ( returnTypeName == null ) {
|
// if ( returnTypeName == null ) {
|
||||||
throw new AssertionFailure("array return type, but no type name");
|
// throw new AssertionFailure("array return type, but no type name");
|
||||||
}
|
// }
|
||||||
type.append(annotationMetaEntity.importType(returnTypeName)).append("[]");
|
// type.append(annotationMetaEntity.importType(returnTypeName)).append("[]");
|
||||||
}
|
// }
|
||||||
else {
|
// else {
|
||||||
final boolean returnsUni = isReactive() && isUnifiableReturnType(containerType);
|
// final boolean returnsUni = isReactive() && isUnifiableReturnType(containerType);
|
||||||
if ( returnsUni ) {
|
// if ( returnsUni ) {
|
||||||
type.append(annotationMetaEntity.importType(Constants.UNI)).append('<');
|
// type.append(annotationMetaEntity.importType(Constants.UNI)).append('<');
|
||||||
}
|
// }
|
||||||
if ( containerType != null ) {
|
// if ( containerType != null ) {
|
||||||
type.append(annotationMetaEntity.importType(containerType)).append('<');
|
// type.append(annotationMetaEntity.importType(containerType)).append('<');
|
||||||
}
|
// }
|
||||||
type.append(annotationMetaEntity.importType(entity));
|
// type.append(annotationMetaEntity.importType(entity));
|
||||||
if ( containerType != null ) {
|
// if ( containerType != null ) {
|
||||||
type.append('>');
|
// type.append('>');
|
||||||
}
|
// }
|
||||||
if ( returnsUni ) {
|
// if ( returnsUni ) {
|
||||||
type.append('>');
|
// type.append('>');
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
return type.toString();
|
// return type.toString();
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,9 +30,10 @@ public class IdFinderMethod extends AbstractFinderMethod {
|
||||||
String sessionName,
|
String sessionName,
|
||||||
List<String> fetchProfiles,
|
List<String> fetchProfiles,
|
||||||
boolean addNonnullAnnotation,
|
boolean addNonnullAnnotation,
|
||||||
boolean dataRepository) {
|
boolean dataRepository,
|
||||||
|
String fullReturnType) {
|
||||||
super( annotationMetaEntity, method, methodName, entity, belongsToDao, sessionType, sessionName, fetchProfiles,
|
super( annotationMetaEntity, method, methodName, entity, belongsToDao, sessionType, sessionName, fetchProfiles,
|
||||||
paramNames, paramTypes, emptyList(), addNonnullAnnotation, dataRepository );
|
paramNames, paramTypes, emptyList(), addNonnullAnnotation, dataRepository, fullReturnType );
|
||||||
int idParameter = idParameter(paramNames, paramTypes);
|
int idParameter = idParameter(paramNames, paramTypes);
|
||||||
this.paramName = paramNames.get(idParameter);
|
this.paramName = paramNames.get(idParameter);
|
||||||
this.paramType = paramTypes.get(idParameter);
|
this.paramType = paramTypes.get(idParameter);
|
||||||
|
@ -61,7 +62,8 @@ public class IdFinderMethod extends AbstractFinderMethod {
|
||||||
public String getAttributeDeclarationString() {
|
public String getAttributeDeclarationString() {
|
||||||
final StringBuilder declaration = new StringBuilder();
|
final StringBuilder declaration = new StringBuilder();
|
||||||
comment( declaration );
|
comment( declaration );
|
||||||
preamble( declaration );
|
modifiers( declaration );
|
||||||
|
preamble( declaration, paramTypes );
|
||||||
if ( paramName != null && !isPrimitive(paramType) ) {
|
if ( paramName != null && !isPrimitive(paramType) ) {
|
||||||
nullCheck( declaration, paramName );
|
nullCheck( declaration, paramName );
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,9 +29,10 @@ public class NaturalIdFinderMethod extends AbstractFinderMethod {
|
||||||
String sessionName,
|
String sessionName,
|
||||||
List<String> fetchProfiles,
|
List<String> fetchProfiles,
|
||||||
boolean addNonnullAnnotation,
|
boolean addNonnullAnnotation,
|
||||||
boolean dataRepository) {
|
boolean dataRepository,
|
||||||
|
String fullReturnType) {
|
||||||
super( annotationMetaEntity, method, methodName, entity, belongsToDao, sessionType, sessionName, fetchProfiles,
|
super( annotationMetaEntity, method, methodName, entity, belongsToDao, sessionType, sessionName, fetchProfiles,
|
||||||
paramNames, paramTypes, emptyList(), addNonnullAnnotation, dataRepository );
|
paramNames, paramTypes, emptyList(), addNonnullAnnotation, dataRepository, fullReturnType );
|
||||||
this.paramNullability = paramNullability;
|
this.paramNullability = paramNullability;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -50,7 +51,8 @@ public class NaturalIdFinderMethod extends AbstractFinderMethod {
|
||||||
public String getAttributeDeclarationString() {
|
public String getAttributeDeclarationString() {
|
||||||
final StringBuilder declaration = new StringBuilder();
|
final StringBuilder declaration = new StringBuilder();
|
||||||
comment( declaration );
|
comment( declaration );
|
||||||
preamble( declaration );
|
modifiers( declaration );
|
||||||
|
preamble( declaration, paramTypes );
|
||||||
tryReturn( declaration );
|
tryReturn( declaration );
|
||||||
unwrapSession( declaration );
|
unwrapSession( declaration );
|
||||||
if ( isReactive() ) {
|
if ( isReactive() ) {
|
||||||
|
|
|
@ -7,14 +7,12 @@
|
||||||
package org.hibernate.processor.annotation;
|
package org.hibernate.processor.annotation;
|
||||||
|
|
||||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
import org.hibernate.AssertionFailure;
|
|
||||||
import org.hibernate.internal.util.StringHelper;
|
import org.hibernate.internal.util.StringHelper;
|
||||||
|
|
||||||
import javax.lang.model.element.ExecutableElement;
|
import javax.lang.model.element.ExecutableElement;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static org.hibernate.processor.util.Constants.QUERY;
|
import static org.hibernate.processor.util.Constants.QUERY;
|
||||||
import static org.hibernate.processor.util.Constants.UNI;
|
|
||||||
import static org.hibernate.processor.util.StringUtil.getUpperUnderscoreCaseFromLowerCamelCase;
|
import static org.hibernate.processor.util.StringUtil.getUpperUnderscoreCaseFromLowerCamelCase;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -48,14 +46,16 @@ public class QueryMethod extends AbstractQueryMethod {
|
||||||
String sessionName,
|
String sessionName,
|
||||||
List<OrderBy> orderBys,
|
List<OrderBy> orderBys,
|
||||||
boolean addNonnullAnnotation,
|
boolean addNonnullAnnotation,
|
||||||
boolean dataRepository) {
|
boolean dataRepository,
|
||||||
|
String fullReturnType) {
|
||||||
super( annotationMetaEntity, method,
|
super( annotationMetaEntity, method,
|
||||||
methodName,
|
methodName,
|
||||||
paramNames, paramTypes, returnTypeName,
|
paramNames, paramTypes, returnTypeName,
|
||||||
sessionType, sessionName,
|
sessionType, sessionName,
|
||||||
belongsToDao, orderBys,
|
belongsToDao, orderBys,
|
||||||
addNonnullAnnotation,
|
addNonnullAnnotation,
|
||||||
dataRepository );
|
dataRepository,
|
||||||
|
fullReturnType );
|
||||||
this.queryString = queryString;
|
this.queryString = queryString;
|
||||||
this.returnTypeClass = returnTypeClass;
|
this.returnTypeClass = returnTypeClass;
|
||||||
this.containerType = containerType;
|
this.containerType = containerType;
|
||||||
|
@ -86,15 +86,14 @@ public class QueryMethod extends AbstractQueryMethod {
|
||||||
@Override
|
@Override
|
||||||
public String getAttributeDeclarationString() {
|
public String getAttributeDeclarationString() {
|
||||||
final List<String> paramTypes = parameterTypes();
|
final List<String> paramTypes = parameterTypes();
|
||||||
final String returnType = returnType();
|
|
||||||
final StringBuilder declaration = new StringBuilder();
|
final StringBuilder declaration = new StringBuilder();
|
||||||
comment( declaration );
|
comment( declaration );
|
||||||
modifiers( paramTypes, declaration );
|
modifiers( paramTypes, declaration );
|
||||||
preamble( declaration, returnType, paramTypes );
|
preamble( declaration, paramTypes );
|
||||||
collectOrdering( declaration, paramTypes );
|
collectOrdering( declaration, paramTypes );
|
||||||
chainSession( declaration );
|
chainSession( declaration );
|
||||||
tryReturn( declaration, paramTypes, containerType );
|
tryReturn( declaration, paramTypes, containerType );
|
||||||
castResult( declaration, returnType );
|
castResult( declaration );
|
||||||
createQuery( declaration );
|
createQuery( declaration );
|
||||||
setParameters( declaration, paramTypes, "");
|
setParameters( declaration, paramTypes, "");
|
||||||
handlePageParameters( declaration, paramTypes, containerType );
|
handlePageParameters( declaration, paramTypes, containerType );
|
||||||
|
@ -142,14 +141,14 @@ public class QueryMethod extends AbstractQueryMethod {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void castResult(StringBuilder declaration, String returnType) {
|
private void castResult(StringBuilder declaration) {
|
||||||
if ( isNative && returnTypeName != null && containerType == null
|
if ( isNative && returnTypeName != null && containerType == null
|
||||||
&& isUsingEntityManager() ) {
|
&& isUsingEntityManager() ) {
|
||||||
// EntityManager.createNativeQuery() does not return TypedQuery,
|
// EntityManager.createNativeQuery() does not return TypedQuery,
|
||||||
// so we need to cast to the entity type
|
// so we need to cast to the entity type
|
||||||
declaration
|
declaration
|
||||||
.append("(")
|
.append("(")
|
||||||
.append(returnType)
|
.append(fullReturnType)
|
||||||
.append(") ");
|
.append(") ");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -211,34 +210,34 @@ public class QueryMethod extends AbstractQueryMethod {
|
||||||
.append(")\n");
|
.append(")\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
private String returnType() {
|
// private String returnType() {
|
||||||
final StringBuilder type = new StringBuilder();
|
// final StringBuilder type = new StringBuilder();
|
||||||
if ( "[]".equals(containerType) ) {
|
// if ( "[]".equals(containerType) ) {
|
||||||
if ( returnTypeName == null ) {
|
// if ( returnTypeName == null ) {
|
||||||
throw new AssertionFailure("array return type, but no type name");
|
// throw new AssertionFailure("array return type, but no type name");
|
||||||
}
|
// }
|
||||||
type.append(annotationMetaEntity.importType(returnTypeName)).append("[]");
|
// type.append(annotationMetaEntity.importType(returnTypeName)).append("[]");
|
||||||
}
|
// }
|
||||||
else {
|
// else {
|
||||||
final boolean returnsUni = isReactive() && isUnifiableReturnType(containerType);
|
// final boolean returnsUni = isReactive() && isUnifiableReturnType(containerType);
|
||||||
if ( returnsUni ) {
|
// if ( returnsUni ) {
|
||||||
type.append(annotationMetaEntity.importType(UNI)).append('<');
|
// type.append(annotationMetaEntity.importType(UNI)).append('<');
|
||||||
}
|
// }
|
||||||
if ( containerType != null ) {
|
// if ( containerType != null ) {
|
||||||
type.append(annotationMetaEntity.importType(containerType));
|
// type.append(annotationMetaEntity.importType(containerType));
|
||||||
if ( returnTypeName != null ) {
|
// if ( returnTypeName != null ) {
|
||||||
type.append("<").append(annotationMetaEntity.importType(returnTypeName)).append(">");
|
// type.append("<").append(annotationMetaEntity.importType(returnTypeName)).append(">");
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
else if ( returnTypeName != null ) {
|
// else if ( returnTypeName != null ) {
|
||||||
type.append(annotationMetaEntity.importType(returnTypeName));
|
// type.append(annotationMetaEntity.importType(returnTypeName));
|
||||||
}
|
// }
|
||||||
if ( returnsUni ) {
|
// if ( returnsUni ) {
|
||||||
type.append('>');
|
// type.append('>');
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
return type.toString();
|
// return type.toString();
|
||||||
}
|
// }
|
||||||
|
|
||||||
private void comment(StringBuilder declaration) {
|
private void comment(StringBuilder declaration) {
|
||||||
declaration
|
declaration
|
||||||
|
|
Loading…
Reference in New Issue