#237 - Move @Query annotation to o.s.d.r2dbc.repository.
Original pull request: #238.
This commit is contained in:
committed by
Jens Schauder
parent
d442fca38d
commit
ecc0fca306
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2018-2019 the original author or authors.
|
||||
* Copyright 2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -13,7 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.data.r2dbc.repository.query;
|
||||
package org.springframework.data.r2dbc.repository;
|
||||
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.ElementType;
|
||||
@@ -29,6 +29,7 @@ import org.springframework.data.domain.Sort;
|
||||
import org.springframework.data.mapping.context.MappingContext;
|
||||
import org.springframework.data.projection.ProjectionFactory;
|
||||
import org.springframework.data.r2dbc.repository.Modifying;
|
||||
import org.springframework.data.r2dbc.repository.Query;
|
||||
import org.springframework.data.relational.core.mapping.RelationalPersistentEntity;
|
||||
import org.springframework.data.relational.core.mapping.RelationalPersistentProperty;
|
||||
import org.springframework.data.relational.repository.query.RelationalEntityMetadata;
|
||||
@@ -60,7 +61,7 @@ public class R2dbcQueryMethod extends QueryMethod {
|
||||
|
||||
private final Method method;
|
||||
private final MappingContext<? extends RelationalPersistentEntity<?>, ? extends RelationalPersistentProperty> mappingContext;
|
||||
private final Optional<Query> query;
|
||||
private final Optional<org.springframework.data.r2dbc.repository.Query> query;
|
||||
private final boolean modifying;
|
||||
|
||||
private @Nullable RelationalEntityMetadata<?> metadata;
|
||||
@@ -110,7 +111,8 @@ public class R2dbcQueryMethod extends QueryMethod {
|
||||
}
|
||||
|
||||
this.method = method;
|
||||
this.query = Optional.ofNullable(AnnotatedElementUtils.findMergedAnnotation(method, Query.class));
|
||||
this.query = Optional.ofNullable(
|
||||
AnnotatedElementUtils.findMergedAnnotation(method, org.springframework.data.r2dbc.repository.Query.class));
|
||||
this.modifying = AnnotatedElementUtils.hasAnnotation(method, Modifying.class);
|
||||
}
|
||||
|
||||
@@ -207,14 +209,14 @@ public class R2dbcQueryMethod extends QueryMethod {
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the required query string declared in a {@link Query} annotation or throws {@link IllegalStateException} if
|
||||
* neither the annotation found nor the attribute was specified.
|
||||
* Returns the required query string declared in a {@link org.springframework.data.r2dbc.repository.Query} annotation
|
||||
* or throws {@link IllegalStateException} if neither the annotation found nor the attribute was specified.
|
||||
*
|
||||
* @return the query string.
|
||||
* @throws IllegalStateException in case query method has no annotated query.
|
||||
*/
|
||||
public String getRequiredAnnotatedQuery() {
|
||||
return this.query.map(Query::value)
|
||||
return this.query.map(org.springframework.data.r2dbc.repository.Query::value)
|
||||
.orElseThrow(() -> new IllegalStateException("Query method " + this + " has no annotated query"));
|
||||
}
|
||||
|
||||
@@ -223,12 +225,13 @@ public class R2dbcQueryMethod extends QueryMethod {
|
||||
*
|
||||
* @return the optional query annotation.
|
||||
*/
|
||||
Optional<Query> getQueryAnnotation() {
|
||||
Optional<org.springframework.data.r2dbc.repository.Query> getQueryAnnotation() {
|
||||
return this.query;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return {@literal true} if the {@link Method} is annotated with {@link Query}.
|
||||
* @return {@literal true} if the {@link Method} is annotated with
|
||||
* {@link org.springframework.data.r2dbc.repository.Query}.
|
||||
*/
|
||||
public boolean hasAnnotatedQuery() {
|
||||
return getQueryAnnotation().isPresent();
|
||||
|
||||
@@ -23,6 +23,7 @@ import java.util.regex.Pattern;
|
||||
import org.springframework.data.r2dbc.convert.R2dbcConverter;
|
||||
import org.springframework.data.r2dbc.core.DatabaseClient;
|
||||
import org.springframework.data.r2dbc.core.DatabaseClient.BindSpec;
|
||||
import org.springframework.data.r2dbc.repository.Query;
|
||||
import org.springframework.data.relational.repository.query.RelationalParameterAccessor;
|
||||
import org.springframework.data.repository.query.Parameter;
|
||||
import org.springframework.data.repository.query.Parameters;
|
||||
|
||||
@@ -33,8 +33,8 @@ import org.springframework.context.annotation.FilterType;
|
||||
import org.springframework.dao.DataAccessException;
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.r2dbc.core.DatabaseClient;
|
||||
import org.springframework.data.r2dbc.repository.Query;
|
||||
import org.springframework.data.r2dbc.repository.config.EnableR2dbcRepositories;
|
||||
import org.springframework.data.r2dbc.repository.query.Query;
|
||||
import org.springframework.data.r2dbc.testing.H2TestSupport;
|
||||
import org.springframework.data.relational.core.mapping.Table;
|
||||
import org.springframework.data.repository.reactive.ReactiveCrudRepository;
|
||||
|
||||
@@ -41,7 +41,6 @@ import org.springframework.dao.DataAccessException;
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.annotation.PersistenceConstructor;
|
||||
import org.springframework.data.r2dbc.connectionfactory.R2dbcTransactionManager;
|
||||
import org.springframework.data.r2dbc.repository.query.Query;
|
||||
import org.springframework.data.r2dbc.repository.support.R2dbcRepositoryFactory;
|
||||
import org.springframework.data.r2dbc.testing.R2dbcIntegrationTestSupport;
|
||||
import org.springframework.data.relational.core.mapping.Table;
|
||||
|
||||
@@ -32,7 +32,6 @@ import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.FilterType;
|
||||
import org.springframework.data.r2dbc.config.AbstractR2dbcConfiguration;
|
||||
import org.springframework.data.r2dbc.repository.config.EnableR2dbcRepositories;
|
||||
import org.springframework.data.r2dbc.repository.query.Query;
|
||||
import org.springframework.data.r2dbc.repository.support.R2dbcRepositoryFactory;
|
||||
import org.springframework.data.r2dbc.testing.H2TestSupport;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
|
||||
@@ -16,13 +16,13 @@
|
||||
package org.springframework.data.r2dbc.repository;
|
||||
|
||||
import io.r2dbc.spi.ConnectionFactory;
|
||||
import org.junit.Ignore;
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.junit.ClassRule;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
@@ -31,7 +31,6 @@ import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.FilterType;
|
||||
import org.springframework.data.r2dbc.config.AbstractR2dbcConfiguration;
|
||||
import org.springframework.data.r2dbc.repository.config.EnableR2dbcRepositories;
|
||||
import org.springframework.data.r2dbc.repository.query.Query;
|
||||
import org.springframework.data.r2dbc.repository.support.R2dbcRepositoryFactory;
|
||||
import org.springframework.data.r2dbc.testing.ExternalDatabase;
|
||||
import org.springframework.data.r2dbc.testing.MySqlTestSupport;
|
||||
|
||||
@@ -30,7 +30,6 @@ import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.FilterType;
|
||||
import org.springframework.data.r2dbc.config.AbstractR2dbcConfiguration;
|
||||
import org.springframework.data.r2dbc.repository.config.EnableR2dbcRepositories;
|
||||
import org.springframework.data.r2dbc.repository.query.Query;
|
||||
import org.springframework.data.r2dbc.repository.support.R2dbcRepositoryFactory;
|
||||
import org.springframework.data.r2dbc.testing.ExternalDatabase;
|
||||
import org.springframework.data.r2dbc.testing.MySqlTestSupport;
|
||||
|
||||
@@ -30,7 +30,6 @@ import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.FilterType;
|
||||
import org.springframework.data.r2dbc.config.AbstractR2dbcConfiguration;
|
||||
import org.springframework.data.r2dbc.repository.config.EnableR2dbcRepositories;
|
||||
import org.springframework.data.r2dbc.repository.query.Query;
|
||||
import org.springframework.data.r2dbc.repository.support.R2dbcRepositoryFactory;
|
||||
import org.springframework.data.r2dbc.testing.ExternalDatabase;
|
||||
import org.springframework.data.r2dbc.testing.PostgresTestSupport;
|
||||
|
||||
@@ -31,7 +31,6 @@ import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.FilterType;
|
||||
import org.springframework.data.r2dbc.config.AbstractR2dbcConfiguration;
|
||||
import org.springframework.data.r2dbc.repository.config.EnableR2dbcRepositories;
|
||||
import org.springframework.data.r2dbc.repository.query.Query;
|
||||
import org.springframework.data.r2dbc.repository.support.R2dbcRepositoryFactory;
|
||||
import org.springframework.data.r2dbc.testing.ExternalDatabase;
|
||||
import org.springframework.data.r2dbc.testing.SqlServerTestSupport;
|
||||
|
||||
@@ -32,6 +32,7 @@ import org.springframework.data.projection.SpelAwareProxyProjectionFactory;
|
||||
import org.springframework.data.r2dbc.convert.MappingR2dbcConverter;
|
||||
import org.springframework.data.r2dbc.core.DatabaseClient;
|
||||
import org.springframework.data.r2dbc.core.DatabaseClient.GenericExecuteSpec;
|
||||
import org.springframework.data.r2dbc.repository.Query;
|
||||
import org.springframework.data.relational.core.mapping.RelationalMappingContext;
|
||||
import org.springframework.data.repository.Repository;
|
||||
import org.springframework.data.repository.core.RepositoryMetadata;
|
||||
@@ -140,16 +141,16 @@ public class StringBasedR2dbcQueryUnitTests {
|
||||
@SuppressWarnings("unused")
|
||||
private interface SampleRepository extends Repository<Person, String> {
|
||||
|
||||
@Query("SELECT * FROM person WHERE lastname = $1")
|
||||
@org.springframework.data.r2dbc.repository.Query("SELECT * FROM person WHERE lastname = $1")
|
||||
Person findByLastname(String lastname);
|
||||
|
||||
@Query("SELECT * FROM person WHERE lastname = :lastname")
|
||||
@org.springframework.data.r2dbc.repository.Query("SELECT * FROM person WHERE lastname = :lastname")
|
||||
Person findByNamedParameter(@Param("lastname") String lastname);
|
||||
|
||||
@Query("SELECT * FROM person WHERE lastname = :unknown")
|
||||
Person findNotByNamedBindMarker(String lastname);
|
||||
|
||||
@Query("SELECT * FROM person WHERE lastname = @lastname")
|
||||
@org.springframework.data.r2dbc.repository.Query("SELECT * FROM person WHERE lastname = @lastname")
|
||||
Person findByNamedBindMarker(@Param("lastname") String lastname);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user