24
24
import java .util .List ;
25
25
import java .util .Set ;
26
26
27
+ import org .jspecify .annotations .Nullable ;
28
+
27
29
import org .springframework .core .convert .converter .Converter ;
28
30
import org .springframework .data .convert .ReadingConverter ;
29
31
import org .springframework .data .relational .core .dialect .SqlServerDialect ;
32
+ import org .springframework .data .util .ClassUtils ;
30
33
31
34
/**
32
35
* {@link SqlServerDialect} that registers JDBC specific converters.
@@ -41,7 +44,21 @@ public class JdbcSqlServerDialect extends SqlServerDialect implements JdbcDialec
41
44
42
45
public static final JdbcSqlServerDialect INSTANCE = new JdbcSqlServerDialect ();
43
46
44
- private static final Set <Class <?>> SIMPLE_TYPES = Set .of (DateTimeOffset .class );
47
+ private static final @ Nullable Class <?> DATE_TIME_OFFSET_CLASS = ClassUtils
48
+ .loadIfPresent ("microsoft.sql.DateTimeOffset" , JdbcSqlServerDialect .class .getClassLoader ());
49
+ private static final Set <Class <?>> SIMPLE_TYPES ;
50
+ private static final List <Object > CONVERTERS ;
51
+
52
+ static {
53
+
54
+ if (DATE_TIME_OFFSET_CLASS != null ) {
55
+ SIMPLE_TYPES = Set .of (DATE_TIME_OFFSET_CLASS );
56
+ CONVERTERS = List .of (DateTimeOffsetToOffsetDateTimeConverter .INSTANCE , DateTimeOffsetToInstantConverter .INSTANCE );
57
+ } else {
58
+ SIMPLE_TYPES = Set .of ();
59
+ CONVERTERS = List .of ();
60
+ }
61
+ }
45
62
46
63
@ Override
47
64
public Set <Class <?>> simpleTypes () {
@@ -52,8 +69,7 @@ public Set<Class<?>> simpleTypes() {
52
69
public Collection <Object > getConverters () {
53
70
54
71
List <Object > converters = new ArrayList <>(super .getConverters ());
55
- converters .add (DateTimeOffsetToOffsetDateTimeConverter .INSTANCE );
56
- converters .add (DateTimeOffsetToInstantConverter .INSTANCE );
72
+ converters .addAll (CONVERTERS );
57
73
return converters ;
58
74
}
59
75
0 commit comments