Skip to content

Commit 9f7d386

Browse files
christophstroblmp911de
authored andcommitted
#13 - Polishing.
Add missing header & package-info. Update nullability and add tests. Original pull request: #17.
1 parent 6267047 commit 9f7d386

20 files changed

+164
-30
lines changed

src/main/java/org/springframework/data/r2dbc/InvalidResultAccessException.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
* Exception thrown when a {@link io.r2dbc.spi.Result} has been accessed in an invalid fashion. Such exceptions always
2626
* have a {@link io.r2dbc.spi.R2dbcException} root cause.
2727
* <p>
28-
* This typically happens when an invalid {@link Result} column index or name has been specified.
28+
* This typically happens when an invalid {@link org.springframework.data.r2dbc.function.SqlResult} column index or name has been specified.
2929
*
3030
* @author Mark Paluch
3131
* @see BadSqlGrammarException
@@ -42,7 +42,7 @@ public class InvalidResultAccessException extends InvalidDataAccessResourceUsage
4242
* @param sql the offending SQL statement.
4343
* @param ex the root cause.
4444
*/
45-
public InvalidResultAccessException(String task, String sql, R2dbcException ex) {
45+
public InvalidResultAccessException(String task, @Nullable String sql, R2dbcException ex) {
4646

4747
super(task + "; invalid Result access for SQL [" + sql + "]", ex);
4848

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/**
2+
* Connection and ConnectionFactory specifics for R2DBC.
3+
*/
4+
@org.springframework.lang.NonNullApi
5+
@org.springframework.lang.NonNullFields
6+
package org.springframework.data.r2dbc.function.connectionfactory;

src/main/java/org/springframework/data/r2dbc/function/convert/EntityRowMapper.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import org.springframework.data.relational.core.conversion.RelationalConverter;
3434
import org.springframework.data.relational.core.mapping.RelationalPersistentEntity;
3535
import org.springframework.data.relational.core.mapping.RelationalPersistentProperty;
36+
import org.springframework.lang.Nullable;
3637

3738
/**
3839
* Maps a {@link io.r2dbc.spi.Row} to an entity of type {@code T}, including entities referenced.
@@ -150,6 +151,7 @@ private static class RowParameterValueProvider implements ParameterValueProvider
150151
* @see org.springframework.data.mapping.model.ParameterValueProvider#getParameterValue(org.springframework.data.mapping.PreferredConstructor.Parameter)
151152
*/
152153
@Override
154+
@Nullable
153155
public <T> T getParameterValue(Parameter<T, RelationalPersistentProperty> parameter) {
154156

155157
String column = prefix + entity.getRequiredPersistentProperty(parameter.getName()).getColumnName();
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/**
2+
* R2DBC-specific conversion and converter implementations.
3+
*/
4+
@org.springframework.lang.NonNullApi
5+
@org.springframework.lang.NonNullFields
6+
package org.springframework.data.r2dbc.function.convert;
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/**
2+
* Core domain types around DatabaseClient.
3+
*/
4+
@org.springframework.lang.NonNullApi
5+
@org.springframework.lang.NonNullFields
6+
package org.springframework.data.r2dbc.function;
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/**
2+
* Support infrastructure for the configuration of R2DBC-specific repositories.
3+
*/
4+
@org.springframework.lang.NonNullApi
5+
@org.springframework.lang.NonNullFields
6+
package org.springframework.data.r2dbc;

src/main/java/org/springframework/data/r2dbc/repository/config/AbstractR2dbcConfiguration.java

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,23 @@
1+
/*
2+
* Copyright 2018 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
116
package org.springframework.data.r2dbc.repository.config;
217

3-
import io.r2dbc.spi.ConnectionFactory;
4-
518
import java.util.Optional;
619

20+
import io.r2dbc.spi.ConnectionFactory;
721
import org.springframework.context.annotation.Bean;
822
import org.springframework.context.annotation.Configuration;
923
import org.springframework.data.r2dbc.function.DatabaseClient;
@@ -14,6 +28,7 @@
1428
import org.springframework.data.relational.core.conversion.BasicRelationalConverter;
1529
import org.springframework.data.relational.core.mapping.NamingStrategy;
1630
import org.springframework.data.relational.core.mapping.RelationalMappingContext;
31+
import org.springframework.util.Assert;
1732

1833
/**
1934
* Base class for Spring Data R2DBC configuration containing bean declarations that must be registered for Spring Data
@@ -39,40 +54,54 @@ public abstract class AbstractR2dbcConfiguration {
3954
* Register a {@link DatabaseClient} using {@link #connectionFactory()} and {@link RelationalMappingContext}.
4055
*
4156
* @return must not be {@literal null}.
57+
* @throws IllegalArgumentException if any of the required args is {@literal null}.
4258
*/
4359
@Bean
4460
public DatabaseClient databaseClient(ReactiveDataAccessStrategy dataAccessStrategy,
4561
R2dbcExceptionTranslator exceptionTranslator) {
4662

47-
return DatabaseClient.builder().connectionFactory(connectionFactory()).dataAccessStrategy(dataAccessStrategy)
48-
.exceptionTranslator(exceptionTranslator).build();
63+
Assert.notNull(dataAccessStrategy, "DataAccessStrategy must not be null!");
64+
Assert.notNull(exceptionTranslator, "ExceptionTranslator must not be null!");
65+
66+
return DatabaseClient.builder() //
67+
.connectionFactory(connectionFactory()) //
68+
.dataAccessStrategy(dataAccessStrategy) //
69+
.exceptionTranslator(exceptionTranslator) //
70+
.build();
4971
}
5072

5173
/**
5274
* Register a {@link RelationalMappingContext} and apply an optional {@link NamingStrategy}.
5375
*
5476
* @param namingStrategy optional {@link NamingStrategy}. Use {@link NamingStrategy#INSTANCE} as fallback.
5577
* @return must not be {@literal null}.
78+
* @throws IllegalArgumentException if any of the required args is {@literal null}.
5679
*/
5780
@Bean
5881
public RelationalMappingContext r2dbcMappingContext(Optional<NamingStrategy> namingStrategy) {
82+
83+
Assert.notNull(namingStrategy, "NamingStrategy must not be null!");
84+
5985
return new RelationalMappingContext(namingStrategy.orElse(NamingStrategy.INSTANCE));
6086
}
6187

6288
/**
63-
* Creates a {@link ReactiveDataAccessStrategy} using the configured {@link #r2dbcMappingContext(Optional)}.
89+
* Creates a {@link ReactiveDataAccessStrategy} using the configured {@link #r2dbcMappingContext(Optional) RelationalMappingContext}.
6490
*
6591
* @param mappingContext the configured {@link RelationalMappingContext}.
6692
* @return must not be {@literal null}.
6793
* @see #r2dbcMappingContext(Optional)
94+
* @throws IllegalArgumentException if any of the {@literal mappingContext} is {@literal null}.
6895
*/
6996
@Bean
7097
public ReactiveDataAccessStrategy reactiveDataAccessStrategy(RelationalMappingContext mappingContext) {
98+
99+
Assert.notNull(mappingContext, "MappingContext must not be null!");
71100
return new DefaultReactiveDataAccessStrategy(new BasicRelationalConverter(mappingContext));
72101
}
73102

74103
/**
75-
* Creates a {@link R2dbcExceptionTranslator} using the configured {@link #connectionFactory()}.
104+
* Creates a {@link R2dbcExceptionTranslator} using the configured {@link #connectionFactory() ConnectionFactory}.
76105
*
77106
* @return must not be {@literal null}.
78107
* @see #connectionFactory()

src/main/java/org/springframework/data/r2dbc/repository/config/EnableR2dbcRepositories.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016-2018 the original author or authors.
2+
* Copyright 2018 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -13,7 +13,6 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
1716
package org.springframework.data.r2dbc.repository.config;
1817

1918
import java.lang.annotation.Documented;
@@ -37,6 +36,7 @@
3736
* annotated class.
3837
*
3938
* @author Mark Paluch
39+
* @author Christoph Strobl
4040
*/
4141
@Target(ElementType.TYPE)
4242
@Retention(RetentionPolicy.RUNTIME)
@@ -87,7 +87,7 @@
8787

8888
/**
8989
* Configures the location of where to find the Spring Data named queries properties file. Will default to
90-
* {@code META-INF/r2dbc-named-queries.properties}.
90+
* {@code META-INF/r2dbc-named-queries.properties} if not configured otherwise.
9191
*
9292
* @return
9393
*/

src/main/java/org/springframework/data/r2dbc/repository/config/R2dbcRepositoriesRegistrar.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
/*
2+
* Copyright 2018 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
116
package org.springframework.data.r2dbc.repository.config;
217

318
import java.lang.annotation.Annotation;

src/main/java/org/springframework/data/r2dbc/repository/config/R2dbcRepositoryConfigurationExtension.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016-2018 the original author or authors.
2+
* Copyright 2018 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.

0 commit comments

Comments
 (0)