Skip to content
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

Expose query method metadata #3259

Closed
Closed
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 @@ -41,27 +41,31 @@ class PersistentEntityIsNewStrategy implements IsNewStrategy {
* Creates a new {@link PersistentEntityIsNewStrategy} for the given entity.
*
* @param entity must not be {@literal null}.
* @param idOnly {@code true} if should consider only the ID property of the {@link PersistentEntity}, {@code false}
* if other properties such as {@link PersistentEntity#getVersionProperty() version} shall be
* considered.
*/
private PersistentEntityIsNewStrategy(PersistentEntity<?, ?> entity, boolean idOnly) {

Assert.notNull(entity, "PersistentEntity must not be null");

this.valueLookup = entity.hasVersionProperty() && !idOnly //
? source -> entity.getPropertyAccessor(source).getProperty(entity.getRequiredVersionProperty())
: source -> entity.getIdentifierAccessor(source).getIdentifier();

this.valueType = entity.hasVersionProperty() && !idOnly //
? entity.getRequiredVersionProperty().getType() //
: entity.hasIdProperty() ? entity.getRequiredIdProperty().getType() : null;
if (entity.hasVersionProperty() && !idOnly) {
this.valueLookup = source -> entity.getPropertyAccessor(source).getProperty(entity.getRequiredVersionProperty());
this.valueType = entity.getRequiredVersionProperty().getType();
} else {
this.valueLookup = source -> entity.getIdentifierAccessor(source).getIdentifier();
this.valueType = entity.hasIdProperty() ? entity.getRequiredIdProperty().getType() : null;
}

Class<?> type = valueType;

if (type != null && type.isPrimitive()) {

if (!ClassUtils.isAssignable(Number.class, type)) {

throw new IllegalArgumentException(String
.format("Only numeric primitives are supported as identifier / version field types; Got: %s", valueType));
throw new IllegalArgumentException(
String.format("Only numeric primitives are supported as identifier / version field types; Got: %s",
valueType));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
/**
* Abstracts method parameters that have to be bound to query parameters or applied to the query independently.
*
* @param <T> The exact type of {@link Parameter} inside {@link Parameters}
* @param <S> The exact type of {@link Parameters} to be used. Generified to allow for recursive generics.
* @author Oliver Gierke
* @author Christoph Strobl
* @author Johannes Englmeier
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public QueryMethod(Method method, RepositoryMetadata metadata, ProjectionFactory
this.method = method;
this.unwrappedReturnType = potentiallyUnwrapReturnTypeFor(metadata, method);
this.metadata = metadata;
this.parameters = createParameters(method, metadata.getDomainTypeInformation());
this.parameters = createParameters(ParametersSource.of(getMetadata(), method));

this.domainClass = Lazy.of(() -> {

Expand Down Expand Up @@ -316,11 +316,11 @@ public ResultProcessor getResultProcessor() {
return resultProcessor;
}

RepositoryMetadata getMetadata() {
public RepositoryMetadata getMetadata() {
return metadata;
}

Method getMethod() {
public Method getMethod() {
return method;
}

Expand All @@ -329,7 +329,7 @@ public String toString() {
return method.toString();
}

private static Class<? extends Object> potentiallyUnwrapReturnTypeFor(RepositoryMetadata metadata, Method method) {
private static Class<?> potentiallyUnwrapReturnTypeFor(RepositoryMetadata metadata, Method method) {

TypeInformation<?> returnType = metadata.getReturnType(method);
if (QueryExecutionConverters.supports(returnType.getType())
Expand Down