Skip to content

simplifications in QueryMethod #10419

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 26, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,6 @@ void parameters(List<String> paramTypes, StringBuilder declaration) {
boolean isNonNull(int i, List<String> paramTypes) {
final String paramType = paramTypes.get(i);
return !isNullable(i) && !isPrimitive(paramType)
|| isSessionParameter(paramType)
|| isSpecialParam(paramType);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2017,8 +2017,8 @@ private static boolean isFinderParameterMappingToAttribute(VariableElement param
private String[] sessionTypeFromParameters(List<String> paramNames, List<String> paramTypes) {
for ( int i = 0; i < paramNames.size(); i ++ ) {
final String type = paramTypes.get(i);
final String name = paramNames.get(i);
if ( isSessionParameter(type) ) {
final String name = paramNames.get(i);
return new String[] { type, name };
}
}
Expand Down Expand Up @@ -2208,7 +2208,6 @@ private void createSingleParameterFinder(
// else intentionally fall through
case BASIC:
case MULTIVALUED:
final List<Boolean> paramPatterns = parameterPatterns( method );
putMember( methodKey,
new CriteriaFinderMethod(
this, method,
Expand All @@ -2218,11 +2217,8 @@ private void createSingleParameterFinder(
paramNames,
paramTypes,
parameterNullability(method, entity),
method.getParameters().stream()
.map(param -> isFinderParameterMappingToAttribute(param)
&& fieldType == FieldType.MULTIVALUED)
.collect(toList()),
paramPatterns,
parameterMultivalued( method, fieldType ),
parameterPatterns( method ),
repository,
sessionType[0],
sessionType[1],
Expand All @@ -2239,6 +2235,13 @@ private void createSingleParameterFinder(
}
}

private static List<Boolean> parameterMultivalued(ExecutableElement method, FieldType fieldType) {
return method.getParameters().stream()
.map( param -> isFinderParameterMappingToAttribute( param )
&& fieldType == FieldType.MULTIVALUED )
.collect( toList() );
}

private static FieldType pickStrategy(FieldType fieldType, String sessionType, List<String> profiles) {
if ( ( usingStatelessSession(sessionType) || usingReactiveSession(sessionType) )
&& !profiles.isEmpty() ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,7 @@ String specificationType() {

@Override
void createQuery(StringBuilder declaration) {
final boolean specification = isUsingSpecification();
if ( specification ) {
if ( isUsingSpecification() ) {
if ( isReactive() ) {
declaration
.append(localSessionName())
Expand Down Expand Up @@ -226,9 +225,8 @@ else if ( BOOLEAN.equals(returnTypeName) ) {
@Override
void setParameters(StringBuilder declaration, List<String> paramTypes, String indent) {
for ( int i = 0; i < paramNames.size(); i++ ) {
final String paramName = paramNames.get(i);
final String paramType = paramTypes.get(i);
if ( !isSpecialParam(paramType) ) {
if ( !isSpecialParam( paramTypes.get(i) ) ) {
final String paramName = paramNames.get(i);
final int ordinal = i+1;
if ( queryString.contains(":" + paramName) ) {
declaration.append(indent);
Expand Down Expand Up @@ -291,8 +289,7 @@ private static void setNamedParameter(StringBuilder declaration, String paramNam

private void comment(StringBuilder declaration) {
declaration
.append("\n/**");
declaration
.append("\n/**")
.append("\n * Execute the query {@value #")
.append(getConstantName())
.append("}.")
Expand All @@ -303,7 +300,8 @@ private void comment(StringBuilder declaration) {
}

private void modifiers(StringBuilder declaration, List<String> paramTypes) {
boolean hasVarargs = paramTypes.stream().anyMatch(ptype -> ptype.endsWith("..."));
final boolean hasVarargs =
paramTypes.stream().anyMatch(ptype -> ptype.endsWith("..."));
if ( hasVarargs ) {
declaration
.append("@SafeVarargs\n");
Expand All @@ -326,15 +324,16 @@ void nullChecks(StringBuilder declaration, List<String> paramTypes) {
for ( int i = 0; i<paramNames.size(); i++ ) {
final String paramType = paramTypes.get( i );
// we don't do null checks on query parameters
if ( isSessionParameter( paramType ) || isSpecialParam( paramType) ) {
if ( isSpecialParam(paramType) ) {
nullCheck( declaration, paramNames.get(i) );
}
}
}

@Override
public String getAttributeNameDeclarationString() {
StringBuilder declaration = new StringBuilder( queryString.length() + 200 );
final StringBuilder declaration =
new StringBuilder( queryString.length() + 200 );
declaration
.append("\n/**\n * @see ")
.append("#");
Expand All @@ -346,42 +345,33 @@ public String getAttributeNameDeclarationString() {
.append( " = \"" );
for ( int i = 0; i < queryString.length(); i++ ) {
final char c = queryString.charAt( i );
switch ( c ) {
case '\r':
declaration.append( "\\r" );
break;
case '\n':
declaration.append( "\\n" );
break;
case '\\':
declaration.append( "\\\\" );
break;
case '"':
declaration.append( "\\\"" );
break;
default:
declaration.append( c );
break;
}
declaration.append(switch ( c ) {
case '\r' -> "\\r";
case '\n' -> "\\n";
case '\\' -> "\\\\";
case '"' -> "\\\"";
default -> c;
});
}
return declaration.append("\";").toString();
return declaration
.append("\";")
.toString();
}

private String getConstantName() {
final String stem = getUpperUnderscoreCaseFromLowerCamelCase(methodName);
if ( paramTypes.isEmpty() ) {
return stem;
}
else {
return stem + "_"
+ paramTypes.stream()
.filter(type -> !isSpecialParam(type))
.map(type -> type.indexOf('<')>0 ? type.substring(0, type.indexOf('<')) : type)
.map(StringHelper::unqualify)
.map(type -> type.replace("[]", "Array"))
.reduce((x,y) -> x + '_' + y)
.orElse("");
}
return paramTypes.isEmpty()
|| paramTypes.stream().allMatch(AbstractQueryMethod::isSpecialParam)
? stem
: stem + "_" + paramTypes.stream()
.filter( type -> !isSpecialParam(type) )
.map( type -> type.indexOf('<') > 0
? type.substring(0, type.indexOf('<'))
: type )
.map( StringHelper::unqualify )
.map( type -> type.replace("[]", "Array") )
.reduce( (x, y) -> x + '_' + y )
.orElseThrow();
}

public String getTypeDeclaration() {
Expand Down