Deprecate redundant getReference(IdentifierProcessing) method.

Closes #1110
Original pull request #1458
This commit is contained in:
Kurt Niemi
2023-03-20 18:27:02 -04:00
committed by Jens Schauder
parent e4ec418386
commit 18eda61f15
17 changed files with 37 additions and 26 deletions

View File

@@ -79,7 +79,7 @@ class IdGeneratingBatchInsertStrategy implements BatchInsertStrategy {
Map<String, Object> keys = keyList.get(i);
if (keys.size() > 1) {
if (idColumn != null) {
ids[i] = keys.get(idColumn.getReference(dialect.getIdentifierProcessing()));
ids[i] = keys.get(idColumn.getReference());
}
} else {
ids[i] = keys.entrySet().stream().findFirst() //
@@ -93,7 +93,7 @@ class IdGeneratingBatchInsertStrategy implements BatchInsertStrategy {
private String[] getKeyColumnNames() {
return Optional.ofNullable(idColumn)
.map(idColumn -> new String[] { idColumn.getReference(dialect.getIdentifierProcessing()) })
.map(idColumn -> new String[] { idColumn.getReference() })
.orElse(new String[0]);
}
}

View File

@@ -79,13 +79,13 @@ class IdGeneratingInsertStrategy implements InsertStrategy {
return null;
}
return keys.get(idColumn.getReference(dialect.getIdentifierProcessing()));
return keys.get(idColumn.getReference());
}
}
private String[] getKeyColumnNames() {
return Optional.ofNullable(idColumn)
.map(idColumn -> new String[] { idColumn.getReference(dialect.getIdentifierProcessing()) })
.map(idColumn -> new String[] { idColumn.getReference() })
.orElse(new String[0]);
}
}

View File

@@ -50,7 +50,7 @@ class JdbcBackReferencePropertyValueProvider implements PropertyValueProvider<Re
@Override
public <T> T getPropertyValue(RelationalPersistentProperty property) {
return (T) resultSet
.getObject(basePath.extendBy(property).getReverseColumnNameAlias().getReference(identifierProcessing));
.getObject(basePath.extendBy(property).getReverseColumnNameAlias().getReference());
}
public JdbcBackReferencePropertyValueProvider extendBy(RelationalPersistentProperty property) {

View File

@@ -62,7 +62,7 @@ class JdbcPropertyValueProvider implements PropertyValueProvider<RelationalPersi
}
private String getColumnName(RelationalPersistentProperty property) {
return basePath.extendBy(property).getColumnAlias().getReference(identifierProcessing);
return basePath.extendBy(property).getColumnAlias().getReference();
}
public JdbcPropertyValueProvider extendBy(RelationalPersistentProperty property) {

View File

@@ -53,7 +53,7 @@ class MapEntityRowMapper<T> implements RowMapper<Map.Entry<Object, T>> {
@Override
public Map.Entry<Object, T> mapRow(ResultSet rs, int rowNum) throws SQLException {
Object key = rs.getObject(keyColumn.getReference(identifierProcessing));
Object key = rs.getObject(keyColumn.getReference());
return new HashMap.SimpleEntry<>(key, mapEntity(rs, key));
}

View File

@@ -772,7 +772,7 @@ class SqlGenerator {
}
private String renderReference(SqlIdentifier identifier) {
return identifier.getReference(renderContext.getIdentifierProcessing());
return identifier.getReference();
}
private List<OrderByField> extractOrderByFields(Sort sort) {

View File

@@ -68,7 +68,7 @@ class SqlIdentifierParameterSource extends AbstractSqlParameterSource {
void addValue(SqlIdentifier identifier, Object value, int sqlType) {
identifiers.add(identifier);
String name = BindParameterNameSanitizer.sanitize(identifier.getReference(identifierProcessing));
String name = BindParameterNameSanitizer.sanitize(identifier.getReference());
namesToValues.put(name, value);
registerSqlType(name, sqlType);
}
@@ -77,7 +77,7 @@ class SqlIdentifierParameterSource extends AbstractSqlParameterSource {
for (SqlIdentifier identifier : others.getIdentifiers()) {
String name = identifier.getReference(identifierProcessing);
String name = identifier.getReference();
addValue(identifier, others.getValue(name), others.getSqlType(name));
}
}

View File

@@ -47,7 +47,7 @@ public class H2Dialect extends org.springframework.data.relational.core.dialect.
@Override
public String renderForGeneratedValues(SqlIdentifier identifier) {
return identifier.getReference(getIdentifierProcessing());
return identifier.getReference();
}
@Override

View File

@@ -95,7 +95,7 @@ public class MySqlDialect extends org.springframework.data.relational.core.diale
@Override
public String renderForGeneratedValues(SqlIdentifier identifier) {
return identifier.getReference(getIdentifierProcessing());
return identifier.getReference();
}
/**

View File

@@ -65,8 +65,9 @@ class DerivedSqlIdentifier implements SqlIdentifier {
}
@Override
@Deprecated(since="3.1", forRemoval = true)
public String getReference(IdentifierProcessing processing) {
return this.name;
return toSql(processing);
}
@Override

View File

@@ -84,7 +84,7 @@ public interface NamingStrategy {
Assert.notNull(property, "Property must not be null");
return property.getOwner().getTableName().getReference(IdentifierProcessing.NONE);
return property.getOwner().getTableName().getReference();
}
default String getReverseColumnName(PersistentPropertyPathExtension path) {

View File

@@ -482,7 +482,7 @@ public class PersistentPropertyPathExtension {
SqlIdentifier tableAlias = getTableAlias();
return tableAlias == null ? columnName
: columnName.transform(name -> tableAlias.getReference(IdentifierProcessing.NONE) + "_" + name);
: columnName.transform(name -> tableAlias.getReference() + "_" + name);
}
@Override

View File

@@ -66,6 +66,7 @@ class CompositeSqlIdentifier implements SqlIdentifier {
}
@Override
@Deprecated(since="3.1", forRemoval = true)
public String getReference(IdentifierProcessing processing) {
throw new UnsupportedOperationException("Composite SQL Identifiers can't be used for reference name retrieval");
}

View File

@@ -57,12 +57,13 @@ class DefaultSqlIdentifier implements SqlIdentifier {
@Override
public String toSql(IdentifierProcessing processing) {
return quoted ? processing.quote(getReference(processing)) : getReference(processing);
return quoted ? processing.quote(name) : name;
}
@Override
@Deprecated(since="3.1", forRemoval = true)
public String getReference(IdentifierProcessing processing) {
return name;
return toSql(processing);
}
@Override

View File

@@ -26,7 +26,7 @@ import org.springframework.data.util.Streamable;
* from a {@link String name} with specifying whether the name should be quoted or unquoted.
* <p>
* {@link SqlIdentifier} renders its name using {@link IdentifierProcessing} rules. Use
* {@link #getReference(IdentifierProcessing)} to refer to an object using the identifier when e.g. obtaining values
* {@link #getReference()} to refer to an object using the identifier when e.g. obtaining values
* from a result or providing values for a prepared statement. {@link #toSql(IdentifierProcessing)} renders the
* identifier for SQL statement usage.
* <p>
@@ -39,6 +39,7 @@ import org.springframework.data.util.Streamable;
*
* @author Jens Schauder
* @author Mark Paluch
* @author Kurt Niemi
* @since 2.0
*/
public interface SqlIdentifier extends Streamable<SqlIdentifier> {
@@ -79,23 +80,26 @@ public interface SqlIdentifier extends Streamable<SqlIdentifier> {
*
* @param processing identifier processing rules.
* @return
* @deprecated since 3.1, use the #getReference() method instead.
*/
@Deprecated(since="3.1", forRemoval = true)
String getReference(IdentifierProcessing processing);
/**
* Return the reference name without any further transformation. The reference name is used for programmatic access to
* the object identified by this {@link SqlIdentifier}.
* Use this method whenever accessing a column in a ResultSet and we do not want any quoting applied. The
* reference name is used for programmatic access to the object identified by this {@link SqlIdentifier}.
*
* @return
* @see IdentifierProcessing#NONE
*/
default String getReference() {
return getReference(IdentifierProcessing.NONE);
return toSql(IdentifierProcessing.NONE);
}
/**
* Return the identifier for SQL usage after applying {@link IdentifierProcessing} rules. The identifier name is used
* to construct SQL statements.
* Use this method when rendering an identifier in SQL statements as in:
* <pre><code>select yourColumn from someTable</code></pre>
* {@link IdentifierProcessing} rules are applied to the identifier.
*
* @param processing identifier processing rules.
* @return

View File

@@ -41,7 +41,8 @@ public class DerivedSqlIdentifierUnitTests {
SqlIdentifier identifier = new DerivedSqlIdentifier("someName", true);
assertThat(identifier.toSql(BRACKETS_LOWER_CASE)).isEqualTo("[somename]");
assertThat(identifier.getReference(BRACKETS_LOWER_CASE)).isEqualTo("someName");
assertThat(identifier.getReference(BRACKETS_LOWER_CASE)).isEqualTo("[somename]");
assertThat(identifier.getReference()).isEqualTo("someName");
}
@@ -52,7 +53,8 @@ public class DerivedSqlIdentifierUnitTests {
String sql = identifier.toSql(BRACKETS_LOWER_CASE);
assertThat(sql).isEqualTo("somename");
assertThat(identifier.getReference(BRACKETS_LOWER_CASE)).isEqualTo("someName");
assertThat(identifier.getReference(BRACKETS_LOWER_CASE)).isEqualTo("somename");
assertThat(identifier.getReference()).isEqualTo("someName");
}
@Test // DATAJDBC-386

View File

@@ -40,7 +40,8 @@ public class SqlIdentifierUnitTests {
SqlIdentifier identifier = quoted("someName");
assertThat(identifier.toSql(BRACKETS_LOWER_CASE)).isEqualTo("[someName]");
assertThat(identifier.getReference(BRACKETS_LOWER_CASE)).isEqualTo("someName");
assertThat(identifier.getReference(BRACKETS_LOWER_CASE)).isEqualTo("[someName]");
assertThat(identifier.getReference()).isEqualTo("someName");
}
@Test // DATAJDBC-386
@@ -51,6 +52,7 @@ public class SqlIdentifierUnitTests {
assertThat(sql).isEqualTo("someName");
assertThat(identifier.getReference(BRACKETS_LOWER_CASE)).isEqualTo("someName");
assertThat(identifier.getReference()).isEqualTo("someName");
}
@Test // DATAJDBC-386