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. 16
      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; @@ -42,7 +42,17 @@ import org.springframework.lang.NonNull;
*/
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) {
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 @@ -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.Sequence;
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.namedparam.NamedParameterJdbcOperations;
import org.springframework.jdbc.core.namedparam.SqlParameterSource;
@ -50,6 +51,8 @@ class IdGeneratingEntityCallbackTest { @@ -50,6 +51,8 @@ class IdGeneratingEntityCallbackTest {
@Mock NamedParameterJdbcOperations operations;
RelationalMappingContext relationalMappingContext;
private JdbcMySqlDialect mySqlDialect = new JdbcMySqlDialect(
IdentifierProcessing.create(new IdentifierProcessing.Quoting("`"), IdentifierProcessing.LetterCasing.LOWER_CASE));
@BeforeEach
void setUp() {
@ -64,8 +67,8 @@ class IdGeneratingEntityCallbackTest { @@ -64,8 +67,8 @@ class IdGeneratingEntityCallbackTest {
NamedParameterJdbcOperations operations = mock(NamedParameterJdbcOperations.class);
IdGeneratingEntityCallback subject = new IdGeneratingEntityCallback(relationalMappingContext,
JdbcMySqlDialect.INSTANCE, operations);
IdGeneratingEntityCallback subject = new IdGeneratingEntityCallback(relationalMappingContext, mySqlDialect,
operations);
EntityWithSequence processed = (EntityWithSequence) subject.onBeforeSave(new EntityWithSequence(),
MutableAggregateChange.forSave(new EntityWithSequence()));
@ -76,8 +79,8 @@ class IdGeneratingEntityCallbackTest { @@ -76,8 +79,8 @@ class IdGeneratingEntityCallbackTest {
@Test // GH-1923
void entityIsNotMarkedWithTargetSequence() {
IdGeneratingEntityCallback subject = new IdGeneratingEntityCallback(relationalMappingContext,
JdbcMySqlDialect.INSTANCE, operations);
IdGeneratingEntityCallback subject = new IdGeneratingEntityCallback(relationalMappingContext, mySqlDialect,
operations);
NoSequenceEntity processed = (NoSequenceEntity) subject.onBeforeSave(new NoSequenceEntity(),
MutableAggregateChange.forSave(new NoSequenceEntity()));

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

@ -37,9 +37,18 @@ public class MySqlDialect extends AbstractDialect { @@ -37,9 +37,18 @@ public class MySqlDialect extends AbstractDialect {
/**
* 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("`"),
LetterCasing.LOWER_CASE);
@Deprecated(forRemoval = true,
since = "4.0") public static final IdentifierProcessing MYSQL_IDENTIFIER_PROCESSING = IdentifierProcessing
.create(new Quoting("`"), LetterCasing.LOWER_CASE);
/**
* Singleton instance.
@ -47,8 +56,7 @@ public class MySqlDialect extends AbstractDialect { @@ -47,8 +56,7 @@ public class MySqlDialect extends AbstractDialect {
* @deprecated use either the {@code org.springframework.data.r2dbc.dialect.MySqlDialect} or
* {@code org.springframework.data.jdbc.core.dialect.JdbcMySqlDialect}
*/
@Deprecated(forRemoval = true)
public static final MySqlDialect INSTANCE = new MySqlDialect();
@Deprecated(forRemoval = true) public static final MySqlDialect INSTANCE = new MySqlDialect();
private final IdentifierProcessing identifierProcessing;

Loading…
Cancel
Save