Browse Source

Deprecate JdbcMySqlDialect.INSTANCE and MySqlDialect.MYSQL_IDENTIFIER_PROCESSING.

MySql does not have a fixed Identifierprocessing, therefore predefined instances doesn't make sense.

Closes #2060
See https://dev.mysql.com/doc/refman/8.4/en/identifier-case-sensitivity.html
pull/2070/head
Jens Schauder 6 months ago
parent
commit
243c060bd8
No known key found for this signature in database
GPG Key ID: 2BE5D185CD2A1CE6
  1. 12
      spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/dialect/JdbcMySqlDialect.java
  2. 11
      spring-data-jdbc/src/test/java/org/springframework/data/jdbc/core/convert/IdGeneratingEntityCallbackTest.java
  3. 18
      spring-data-relational/src/main/java/org/springframework/data/relational/core/dialect/MySqlDialect.java

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

@ -42,7 +42,17 @@ import org.springframework.lang.NonNull;
*/ */
public class JdbcMySqlDialect extends MySqlDialect implements JdbcDialect { public class JdbcMySqlDialect extends MySqlDialect implements JdbcDialect {
public static final JdbcMySqlDialect INSTANCE = new JdbcMySqlDialect(); /**
* Predefined instance of the {@literal JdbcMySqlDialect}.
*
* @deprecated Use the constructor instead. There is no one correct MySqlDialect, since the behaviour of MySql depends
* on various configuration options. See
*
* <pre>
* <a href="https://dev.mysql.com/doc/refman/8.4/en/identifier-case-sensitivity.html">Identifier Case Sensitivity</a>
* </pre>
*/
@Deprecated(forRemoval = true, since = "4.0") public static final JdbcMySqlDialect INSTANCE = new JdbcMySqlDialect();
public JdbcMySqlDialect(IdentifierProcessing identifierProcessing) { public JdbcMySqlDialect(IdentifierProcessing identifierProcessing) {
super(identifierProcessing); super(identifierProcessing);

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

@ -35,6 +35,7 @@ import org.springframework.data.relational.core.conversion.MutableAggregateChang
import org.springframework.data.relational.core.mapping.RelationalMappingContext; import org.springframework.data.relational.core.mapping.RelationalMappingContext;
import org.springframework.data.relational.core.mapping.Sequence; import org.springframework.data.relational.core.mapping.Sequence;
import org.springframework.data.relational.core.mapping.Table; import org.springframework.data.relational.core.mapping.Table;
import org.springframework.data.relational.core.sql.IdentifierProcessing;
import org.springframework.jdbc.core.RowMapper; import org.springframework.jdbc.core.RowMapper;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcOperations; import org.springframework.jdbc.core.namedparam.NamedParameterJdbcOperations;
import org.springframework.jdbc.core.namedparam.SqlParameterSource; import org.springframework.jdbc.core.namedparam.SqlParameterSource;
@ -50,6 +51,8 @@ class IdGeneratingEntityCallbackTest {
@Mock NamedParameterJdbcOperations operations; @Mock NamedParameterJdbcOperations operations;
RelationalMappingContext relationalMappingContext; RelationalMappingContext relationalMappingContext;
private JdbcMySqlDialect mySqlDialect = new JdbcMySqlDialect(
IdentifierProcessing.create(new IdentifierProcessing.Quoting("`"), IdentifierProcessing.LetterCasing.LOWER_CASE));
@BeforeEach @BeforeEach
void setUp() { void setUp() {
@ -64,8 +67,8 @@ class IdGeneratingEntityCallbackTest {
NamedParameterJdbcOperations operations = mock(NamedParameterJdbcOperations.class); NamedParameterJdbcOperations operations = mock(NamedParameterJdbcOperations.class);
IdGeneratingEntityCallback subject = new IdGeneratingEntityCallback(relationalMappingContext, IdGeneratingEntityCallback subject = new IdGeneratingEntityCallback(relationalMappingContext, mySqlDialect,
JdbcMySqlDialect.INSTANCE, operations); operations);
EntityWithSequence processed = (EntityWithSequence) subject.onBeforeSave(new EntityWithSequence(), EntityWithSequence processed = (EntityWithSequence) subject.onBeforeSave(new EntityWithSequence(),
MutableAggregateChange.forSave(new EntityWithSequence())); MutableAggregateChange.forSave(new EntityWithSequence()));
@ -76,8 +79,8 @@ class IdGeneratingEntityCallbackTest {
@Test // GH-1923 @Test // GH-1923
void entityIsNotMarkedWithTargetSequence() { void entityIsNotMarkedWithTargetSequence() {
IdGeneratingEntityCallback subject = new IdGeneratingEntityCallback(relationalMappingContext, IdGeneratingEntityCallback subject = new IdGeneratingEntityCallback(relationalMappingContext, mySqlDialect,
JdbcMySqlDialect.INSTANCE, operations); operations);
NoSequenceEntity processed = (NoSequenceEntity) subject.onBeforeSave(new NoSequenceEntity(), NoSequenceEntity processed = (NoSequenceEntity) subject.onBeforeSave(new NoSequenceEntity(),
MutableAggregateChange.forSave(new NoSequenceEntity())); MutableAggregateChange.forSave(new NoSequenceEntity()));

18
spring-data-relational/src/main/java/org/springframework/data/relational/core/dialect/MySqlDialect.java

@ -37,18 +37,26 @@ public class MySqlDialect extends AbstractDialect {
/** /**
* MySQL defaults for {@link IdentifierProcessing}. * MySQL defaults for {@link IdentifierProcessing}.
*
* @deprecated Construct your own {@link IdentifierProcessing}. There is no one standard identifier processing for
* MySql.See
*
* <pre>
* <a href=
"https://dev.mysql.com/doc/refman/8.4/en/identifier-case-sensitivity.html">Identifier Case Sensitivity</a>
* </pre>
*/ */
public static final IdentifierProcessing MYSQL_IDENTIFIER_PROCESSING = IdentifierProcessing.create(new Quoting("`"), @Deprecated(forRemoval = true,
LetterCasing.LOWER_CASE); since = "4.0") public static final IdentifierProcessing MYSQL_IDENTIFIER_PROCESSING = IdentifierProcessing
.create(new Quoting("`"), LetterCasing.LOWER_CASE);
/** /**
* Singleton instance. * Singleton instance.
* *
* @deprecated use either the {@code org.springframework.data.r2dbc.dialect.MySqlDialect} or * @deprecated use either the {@code org.springframework.data.r2dbc.dialect.MySqlDialect} or
* {@code org.springframework.data.jdbc.core.dialect.JdbcMySqlDialect} * {@code org.springframework.data.jdbc.core.dialect.JdbcMySqlDialect}
*/ */
@Deprecated(forRemoval = true) @Deprecated(forRemoval = true) public static final MySqlDialect INSTANCE = new MySqlDialect();
public static final MySqlDialect INSTANCE = new MySqlDialect();
private final IdentifierProcessing identifierProcessing; private final IdentifierProcessing identifierProcessing;

Loading…
Cancel
Save