Deprecate mutability of DelegatingDataAccessStrategy.
See: #1315 Original pull request: #1324.
This commit is contained in:
committed by
Jens Schauder
parent
26c5c5dd93
commit
76ea47ab16
@@ -43,6 +43,14 @@ public class DelegatingDataAccessStrategy implements DataAccessStrategy {
|
||||
|
||||
private DataAccessStrategy delegate;
|
||||
|
||||
public DelegatingDataAccessStrategy() {}
|
||||
|
||||
public DelegatingDataAccessStrategy(DataAccessStrategy delegate) {
|
||||
|
||||
Assert.notNull(delegate, "DataAccessStrategy must not be null");
|
||||
this.delegate = delegate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> Object insert(T instance, Class<T> domainType, Identifier identifier, IdValueSource idValueSource) {
|
||||
return delegate.insert(instance, domainType, identifier, idValueSource);
|
||||
@@ -182,7 +190,9 @@ public class DelegatingDataAccessStrategy implements DataAccessStrategy {
|
||||
* Must be called exactly once before calling any of the other methods.
|
||||
*
|
||||
* @param delegate Must not be {@literal null}
|
||||
* @deprecated since 3.0, use {@link #DelegatingDataAccessStrategy(DataAccessStrategy)} to avoid mutable state.
|
||||
*/
|
||||
@Deprecated(since = "3.0", forRemoval = true)
|
||||
public void setDelegate(DataAccessStrategy delegate) {
|
||||
|
||||
Assert.isNull(this.delegate, "The delegate must be set exactly once");
|
||||
|
||||
@@ -86,16 +86,6 @@ public class MyBatisDataAccessStrategy implements DataAccessStrategy {
|
||||
JdbcConverter converter, NamedParameterJdbcOperations operations, SqlSession sqlSession,
|
||||
NamespaceStrategy namespaceStrategy, Dialect dialect) {
|
||||
|
||||
// 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.
|
||||
DelegatingDataAccessStrategy delegatingDataAccessStrategy = new DelegatingDataAccessStrategy();
|
||||
MyBatisDataAccessStrategy myBatisDataAccessStrategy = new MyBatisDataAccessStrategy(sqlSession,
|
||||
dialect.getIdentifierProcessing());
|
||||
myBatisDataAccessStrategy.setNamespaceStrategy(namespaceStrategy);
|
||||
|
||||
CascadingDataAccessStrategy cascadingDataAccessStrategy = new CascadingDataAccessStrategy(
|
||||
asList(myBatisDataAccessStrategy, delegatingDataAccessStrategy));
|
||||
|
||||
SqlGeneratorSource sqlGeneratorSource = new SqlGeneratorSource(context, converter, dialect);
|
||||
SqlParametersFactory sqlParametersFactory = new SqlParametersFactory(context, converter, dialect);
|
||||
@@ -110,7 +100,17 @@ public class MyBatisDataAccessStrategy implements DataAccessStrategy {
|
||||
insertStrategyFactory //
|
||||
);
|
||||
|
||||
delegatingDataAccessStrategy.setDelegate(defaultDataAccessStrategy);
|
||||
// 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.
|
||||
DelegatingDataAccessStrategy delegatingDataAccessStrategy = new DelegatingDataAccessStrategy(
|
||||
defaultDataAccessStrategy);
|
||||
MyBatisDataAccessStrategy myBatisDataAccessStrategy = new MyBatisDataAccessStrategy(sqlSession,
|
||||
dialect.getIdentifierProcessing());
|
||||
myBatisDataAccessStrategy.setNamespaceStrategy(namespaceStrategy);
|
||||
|
||||
CascadingDataAccessStrategy cascadingDataAccessStrategy = new CascadingDataAccessStrategy(
|
||||
asList(myBatisDataAccessStrategy, delegatingDataAccessStrategy));
|
||||
|
||||
return cascadingDataAccessStrategy;
|
||||
}
|
||||
@@ -316,17 +316,17 @@ public class MyBatisDataAccessStrategy implements DataAccessStrategy {
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> Optional<T> selectOne(Query query, Class<T> probeType) {
|
||||
public <T> Optional<T> findOne(Query query, Class<T> probeType) {
|
||||
throw new UnsupportedOperationException("Not implemented");
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> Iterable<T> select(Query query, Class<T> probeType) {
|
||||
public <T> Iterable<T> findAll(Query query, Class<T> probeType) {
|
||||
throw new UnsupportedOperationException("Not implemented");
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> Iterable<T> select(Query query, Class<T> probeType, Pageable pageable) {
|
||||
public <T> Iterable<T> findAll(Query query, Class<T> probeType, Pageable pageable) {
|
||||
throw new UnsupportedOperationException("Not implemented");
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user