Browse Source

Polishing.

Add convenience methods for domain type and actual type resolution.

See #3344
Original pull request: #3351
issue/3353
Mark Paluch 4 months ago
parent
commit
66f5ee0432
No known key found for this signature in database
GPG Key ID: 55BC6374BAA9D973
  1. 14
      src/main/java/org/springframework/data/repository/aot/generate/AotQueryMethodGenerationContext.java
  2. 9
      src/main/java/org/springframework/data/repository/aot/generate/MethodMetadata.java

14
src/main/java/org/springframework/data/repository/aot/generate/AotQueryMethodGenerationContext.java

@ -128,6 +128,13 @@ public class AotQueryMethodGenerationContext { @@ -128,6 +128,13 @@ public class AotQueryMethodGenerationContext {
return annotations.get(annotationType);
}
/**
* @return the repository domain type.
*/
public Class<?> getDomainType() {
return getRepositoryInformation().getDomainType();
}
/**
* @return the returned type without considering dynamic projections.
*/
@ -158,6 +165,13 @@ public class AotQueryMethodGenerationContext { @@ -158,6 +165,13 @@ public class AotQueryMethodGenerationContext {
return TypeName.get(getReturnType().getType());
}
/**
* @return the {@link TypeName} representing the actual (component) method return type.
*/
public TypeName getActualReturnTypeName() {
return TypeName.get(getActualReturnType().getType());
}
/**
* Returns the required parameter name for the {@link Parameter#isBindable() bindable parameter} at the given
* {@code parameterIndex} or throws {@link IllegalArgumentException} if the parameter cannot be determined by its

9
src/main/java/org/springframework/data/repository/aot/generate/MethodMetadata.java

@ -32,8 +32,10 @@ import org.springframework.core.MethodParameter; @@ -32,8 +32,10 @@ import org.springframework.core.MethodParameter;
import org.springframework.core.ParameterNameDiscoverer;
import org.springframework.core.ResolvableType;
import org.springframework.data.repository.core.RepositoryInformation;
import org.springframework.data.util.TypeInformation;
import org.springframework.javapoet.ParameterSpec;
import org.springframework.javapoet.TypeName;
import org.springframework.util.ClassUtils;
/**
* Metadata about an AOT Repository method.
@ -53,7 +55,7 @@ class MethodMetadata { @@ -53,7 +55,7 @@ class MethodMetadata {
MethodMetadata(RepositoryInformation repositoryInformation, Method method) {
this.returnType = repositoryInformation.getReturnType(method).toResolvableType();
this.actualReturnType = repositoryInformation.getReturnedDomainTypeInformation(method).toResolvableType();
this.actualReturnType = resolvePrimaryIfNecessary(repositoryInformation.getReturnedDomainTypeInformation(method));
Map<String, ParameterSpec> methodArguments = new LinkedHashMap<>();
Map<String, MethodParameter> methodParameters = new LinkedHashMap<>();
@ -67,6 +69,11 @@ class MethodMetadata { @@ -67,6 +69,11 @@ class MethodMetadata {
this.methodParameters = Collections.unmodifiableMap(methodParameters);
}
static ResolvableType resolvePrimaryIfNecessary(TypeInformation<?> type) {
return type.getType().isPrimitive() ? ResolvableType.forType(ClassUtils.resolvePrimitiveIfNecessary(type.getType()))
: type.toResolvableType();
}
private static void initializeMethodArguments(Method method, ParameterNameDiscoverer nameDiscoverer,
ResolvableType repositoryInterface, Map<String, ParameterSpec> methodArguments,
Map<String, MethodParameter> methodParameters) {

Loading…
Cancel
Save