File tree 5 files changed +46
-13
lines changed
main/java/org/springframework/data/jdbc/core/dialect
test/java/org/springframework/data/jdbc
spring-data-relational/src/main/java/org/springframework/data/relational/core/dialect
5 files changed +46
-13
lines changed Original file line number Diff line number Diff line change 17
17
18
18
import microsoft .sql .DateTimeOffset ;
19
19
20
+ import java .time .Instant ;
20
21
import java .time .OffsetDateTime ;
21
22
import java .util .ArrayList ;
22
23
import java .util .Collection ;
31
32
*
32
33
* @author Jens Schauder
33
34
* @author Christoph Strobl
35
+ * @author Mikhail Polivakha
34
36
* @since 2.3
35
37
*/
36
38
public class JdbcSqlServerDialect extends SqlServerDialect {
@@ -42,6 +44,7 @@ public Collection<Object> getConverters() {
42
44
43
45
List <Object > converters = new ArrayList <>(super .getConverters ());
44
46
converters .add (DateTimeOffsetToOffsetDateTimeConverter .INSTANCE );
47
+ converters .add (DateTimeOffsetToInstantConverter .INSTANCE );
45
48
return converters ;
46
49
}
47
50
@@ -55,4 +58,15 @@ public OffsetDateTime convert(DateTimeOffset source) {
55
58
return source .getOffsetDateTime ();
56
59
}
57
60
}
61
+
62
+ @ ReadingConverter
63
+ enum DateTimeOffsetToInstantConverter implements Converter <DateTimeOffset , Instant > {
64
+
65
+ INSTANCE ;
66
+
67
+ @ Override
68
+ public Instant convert (DateTimeOffset source ) {
69
+ return source .getOffsetDateTime ().toInstant ();
70
+ }
71
+ }
58
72
}
Original file line number Diff line number Diff line change
1
+ package org .springframework .data .jdbc .core .dialect ;
2
+
3
+ import java .time .Instant ;
4
+ import java .util .List ;
5
+
6
+ import org .assertj .core .api .Assertions ;
7
+ import org .junit .jupiter .api .Test ;
8
+ import org .springframework .data .jdbc .core .convert .JdbcCustomConversions ;
9
+
10
+ /**
11
+ * Tests for {@link JdbcSqlServerDialect}
12
+ *
13
+ * @author Mikhail Polivakha
14
+ */
15
+ class JdbcSqlServerDialectTest {
16
+
17
+ @ Test
18
+ void testCustomConversions () {
19
+ JdbcCustomConversions jdbcCustomConversions = new JdbcCustomConversions (
20
+ (List <?>) JdbcSqlServerDialect .INSTANCE .getConverters ());
21
+
22
+ Assertions
23
+ .assertThat (jdbcCustomConversions .hasCustomReadTarget (microsoft .sql .DateTimeOffset .class , Instant .class ))
24
+ .isTrue ();
25
+ }
26
+ }
Original file line number Diff line number Diff line change 44
44
*/
45
45
@ Retention (RetentionPolicy .RUNTIME )
46
46
@ Target (ElementType .TYPE )
47
- // required twice as the annotation lookup doesn't merge multiple occurences of the same annotation
47
+ // required twice as the annotation lookup doesn't merge multiple occurrences of the same annotation
48
48
@ ContextCustomizerFactories (value = { TestClassCustomizerFactory .class , EnabledOnDatabaseCustomizerFactory .class })
49
49
@ Documented
50
50
@ Inherited
Original file line number Diff line number Diff line change 49
49
* @see EnabledOnDatabase
50
50
*/
51
51
@ TestExecutionListeners (value = AssumeFeatureTestExecutionListener .class , mergeMode = MERGE_WITH_DEFAULTS )
52
- // required twice as the annotation lookup doesn't merge multiple occurences of the same annotation
52
+ // required twice as the annotation lookup doesn't merge multiple occurrences of the same annotation
53
53
@ ContextCustomizerFactories (value = { TestClassCustomizerFactory .class , EnabledOnDatabaseCustomizerFactory .class })
54
54
@ ActiveProfiles (resolver = CombiningActiveProfileResolver .class )
55
55
@ ExtendWith (SpringExtension .class )
Original file line number Diff line number Diff line change @@ -81,17 +81,10 @@ public Position getClausePosition() {
81
81
82
82
@ Override
83
83
public String getLock (LockOptions lockOptions ) {
84
- switch (lockOptions .getLockMode ()) {
85
-
86
- case PESSIMISTIC_WRITE :
87
- return "WITH (UPDLOCK, ROWLOCK)" ;
88
-
89
- case PESSIMISTIC_READ :
90
- return "WITH (HOLDLOCK, ROWLOCK)" ;
91
-
92
- default :
93
- return "" ;
94
- }
84
+ return switch (lockOptions .getLockMode ()) {
85
+ case PESSIMISTIC_WRITE -> "WITH (UPDLOCK, ROWLOCK)" ;
86
+ case PESSIMISTIC_READ -> "WITH (HOLDLOCK, ROWLOCK)" ;
87
+ };
95
88
}
96
89
97
90
@ Override
You can’t perform that action at this time.
0 commit comments