Remove deprecated code.

Original pull request #1869
This commit is contained in:
Jens Schauder
2024-08-29 14:02:01 +02:00
parent c8b9697c51
commit 848ffee253
38 changed files with 11 additions and 1589 deletions

View File

@@ -265,22 +265,6 @@ public interface JdbcAggregateOperations {
*/
<T> void delete(T aggregateRoot);
/**
* Delete an aggregate identified by its aggregate root.
*
* @param aggregateRoot to delete. Must not be {@code null}.
* @param domainType the type of the aggregate root. Must not be {@code null}.
* @param <T> the type of the aggregate root.
* @throws org.springframework.dao.OptimisticLockingFailureException when {@literal T} has a version attribute and the
* version attribute of the provided entity does not match the version attribute in the database, or when
* there is no aggregate root with matching id. In other cases a NOOP delete is silently ignored.
* @deprecated since 3.0 use {@link #delete(Object)} instead
*/
@Deprecated(since = "3.0")
default <T> void delete(T aggregateRoot, Class<T> domainType) {
delete(aggregateRoot);
}
/**
* Delete all aggregates of a given type.
*
@@ -295,21 +279,4 @@ public interface JdbcAggregateOperations {
* @param <T> the type of the aggregate roots.
*/
<T> void deleteAll(Iterable<? extends T> aggregateRoots);
/**
* Delete all aggregates identified by their aggregate roots.
*
* @param aggregateRoots to delete. Must not be {@code null}.
* @param domainType type of the aggregate roots to be deleted. Must not be {@code null}.
* @param <T> the type of the aggregate roots.
* @throws org.springframework.dao.OptimisticLockingFailureException when {@literal T} has a version attribute and for
* at least on entity the version attribute of the entity does not match the version attribute in the
* database, or when there is no aggregate root with matching id. In other cases a NOOP delete is silently
* ignored.
* @deprecated since 3.0 use {@link #deleteAll(Iterable)} instead.
*/
@Deprecated(since = "3.0")
default <T> void deleteAll(Iterable<? extends T> aggregateRoots, Class<T> domainType) {
deleteAll(aggregateRoots);
}
}

View File

@@ -1,77 +0,0 @@
/*
* Copyright 2023-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.jdbc.core.convert;
import org.springframework.data.convert.CustomConversions;
import org.springframework.data.mapping.context.MappingContext;
import org.springframework.data.relational.core.conversion.RelationalConverter;
import org.springframework.data.relational.core.mapping.RelationalMappingContext;
import org.springframework.data.relational.core.sql.IdentifierProcessing;
/**
* {@link RelationalConverter} that uses a {@link MappingContext} to apply conversion of relational values to property
* values.
* <p>
* Conversion is configurable by providing a customized {@link CustomConversions}.
*
* @author Mark Paluch
* @since 1.1
* @deprecated since 3.2, use {@link MappingJdbcConverter} instead as the naming suggests a limited scope of
* functionality.
*/
@Deprecated(since = "3.2")
public class BasicJdbcConverter extends MappingJdbcConverter {
/**
* Creates a new {@link BasicJdbcConverter} given {@link MappingContext} and a {@link JdbcTypeFactory#unsupported()
* no-op type factory} throwing {@link UnsupportedOperationException} on type creation. Use
* {@link #BasicJdbcConverter(RelationalMappingContext, RelationResolver, CustomConversions, JdbcTypeFactory, IdentifierProcessing)}
* (MappingContext, RelationResolver, JdbcTypeFactory)} to convert arrays and large objects into JDBC-specific types.
*
* @param context must not be {@literal null}.
* @param relationResolver used to fetch additional relations from the database. Must not be {@literal null}.
*/
public BasicJdbcConverter(RelationalMappingContext context, RelationResolver relationResolver) {
super(context, relationResolver);
}
/**
* Creates a new {@link BasicJdbcConverter} given {@link MappingContext}.
*
* @param context must not be {@literal null}.
* @param relationResolver used to fetch additional relations from the database. Must not be {@literal null}.
* @param typeFactory must not be {@literal null}
* @since 3.2
*/
public BasicJdbcConverter(RelationalMappingContext context, RelationResolver relationResolver,
CustomConversions conversions, JdbcTypeFactory typeFactory) {
super(context, relationResolver, conversions, typeFactory);
}
/**
* Creates a new {@link BasicJdbcConverter} given {@link MappingContext}.
*
* @param context must not be {@literal null}.
* @param relationResolver used to fetch additional relations from the database. Must not be {@literal null}.
* @param typeFactory must not be {@literal null}
* @param identifierProcessing must not be {@literal null}
* @since 2.0
*/
public BasicJdbcConverter(RelationalMappingContext context, RelationResolver relationResolver,
CustomConversions conversions, JdbcTypeFactory typeFactory, IdentifierProcessing identifierProcessing) {
super(context, relationResolver, conversions, typeFactory);
}
}

View File

@@ -1,79 +0,0 @@
/*
* Copyright 2022-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.jdbc.core.convert;
import org.springframework.jdbc.core.JdbcOperations;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcOperations;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import org.springframework.jdbc.core.namedparam.SqlParameterSource;
import org.springframework.jdbc.support.KeyHolder;
import org.springframework.lang.Nullable;
/**
* Counterpart to {@link org.springframework.jdbc.core.namedparam.NamedParameterJdbcOperations} containing methods for
* performing batch updates with generated keys.
*
* @author Chirag Tailor
* @author Mark Paluch
* @since 2.4
* @deprecated since 3.2. Use {@link org.springframework.jdbc.core.namedparam.NamedParameterJdbcOperations#batchUpdate}
* methods instead.
*/
@Deprecated(since = "3.2")
public class BatchJdbcOperations {
private final NamedParameterJdbcOperations jdbcOperations;
public BatchJdbcOperations(JdbcOperations jdbcOperations) {
this.jdbcOperations = new NamedParameterJdbcTemplate(jdbcOperations);
}
/**
* Execute a batch using the supplied SQL statement with the batch of supplied arguments, returning generated keys.
*
* @param sql the SQL statement to execute
* @param batchArgs the array of {@link SqlParameterSource} containing the batch of arguments for the query
* @param generatedKeyHolder a {@link KeyHolder} that will hold the generated keys
* @return an array containing the numbers of rows affected by each update in the batch (may also contain special
* JDBC-defined negative values for affected rows such as
* {@link java.sql.Statement#SUCCESS_NO_INFO}/{@link java.sql.Statement#EXECUTE_FAILED})
* @throws org.springframework.dao.DataAccessException if there is any problem issuing the update
* @see org.springframework.jdbc.support.GeneratedKeyHolder
* @since 2.4
*/
int[] batchUpdate(String sql, SqlParameterSource[] batchArgs, KeyHolder generatedKeyHolder) {
return jdbcOperations.batchUpdate(sql, batchArgs, generatedKeyHolder);
}
/**
* Execute a batch using the supplied SQL statement with the batch of supplied arguments, returning generated keys.
*
* @param sql the SQL statement to execute
* @param batchArgs the array of {@link SqlParameterSource} containing the batch of arguments for the query
* @param generatedKeyHolder a {@link KeyHolder} that will hold the generated keys
* @param keyColumnNames names of the columns that will have keys generated for them
* @return an array containing the numbers of rows affected by each update in the batch (may also contain special
* JDBC-defined negative values for affected rows such as
* {@link java.sql.Statement#SUCCESS_NO_INFO}/{@link java.sql.Statement#EXECUTE_FAILED})
* @throws org.springframework.dao.DataAccessException if there is any problem issuing the update
* @see org.springframework.jdbc.support.GeneratedKeyHolder
* @since 2.4
*/
int[] batchUpdate(String sql, SqlParameterSource[] batchArgs, KeyHolder generatedKeyHolder,
@Nullable String[] keyColumnNames) {
return jdbcOperations.batchUpdate(sql, batchArgs, generatedKeyHolder, keyColumnNames);
}
}

View File

@@ -19,7 +19,6 @@ import java.sql.ResultSet;
import java.sql.SQLException;
import org.springframework.data.relational.core.mapping.AggregatePath;
import org.springframework.data.relational.core.mapping.PersistentPropertyPathExtension;
import org.springframework.data.relational.core.mapping.RelationalPersistentEntity;
import org.springframework.data.relational.domain.RowDocument;
import org.springframework.jdbc.core.RowMapper;
@@ -43,19 +42,6 @@ public class EntityRowMapper<T> implements RowMapper<T> {
private final JdbcConverter converter;
private final @Nullable Identifier identifier;
/**
* @deprecated use {@link EntityRowMapper#EntityRowMapper(AggregatePath, JdbcConverter, Identifier)} instead
*/
@Deprecated(since = "3.2", forRemoval = true)
@SuppressWarnings("unchecked")
public EntityRowMapper(PersistentPropertyPathExtension path, JdbcConverter converter, Identifier identifier) {
this.entity = (RelationalPersistentEntity<T>) path.getLeafEntity();
this.path = path.getAggregatePath();
this.converter = converter;
this.identifier = identifier;
}
@SuppressWarnings("unchecked")
public EntityRowMapper(AggregatePath path, JdbcConverter converter, Identifier identifier) {

View File

@@ -41,18 +41,6 @@ public class InsertStrategyFactory {
this.dialect = dialect;
}
/**
* Constructor with additional {@link BatchJdbcOperations} constructor.
*
* @deprecated since 3.2, use
* {@link InsertStrategyFactory#InsertStrategyFactory(NamedParameterJdbcOperations, Dialect)} instead.
*/
@Deprecated(since = "3.2")
public InsertStrategyFactory(NamedParameterJdbcOperations namedParameterJdbcOperations,
BatchJdbcOperations batchJdbcOperations, Dialect dialect) {
this(namedParameterJdbcOperations, dialect);
}
/**
* @param idValueSource the {@link IdValueSource} for the insert.
* @param idColumn the identifier for the id, if an id is expected to be generated. May be {@code null}.

View File

@@ -15,15 +15,11 @@
*/
package org.springframework.data.jdbc.core.convert;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.SQLType;
import org.springframework.data.jdbc.core.mapping.JdbcValue;
import org.springframework.data.relational.core.conversion.RelationalConverter;
import org.springframework.data.relational.core.mapping.PersistentPropertyPathExtension;
import org.springframework.data.relational.core.mapping.RelationalMappingContext;
import org.springframework.data.relational.core.mapping.RelationalPersistentEntity;
import org.springframework.data.relational.core.mapping.RelationalPersistentProperty;
import org.springframework.data.relational.domain.RowDocument;
import org.springframework.data.util.TypeInformation;
@@ -65,48 +61,6 @@ public interface JdbcConverter extends RelationalConverter {
*/
JdbcValue writeJdbcValue(@Nullable Object value, TypeInformation<?> type, SQLType sqlType);
/**
* Read the current row from {@link ResultSet} to an {@link RelationalPersistentEntity#getType() entity}.
*
* @param entity the persistent entity type.
* @param resultSet the {@link ResultSet} to read from.
* @param key primary key.
* @param <T>
* @return
* @deprecated since 3.2, use {@link #readAndResolve(Class, RowDocument, Identifier)} instead.
*/
@Deprecated(since = "3.2")
default <T> T mapRow(RelationalPersistentEntity<T> entity, ResultSet resultSet, Object key) {
try {
return readAndResolve(entity.getType(), RowDocumentResultSetExtractor.toRowDocument(resultSet));
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
/**
* Read the current row from {@link ResultSet} to an {@link PersistentPropertyPathExtension#getActualType() entity}.
*
* @param path path to the owning property.
* @param resultSet the {@link ResultSet} to read from.
* @param identifier entity identifier.
* @param key primary key.
* @param <T>
* @return
* @deprecated use {@link #readAndResolve(Class, RowDocument, Identifier)} instead.
*/
@SuppressWarnings("unchecked")
@Deprecated(since = "3.2", forRemoval = true)
default <T> T mapRow(PersistentPropertyPathExtension path, ResultSet resultSet, Identifier identifier, Object key) {
try {
return (T) readAndResolve(path.getRequiredLeafEntity().getTypeInformation(),
RowDocumentResultSetExtractor.toRowDocument(resultSet), identifier);
} catch (SQLException e) {
throw new RuntimeException(e);
}
};
/**
* Read a {@link RowDocument} into the requested {@link Class aggregate type} and resolve references by looking these
* up from {@link RelationResolver}.

View File

@@ -16,7 +16,6 @@
package org.springframework.data.jdbc.core.convert;
import org.springframework.data.relational.core.mapping.AggregatePath;
import org.springframework.data.relational.core.mapping.PersistentPropertyPathExtension;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
@@ -38,17 +37,6 @@ public class JdbcIdentifierBuilder {
return new JdbcIdentifierBuilder(Identifier.empty());
}
/**
* Creates ParentKeys with backreference for the given path and value of the parents id.
*
* @deprecated Use {@link #forBackReferences(JdbcConverter, AggregatePath, Object)} instead.
*/
@Deprecated(since = "3.2", forRemoval = true)
public static JdbcIdentifierBuilder forBackReferences(JdbcConverter converter, PersistentPropertyPathExtension path,
@Nullable Object value) {
return forBackReferences(converter, path.getAggregatePath(), value);
}
/**
* Creates ParentKeys with backreference for the given path and value of the parents id.
*/
@@ -64,20 +52,6 @@ public class JdbcIdentifierBuilder {
return new JdbcIdentifierBuilder(identifier);
}
/**
* Adds a qualifier to the identifier to build. A qualifier is a map key or a list index.
*
* @param path path to the map that gets qualified by {@code value}. Must not be {@literal null}.
* @param value map key or list index qualifying the map identified by {@code path}. Must not be {@literal null}.
* @return this builder. Guaranteed to be not {@literal null}.
*/
@Deprecated
public JdbcIdentifierBuilder withQualifier(PersistentPropertyPathExtension path, Object value) {
return withQualifier(path.getAggregatePath(), value);
}
/**
* Adds a qualifier to the identifier to build. A qualifier is a map key or a list index.
*
@@ -90,7 +64,8 @@ public class JdbcIdentifierBuilder {
Assert.notNull(path, "Path must not be null");
Assert.notNull(value, "Value must not be null");
identifier = identifier.withPart(path.getTableInfo().qualifierColumnInfo().name(), value, path.getTableInfo().qualifierColumnType());
identifier = identifier.withPart(path.getTableInfo().qualifierColumnInfo().name(), value,
path.getTableInfo().qualifierColumnType());
return this;
}

View File

@@ -61,23 +61,6 @@ public class QueryMapper {
private final JdbcConverter converter;
private final MappingContext<? extends RelationalPersistentEntity<?>, RelationalPersistentProperty> mappingContext;
/**
* Creates a new {@link QueryMapper} with the given {@link JdbcConverter}.
*
* @param dialect must not be {@literal null}.
* @param converter must not be {@literal null}.
* @deprecated use {@link QueryMapper(JdbcConverter)} instead.
*/
@Deprecated(since="3.2")
public QueryMapper(Dialect dialect, JdbcConverter converter) {
Assert.notNull(dialect, "Dialect must not be null");
Assert.notNull(converter, "JdbcConverter must not be null");
this.converter = converter;
this.mappingContext = converter.getMappingContext();
}
/**
* Creates a new {@link QueryMapper} with the given {@link JdbcConverter}.
*

View File

@@ -47,15 +47,7 @@ import org.springframework.util.Assert;
public class SqlParametersFactory {
private final RelationalMappingContext context;
private final JdbcConverter converter;
/**
* @deprecated use {@link SqlParametersFactory(RelationalMappingContext, JdbcConverter)} instead.
*/
@Deprecated(since = "3.1", forRemoval = true)
public SqlParametersFactory(RelationalMappingContext context, JdbcConverter converter, Dialect dialect) {
this(context, converter);
}
/**
* @since 3.1
*/

View File

@@ -36,9 +36,7 @@ import org.springframework.data.relational.core.dialect.Dialect;
import org.springframework.data.relational.core.mapping.RelationalMappingContext;
import org.springframework.data.relational.core.mapping.RelationalPersistentProperty;
import org.springframework.data.relational.core.query.Query;
import org.springframework.data.relational.core.sql.IdentifierProcessing;
import org.springframework.data.relational.core.sql.LockMode;
import org.springframework.data.relational.core.sql.SqlIdentifier;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcOperations;
import org.springframework.util.Assert;
@@ -102,8 +100,7 @@ public class MyBatisDataAccessStrategy implements DataAccessStrategy {
// the DefaultDataAccessStrategy needs a reference to the returned DataAccessStrategy. This creates a dependency
// cycle. In order to create it, we need something that allows to defer closing the cycle until all the elements are
// created. That is the purpose of the DelegatingAccessStrategy.
MyBatisDataAccessStrategy myBatisDataAccessStrategy = new MyBatisDataAccessStrategy(sqlSession,
dialect.getIdentifierProcessing());
MyBatisDataAccessStrategy myBatisDataAccessStrategy = new MyBatisDataAccessStrategy(sqlSession);
myBatisDataAccessStrategy.setNamespaceStrategy(namespaceStrategy);
return new CascadingDataAccessStrategy(
@@ -120,15 +117,6 @@ public class MyBatisDataAccessStrategy implements DataAccessStrategy {
* to create such a {@link DataAccessStrategy}.
*
* @param sqlSession Must be non {@literal null}.
* @deprecated because identifierProcessing now will not be considered in the process of applying it to
* {@link SqlIdentifier}, use {@link MyBatisDataAccessStrategy(SqlSession)} constructor instead
*/
@Deprecated(since = "3.1", forRemoval = true)
public MyBatisDataAccessStrategy(SqlSession sqlSession, IdentifierProcessing identifierProcessing) {
this(sqlSession);
}
/**
* @since 3.1
*/
public MyBatisDataAccessStrategy(SqlSession sqlSession) {

View File

@@ -72,23 +72,6 @@ public abstract class AbstractJdbcQuery implements RepositoryQuery {
return queryMethod;
}
/**
* Creates a {@link JdbcQueryExecution} given a {@link JdbcQueryMethod}, and ac{@link ResultSetExtractor} or a
* {@link RowMapper}. Prefers the given {@link ResultSetExtractor} over {@link RowMapper}.
*
* @param queryMethod must not be {@literal null}.
* @param extractor must not be {@literal null}.
* @param rowMapper must not be {@literal null}.
* @return a JdbcQueryExecution appropriate for {@literal queryMethod}. Guaranteed to be not {@literal null}.
* @deprecated use {@link #createReadingQueryExecution(ResultSetExtractor, RowMapper)} instead.
*/
@Deprecated(since = "3.1", forRemoval = true)
// a better name would be createReadingQueryExecution
JdbcQueryExecution<?> getQueryExecution(JdbcQueryMethod queryMethod,
@Nullable ResultSetExtractor<?> extractor, RowMapper<?> rowMapper) {
return createReadingQueryExecution(extractor, () -> rowMapper);
}
/**
* Creates a {@link JdbcQueryExecution} given a {@link ResultSetExtractor} or a {@link RowMapper}. Prefers the given
* {@link ResultSetExtractor} over {@link RowMapper}.

View File

@@ -1,290 +0,0 @@
/*
* Copyright 2019-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.jdbc.core;
import static org.assertj.core.api.Assertions.*;
import static org.assertj.core.api.SoftAssertions.*;
import static org.springframework.data.relational.core.sql.SqlIdentifier.*;
import java.util.List;
import org.junit.jupiter.api.Test;
import org.springframework.data.annotation.Id;
import org.springframework.data.annotation.ReadOnlyProperty;
import org.springframework.data.jdbc.core.mapping.JdbcMappingContext;
import org.springframework.data.mapping.PersistentPropertyPath;
import org.springframework.data.relational.core.mapping.Embedded;
import org.springframework.data.relational.core.mapping.Embedded.OnEmpty;
import org.springframework.data.relational.core.mapping.PersistentPropertyPathExtension;
import org.springframework.data.relational.core.mapping.RelationalPersistentEntity;
import org.springframework.data.relational.core.mapping.RelationalPersistentProperty;
/**
* @author Jens Schauder
* @author Daniil Razorenov
*/
public class PersistentPropertyPathExtensionUnitTests {
JdbcMappingContext context = new JdbcMappingContext();
private RelationalPersistentEntity<?> entity = context.getRequiredPersistentEntity(DummyEntity.class);
@Test // DATAJDBC-340
void isEmbedded() {
assertSoftly(softly -> {
softly.assertThat(extPath(entity).isEmbedded()).isFalse();
softly.assertThat(extPath("second").isEmbedded()).isFalse();
softly.assertThat(extPath("second.third2").isEmbedded()).isTrue();
});
}
@Test // DATAJDBC-340
void isMultiValued() {
assertSoftly(softly -> {
softly.assertThat(extPath(entity).isMultiValued()).isFalse();
softly.assertThat(extPath("second").isMultiValued()).isFalse();
softly.assertThat(extPath("second.third2").isMultiValued()).isFalse();
softly.assertThat(extPath("secondList.third2").isMultiValued()).isTrue();
softly.assertThat(extPath("secondList").isMultiValued()).isTrue();
});
}
@Test // DATAJDBC-340
void leafEntity() {
RelationalPersistentEntity<?> second = context.getRequiredPersistentEntity(Second.class);
RelationalPersistentEntity<?> third = context.getRequiredPersistentEntity(Third.class);
assertSoftly(softly -> {
softly.assertThat(extPath(entity).getLeafEntity()).isEqualTo(entity);
softly.assertThat(extPath("second").getLeafEntity()).isEqualTo(second);
softly.assertThat(extPath("second.third2").getLeafEntity()).isEqualTo(third);
softly.assertThat(extPath("secondList.third2").getLeafEntity()).isEqualTo(third);
softly.assertThat(extPath("secondList").getLeafEntity()).isEqualTo(second);
});
}
@Test // DATAJDBC-340
void isEntity() {
assertSoftly(softly -> {
softly.assertThat(extPath(entity).isEntity()).isTrue();
String path = "second";
softly.assertThat(extPath(path).isEntity()).isTrue();
softly.assertThat(extPath("second.third2").isEntity()).isTrue();
softly.assertThat(extPath("second.third2.value").isEntity()).isFalse();
softly.assertThat(extPath("secondList.third2").isEntity()).isTrue();
softly.assertThat(extPath("secondList.third2.value").isEntity()).isFalse();
softly.assertThat(extPath("secondList").isEntity()).isTrue();
});
}
@Test // DATAJDBC-340
void getTableName() {
assertSoftly(softly -> {
softly.assertThat(extPath(entity).getQualifiedTableName()).isEqualTo(quoted("DUMMY_ENTITY"));
softly.assertThat(extPath("second").getQualifiedTableName()).isEqualTo(quoted("SECOND"));
softly.assertThat(extPath("second.third2").getQualifiedTableName()).isEqualTo(quoted("SECOND"));
softly.assertThat(extPath("second.third2.value").getQualifiedTableName()).isEqualTo(quoted("SECOND"));
softly.assertThat(extPath("secondList.third2").getQualifiedTableName()).isEqualTo(quoted("SECOND"));
softly.assertThat(extPath("secondList.third2.value").getQualifiedTableName()).isEqualTo(quoted("SECOND"));
softly.assertThat(extPath("secondList").getQualifiedTableName()).isEqualTo(quoted("SECOND"));
});
}
@Test // DATAJDBC-340
void getTableAlias() {
assertSoftly(softly -> {
softly.assertThat(extPath(entity).getTableAlias()).isEqualTo(null);
softly.assertThat(extPath("second").getTableAlias()).isEqualTo(quoted("second"));
softly.assertThat(extPath("second.third2").getTableAlias()).isEqualTo(quoted("second"));
softly.assertThat(extPath("second.third2.value").getTableAlias()).isEqualTo(quoted("second"));
softly.assertThat(extPath("second.third").getTableAlias()).isEqualTo(quoted("second_third"));
softly.assertThat(extPath("second.third.value").getTableAlias()).isEqualTo(quoted("second_third"));
softly.assertThat(extPath("secondList.third2").getTableAlias()).isEqualTo(quoted("secondList"));
softly.assertThat(extPath("secondList.third2.value").getTableAlias()).isEqualTo(quoted("secondList"));
softly.assertThat(extPath("secondList.third").getTableAlias()).isEqualTo(quoted("secondList_third"));
softly.assertThat(extPath("secondList.third.value").getTableAlias()).isEqualTo(quoted("secondList_third"));
softly.assertThat(extPath("secondList").getTableAlias()).isEqualTo(quoted("secondList"));
softly.assertThat(extPath("second2.third").getTableAlias()).isEqualTo(quoted("secthird"));
softly.assertThat(extPath("second3.third").getTableAlias()).isEqualTo(quoted("third"));
});
}
@Test // DATAJDBC-340
void getColumnName() {
assertSoftly(softly -> {
softly.assertThat(extPath("second.third2.value").getColumnName()).isEqualTo(quoted("THRDVALUE"));
softly.assertThat(extPath("second.third.value").getColumnName()).isEqualTo(quoted("VALUE"));
softly.assertThat(extPath("secondList.third2.value").getColumnName()).isEqualTo(quoted("THRDVALUE"));
softly.assertThat(extPath("secondList.third.value").getColumnName()).isEqualTo(quoted("VALUE"));
softly.assertThat(extPath("second2.third2.value").getColumnName()).isEqualTo(quoted("SECTHRDVALUE"));
softly.assertThat(extPath("second2.third.value").getColumnName()).isEqualTo(quoted("VALUE"));
});
}
@Test // DATAJDBC-359
void idDefiningPath() {
assertSoftly(softly -> {
softly.assertThat(extPath("second.third2.value").getIdDefiningParentPath().getLength()).isEqualTo(0);
softly.assertThat(extPath("second.third.value").getIdDefiningParentPath().getLength()).isEqualTo(0);
softly.assertThat(extPath("secondList.third2.value").getIdDefiningParentPath().getLength()).isEqualTo(0);
softly.assertThat(extPath("secondList.third.value").getIdDefiningParentPath().getLength()).isEqualTo(0);
softly.assertThat(extPath("second2.third2.value").getIdDefiningParentPath().getLength()).isEqualTo(0);
softly.assertThat(extPath("second2.third.value").getIdDefiningParentPath().getLength()).isEqualTo(0);
softly.assertThat(extPath("withId.second.third2.value").getIdDefiningParentPath().getLength()).isEqualTo(1);
softly.assertThat(extPath("withId.second.third.value").getIdDefiningParentPath().getLength()).isEqualTo(1);
});
}
@Test // DATAJDBC-359
void reverseColumnName() {
assertSoftly(softly -> {
softly.assertThat(extPath("second.third2").getReverseColumnName()).isEqualTo(quoted("DUMMY_ENTITY"));
softly.assertThat(extPath("second.third").getReverseColumnName()).isEqualTo(quoted("DUMMY_ENTITY"));
softly.assertThat(extPath("secondList.third2").getReverseColumnName()).isEqualTo(quoted("DUMMY_ENTITY"));
softly.assertThat(extPath("secondList.third").getReverseColumnName()).isEqualTo(quoted("DUMMY_ENTITY"));
softly.assertThat(extPath("second2.third2").getReverseColumnName()).isEqualTo(quoted("DUMMY_ENTITY"));
softly.assertThat(extPath("second2.third").getReverseColumnName()).isEqualTo(quoted("DUMMY_ENTITY"));
softly.assertThat(extPath("withId.second.third2.value").getReverseColumnName()).isEqualTo(quoted("WITH_ID"));
softly.assertThat(extPath("withId.second.third").getReverseColumnName()).isEqualTo(quoted("WITH_ID"));
softly.assertThat(extPath("withId.second2.third").getReverseColumnName()).isEqualTo(quoted("WITH_ID"));
});
}
@Test // DATAJDBC-359
void getRequiredIdProperty() {
assertSoftly(softly -> {
softly.assertThat(extPath(entity).getRequiredIdProperty().getName()).isEqualTo("entityId");
softly.assertThat(extPath("withId").getRequiredIdProperty().getName()).isEqualTo("withIdId");
softly.assertThatThrownBy(() -> extPath("second").getRequiredIdProperty())
.isInstanceOf(IllegalStateException.class);
});
}
@Test // DATAJDBC-359
void extendBy() {
assertSoftly(softly -> {
softly.assertThat(extPath(entity).extendBy(entity.getRequiredPersistentProperty("withId")))
.isEqualTo(extPath("withId"));
softly.assertThat(extPath("withId").extendBy(extPath("withId").getRequiredIdProperty()))
.isEqualTo(extPath("withId.withIdId"));
});
}
@Test // GH-1164
void equalsWorks() {
PersistentPropertyPathExtension root1 = extPath(entity);
PersistentPropertyPathExtension root2 = extPath(entity);
PersistentPropertyPathExtension path1 = extPath("withId");
PersistentPropertyPathExtension path2 = extPath("withId");
assertSoftly(softly -> {
softly.assertThat(root1).describedAs("root is equal to self").isEqualTo(root1);
softly.assertThat(root2).describedAs("root is equal to identical root").isEqualTo(root1);
softly.assertThat(path1).describedAs("path is equal to self").isEqualTo(path1);
softly.assertThat(path2).describedAs("path is equal to identical path").isEqualTo(path1);
softly.assertThat(path1).describedAs("path is not equal to other path").isNotEqualTo(extPath("entityId"));
softly.assertThat(root1).describedAs("root is not equal to path").isNotEqualTo(path1);
softly.assertThat(path1).describedAs("path is not equal to root").isNotEqualTo(root1);
});
}
@Test // GH-1249
void isWritable() {
assertSoftly(softly -> {
softly.assertThat(PersistentPropertyPathExtension.isWritable(createSimplePath("withId")))
.describedAs("simple path is writable").isTrue();
softly.assertThat(PersistentPropertyPathExtension.isWritable(createSimplePath("secondList.third2")))
.describedAs("long path is writable").isTrue();
softly.assertThat(PersistentPropertyPathExtension.isWritable(createSimplePath("second")))
.describedAs("simple read only path is not writable").isFalse();
softly.assertThat(PersistentPropertyPathExtension.isWritable(createSimplePath("second.third")))
.describedAs("long path containing read only element is not writable").isFalse();
});
}
@Test // GH-1525
void getAggregatePath() {
assertThat(extPath("withId").getAggregatePath()).isNotNull();
}
@Test // GH-1525
void getAggregatePathFromRoot() {
assertThat(extPath(entity).getAggregatePath()).isNotNull();
}
private PersistentPropertyPathExtension extPath(RelationalPersistentEntity<?> entity) {
return new PersistentPropertyPathExtension(context, entity);
}
private PersistentPropertyPathExtension extPath(String path) {
return new PersistentPropertyPathExtension(context, createSimplePath(path));
}
PersistentPropertyPath<RelationalPersistentProperty> createSimplePath(String path) {
return PersistentPropertyPathTestUtils.getPath(path, DummyEntity.class, context);
}
@SuppressWarnings("unused")
static class DummyEntity {
@Id Long entityId;
@ReadOnlyProperty Second second;
@Embedded(onEmpty = OnEmpty.USE_NULL, prefix = "sec") Second second2;
@Embedded(onEmpty = OnEmpty.USE_NULL) Second second3;
List<Second> secondList;
WithId withId;
}
@SuppressWarnings("unused")
static class Second {
Third third;
@Embedded(onEmpty = OnEmpty.USE_NULL, prefix = "thrd") Third third2;
}
@SuppressWarnings("unused")
static class Third {
String value;
}
@SuppressWarnings("unused")
static class WithId {
@Id Long withIdId;
Second second;
@Embedded(onEmpty = OnEmpty.USE_NULL, prefix = "sec") Second second2;
}
}

View File

@@ -118,8 +118,7 @@ public class MyBatisCustomizingNamespaceHsqlIntegrationTests {
RelationalMappingContext context = new JdbcMappingContext();
JdbcConverter converter = new MappingJdbcConverter(context, (Identifier, path) -> null);
MyBatisDataAccessStrategy strategy = new MyBatisDataAccessStrategy(sqlSession,
HsqlDbDialect.INSTANCE.getIdentifierProcessing());
MyBatisDataAccessStrategy strategy = new MyBatisDataAccessStrategy(sqlSession);
strategy.setNamespaceStrategy(new NamespaceStrategy() {
@Override

View File

@@ -35,7 +35,6 @@ import org.springframework.data.mapping.PersistentPropertyPath;
import org.springframework.data.relational.core.conversion.IdValueSource;
import org.springframework.data.relational.core.mapping.RelationalMappingContext;
import org.springframework.data.relational.core.mapping.RelationalPersistentProperty;
import org.springframework.data.relational.core.sql.IdentifierProcessing;
/**
* Unit tests for the {@link MyBatisDataAccessStrategy}, mainly ensuring that the correct statements get's looked up.
@@ -52,7 +51,7 @@ public class MyBatisDataAccessStrategyUnitTests {
SqlSession session = mock(SqlSession.class);
ArgumentCaptor<MyBatisContext> captor = ArgumentCaptor.forClass(MyBatisContext.class);
MyBatisDataAccessStrategy accessStrategy = new MyBatisDataAccessStrategy(session, IdentifierProcessing.ANSI);
MyBatisDataAccessStrategy accessStrategy = new MyBatisDataAccessStrategy(session);
PersistentPropertyPath<RelationalPersistentProperty> path = PersistentPropertyPathTestUtils.getPath("one.two",
DummyEntity.class, context);