Skip to content

Commit 49f4b5f

Browse files
committed
Extraneous warnings related to JdbcSqlServerDialect.
Add tests for R2DBC types as well. Closes #2147
1 parent c8196b5 commit 49f4b5f

File tree

7 files changed

+84
-5
lines changed

7 files changed

+84
-5
lines changed

spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/convert/JdbcCustomConversions.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import org.springframework.data.convert.ConverterBuilder;
3030
import org.springframework.data.convert.CustomConversions;
3131
import org.springframework.data.jdbc.core.mapping.JdbcSimpleTypes;
32+
import org.springframework.data.mapping.model.SimpleTypeHolder;
3233
import org.springframework.data.relational.core.dialect.Dialect;
3334
import org.springframework.lang.Contract;
3435
import org.springframework.util.Assert;
@@ -177,9 +178,8 @@ static JdbcConverterConfigurer from(Dialect dialect) {
177178
converters.addAll(dialect.getConverters());
178179
converters.addAll(JdbcCustomConversions.storeConverters());
179180

180-
StoreConversions storeConversions = StoreConversions.of(JdbcSimpleTypes.HOLDER, converters);
181-
182-
return new JdbcConverterConfigurer(storeConversions);
181+
SimpleTypeHolder simpleTypeHolder = new SimpleTypeHolder(dialect.simpleTypes(), JdbcSimpleTypes.HOLDER);
182+
return new JdbcConverterConfigurer(StoreConversions.of(simpleTypeHolder, converters));
183183
}
184184

185185
/**

spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/dialect/JdbcSqlServerDialect.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import java.util.ArrayList;
2323
import java.util.Collection;
2424
import java.util.List;
25+
import java.util.Set;
2526

2627
import org.springframework.core.convert.converter.Converter;
2728
import org.springframework.data.convert.ReadingConverter;
@@ -33,12 +34,20 @@
3334
* @author Jens Schauder
3435
* @author Christoph Strobl
3536
* @author Mikhail Polivakha
37+
* @author Mark Paluch
3638
* @since 2.3
3739
*/
3840
public class JdbcSqlServerDialect extends SqlServerDialect implements JdbcDialect {
3941

4042
public static final JdbcSqlServerDialect INSTANCE = new JdbcSqlServerDialect();
4143

44+
private static final Set<Class<?>> SIMPLE_TYPES = Set.of(DateTimeOffset.class);
45+
46+
@Override
47+
public Set<Class<?>> simpleTypes() {
48+
return SIMPLE_TYPES;
49+
}
50+
4251
@Override
4352
public Collection<Object> getConverters() {
4453

spring-data-jdbc/src/test/java/org/springframework/data/jdbc/core/dialect/JdbcSqlServerDialectTest.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717

1818
import static org.assertj.core.api.Assertions.*;
1919

20+
import microsoft.sql.DateTimeOffset;
21+
2022
import java.time.Instant;
2123
import java.util.List;
2224

@@ -28,6 +30,7 @@
2830
* Tests for {@link JdbcSqlServerDialect}
2931
*
3032
* @author Mikhail Polivakha
33+
* @author Mark Paluch
3134
*/
3235
class JdbcSqlServerDialectTest {
3336

@@ -36,7 +39,16 @@ void testCustomConversions() {
3639

3740
JdbcCustomConversions conversions = JdbcCustomConversions.of(JdbcSqlServerDialect.INSTANCE, List.of());
3841

39-
assertThat(conversions.hasCustomReadTarget(microsoft.sql.DateTimeOffset.class, Instant.class))
42+
assertThat(conversions.hasCustomReadTarget(DateTimeOffset.class, Instant.class))
4043
.isTrue();
4144
}
45+
46+
@Test // GH-2147
47+
void shouldReportSimpleTypes() {
48+
49+
JdbcCustomConversions conversions = JdbcCustomConversions.of(JdbcSqlServerDialect.INSTANCE, List.of());
50+
51+
assertThat(conversions.isSimpleType(DateTimeOffset.class)).isTrue();
52+
assertThat(conversions.getSimpleTypeHolder().isSimpleType(DateTimeOffset.class)).isTrue();
53+
}
4254
}

spring-data-r2dbc/src/main/java/org/springframework/data/r2dbc/convert/R2dbcCustomConversions.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
/*
2+
* Copyright 2018-2025 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+
* https://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.convert;
217

318
import java.util.ArrayList;

spring-data-r2dbc/src/main/java/org/springframework/data/r2dbc/dialect/R2dbcDialect.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ default SimpleTypeHolder getSimpleTypeHolder() {
4949
Set<Class<?>> simpleTypes = new HashSet<>(getSimpleTypes());
5050
simpleTypes.addAll(R2dbcSimpleTypeHolder.R2DBC_SIMPLE_TYPES);
5151

52-
return new SimpleTypeHolder(simpleTypes, true);
52+
return new SimpleTypeHolder(simpleTypes, R2dbcSimpleTypeHolder.HOLDER);
5353
}
5454

5555
/**
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
* Copyright 2025 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+
* https://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+
*/
16+
package org.springframework.data.r2dbc.convert;
17+
18+
import static org.assertj.core.api.Assertions.*;
19+
20+
import io.r2dbc.spi.Blob;
21+
22+
import org.junit.jupiter.api.Test;
23+
24+
import org.springframework.data.r2dbc.dialect.H2Dialect;
25+
26+
/**
27+
* Unit tests for {@link R2dbcCustomConversions}.
28+
*
29+
* @author Mark Paluch
30+
*/
31+
class R2dbcCustomConversionsUnitTests {
32+
33+
@Test // GH-2147
34+
void shouldReportR2dbcSimpleTypes() {
35+
36+
R2dbcCustomConversions conversions = R2dbcCustomConversions.of(H2Dialect.INSTANCE);
37+
38+
assertThat(conversions.isSimpleType(Blob.class)).isTrue();
39+
}
40+
}

spring-data-r2dbc/src/test/java/org/springframework/data/r2dbc/dialect/PostgresDialectUnitTests.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
import static org.assertj.core.api.Assertions.*;
1919
import static org.assertj.core.api.SoftAssertions.*;
2020

21+
import io.r2dbc.postgresql.codec.Box;
22+
2123
import java.util.List;
2224

2325
import org.junit.jupiter.api.Test;
@@ -55,6 +57,7 @@ void shouldConsiderSimpleTypes() {
5557
it.assertThat(holder.isSimpleType(String.class)).isTrue();
5658
it.assertThat(holder.isSimpleType(int.class)).isTrue();
5759
it.assertThat(holder.isSimpleType(Integer.class)).isTrue();
60+
it.assertThat(holder.isSimpleType(Box.class)).isTrue();
5861
});
5962
}
6063

0 commit comments

Comments
 (0)