Skip to content

Commit 034539d

Browse files
committed
spring-projectsGH-2031 Introduced new JDBC dialect counterparts
1 parent 1f2e694 commit 034539d

29 files changed

+255
-76
lines changed

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
* @author Christoph Strobl
3434
* @since 2.3
3535
*/
36-
public class JdbcDb2Dialect extends Db2Dialect {
36+
public class JdbcDb2Dialect extends Db2Dialect implements JdbcDialect {
3737

3838
public static JdbcDb2Dialect INSTANCE = new JdbcDb2Dialect();
3939

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

+3-2
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ public interface JdbcDialect extends Dialect {
3333
* @return the JDBC specific array support object that describes how array-typed columns are supported by this
3434
* dialect.
3535
*/
36-
@Override
37-
JdbcArrayColumns getArraySupport();
36+
default JdbcArrayColumns getArraySupport() {
37+
return JdbcArrayColumns.Unsupported.INSTANCE;
38+
}
3839
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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+
17+
package org.springframework.data.jdbc.core.dialect;
18+
19+
import org.springframework.data.relational.core.dialect.H2Dialect;
20+
21+
/**
22+
* JDBC specific H2 Dialect.
23+
*
24+
* @author Mikhail Polivakha
25+
*/
26+
public class JdbcH2Dialect extends H2Dialect implements JdbcDialect {
27+
28+
public static JdbcH2Dialect INSTANCE = new JdbcH2Dialect();
29+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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+
17+
package org.springframework.data.jdbc.core.dialect;
18+
19+
import org.springframework.data.relational.core.dialect.HsqlDbDialect;
20+
21+
public class JdbcHsqlDbDialect extends HsqlDbDialect implements JdbcDialect {
22+
23+
public static JdbcHsqlDbDialect INSTANCE = new JdbcHsqlDbDialect();
24+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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+
17+
package org.springframework.data.jdbc.core.dialect;
18+
19+
import org.springframework.data.relational.core.dialect.MariaDbDialect;
20+
import org.springframework.data.relational.core.sql.IdentifierProcessing;
21+
22+
/**
23+
* JDBC specific MariaDb Dialect.
24+
*
25+
* @author Mikhail Polivakha
26+
*/
27+
public class JdbcMariaDdDialect extends MariaDbDialect implements JdbcDialect {
28+
29+
public JdbcMariaDdDialect(IdentifierProcessing identifierProcessing) {
30+
super(identifierProcessing);
31+
}
32+
}

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

+3-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,9 @@
4040
* @author Christoph Strobl
4141
* @since 2.3
4242
*/
43-
public class JdbcMySqlDialect extends MySqlDialect {
43+
public class JdbcMySqlDialect extends MySqlDialect implements JdbcDialect {
44+
45+
public static JdbcMySqlDialect INSTANCE = new JdbcMySqlDialect();
4446

4547
public JdbcMySqlDialect(IdentifierProcessing identifierProcessing) {
4648
super(identifierProcessing);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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+
17+
package org.springframework.data.jdbc.core.dialect;
18+
19+
import org.springframework.data.relational.core.dialect.OracleDialect;
20+
21+
/**
22+
* JDBC specific Oracle Dialect.
23+
*
24+
* @author Mikhail Polivakha
25+
*/
26+
public class JdbcOracleDialect extends OracleDialect implements JdbcDialect {
27+
28+
public static JdbcOracleDialect INSTANCE = new JdbcOracleDialect();
29+
}

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
* @author Mikhail Polivakha
3636
* @since 2.3
3737
*/
38-
public class JdbcSqlServerDialect extends SqlServerDialect {
38+
public class JdbcSqlServerDialect extends SqlServerDialect implements JdbcDialect {
3939

4040
public static JdbcSqlServerDialect INSTANCE = new JdbcSqlServerDialect();
4141

spring-data-jdbc/src/main/java/org/springframework/data/jdbc/repository/config/DialectResolver.java

+10-5
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,12 @@
2929
import org.springframework.core.io.support.SpringFactoriesLoader;
3030
import org.springframework.dao.NonTransientDataAccessException;
3131
import org.springframework.data.jdbc.core.dialect.JdbcDb2Dialect;
32+
import org.springframework.data.jdbc.core.dialect.JdbcDialect;
33+
import org.springframework.data.jdbc.core.dialect.JdbcH2Dialect;
34+
import org.springframework.data.jdbc.core.dialect.JdbcHsqlDbDialect;
35+
import org.springframework.data.jdbc.core.dialect.JdbcMariaDdDialect;
3236
import org.springframework.data.jdbc.core.dialect.JdbcMySqlDialect;
37+
import org.springframework.data.jdbc.core.dialect.JdbcOracleDialect;
3338
import org.springframework.data.jdbc.core.dialect.JdbcPostgresDialect;
3439
import org.springframework.data.jdbc.core.dialect.JdbcSqlServerDialect;
3540
import org.springframework.data.relational.core.dialect.Dialect;
@@ -109,23 +114,23 @@ public Optional<Dialect> getDialect(JdbcOperations operations) {
109114
}
110115

111116
@Nullable
112-
private static Dialect getDialect(Connection connection) throws SQLException {
117+
private static JdbcDialect getDialect(Connection connection) throws SQLException {
113118

114119
DatabaseMetaData metaData = connection.getMetaData();
115120

116121
String name = metaData.getDatabaseProductName().toLowerCase(Locale.ENGLISH);
117122

118123
if (name.contains("hsql")) {
119-
return HsqlDbDialect.INSTANCE;
124+
return JdbcHsqlDbDialect.INSTANCE;
120125
}
121126
if (name.contains("h2")) {
122-
return H2Dialect.INSTANCE;
127+
return JdbcH2Dialect.INSTANCE;
123128
}
124129
if (name.contains("mysql")) {
125130
return new JdbcMySqlDialect(getIdentifierProcessing(metaData));
126131
}
127132
if (name.contains("mariadb")) {
128-
return new MariaDbDialect(getIdentifierProcessing(metaData));
133+
return new JdbcMariaDdDialect(getIdentifierProcessing(metaData));
129134
}
130135
if (name.contains("postgresql")) {
131136
return JdbcPostgresDialect.INSTANCE;
@@ -137,7 +142,7 @@ private static Dialect getDialect(Connection connection) throws SQLException {
137142
return JdbcDb2Dialect.INSTANCE;
138143
}
139144
if (name.contains("oracle")) {
140-
return OracleDialect.INSTANCE;
145+
return JdbcOracleDialect.INSTANCE;
141146
}
142147

143148
LOG.info(String.format("Couldn't determine Dialect for \"%s\"", name));

spring-data-jdbc/src/test/java/org/springframework/data/jdbc/core/convert/DefaultDataAccessStrategyUnitTests.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import org.junit.jupiter.api.BeforeEach;
2323
import org.junit.jupiter.api.Test;
2424
import org.springframework.data.annotation.Id;
25+
import org.springframework.data.jdbc.core.dialect.JdbcHsqlDbDialect;
2526
import org.springframework.data.jdbc.core.mapping.JdbcMappingContext;
2627
import org.springframework.data.relational.core.conversion.IdValueSource;
2728
import org.springframework.data.relational.core.dialect.Dialect;
@@ -58,7 +59,7 @@ class DefaultDataAccessStrategyUnitTests {
5859
void before() {
5960

6061
DelegatingDataAccessStrategy relationResolver = new DelegatingDataAccessStrategy();
61-
Dialect dialect = HsqlDbDialect.INSTANCE;
62+
Dialect dialect = JdbcHsqlDbDialect.INSTANCE;
6263
converter = new MappingJdbcConverter(context, relationResolver, new JdbcCustomConversions(),
6364
new DefaultJdbcTypeFactory(jdbcOperations));
6465
accessStrategy = new DataAccessStrategyFactory( //

spring-data-jdbc/src/test/java/org/springframework/data/jdbc/core/convert/IdGeneratingEntityCallbackTest.java

+12-12
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,11 @@
1515
*/
1616
package org.springframework.data.jdbc.core.convert;
1717

18-
import static org.assertj.core.api.Assertions.*;
19-
import static org.mockito.ArgumentMatchers.*;
20-
import static org.mockito.Mockito.*;
18+
import static org.assertj.core.api.Assertions.assertThat;
19+
import static org.mockito.ArgumentMatchers.anyString;
2120
import static org.mockito.Mockito.any;
21+
import static org.mockito.Mockito.mock;
22+
import static org.mockito.Mockito.when;
2223

2324
import java.util.UUID;
2425

@@ -27,12 +28,11 @@
2728
import org.mockito.Mock;
2829
import org.mockito.junit.jupiter.MockitoSettings;
2930
import org.mockito.quality.Strictness;
30-
3131
import org.springframework.data.annotation.Id;
32+
import org.springframework.data.jdbc.core.dialect.JdbcMySqlDialect;
33+
import org.springframework.data.jdbc.core.dialect.JdbcPostgresDialect;
3234
import org.springframework.data.mapping.model.SimpleTypeHolder;
3335
import org.springframework.data.relational.core.conversion.MutableAggregateChange;
34-
import org.springframework.data.relational.core.dialect.MySqlDialect;
35-
import org.springframework.data.relational.core.dialect.PostgresDialect;
3636
import org.springframework.data.relational.core.mapping.RelationalMappingContext;
3737
import org.springframework.data.relational.core.mapping.Sequence;
3838
import org.springframework.data.relational.core.mapping.Table;
@@ -56,7 +56,7 @@ class IdGeneratingEntityCallbackTest {
5656
void setUp() {
5757

5858
relationalMappingContext = new RelationalMappingContext();
59-
relationalMappingContext.setSimpleTypeHolder(new SimpleTypeHolder(PostgresDialect.INSTANCE.simpleTypes(), true));
59+
relationalMappingContext.setSimpleTypeHolder(new SimpleTypeHolder(JdbcPostgresDialect.INSTANCE.simpleTypes(), true));
6060
}
6161

6262
@Test // GH-1923
@@ -65,7 +65,7 @@ void sequenceGenerationIsNotSupported() {
6565
NamedParameterJdbcOperations operations = mock(NamedParameterJdbcOperations.class);
6666

6767
IdGeneratingEntityCallback subject = new IdGeneratingEntityCallback(relationalMappingContext,
68-
MySqlDialect.INSTANCE, operations);
68+
JdbcMySqlDialect.INSTANCE, operations);
6969

7070
EntityWithSequence processed = (EntityWithSequence) subject.onBeforeSave(new EntityWithSequence(),
7171
MutableAggregateChange.forSave(new EntityWithSequence()));
@@ -77,7 +77,7 @@ void sequenceGenerationIsNotSupported() {
7777
void entityIsNotMarkedWithTargetSequence() {
7878

7979
IdGeneratingEntityCallback subject = new IdGeneratingEntityCallback(relationalMappingContext,
80-
MySqlDialect.INSTANCE, operations);
80+
JdbcMySqlDialect.INSTANCE, operations);
8181

8282
NoSequenceEntity processed = (NoSequenceEntity) subject.onBeforeSave(new NoSequenceEntity(),
8383
MutableAggregateChange.forSave(new NoSequenceEntity()));
@@ -93,7 +93,7 @@ void entityIdIsPopulatedFromSequence() {
9393
.thenReturn(generatedId);
9494

9595
IdGeneratingEntityCallback subject = new IdGeneratingEntityCallback(relationalMappingContext,
96-
PostgresDialect.INSTANCE, operations);
96+
JdbcPostgresDialect.INSTANCE, operations);
9797

9898
EntityWithSequence processed = (EntityWithSequence) subject.onBeforeSave(new EntityWithSequence(),
9999
MutableAggregateChange.forSave(new EntityWithSequence()));
@@ -109,7 +109,7 @@ void appliesIntegerConversion() {
109109
.thenReturn(generatedId);
110110

111111
IdGeneratingEntityCallback subject = new IdGeneratingEntityCallback(relationalMappingContext,
112-
PostgresDialect.INSTANCE, operations);
112+
JdbcPostgresDialect.INSTANCE, operations);
113113

114114
EntityWithIntSequence processed = (EntityWithIntSequence) subject.onBeforeSave(new EntityWithIntSequence(),
115115
MutableAggregateChange.forSave(new EntityWithIntSequence()));
@@ -125,7 +125,7 @@ void assignsUuidValues() {
125125
.thenReturn(generatedId);
126126

127127
IdGeneratingEntityCallback subject = new IdGeneratingEntityCallback(relationalMappingContext,
128-
PostgresDialect.INSTANCE, operations);
128+
JdbcPostgresDialect.INSTANCE, operations);
129129

130130
EntityWithUuidSequence processed = (EntityWithUuidSequence) subject.onBeforeSave(new EntityWithUuidSequence(),
131131
MutableAggregateChange.forSave(new EntityWithUuidSequence()));

spring-data-jdbc/src/test/java/org/springframework/data/jdbc/core/convert/NonQuotingDialect.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616
package org.springframework.data.jdbc.core.convert;
1717

18+
import org.springframework.data.jdbc.core.dialect.JdbcHsqlDbDialect;
1819
import org.springframework.data.relational.core.dialect.AbstractDialect;
1920
import org.springframework.data.relational.core.dialect.Dialect;
2021
import org.springframework.data.relational.core.dialect.HsqlDbDialect;
@@ -38,12 +39,12 @@ private NonQuotingDialect() {}
3839

3940
@Override
4041
public LimitClause limit() {
41-
return HsqlDbDialect.INSTANCE.limit();
42+
return JdbcHsqlDbDialect.INSTANCE.limit();
4243
}
4344

4445
@Override
4546
public LockClause lock() {
46-
return HsqlDbDialect.INSTANCE.lock();
47+
return JdbcHsqlDbDialect.INSTANCE.lock();
4748
}
4849

4950
@Override

0 commit comments

Comments
 (0)