Introduced new JDBC dialect counterparts.

Signed-off-by: mipo256 <mikhailpolivakha@gmail.com>

Commit message edited by Jens Schauder

Original pull request #2036
Closes #2031
This commit is contained in:
mipo256
2025-04-20 16:05:52 +03:00
committed by Jens Schauder
parent 58a3f01ccd
commit 7698d487ba
30 changed files with 281 additions and 88 deletions

View File

@@ -22,6 +22,7 @@ import static org.mockito.Mockito.*;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.data.annotation.Id;
import org.springframework.data.jdbc.core.dialect.JdbcHsqlDbDialect;
import org.springframework.data.jdbc.core.mapping.JdbcMappingContext;
import org.springframework.data.relational.core.conversion.IdValueSource;
import org.springframework.data.relational.core.dialect.Dialect;
@@ -58,7 +59,7 @@ class DefaultDataAccessStrategyUnitTests {
void before() {
DelegatingDataAccessStrategy relationResolver = new DelegatingDataAccessStrategy();
Dialect dialect = HsqlDbDialect.INSTANCE;
Dialect dialect = JdbcHsqlDbDialect.INSTANCE;
converter = new MappingJdbcConverter(context, relationResolver, new JdbcCustomConversions(),
new DefaultJdbcTypeFactory(jdbcOperations));
accessStrategy = new DataAccessStrategyFactory( //

View File

@@ -15,10 +15,11 @@
*/
package org.springframework.data.jdbc.core.convert;
import static org.assertj.core.api.Assertions.*;
import static org.mockito.ArgumentMatchers.*;
import static org.mockito.Mockito.*;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import java.util.UUID;
@@ -27,12 +28,11 @@ import org.junit.jupiter.api.Test;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoSettings;
import org.mockito.quality.Strictness;
import org.springframework.data.annotation.Id;
import org.springframework.data.jdbc.core.dialect.JdbcMySqlDialect;
import org.springframework.data.jdbc.core.dialect.JdbcPostgresDialect;
import org.springframework.data.mapping.model.SimpleTypeHolder;
import org.springframework.data.relational.core.conversion.MutableAggregateChange;
import org.springframework.data.relational.core.dialect.MySqlDialect;
import org.springframework.data.relational.core.dialect.PostgresDialect;
import org.springframework.data.relational.core.mapping.RelationalMappingContext;
import org.springframework.data.relational.core.mapping.Sequence;
import org.springframework.data.relational.core.mapping.Table;
@@ -56,7 +56,7 @@ class IdGeneratingEntityCallbackTest {
void setUp() {
relationalMappingContext = new RelationalMappingContext();
relationalMappingContext.setSimpleTypeHolder(new SimpleTypeHolder(PostgresDialect.INSTANCE.simpleTypes(), true));
relationalMappingContext.setSimpleTypeHolder(new SimpleTypeHolder(JdbcPostgresDialect.INSTANCE.simpleTypes(), true));
}
@Test // GH-1923
@@ -65,7 +65,7 @@ class IdGeneratingEntityCallbackTest {
NamedParameterJdbcOperations operations = mock(NamedParameterJdbcOperations.class);
IdGeneratingEntityCallback subject = new IdGeneratingEntityCallback(relationalMappingContext,
MySqlDialect.INSTANCE, operations);
JdbcMySqlDialect.INSTANCE, operations);
EntityWithSequence processed = (EntityWithSequence) subject.onBeforeSave(new EntityWithSequence(),
MutableAggregateChange.forSave(new EntityWithSequence()));
@@ -77,7 +77,7 @@ class IdGeneratingEntityCallbackTest {
void entityIsNotMarkedWithTargetSequence() {
IdGeneratingEntityCallback subject = new IdGeneratingEntityCallback(relationalMappingContext,
MySqlDialect.INSTANCE, operations);
JdbcMySqlDialect.INSTANCE, operations);
NoSequenceEntity processed = (NoSequenceEntity) subject.onBeforeSave(new NoSequenceEntity(),
MutableAggregateChange.forSave(new NoSequenceEntity()));
@@ -93,7 +93,7 @@ class IdGeneratingEntityCallbackTest {
.thenReturn(generatedId);
IdGeneratingEntityCallback subject = new IdGeneratingEntityCallback(relationalMappingContext,
PostgresDialect.INSTANCE, operations);
JdbcPostgresDialect.INSTANCE, operations);
EntityWithSequence processed = (EntityWithSequence) subject.onBeforeSave(new EntityWithSequence(),
MutableAggregateChange.forSave(new EntityWithSequence()));
@@ -109,7 +109,7 @@ class IdGeneratingEntityCallbackTest {
.thenReturn(generatedId);
IdGeneratingEntityCallback subject = new IdGeneratingEntityCallback(relationalMappingContext,
PostgresDialect.INSTANCE, operations);
JdbcPostgresDialect.INSTANCE, operations);
EntityWithIntSequence processed = (EntityWithIntSequence) subject.onBeforeSave(new EntityWithIntSequence(),
MutableAggregateChange.forSave(new EntityWithIntSequence()));
@@ -125,7 +125,7 @@ class IdGeneratingEntityCallbackTest {
.thenReturn(generatedId);
IdGeneratingEntityCallback subject = new IdGeneratingEntityCallback(relationalMappingContext,
PostgresDialect.INSTANCE, operations);
JdbcPostgresDialect.INSTANCE, operations);
EntityWithUuidSequence processed = (EntityWithUuidSequence) subject.onBeforeSave(new EntityWithUuidSequence(),
MutableAggregateChange.forSave(new EntityWithUuidSequence()));

View File

@@ -15,6 +15,7 @@
*/
package org.springframework.data.jdbc.core.convert;
import org.springframework.data.jdbc.core.dialect.JdbcHsqlDbDialect;
import org.springframework.data.relational.core.dialect.AbstractDialect;
import org.springframework.data.relational.core.dialect.Dialect;
import org.springframework.data.relational.core.dialect.HsqlDbDialect;
@@ -38,12 +39,12 @@ public class NonQuotingDialect extends AbstractDialect implements Dialect {
@Override
public LimitClause limit() {
return HsqlDbDialect.INSTANCE.limit();
return JdbcHsqlDbDialect.INSTANCE.limit();
}
@Override
public LockClause lock() {
return HsqlDbDialect.INSTANCE.lock();
return JdbcHsqlDbDialect.INSTANCE.lock();
}
@Override

View File

@@ -15,11 +15,17 @@
*/
package org.springframework.data.jdbc.core.convert;
import static java.util.Collections.*;
import static org.assertj.core.api.Assertions.*;
import static org.assertj.core.api.SoftAssertions.*;
import static org.springframework.data.relational.core.mapping.ForeignKeyNaming.*;
import static org.springframework.data.relational.core.sql.SqlIdentifier.*;
import static java.util.Collections.emptySet;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.assertj.core.api.Assertions.entry;
import static org.assertj.core.api.SoftAssertions.assertSoftly;
import static org.springframework.data.relational.core.mapping.ForeignKeyNaming.APPLY_RENAMING;
import static org.springframework.data.relational.core.mapping.ForeignKeyNaming.IGNORE_RENAMING;
import static org.springframework.data.relational.core.sql.SqlIdentifier.EMPTY;
import static org.springframework.data.relational.core.sql.SqlIdentifier.quoted;
import static org.springframework.data.relational.core.sql.SqlIdentifier.unquoted;
import java.util.Map;
import java.util.Set;
@@ -33,13 +39,13 @@ import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.jdbc.core.PersistentPropertyPathTestUtils;
import org.springframework.data.jdbc.core.dialect.JdbcPostgresDialect;
import org.springframework.data.jdbc.core.dialect.JdbcSqlServerDialect;
import org.springframework.data.jdbc.core.mapping.AggregateReference;
import org.springframework.data.jdbc.core.mapping.JdbcMappingContext;
import org.springframework.data.mapping.PersistentPropertyPath;
import org.springframework.data.relational.core.dialect.AnsiDialect;
import org.springframework.data.relational.core.dialect.Dialect;
import org.springframework.data.relational.core.dialect.PostgresDialect;
import org.springframework.data.relational.core.dialect.SqlServerDialect;
import org.springframework.data.relational.core.mapping.AggregatePath;
import org.springframework.data.relational.core.mapping.Column;
import org.springframework.data.relational.core.mapping.DefaultNamingStrategy;
@@ -274,7 +280,7 @@ class SqlGeneratorUnitTests {
@Test // GH-821
void findAllSortedWithNullHandling_resolvesNullHandlingWhenDialectSupportsIt() {
SqlGenerator sqlGenerator = createSqlGenerator(DummyEntity.class, PostgresDialect.INSTANCE);
SqlGenerator sqlGenerator = createSqlGenerator(DummyEntity.class, JdbcPostgresDialect.INSTANCE);
String sql = sqlGenerator
.getFindAll(Sort.by(new Sort.Order(Sort.Direction.ASC, "name", Sort.NullHandling.NULLS_LAST)));
@@ -285,7 +291,7 @@ class SqlGeneratorUnitTests {
@Test // GH-821
void findAllSortedWithNullHandling_ignoresNullHandlingWhenDialectDoesNotSupportIt() {
SqlGenerator sqlGenerator = createSqlGenerator(DummyEntity.class, SqlServerDialect.INSTANCE);
SqlGenerator sqlGenerator = createSqlGenerator(DummyEntity.class, JdbcSqlServerDialect.INSTANCE);
String sql = sqlGenerator
.getFindAll(Sort.by(new Sort.Order(Sort.Direction.ASC, "name", Sort.NullHandling.NULLS_LAST)));
@@ -512,7 +518,7 @@ class SqlGeneratorUnitTests {
@Test // DATAJDBC-264
void getInsertForEmptyColumnListPostgres() {
SqlGenerator sqlGenerator = createSqlGenerator(IdOnlyEntity.class, PostgresDialect.INSTANCE);
SqlGenerator sqlGenerator = createSqlGenerator(IdOnlyEntity.class, JdbcPostgresDialect.INSTANCE);
String insert = sqlGenerator.getInsert(emptySet());
@@ -522,7 +528,7 @@ class SqlGeneratorUnitTests {
@Test // GH-777
void gerInsertForEmptyColumnListMsSqlServer() {
SqlGenerator sqlGenerator = createSqlGenerator(IdOnlyEntity.class, SqlServerDialect.INSTANCE);
SqlGenerator sqlGenerator = createSqlGenerator(IdOnlyEntity.class, JdbcSqlServerDialect.INSTANCE);
String insert = sqlGenerator.getInsert(emptySet());

View File

@@ -15,9 +15,7 @@
*/
package org.springframework.data.jdbc.mybatis;
import static org.assertj.core.api.Assertions.*;
import junit.framework.AssertionFailedError;
import static org.assertj.core.api.Assertions.assertThat;
import org.apache.ibatis.session.Configuration;
import org.apache.ibatis.session.SqlSession;
@@ -31,18 +29,20 @@ import org.springframework.context.annotation.Import;
import org.springframework.context.annotation.Primary;
import org.springframework.data.jdbc.core.convert.DataAccessStrategy;
import org.springframework.data.jdbc.core.convert.JdbcConverter;
import org.springframework.data.jdbc.core.dialect.JdbcHsqlDbDialect;
import org.springframework.data.jdbc.repository.config.EnableJdbcRepositories;
import org.springframework.data.jdbc.testing.DatabaseType;
import org.springframework.data.jdbc.testing.EnabledOnDatabase;
import org.springframework.data.jdbc.testing.IntegrationTest;
import org.springframework.data.jdbc.testing.TestClass;
import org.springframework.data.jdbc.testing.TestConfiguration;
import org.springframework.data.relational.core.dialect.HsqlDbDialect;
import org.springframework.data.relational.core.mapping.RelationalMappingContext;
import org.springframework.data.repository.CrudRepository;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabase;
import junit.framework.AssertionFailedError;
/**
* Tests the integration with Mybatis.
*
@@ -119,7 +119,7 @@ public class MyBatisHsqlIntegrationTests {
SqlSession sqlSession, EmbeddedDatabase db) {
return MyBatisDataAccessStrategy.createCombinedAccessStrategy(context, converter,
new NamedParameterJdbcTemplate(db), sqlSession, HsqlDbDialect.INSTANCE);
new NamedParameterJdbcTemplate(db), sqlSession, JdbcHsqlDbDialect.INSTANCE);
}
}
}

View File

@@ -16,8 +16,11 @@
package org.springframework.data.jdbc.repository;
import static org.assertj.core.api.Assertions.*;
import static org.mockito.Mockito.*;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
import static org.mockito.Mockito.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import org.jetbrains.annotations.NotNull;
import org.junit.jupiter.api.Test;
@@ -30,11 +33,11 @@ import org.springframework.data.jdbc.core.convert.DelegatingDataAccessStrategy;
import org.springframework.data.jdbc.core.convert.JdbcConverter;
import org.springframework.data.jdbc.core.convert.JdbcCustomConversions;
import org.springframework.data.jdbc.core.convert.MappingJdbcConverter;
import org.springframework.data.jdbc.core.dialect.JdbcHsqlDbDialect;
import org.springframework.data.jdbc.core.mapping.JdbcMappingContext;
import org.springframework.data.jdbc.repository.query.Query;
import org.springframework.data.jdbc.repository.support.JdbcRepositoryFactory;
import org.springframework.data.relational.core.dialect.Dialect;
import org.springframework.data.relational.core.dialect.HsqlDbDialect;
import org.springframework.data.relational.core.mapping.RelationalMappingContext;
import org.springframework.data.relational.core.mapping.Table;
import org.springframework.data.repository.CrudRepository;
@@ -93,7 +96,7 @@ public class DeclaredQueryRepositoryUnitTests {
private @NotNull <T extends CrudRepository> T repository(Class<T> repositoryInterface) {
Dialect dialect = HsqlDbDialect.INSTANCE;
Dialect dialect = JdbcHsqlDbDialect.INSTANCE;
RelationalMappingContext context = new JdbcMappingContext();

View File

@@ -15,11 +15,16 @@
*/
package org.springframework.data.jdbc.repository;
import static java.util.Arrays.*;
import static org.assertj.core.api.Assertions.*;
import static java.util.Arrays.asList;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.groups.Tuple.tuple;
import static org.mockito.ArgumentMatchers.*;
import static org.mockito.Mockito.*;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.when;
import java.util.ArrayList;
import java.util.HashMap;
@@ -33,13 +38,21 @@ import org.springframework.data.annotation.Id;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.jdbc.core.convert.*;
import org.springframework.data.jdbc.core.convert.DefaultDataAccessStrategy;
import org.springframework.data.jdbc.core.convert.DefaultJdbcTypeFactory;
import org.springframework.data.jdbc.core.convert.DelegatingDataAccessStrategy;
import org.springframework.data.jdbc.core.convert.InsertStrategyFactory;
import org.springframework.data.jdbc.core.convert.JdbcConverter;
import org.springframework.data.jdbc.core.convert.JdbcCustomConversions;
import org.springframework.data.jdbc.core.convert.MappingJdbcConverter;
import org.springframework.data.jdbc.core.convert.SqlGeneratorSource;
import org.springframework.data.jdbc.core.convert.SqlParametersFactory;
import org.springframework.data.jdbc.core.dialect.JdbcH2Dialect;
import org.springframework.data.jdbc.core.dialect.JdbcHsqlDbDialect;
import org.springframework.data.jdbc.core.mapping.JdbcMappingContext;
import org.springframework.data.jdbc.repository.support.JdbcRepositoryFactory;
import org.springframework.data.jdbc.repository.support.SimpleJdbcRepository;
import org.springframework.data.relational.core.dialect.Dialect;
import org.springframework.data.relational.core.dialect.H2Dialect;
import org.springframework.data.relational.core.dialect.HsqlDbDialect;
import org.springframework.data.relational.core.mapping.RelationalMappingContext;
import org.springframework.data.relational.core.mapping.event.AfterConvertEvent;
import org.springframework.data.relational.core.mapping.event.AfterDeleteEvent;
@@ -86,7 +99,7 @@ class SimpleJdbcRepositoryEventsUnitTests {
RelationalMappingContext context = new JdbcMappingContext();
NamedParameterJdbcOperations operations = createIdGeneratingOperations();
Dialect dialect = HsqlDbDialect.INSTANCE;
Dialect dialect = JdbcHsqlDbDialect.INSTANCE;
DelegatingDataAccessStrategy delegatingDataAccessStrategy = new DelegatingDataAccessStrategy();
JdbcConverter converter = new MappingJdbcConverter(context, delegatingDataAccessStrategy,
new JdbcCustomConversions(), new DefaultJdbcTypeFactory(operations.getJdbcOperations()));
@@ -100,7 +113,7 @@ class SimpleJdbcRepositoryEventsUnitTests {
doReturn(true).when(dataAccessStrategy).update(any(), any());
JdbcRepositoryFactory factory = new JdbcRepositoryFactory(dataAccessStrategy, context, converter,
H2Dialect.INSTANCE, publisher, operations);
JdbcH2Dialect.INSTANCE, publisher, operations);
this.repository = factory.getRepository(DummyEntityRepository.class);
}

View File

@@ -26,6 +26,7 @@ import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.jdbc.core.convert.CascadingDataAccessStrategy;
import org.springframework.data.jdbc.core.convert.DataAccessStrategy;
import org.springframework.data.jdbc.core.dialect.JdbcHsqlDbDialect;
import org.springframework.data.jdbc.mybatis.MyBatisDataAccessStrategy;
import org.springframework.data.relational.core.dialect.Dialect;
import org.springframework.data.relational.core.dialect.HsqlDbDialect;
@@ -70,7 +71,7 @@ public class MyBatisJdbcConfigurationIntegrationTests extends AbstractJdbcConfig
@Override
@Bean
public Dialect jdbcDialect(NamedParameterJdbcOperations operations) {
return HsqlDbDialect.INSTANCE;
return JdbcHsqlDbDialect.INSTANCE;
}
}
}

View File

@@ -33,6 +33,7 @@ import org.springframework.data.annotation.Id;
import org.springframework.data.jdbc.core.convert.JdbcConverter;
import org.springframework.data.jdbc.core.convert.MappingJdbcConverter;
import org.springframework.data.jdbc.core.convert.RelationResolver;
import org.springframework.data.jdbc.core.dialect.JdbcH2Dialect;
import org.springframework.data.jdbc.core.mapping.AggregateReference;
import org.springframework.data.jdbc.core.mapping.JdbcMappingContext;
import org.springframework.data.projection.SpelAwareProxyProjectionFactory;
@@ -669,7 +670,7 @@ public class PartTreeJdbcQueryUnitTests {
}
private PartTreeJdbcQuery createQuery(JdbcQueryMethod queryMethod) {
return new PartTreeJdbcQuery(mappingContext, queryMethod, H2Dialect.INSTANCE, converter,
return new PartTreeJdbcQuery(mappingContext, queryMethod, JdbcH2Dialect.INSTANCE, converter,
mock(NamedParameterJdbcOperations.class), mock(RowMapper.class));
}

View File

@@ -30,6 +30,7 @@ import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.data.jdbc.core.convert.JdbcConverter;
import org.springframework.data.jdbc.core.dialect.JdbcH2Dialect;
import org.springframework.data.jdbc.repository.QueryMappingConfiguration;
import org.springframework.data.jdbc.repository.config.DefaultQueryMappingConfiguration;
import org.springframework.data.jdbc.repository.query.Query;
@@ -138,7 +139,7 @@ class JdbcQueryLookupStrategyUnitTests {
.registerRowMapper(NumberFormat.class, numberFormatMapper);
QueryLookupStrategy queryLookupStrategy = JdbcQueryLookupStrategy.create(key, publisher, callbacks, mappingContext,
converter, H2Dialect.INSTANCE, mappingConfiguration, operations, null, ValueExpressionDelegate.create());
converter, JdbcH2Dialect.INSTANCE, mappingConfiguration, operations, null, ValueExpressionDelegate.create());
assertThat(queryLookupStrategy).isInstanceOf(expectedClass);
}
@@ -158,7 +159,7 @@ class JdbcQueryLookupStrategyUnitTests {
QueryMappingConfiguration mappingConfiguration) {
QueryLookupStrategy queryLookupStrategy = JdbcQueryLookupStrategy.create(key, publisher, callbacks, mappingContext,
converter, H2Dialect.INSTANCE, mappingConfiguration, operations, null, ValueExpressionDelegate.create());
converter, JdbcH2Dialect.INSTANCE, mappingConfiguration, operations, null, ValueExpressionDelegate.create());
Method method = ReflectionUtils.findMethod(MyRepository.class, name);
return queryLookupStrategy.resolveQuery(method, metadata, projectionFactory, namedQueries);