diff --git a/src/main/java/org/springframework/data/r2dbc/InvalidResultAccessException.java b/src/main/java/org/springframework/data/r2dbc/InvalidResultAccessException.java index 3dd808a..82d5fe1 100644 --- a/src/main/java/org/springframework/data/r2dbc/InvalidResultAccessException.java +++ b/src/main/java/org/springframework/data/r2dbc/InvalidResultAccessException.java @@ -25,7 +25,7 @@ import org.springframework.lang.Nullable; * Exception thrown when a {@link io.r2dbc.spi.Result} has been accessed in an invalid fashion. Such exceptions always * have a {@link io.r2dbc.spi.R2dbcException} root cause. *

- * This typically happens when an invalid {@link Result} column index or name has been specified. + * This typically happens when an invalid {@link org.springframework.data.r2dbc.function.SqlResult} column index or name has been specified. * * @author Mark Paluch * @see BadSqlGrammarException @@ -42,7 +42,7 @@ public class InvalidResultAccessException extends InvalidDataAccessResourceUsage * @param sql the offending SQL statement. * @param ex the root cause. */ - public InvalidResultAccessException(String task, String sql, R2dbcException ex) { + public InvalidResultAccessException(String task, @Nullable String sql, R2dbcException ex) { super(task + "; invalid Result access for SQL [" + sql + "]", ex); diff --git a/src/main/java/org/springframework/data/r2dbc/function/connectionfactory/package-info.java b/src/main/java/org/springframework/data/r2dbc/function/connectionfactory/package-info.java new file mode 100644 index 0000000..bc8fcfb --- /dev/null +++ b/src/main/java/org/springframework/data/r2dbc/function/connectionfactory/package-info.java @@ -0,0 +1,6 @@ +/** + * Connection and ConnectionFactory specifics for R2DBC. + */ +@org.springframework.lang.NonNullApi +@org.springframework.lang.NonNullFields +package org.springframework.data.r2dbc.function.connectionfactory; diff --git a/src/main/java/org/springframework/data/r2dbc/function/convert/EntityRowMapper.java b/src/main/java/org/springframework/data/r2dbc/function/convert/EntityRowMapper.java index 0aa86be..c1c67b2 100644 --- a/src/main/java/org/springframework/data/r2dbc/function/convert/EntityRowMapper.java +++ b/src/main/java/org/springframework/data/r2dbc/function/convert/EntityRowMapper.java @@ -33,6 +33,7 @@ import org.springframework.data.mapping.model.ParameterValueProvider; import org.springframework.data.relational.core.conversion.RelationalConverter; import org.springframework.data.relational.core.mapping.RelationalPersistentEntity; import org.springframework.data.relational.core.mapping.RelationalPersistentProperty; +import org.springframework.lang.Nullable; /** * Maps a {@link io.r2dbc.spi.Row} to an entity of type {@code T}, including entities referenced. @@ -150,6 +151,7 @@ public class EntityRowMapper implements BiFunction { * @see org.springframework.data.mapping.model.ParameterValueProvider#getParameterValue(org.springframework.data.mapping.PreferredConstructor.Parameter) */ @Override + @Nullable public T getParameterValue(Parameter parameter) { String column = prefix + entity.getRequiredPersistentProperty(parameter.getName()).getColumnName(); diff --git a/src/main/java/org/springframework/data/r2dbc/function/convert/package-info.java b/src/main/java/org/springframework/data/r2dbc/function/convert/package-info.java new file mode 100644 index 0000000..6839311 --- /dev/null +++ b/src/main/java/org/springframework/data/r2dbc/function/convert/package-info.java @@ -0,0 +1,6 @@ +/** + * R2DBC-specific conversion and converter implementations. + */ +@org.springframework.lang.NonNullApi +@org.springframework.lang.NonNullFields +package org.springframework.data.r2dbc.function.convert; diff --git a/src/main/java/org/springframework/data/r2dbc/function/package-info.java b/src/main/java/org/springframework/data/r2dbc/function/package-info.java new file mode 100644 index 0000000..67ca602 --- /dev/null +++ b/src/main/java/org/springframework/data/r2dbc/function/package-info.java @@ -0,0 +1,6 @@ +/** + * Core domain types around DatabaseClient. + */ +@org.springframework.lang.NonNullApi +@org.springframework.lang.NonNullFields +package org.springframework.data.r2dbc.function; diff --git a/src/main/java/org/springframework/data/r2dbc/package-info.java b/src/main/java/org/springframework/data/r2dbc/package-info.java new file mode 100644 index 0000000..d47e9d3 --- /dev/null +++ b/src/main/java/org/springframework/data/r2dbc/package-info.java @@ -0,0 +1,6 @@ +/** + * Support infrastructure for the configuration of R2DBC-specific repositories. + */ +@org.springframework.lang.NonNullApi +@org.springframework.lang.NonNullFields +package org.springframework.data.r2dbc; diff --git a/src/main/java/org/springframework/data/r2dbc/repository/config/AbstractR2dbcConfiguration.java b/src/main/java/org/springframework/data/r2dbc/repository/config/AbstractR2dbcConfiguration.java index 7e5be5b..561a513 100644 --- a/src/main/java/org/springframework/data/r2dbc/repository/config/AbstractR2dbcConfiguration.java +++ b/src/main/java/org/springframework/data/r2dbc/repository/config/AbstractR2dbcConfiguration.java @@ -1,9 +1,23 @@ +/* + * Copyright 2018 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package org.springframework.data.r2dbc.repository.config; -import io.r2dbc.spi.ConnectionFactory; - import java.util.Optional; +import io.r2dbc.spi.ConnectionFactory; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.data.r2dbc.function.DatabaseClient; @@ -14,6 +28,7 @@ import org.springframework.data.r2dbc.support.SqlErrorCodeR2dbcExceptionTranslat import org.springframework.data.relational.core.conversion.BasicRelationalConverter; import org.springframework.data.relational.core.mapping.NamingStrategy; import org.springframework.data.relational.core.mapping.RelationalMappingContext; +import org.springframework.util.Assert; /** * Base class for Spring Data R2DBC configuration containing bean declarations that must be registered for Spring Data @@ -39,13 +54,20 @@ public abstract class AbstractR2dbcConfiguration { * Register a {@link DatabaseClient} using {@link #connectionFactory()} and {@link RelationalMappingContext}. * * @return must not be {@literal null}. + * @throws IllegalArgumentException if any of the required args is {@literal null}. */ @Bean public DatabaseClient databaseClient(ReactiveDataAccessStrategy dataAccessStrategy, R2dbcExceptionTranslator exceptionTranslator) { - return DatabaseClient.builder().connectionFactory(connectionFactory()).dataAccessStrategy(dataAccessStrategy) - .exceptionTranslator(exceptionTranslator).build(); + Assert.notNull(dataAccessStrategy, "DataAccessStrategy must not be null!"); + Assert.notNull(exceptionTranslator, "ExceptionTranslator must not be null!"); + + return DatabaseClient.builder() // + .connectionFactory(connectionFactory()) // + .dataAccessStrategy(dataAccessStrategy) // + .exceptionTranslator(exceptionTranslator) // + .build(); } /** @@ -53,26 +75,33 @@ public abstract class AbstractR2dbcConfiguration { * * @param namingStrategy optional {@link NamingStrategy}. Use {@link NamingStrategy#INSTANCE} as fallback. * @return must not be {@literal null}. + * @throws IllegalArgumentException if any of the required args is {@literal null}. */ @Bean public RelationalMappingContext r2dbcMappingContext(Optional namingStrategy) { + + Assert.notNull(namingStrategy, "NamingStrategy must not be null!"); + return new RelationalMappingContext(namingStrategy.orElse(NamingStrategy.INSTANCE)); } /** - * Creates a {@link ReactiveDataAccessStrategy} using the configured {@link #r2dbcMappingContext(Optional)}. + * Creates a {@link ReactiveDataAccessStrategy} using the configured {@link #r2dbcMappingContext(Optional) RelationalMappingContext}. * * @param mappingContext the configured {@link RelationalMappingContext}. * @return must not be {@literal null}. * @see #r2dbcMappingContext(Optional) + * @throws IllegalArgumentException if any of the {@literal mappingContext} is {@literal null}. */ @Bean public ReactiveDataAccessStrategy reactiveDataAccessStrategy(RelationalMappingContext mappingContext) { + + Assert.notNull(mappingContext, "MappingContext must not be null!"); return new DefaultReactiveDataAccessStrategy(new BasicRelationalConverter(mappingContext)); } /** - * Creates a {@link R2dbcExceptionTranslator} using the configured {@link #connectionFactory()}. + * Creates a {@link R2dbcExceptionTranslator} using the configured {@link #connectionFactory() ConnectionFactory}. * * @return must not be {@literal null}. * @see #connectionFactory() diff --git a/src/main/java/org/springframework/data/r2dbc/repository/config/EnableR2dbcRepositories.java b/src/main/java/org/springframework/data/r2dbc/repository/config/EnableR2dbcRepositories.java index 2494a0c..75e4ab4 100644 --- a/src/main/java/org/springframework/data/r2dbc/repository/config/EnableR2dbcRepositories.java +++ b/src/main/java/org/springframework/data/r2dbc/repository/config/EnableR2dbcRepositories.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2018 the original author or authors. + * Copyright 2018 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,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.springframework.data.r2dbc.repository.config; import java.lang.annotation.Documented; @@ -37,6 +36,7 @@ import org.springframework.data.repository.query.QueryLookupStrategy.Key; * annotated class. * * @author Mark Paluch + * @author Christoph Strobl */ @Target(ElementType.TYPE) @Retention(RetentionPolicy.RUNTIME) @@ -87,7 +87,7 @@ public @interface EnableR2dbcRepositories { /** * Configures the location of where to find the Spring Data named queries properties file. Will default to - * {@code META-INF/r2dbc-named-queries.properties}. + * {@code META-INF/r2dbc-named-queries.properties} if not configured otherwise. * * @return */ diff --git a/src/main/java/org/springframework/data/r2dbc/repository/config/R2dbcRepositoriesRegistrar.java b/src/main/java/org/springframework/data/r2dbc/repository/config/R2dbcRepositoriesRegistrar.java index 8e5156d..5279e09 100644 --- a/src/main/java/org/springframework/data/r2dbc/repository/config/R2dbcRepositoriesRegistrar.java +++ b/src/main/java/org/springframework/data/r2dbc/repository/config/R2dbcRepositoriesRegistrar.java @@ -1,3 +1,18 @@ +/* + * Copyright 2018 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package org.springframework.data.r2dbc.repository.config; import java.lang.annotation.Annotation; diff --git a/src/main/java/org/springframework/data/r2dbc/repository/config/R2dbcRepositoryConfigurationExtension.java b/src/main/java/org/springframework/data/r2dbc/repository/config/R2dbcRepositoryConfigurationExtension.java index 221124e..c7cc63a 100644 --- a/src/main/java/org/springframework/data/r2dbc/repository/config/R2dbcRepositoryConfigurationExtension.java +++ b/src/main/java/org/springframework/data/r2dbc/repository/config/R2dbcRepositoryConfigurationExtension.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2018 the original author or authors. + * Copyright 2018 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. diff --git a/src/main/java/org/springframework/data/r2dbc/repository/config/package-info.java b/src/main/java/org/springframework/data/r2dbc/repository/config/package-info.java new file mode 100644 index 0000000..4cacf80 --- /dev/null +++ b/src/main/java/org/springframework/data/r2dbc/repository/config/package-info.java @@ -0,0 +1,6 @@ +/** + * Support infrastructure for the configuration of R2DBC-specific repositories. + */ +@org.springframework.lang.NonNullApi +@org.springframework.lang.NonNullFields +package org.springframework.data.r2dbc.repository.config; diff --git a/src/main/java/org/springframework/data/r2dbc/repository/package-info.java b/src/main/java/org/springframework/data/r2dbc/repository/package-info.java index a39ae50..7082b8c 100644 --- a/src/main/java/org/springframework/data/r2dbc/repository/package-info.java +++ b/src/main/java/org/springframework/data/r2dbc/repository/package-info.java @@ -1,7 +1,6 @@ /** * R2DBC-specific repository implementation. */ -@NonNullApi +@org.springframework.lang.NonNullApi +@org.springframework.lang.NonNullFields package org.springframework.data.r2dbc.repository; - -import org.springframework.lang.NonNullApi; diff --git a/src/main/java/org/springframework/data/r2dbc/repository/support/R2dbcRepositoryFactoryBean.java b/src/main/java/org/springframework/data/r2dbc/repository/support/R2dbcRepositoryFactoryBean.java index 054730d..4b06aa2 100644 --- a/src/main/java/org/springframework/data/r2dbc/repository/support/R2dbcRepositoryFactoryBean.java +++ b/src/main/java/org/springframework/data/r2dbc/repository/support/R2dbcRepositoryFactoryBean.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2018 the original author or authors. + * Copyright 2018 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. @@ -33,13 +33,15 @@ import org.springframework.util.Assert; * {@link org.springframework.data.r2dbc.repository.R2dbcRepository} instances. * * @author Mark Paluch + * @author Christoph Strobl * @see org.springframework.data.repository.reactive.ReactiveCrudRepository */ public class R2dbcRepositoryFactoryBean, S, ID extends Serializable> extends RepositoryFactoryBeanSupport { private @Nullable DatabaseClient client; - private @Nullable MappingContext, RelationalPersistentProperty> mappingContext; + private @Nullable + MappingContext, RelationalPersistentProperty> mappingContext; private boolean mappingContextConfigured = false; @@ -67,13 +69,21 @@ public class R2dbcRepositoryFactoryBean, S, ID exten */ @Override @SuppressWarnings("unchecked") - protected void setMappingContext(MappingContext mappingContext) { + protected void setMappingContext(@Nullable MappingContext mappingContext) { super.setMappingContext(mappingContext); - this.mappingContext = (MappingContext, RelationalPersistentProperty>) mappingContext; - this.mappingContextConfigured = true; + + if (mappingContext != null) { + + this.mappingContext = (MappingContext, RelationalPersistentProperty>) mappingContext; + this.mappingContextConfigured = true; + } } + /* + * (non-Javadoc) + * @see org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport#createRepositoryFactory() + */ @Override protected final RepositoryFactorySupport createRepositoryFactory() { return getFactoryInstance(client, this.mappingContext); @@ -82,15 +92,19 @@ public class R2dbcRepositoryFactoryBean, S, ID exten /** * Creates and initializes a {@link RepositoryFactorySupport} instance. * - * @param client - * @param mappingContext - * @return + * @param client must not be {@literal null}. + * @param mappingContext must not be {@literal null}. + * @return new instance of {@link RepositoryFactorySupport}. */ protected RepositoryFactorySupport getFactoryInstance(DatabaseClient client, MappingContext, RelationalPersistentProperty> mappingContext) { return new R2dbcRepositoryFactory(client, mappingContext); } + /* + * (non-Javadoc) + * @see org.springframework.beans.factory.InitializingBean#afterPropertiesSet() + */ @Override public void afterPropertiesSet() { diff --git a/src/main/java/org/springframework/data/r2dbc/repository/support/package-info.java b/src/main/java/org/springframework/data/r2dbc/repository/support/package-info.java index 5fc32c6..8b4a962 100644 --- a/src/main/java/org/springframework/data/r2dbc/repository/support/package-info.java +++ b/src/main/java/org/springframework/data/r2dbc/repository/support/package-info.java @@ -1,7 +1,6 @@ /** * Support infrastructure for query derivation of R2DBC-specific repositories. */ -@NonNullApi +@org.springframework.lang.NonNullApi +@org.springframework.lang.NonNullFields package org.springframework.data.r2dbc.repository.support; - -import org.springframework.lang.NonNullApi; diff --git a/src/main/java/org/springframework/data/r2dbc/support/SqlErrorCodeR2dbcExceptionTranslator.java b/src/main/java/org/springframework/data/r2dbc/support/SqlErrorCodeR2dbcExceptionTranslator.java index 87046a1..7f29fbc 100644 --- a/src/main/java/org/springframework/data/r2dbc/support/SqlErrorCodeR2dbcExceptionTranslator.java +++ b/src/main/java/org/springframework/data/r2dbc/support/SqlErrorCodeR2dbcExceptionTranslator.java @@ -104,7 +104,7 @@ public class SqlErrorCodeR2dbcExceptionTranslator extends AbstractFallbackR2dbcE * * @param sec error codes */ - public SqlErrorCodeR2dbcExceptionTranslator(SQLErrorCodes sec) { + public SqlErrorCodeR2dbcExceptionTranslator(@Nullable SQLErrorCodes sec) { this(); this.sqlErrorCodes = sec; } diff --git a/src/main/java/org/springframework/data/r2dbc/support/package-info.java b/src/main/java/org/springframework/data/r2dbc/support/package-info.java new file mode 100644 index 0000000..fe6a259 --- /dev/null +++ b/src/main/java/org/springframework/data/r2dbc/support/package-info.java @@ -0,0 +1,5 @@ +/** + * Support infrastructure for the configuration of R2DBC-specific repositories. + */ +@org.springframework.lang.NonNullApi +package org.springframework.data.r2dbc.support; diff --git a/src/test/java/org/springframework/data/r2dbc/repository/config/Person.java b/src/test/java/org/springframework/data/r2dbc/repository/config/Person.java index 033b897..f920100 100644 --- a/src/test/java/org/springframework/data/r2dbc/repository/config/Person.java +++ b/src/test/java/org/springframework/data/r2dbc/repository/config/Person.java @@ -1,3 +1,18 @@ +/* + * Copyright 2018 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package org.springframework.data.r2dbc.repository.config; /** diff --git a/src/test/java/org/springframework/data/r2dbc/repository/config/PersonRepository.java b/src/test/java/org/springframework/data/r2dbc/repository/config/PersonRepository.java index d10ba35..b8141ce 100644 --- a/src/test/java/org/springframework/data/r2dbc/repository/config/PersonRepository.java +++ b/src/test/java/org/springframework/data/r2dbc/repository/config/PersonRepository.java @@ -1,3 +1,18 @@ +/* + * Copyright 2018 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package org.springframework.data.r2dbc.repository.config; import org.springframework.data.r2dbc.repository.R2dbcRepository; diff --git a/src/test/java/org/springframework/data/r2dbc/repository/config/R2dbcRepositoriesRegistrarTests.java b/src/test/java/org/springframework/data/r2dbc/repository/config/R2dbcRepositoriesRegistrarTests.java index 6bb3023..b5c29df 100644 --- a/src/test/java/org/springframework/data/r2dbc/repository/config/R2dbcRepositoriesRegistrarTests.java +++ b/src/test/java/org/springframework/data/r2dbc/repository/config/R2dbcRepositoriesRegistrarTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2018 the original author or authors. + * Copyright 2018 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,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.springframework.data.r2dbc.repository.config; import static org.mockito.Mockito.*; diff --git a/src/test/java/org/springframework/data/r2dbc/repository/config/R2dbcRepositoryConfigurationExtensionUnitTests.java b/src/test/java/org/springframework/data/r2dbc/repository/config/R2dbcRepositoryConfigurationExtensionUnitTests.java index c904371..eb40cb7 100644 --- a/src/test/java/org/springframework/data/r2dbc/repository/config/R2dbcRepositoryConfigurationExtensionUnitTests.java +++ b/src/test/java/org/springframework/data/r2dbc/repository/config/R2dbcRepositoryConfigurationExtensionUnitTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2018 the original author or authors. + * Copyright 2018 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. @@ -29,6 +29,7 @@ import org.springframework.core.io.support.PathMatchingResourcePatternResolver; import org.springframework.core.type.StandardAnnotationMetadata; import org.springframework.data.r2dbc.repository.R2dbcRepository; import org.springframework.data.relational.core.mapping.Table; +import org.springframework.data.repository.CrudRepository; import org.springframework.data.repository.config.AnnotationRepositoryConfigurationSource; import org.springframework.data.repository.config.RepositoryConfiguration; import org.springframework.data.repository.config.RepositoryConfigurationSource; @@ -38,6 +39,7 @@ import org.springframework.data.repository.reactive.ReactiveCrudRepository; * Unit tests for {@link R2dbcRepositoryConfigurationExtension}. * * @author Mark Paluch + * @author Christoph Strobl */ public class R2dbcRepositoryConfigurationExtensionUnitTests { @@ -71,6 +73,14 @@ public class R2dbcRepositoryConfigurationExtensionUnitTests { extension.getRepositoryConfigurations(configurationSource, loader, true)); } + @Test // gh-13 + public void doesNotHaveNonReactiveRepository() { + + R2dbcRepositoryConfigurationExtension extension = new R2dbcRepositoryConfigurationExtension(); + assertDoesNotHaveRepo(NonReactiveRepository.class, + extension.getRepositoryConfigurations(configurationSource, loader, true)); + } + private static void assertHasRepo(Class repositoryInterface, Collection> configs) { @@ -107,4 +117,6 @@ public class R2dbcRepositoryConfigurationExtensionUnitTests { interface UnannotatedRepository extends ReactiveCrudRepository {} interface StoreRepository extends R2dbcRepository {} + + interface NonReactiveRepository extends CrudRepository {} }