DATAJDBC-480 - Removed various deprecated symbols.

Removal of public API that was deprecated in version 1.1 or older.

Original pull request: #204.
This commit is contained in:
Jens Schauder
2020-04-01 08:37:51 +02:00
committed by Mark Paluch
parent 10b4ea0a10
commit 2b6f7b2b48
28 changed files with 62 additions and 807 deletions

View File

@@ -1,38 +0,0 @@
/*
* Copyright 2017-2020 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 java.util.List;
import org.springframework.data.jdbc.core.convert.DataAccessStrategy;
/**
* Delegates each methods to the {@link DataAccessStrategy}s passed to the constructor in turn until the first that does
* not throw an exception.
*
* @author Jens Schauder
* @author Mark Paluch
* @deprecated since 1.1, use {@link org.springframework.data.jdbc.core.convert.CascadingDataAccessStrategy}
*/
@Deprecated
public class CascadingDataAccessStrategy
extends org.springframework.data.jdbc.core.convert.CascadingDataAccessStrategy {
public CascadingDataAccessStrategy(List<DataAccessStrategy> strategies) {
super(strategies);
}
}

View File

@@ -1,28 +0,0 @@
/*
* Copyright 2017-2020 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;
/**
* Abstraction for accesses to the database that should be implementable with a single SQL statement per method and
* relates to a single entity as opposed to {@link JdbcAggregateOperations} which provides interactions related to
* complete aggregates.
*
* @author Jens Schauder
* @author Mark Paluch
* @deprecated since 1.1, use {@link org.springframework.data.jdbc.core.convert.DataAccessStrategy}
*/
@Deprecated
public interface DataAccessStrategy extends org.springframework.data.jdbc.core.convert.DataAccessStrategy {}

View File

@@ -1,47 +0,0 @@
/*
* Copyright 2017-2020 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 org.springframework.data.jdbc.core.convert.DataAccessStrategy;
import org.springframework.data.jdbc.core.convert.JdbcConverter;
import org.springframework.data.jdbc.core.convert.SqlGeneratorSource;
import org.springframework.data.relational.core.mapping.RelationalMappingContext;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcOperations;
/**
* The default {@link DataAccessStrategy} is to generate SQL statements based on meta data from the entity.
*
* @author Jens Schauder
* @deprecated since 1.1, use {@link org.springframework.data.jdbc.core.convert.DefaultDataAccessStrategy} instead.
*/
@Deprecated
public class DefaultDataAccessStrategy extends org.springframework.data.jdbc.core.convert.DefaultDataAccessStrategy {
/**
* Creates a {@link org.springframework.data.jdbc.core.convert.DefaultDataAccessStrategy} which references it self for
* resolution of recursive data accesses. Only suitable if this is the only access strategy in use.
*
* @param sqlGeneratorSource must not be {@literal null}.
* @param context must not be {@literal null}.
* @param converter must not be {@literal null}.
* @param operations must not be {@literal null}.
*/
public DefaultDataAccessStrategy(SqlGeneratorSource sqlGeneratorSource, RelationalMappingContext context,
JdbcConverter converter, NamedParameterJdbcOperations operations) {
super(sqlGeneratorSource, context, converter, operations);
}
}

View File

@@ -1,30 +0,0 @@
/*
* Copyright 2017-2020 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 org.springframework.data.jdbc.core.convert.DataAccessStrategy;
/**
* Delegates all method calls to an instance set after construction. This is useful for {@link DataAccessStrategy}s with
* cyclic dependencies.
*
* @author Jens Schauder
* @author Mark Paluch
* @deprecated since 1.1, use {@link org.springframework.data.jdbc.core.convert.DelegatingDataAccessStrategy}.
*/
@Deprecated
public class DelegatingDataAccessStrategy
extends org.springframework.data.jdbc.core.convert.DelegatingDataAccessStrategy {}

View File

@@ -1,33 +0,0 @@
/*
* Copyright 2017-2020 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 org.springframework.data.jdbc.core.convert.DataAccessStrategy;
import org.springframework.data.jdbc.core.convert.JdbcConverter;
import org.springframework.data.relational.core.mapping.RelationalPersistentEntity;
/**
* @author Jens Schauder
* @deprecated since 1.1, use {@link org.springframework.data.jdbc.core.convert.EntityRowMapper} instead.
*/
@Deprecated
public class EntityRowMapper<T> extends org.springframework.data.jdbc.core.convert.EntityRowMapper<T> {
public EntityRowMapper(RelationalPersistentEntity<T> entity, JdbcConverter converter,
DataAccessStrategy accessStrategy) {
super(entity, converter);
}
}

View File

@@ -17,7 +17,6 @@ package org.springframework.data.jdbc.core.convert;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.function.Consumer;
import java.util.function.Function;
@@ -25,7 +24,6 @@ import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.mapping.PersistentPropertyPath;
import org.springframework.data.relational.core.mapping.RelationalPersistentProperty;
import org.springframework.data.relational.core.sql.SqlIdentifier;
import org.springframework.data.relational.domain.Identifier;
/**
@@ -46,15 +44,6 @@ public class CascadingDataAccessStrategy implements DataAccessStrategy {
this.strategies = new ArrayList<>(strategies);
}
/*
* (non-Javadoc)
* @see org.springframework.data.jdbc.core.DataAccessStrategy#insert(java.lang.Object, java.lang.Class, java.util.Map)
*/
@Override
public <T> Object insert(T instance, Class<T> domainType, Map<SqlIdentifier, Object> additionalParameters) {
return collect(das -> das.insert(instance, domainType, additionalParameters));
}
/*
* (non-Javadoc)
* @see org.springframework.data.jdbc.core.DataAccessStrategy#insert(java.lang.Object, java.lang.Class, org.springframework.data.jdbc.core.ParentKeys)
@@ -173,15 +162,6 @@ public class CascadingDataAccessStrategy implements DataAccessStrategy {
return collect(das -> das.findAllByPath(identifier, path));
}
/*
* (non-Javadoc)
* @see org.springframework.data.jdbc.core.DataAccessStrategy#findAllByProperty(java.lang.Object, org.springframework.data.relational.core.mapping.RelationalPersistentProperty)
*/
@Override
public <T> Iterable<T> findAllByProperty(Object rootId, RelationalPersistentProperty property) {
return collect(das -> das.findAllByProperty(rootId, property));
}
/*
* (non-Javadoc)
* @see org.springframework.data.jdbc.core.DataAccessStrategy#existsById(java.lang.Object, java.lang.Class)

View File

@@ -23,7 +23,6 @@ import org.springframework.data.domain.Sort;
import org.springframework.data.jdbc.core.JdbcAggregateOperations;
import org.springframework.data.mapping.PersistentPropertyPath;
import org.springframework.data.relational.core.mapping.RelationalPersistentProperty;
import org.springframework.data.relational.core.sql.SqlIdentifier;
import org.springframework.data.relational.domain.Identifier;
import org.springframework.lang.Nullable;
@@ -38,21 +37,6 @@ import org.springframework.lang.Nullable;
*/
public interface DataAccessStrategy extends RelationResolver {
/**
* Inserts a the data of a single entity. Referenced entities don't get handled.
*
* @param instance the instance to be stored. Must not be {@code null}.
* @param domainType the type of the instance. Must not be {@code null}.
* @param additionalParameters name-value pairs of additional parameters. Especially ids of parent entities that need
* to get referenced are contained in this map. Must not be {@code null}.
* @param <T> the type of the instance.
* @return the id generated by the database if any.
* @deprecated since 1.1, use {@link #insert(Object, Class, Identifier)} instead.
*/
@Deprecated
@Nullable
<T> Object insert(T instance, Class<T> domainType, Map<SqlIdentifier, Object> additionalParameters);
/**
* Inserts a the data of a single entity. Referenced entities don't get handled.
*
@@ -66,9 +50,7 @@ public interface DataAccessStrategy extends RelationResolver {
* @since 1.1
*/
@Nullable
default <T> Object insert(T instance, Class<T> domainType, Identifier identifier) {
return insert(instance, domainType, identifier.toMap());
}
<T> Object insert(T instance, Class<T> domainType, Identifier identifier);
/**
* Updates the data of a single entity in the database. Referenced entities don't get handled.
@@ -192,22 +174,8 @@ public interface DataAccessStrategy extends RelationResolver {
* @see org.springframework.data.jdbc.core.RelationResolver#findAllByPath(org.springframework.data.relational.domain.Identifier, org.springframework.data.mapping.PersistentPropertyPath)
*/
@Override
default Iterable<Object> findAllByPath(Identifier identifier,
PersistentPropertyPath<? extends RelationalPersistentProperty> path) {
Object rootId = identifier.toMap().get(path.getRequiredLeafProperty().getReverseColumnName());
return findAllByProperty(rootId, path.getRequiredLeafProperty());
}
/**
* Finds all entities reachable via {@literal property} from the instance identified by {@literal rootId}.
*
* @param rootId Id of the root object on which the {@literal propertyPath} is based.
* @param property Leading from the root object to the entities to be found.
* @deprecated Use #findAllByPath instead.
*/
@Deprecated
<T> Iterable<T> findAllByProperty(Object rootId, RelationalPersistentProperty property);
Iterable<Object> findAllByPath(Identifier identifier,
PersistentPropertyPath<? extends RelationalPersistentProperty> path);
/**
* returns if a row with the given id exists for the given type.

View File

@@ -95,16 +95,6 @@ public class DefaultDataAccessStrategy implements DataAccessStrategy {
this.operations = operations;
}
/*
* (non-Javadoc)
* @see org.springframework.data.jdbc.core.DataAccessStrategy#insert(java.lang.Object, java.lang.Class, java.util.Map)
*/
@Override
@Nullable
public <T> Object insert(T instance, Class<T> domainType, Map<SqlIdentifier, Object> additionalParameters) {
return insert(instance, domainType, Identifier.from(additionalParameters));
}
/*
* (non-Javadoc)
* @see org.springframework.data.jdbc.core.DataAccessStrategy#insert(java.lang.Object, java.lang.Class, java.util.Map)
@@ -346,21 +336,6 @@ public class DefaultDataAccessStrategy implements DataAccessStrategy {
return parameterSource;
}
/*
* (non-Javadoc)
* @see org.springframework.data.jdbc.core.DataAccessStrategy#findAllByProperty(java.lang.Object, org.springframework.data.jdbc.mapping.model.JdbcPersistentProperty)
*/
@Override
@SuppressWarnings("unchecked")
public Iterable<Object> findAllByProperty(Object rootId, RelationalPersistentProperty property) {
Assert.notNull(rootId, "rootId must not be null.");
Class<?> rootType = property.getOwner().getType();
return findAllByPath(Identifier.of(property.getReverseColumnName(), rootId, rootType),
context.getPersistentPropertyPath(property.getName(), rootType));
}
/*
* (non-Javadoc)
* @see org.springframework.data.jdbc.core.DataAccessStrategy#existsById(java.lang.Object, java.lang.Class)

View File

@@ -15,13 +15,10 @@
*/
package org.springframework.data.jdbc.core.convert;
import java.util.Map;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.mapping.PersistentPropertyPath;
import org.springframework.data.relational.core.mapping.RelationalPersistentProperty;
import org.springframework.data.relational.core.sql.SqlIdentifier;
import org.springframework.data.relational.domain.Identifier;
import org.springframework.util.Assert;
@@ -38,15 +35,6 @@ public class DelegatingDataAccessStrategy implements DataAccessStrategy {
private DataAccessStrategy delegate;
/*
* (non-Javadoc)
* @see org.springframework.data.jdbc.core.DataAccessStrategy#insert(java.lang.Object, java.lang.Class, java.util.Map)
*/
@Override
public <T> Object insert(T instance, Class<T> domainType, Map<SqlIdentifier, Object> additionalParameters) {
return delegate.insert(instance, domainType, additionalParameters);
}
/*
* (non-Javadoc)
* @see org.springframework.data.jdbc.core.DataAccessStrategy#insert(java.lang.Object, java.lang.Class, org.springframework.data.jdbc.core.ParentKeys)
@@ -169,18 +157,6 @@ public class DelegatingDataAccessStrategy implements DataAccessStrategy {
return delegate.findAllByPath(identifier, path);
}
/*
* (non-Javadoc)
* @see org.springframework.data.jdbc.core.DataAccessStrategy#findAllByProperty(java.lang.Object, org.springframework.data.relational.core.mapping.RelationalPersistentProperty)
*/
@Override
public <T> Iterable<T> findAllByProperty(Object rootId, RelationalPersistentProperty property) {
Assert.notNull(delegate, "Delegate is null");
return delegate.findAllByProperty(rootId, property);
}
/*
* (non-Javadoc)
* @see org.springframework.data.jdbc.core.DataAccessStrategy#existsById(java.lang.Object, java.lang.Class)

View File

@@ -22,7 +22,6 @@ import java.util.HashMap;
import java.util.Map;
import java.util.stream.Collectors;
import org.apache.ibatis.exceptions.PersistenceException;
import org.apache.ibatis.session.SqlSession;
import org.mybatis.spring.SqlSessionTemplate;
import org.slf4j.Logger;
@@ -144,20 +143,6 @@ public class MyBatisDataAccessStrategy implements DataAccessStrategy {
this.namespaceStrategy = namespaceStrategy;
}
/*
* (non-Javadoc)
* @see org.springframework.data.jdbc.core.DataAccessStrategy#insert(java.lang.Object, java.lang.Class, java.util.Map)
*/
@Override
public <T> Object insert(T instance, Class<T> domainType, Map<SqlIdentifier, Object> additionalParameters) {
MyBatisContext myBatisContext = new MyBatisContext(null, instance, domainType,
convertToParameterMap(additionalParameters));
sqlSession().insert(namespace(domainType) + ".insert", myBatisContext);
return myBatisContext.getId();
}
/*
* (non-Javadoc)
* @see org.springframework.data.jdbc.core.DataAccessStrategy#insert(java.lang.Object, java.lang.Class, ParentKeys)
@@ -304,28 +289,9 @@ public class MyBatisDataAccessStrategy implements DataAccessStrategy {
String statementName = namespace(path.getBaseProperty().getOwner().getType()) + ".findAllByPath-"
+ path.toDotPath();
try {
return sqlSession().selectList(statementName,
new MyBatisContext(identifier, null, path.getRequiredLeafProperty().getType()));
} catch (PersistenceException pex) {
return sqlSession().selectList(statementName,
new MyBatisContext(identifier, null, path.getRequiredLeafProperty().getType()));
LOG.debug(String.format("Didn't find %s in the MyBatis session. Falling back to findAllByPath.", statementName),
pex);
return DataAccessStrategy.super.findAllByPath(identifier, path);
}
}
/*
* (non-Javadoc)
* @see org.springframework.data.jdbc.core.DataAccessStrategy#findAllByProperty(java.lang.Object, org.springframework.data.relational.core.mapping.RelationalPersistentProperty)
*/
@Override
public <T> Iterable<T> findAllByProperty(Object rootId, RelationalPersistentProperty property) {
String statement = namespace(property.getOwner().getType()) + ".findAllByProperty-" + property.getName();
MyBatisContext parameter = new MyBatisContext(rootId, null, property.getType(), Collections.emptyMap());
return sqlSession().selectList(statement, parameter);
}
/*

View File

@@ -1,56 +0,0 @@
/*
* Copyright 2018-2020 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.repository;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.lang.Nullable;
/**
* A map from a type to a {@link RowMapper} to be used for extracting that type from {@link java.sql.ResultSet}s.
*
* @author Jens Schauder
* @deprecated since 1.1 use {@link QueryMappingConfiguration}
*/
@Deprecated
public interface RowMapperMap extends QueryMappingConfiguration {
/**
* An immutable empty instance that will return {@literal null} for all arguments.
*/
RowMapperMap EMPTY = new RowMapperMap() {
/*
* (non-Javadoc)
* @see org.springframework.data.jdbc.repository.RowMapperMap#rowMapperFor(java.lang.Class)
*/
public <T> RowMapper<? extends T> rowMapperFor(Class<T> type) {
return null;
}
@Override
public <T> RowMapper<? extends T> getRowMapper(Class<T> type) {
return null;
}
};
@Nullable
<T> RowMapper<? extends T> rowMapperFor(Class<T> type);
@Override
default <T> RowMapper<? extends T> getRowMapper(Class<T> type) {
return rowMapperFor(type);
}
}

View File

@@ -1,77 +0,0 @@
/*
* Copyright 2018-2020 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.repository.config;
import java.util.LinkedHashMap;
import java.util.Map;
import org.springframework.data.jdbc.repository.RowMapperMap;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
/**
* A {@link RowMapperMap} that allows for registration of {@link RowMapper}s via a fluent Api.
*
* @author Jens Schauder
* @deprecated Since 1.1 use {@link DefaultQueryMappingConfiguration} instead.
*/
@Deprecated
public class ConfigurableRowMapperMap implements RowMapperMap {
private Map<Class<?>, RowMapper<?>> rowMappers = new LinkedHashMap<>();
/**
* Registers a the given {@link RowMapper} as to be used for the given type.
*
* @return this instance, so this can be used as a fluent interface.
*/
public <T> ConfigurableRowMapperMap register(Class<T> type, RowMapper<? extends T> rowMapper) {
rowMappers.put(type, rowMapper);
return this;
}
/**
* Returns a {@link RowMapper} for the given type if such a {@link RowMapper} is present. If an exact match is found
* that is returned. If not a {@link RowMapper} is returned that produces subtypes of the requested type. If no such
* {@link RowMapper} is found the method returns {@code null}.
*
* @param type the type to be produced by the returned {@link RowMapper}. Must not be {@code null}.
* @param <T> the type to be produced by the returned {@link RowMapper}.
* @return Guaranteed to be not {@code null}.
*/
@SuppressWarnings("unchecked")
@Nullable
public <T> RowMapper<? extends T> rowMapperFor(Class<T> type) {
Assert.notNull(type, "Type must not be null");
RowMapper<? extends T> candidate = (RowMapper<? extends T>) rowMappers.get(type);
if (candidate == null) {
for (Map.Entry<Class<?>, RowMapper<?>> entry : rowMappers.entrySet()) {
if (type.isAssignableFrom(entry.getKey())) {
candidate = (RowMapper<? extends T>) entry.getValue();
}
}
}
return candidate;
}
}

View File

@@ -25,7 +25,6 @@ import org.springframework.data.auditing.IsNewAwareAuditingHandler;
import org.springframework.data.auditing.config.AuditingBeanDefinitionRegistrarSupport;
import org.springframework.data.auditing.config.AuditingConfiguration;
import org.springframework.data.relational.domain.support.RelationalAuditingCallback;
import org.springframework.data.relational.domain.support.RelationalAuditingEventListener;
import org.springframework.util.Assert;
/**
@@ -78,7 +77,7 @@ class JdbcAuditingRegistrar extends AuditingBeanDefinitionRegistrarSupport {
}
/**
* Register the bean definition of {@link RelationalAuditingEventListener}. {@inheritDoc}
* Register the bean definition of {@link RelationalAuditingCallback}. {@inheritDoc}
*
* @see AuditingBeanDefinitionRegistrarSupport#registerAuditListenerBeanDefinition(BeanDefinition,
* BeanDefinitionRegistry)

View File

@@ -1,141 +0,0 @@
/*
* Copyright 2017-2020 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.repository.config;
import java.util.Optional;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Lazy;
import org.springframework.core.convert.converter.Converter;
import org.springframework.data.jdbc.core.JdbcAggregateOperations;
import org.springframework.data.jdbc.core.JdbcAggregateTemplate;
import org.springframework.data.jdbc.core.convert.BasicJdbcConverter;
import org.springframework.data.jdbc.core.convert.DataAccessStrategy;
import org.springframework.data.jdbc.core.convert.DefaultDataAccessStrategy;
import org.springframework.data.jdbc.core.convert.JdbcConverter;
import org.springframework.data.jdbc.core.convert.JdbcCustomConversions;
import org.springframework.data.jdbc.core.convert.JdbcTypeFactory;
import org.springframework.data.jdbc.core.convert.RelationResolver;
import org.springframework.data.jdbc.core.convert.SqlGeneratorSource;
import org.springframework.data.jdbc.core.mapping.JdbcMappingContext;
import org.springframework.data.relational.core.conversion.RelationalConverter;
import org.springframework.data.relational.core.dialect.Dialect;
import org.springframework.data.relational.core.dialect.HsqlDbDialect;
import org.springframework.data.relational.core.mapping.NamingStrategy;
import org.springframework.data.relational.core.mapping.RelationalMappingContext;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcOperations;
/**
* Beans that must be registered for Spring Data JDBC to work.
*
* @author Greg Turnquist
* @author Jens Schauder
* @author Mark Paluch
* @author Michael Simons
* @author Christoph Strobl
* @author Myeonghyeon Lee
* @deprecated Use {@link AbstractJdbcConfiguration} instead.
*/
@Configuration
@Deprecated
public class JdbcConfiguration {
/**
* Register a {@link RelationalMappingContext} and apply an optional {@link NamingStrategy}.
*
* @param namingStrategy optional {@link NamingStrategy}. Use {@link NamingStrategy#INSTANCE} as fallback.
* @return must not be {@literal null}.
*/
@Bean
public RelationalMappingContext jdbcMappingContext(Optional<NamingStrategy> namingStrategy) {
JdbcMappingContext mappingContext = new JdbcMappingContext(namingStrategy.orElse(NamingStrategy.INSTANCE));
mappingContext.setSimpleTypeHolder(jdbcCustomConversions().getSimpleTypeHolder());
return mappingContext;
}
/**
* Creates a {@link RelationalConverter} using the configured {@link #jdbcMappingContext(Optional)}. Will get
* {@link #jdbcCustomConversions()} applied.
*
* @see #jdbcMappingContext(Optional)
* @see #jdbcCustomConversions()
* @return must not be {@literal null}.
*/
@Bean
public RelationalConverter relationalConverter(RelationalMappingContext mappingContext,
@Lazy RelationResolver relationalResolver, Dialect dialect) {
return new BasicJdbcConverter(mappingContext, relationalResolver, jdbcCustomConversions(),
JdbcTypeFactory.unsupported(), dialect.getIdentifierProcessing());
}
/**
* Register custom {@link Converter}s in a {@link JdbcCustomConversions} object if required. These
* {@link JdbcCustomConversions} will be registered with the {@link #relationalConverter(RelationalMappingContext)}.
* Returns an empty {@link JdbcCustomConversions} instance by default.
*
* @return must not be {@literal null}.
*/
@Bean
public JdbcCustomConversions jdbcCustomConversions() {
return new JdbcCustomConversions();
}
/**
* Register a {@link JdbcAggregateTemplate} as a bean for easy use in applications that need a lower level of
* abstraction than the normal repository abstraction.
*
* @param publisher
* @param context
* @param converter
* @param operations
* @param dialect
* @return
*/
@Bean
public JdbcAggregateOperations jdbcAggregateOperations(ApplicationEventPublisher publisher,
RelationalMappingContext context, JdbcConverter converter, NamedParameterJdbcOperations operations,
Dialect dialect) {
return new JdbcAggregateTemplate(publisher, context, converter,
dataAccessStrategy(context, converter, operations, dialect));
}
/**
* Register a {@link DataAccessStrategy} as a bean for reuse in the {@link JdbcAggregateOperations} and the
* {@link RelationalConverter}.
*
* @param context
* @param converter
* @param operations
* @param dialect
* @return
*/
@Bean
public DataAccessStrategy dataAccessStrategy(RelationalMappingContext context, JdbcConverter converter,
NamedParameterJdbcOperations operations, Dialect dialect) {
return new DefaultDataAccessStrategy(new SqlGeneratorSource(context, converter, dialect), context, converter,
operations);
}
@Bean
public Dialect dialect() {
return HsqlDbDialect.INSTANCE;
}
}

View File

@@ -37,10 +37,8 @@ import org.springframework.util.StringUtils;
* @author Jens Schauder
* @author Kazuki Shimizu
* @author Moises Cisneros
* @deprecated Visibility of this class will be reduced to package private.
*/
@Deprecated
public class JdbcQueryMethod extends QueryMethod {
class JdbcQueryMethod extends QueryMethod {
private final Method method;
private final NamedQueries namedQueries;

View File

@@ -22,7 +22,6 @@ import org.springframework.data.jdbc.core.JdbcAggregateTemplate;
import org.springframework.data.jdbc.core.convert.DataAccessStrategy;
import org.springframework.data.jdbc.core.convert.JdbcConverter;
import org.springframework.data.jdbc.repository.QueryMappingConfiguration;
import org.springframework.data.jdbc.repository.RowMapperMap;
import org.springframework.data.mapping.callback.EntityCallbacks;
import org.springframework.data.relational.core.mapping.RelationalMappingContext;
import org.springframework.data.relational.core.mapping.RelationalPersistentEntity;
@@ -92,15 +91,6 @@ public class JdbcRepositoryFactory extends RepositoryFactorySupport {
this.queryMappingConfiguration = queryMappingConfiguration;
}
/**
* @param rowMapperMap must not be {@literal null} consider {@link RowMapperMap#EMPTY} instead.
* @deprecated use {@link #setQueryMappingConfiguration(QueryMappingConfiguration)} instead
*/
@Deprecated
public void setRowMapperMap(RowMapperMap rowMapperMap) {
setQueryMappingConfiguration(rowMapperMap);
}
@SuppressWarnings("unchecked")
@Override
public <T, ID> EntityInformation<T, ID> getEntityInformation(Class<T> aClass) {

View File

@@ -26,7 +26,6 @@ import org.springframework.data.jdbc.core.convert.DefaultDataAccessStrategy;
import org.springframework.data.jdbc.core.convert.JdbcConverter;
import org.springframework.data.jdbc.core.convert.SqlGeneratorSource;
import org.springframework.data.jdbc.repository.QueryMappingConfiguration;
import org.springframework.data.jdbc.repository.RowMapperMap;
import org.springframework.data.mapping.callback.EntityCallbacks;
import org.springframework.data.relational.core.dialect.Dialect;
import org.springframework.data.relational.core.mapping.RelationalMappingContext;
@@ -122,17 +121,6 @@ public class JdbcRepositoryFactoryBean<T extends Repository<S, ID>, S, ID extend
this.queryMappingConfiguration = queryMappingConfiguration;
}
/**
* @param rowMapperMap can be {@literal null}. {@link #afterPropertiesSet()} defaults to {@link RowMapperMap#EMPTY} if
* {@literal null}.
* @deprecated use {@link #setQueryMappingConfiguration(QueryMappingConfiguration)} instead.
*/
@Deprecated
@Autowired(required = false)
public void setRowMapperMap(RowMapperMap rowMapperMap) {
setQueryMappingConfiguration(rowMapperMap);
}
public void setJdbcOperations(NamedParameterJdbcOperations operations) {
this.operations = operations;
}

View File

@@ -24,9 +24,10 @@ import junit.framework.AssertionFailedError;
import java.util.Collections;
import org.junit.Test;
import org.springframework.data.jdbc.core.convert.FunctionCollector.CombinedDataAccessException;
import org.springframework.data.relational.core.mapping.RelationalPersistentProperty;
import org.springframework.data.mapping.PersistentPropertyPath;
import org.springframework.data.relational.core.sql.SqlIdentifier;
import org.springframework.data.relational.domain.Identifier;
/**
* Unit tests for {@link CascadingDataAccessStrategy}.
@@ -75,11 +76,12 @@ public class CascadingDataAccessStrategyUnitTests {
@Test // DATAJDBC-123
public void findByPropertyReturnsFirstSuccess() {
doReturn(Collections.singletonList("success")).when(succeeds).findAllByProperty(eq(23L),
any(RelationalPersistentProperty.class));
Identifier identifier = Identifier.of(SqlIdentifier.quoted("id-name"), 23L, Long.class);
doReturn(Collections.singletonList("success")).when(succeeds).findAllByPath(eq(identifier),
any(PersistentPropertyPath.class));
CascadingDataAccessStrategy access = new CascadingDataAccessStrategy(asList(alwaysFails, succeeds, mayNotCall));
Iterable<Object> findAll = access.findAllByProperty(23L, mock(RelationalPersistentProperty.class));
Iterable<Object> findAll = access.findAllByPath(identifier, mock(PersistentPropertyPath.class));
assertThat(findAll).containsExactly("success");
}

View File

@@ -39,6 +39,7 @@ import org.springframework.data.relational.core.dialect.Dialect;
import org.springframework.data.relational.core.dialect.HsqlDbDialect;
import org.springframework.data.relational.core.mapping.RelationalMappingContext;
import org.springframework.data.relational.core.sql.SqlIdentifier;
import org.springframework.data.relational.domain.Identifier;
import org.springframework.jdbc.core.JdbcOperations;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcOperations;
import org.springframework.jdbc.core.namedparam.SqlParameterSource;
@@ -88,7 +89,7 @@ public class DefaultDataAccessStrategyUnitTests {
additionalParameters.put(SqlIdentifier.quoted("ID"), ID_FROM_ADDITIONAL_VALUES);
accessStrategy.insert(new DummyEntity(ORIGINAL_ID), DummyEntity.class, additionalParameters);
accessStrategy.insert(new DummyEntity(ORIGINAL_ID), DummyEntity.class, Identifier.from( additionalParameters));
verify(namedJdbcOperations).update(eq("INSERT INTO \"DUMMY_ENTITY\" (\"ID\") VALUES (:ID)"),
paramSourceCaptor.capture(), any(KeyHolder.class));
@@ -101,7 +102,7 @@ public class DefaultDataAccessStrategyUnitTests {
additionalParameters.put(unquoted("reference"), ID_FROM_ADDITIONAL_VALUES);
accessStrategy.insert(new DummyEntity(ORIGINAL_ID), DummyEntity.class, additionalParameters);
accessStrategy.insert(new DummyEntity(ORIGINAL_ID), DummyEntity.class, Identifier.from(additionalParameters));
verify(namedJdbcOperations).update(sqlCaptor.capture(), paramSourceCaptor.capture(), any(KeyHolder.class));
@@ -134,7 +135,7 @@ public class DefaultDataAccessStrategyUnitTests {
EntityWithBoolean entity = new EntityWithBoolean(ORIGINAL_ID, true);
accessStrategy.insert(entity, EntityWithBoolean.class, new HashMap<>());
accessStrategy.insert(entity, EntityWithBoolean.class, Identifier.empty());
verify(namedJdbcOperations).update(sqlCaptor.capture(), paramSourceCaptor.capture(), any(KeyHolder.class));

View File

@@ -874,14 +874,14 @@ public class EntityRowMapperUnitTests {
Set<Map.Entry<String, Trivial>> simpleEntriesWithStringKeys = trivials.stream()
.collect(Collectors.toMap(Trivial::getName, Function.identity())).entrySet();
doReturn(trivials).when(accessStrategy).findAllByProperty(eq(ID_FOR_ENTITY_NOT_REFERENCING_MAP),
any(RelationalPersistentProperty.class));
doReturn(trivials).when(accessStrategy).findAllByPath(identifierOfValue(ID_FOR_ENTITY_NOT_REFERENCING_MAP),
any(PersistentPropertyPath.class));
doReturn(simpleEntriesWithStringKeys).when(accessStrategy).findAllByProperty(eq(ID_FOR_ENTITY_REFERENCING_MAP),
any(RelationalPersistentProperty.class));
doReturn(simpleEntriesWithStringKeys).when(accessStrategy)
.findAllByPath(identifierOfValue(ID_FOR_ENTITY_REFERENCING_MAP), any(PersistentPropertyPath.class));
doReturn(simpleEntriesWithInts).when(accessStrategy).findAllByProperty(eq(ID_FOR_ENTITY_REFERENCING_LIST),
any(RelationalPersistentProperty.class));
doReturn(simpleEntriesWithInts).when(accessStrategy)
.findAllByPath(identifierOfValue(ID_FOR_ENTITY_REFERENCING_LIST), any(PersistentPropertyPath.class));
doReturn(trivials).when(accessStrategy).findAllByPath(identifierOfValue(ID_FOR_ENTITY_NOT_REFERENCING_MAP),
any(PersistentPropertyPath.class));

View File

@@ -18,6 +18,7 @@ package org.springframework.data.jdbc.core.mapping;
import static org.assertj.core.api.Assertions.*;
import static org.springframework.data.relational.core.sql.SqlIdentifier.*;
import junit.framework.AssertionFailedError;
import lombok.Data;
import java.time.LocalDateTime;
@@ -26,13 +27,13 @@ import java.util.Date;
import java.util.List;
import java.util.UUID;
import org.assertj.core.api.SoftAssertions;
import org.junit.Test;
import org.springframework.data.annotation.Id;
import org.springframework.data.mapping.PropertyHandler;
import org.springframework.data.mapping.PersistentPropertyPath;
import org.springframework.data.relational.core.mapping.BasicRelationalPersistentProperty;
import org.springframework.data.relational.core.mapping.Column;
import org.springframework.data.relational.core.mapping.MappedCollection;
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;
@@ -53,8 +54,6 @@ public class BasicJdbcPersistentPropertyUnitTests {
@Test // DATAJDBC-106
public void detectsAnnotatedColumnName() {
RelationalPersistentEntity<?> entity = context.getRequiredPersistentEntity(DummyEntity.class);
assertThat(entity.getRequiredPersistentProperty("name").getColumnName()).isEqualTo(quoted("dummy_name"));
assertThat(entity.getRequiredPersistentProperty("localDateTime").getColumnName())
.isEqualTo(quoted("dummy_last_updated_at"));
@@ -63,23 +62,25 @@ public class BasicJdbcPersistentPropertyUnitTests {
@Test // DATAJDBC-218
public void detectsAnnotatedColumnAndKeyName() {
RelationalPersistentProperty listProperty = context //
.getRequiredPersistentEntity(DummyEntity.class) //
.getRequiredPersistentProperty("someList");
String propertyName = "someList";
RelationalPersistentProperty listProperty = entity.getRequiredPersistentProperty(propertyName);
PersistentPropertyPathExtension path = getPersistentPropertyPath(DummyEntity.class, propertyName);
assertThat(listProperty.getReverseColumnName()).isEqualTo(quoted("dummy_column_name"));
assertThat(listProperty.getReverseColumnName(path)).isEqualTo(quoted("dummy_column_name"));
assertThat(listProperty.getKeyColumn()).isEqualTo(quoted("dummy_key_column_name"));
}
@Test // DATAJDBC-331
public void detectsKeyColumnNameFromColumnAnnotation() {
public void detectsReverseColumnNameFromColumnAnnotation() {
String propertyName = "someList";
RelationalPersistentProperty listProperty = context //
.getRequiredPersistentEntity(WithCollections.class) //
.getRequiredPersistentProperty("someList");
.getRequiredPersistentProperty(propertyName);
PersistentPropertyPathExtension path = getPersistentPropertyPath(DummyEntity.class, propertyName);
assertThat(listProperty.getKeyColumn()).isEqualTo(quoted("some_key"));
assertThat(listProperty.getReverseColumnName()).isEqualTo(quoted("some_value"));
assertThat(listProperty.getKeyColumn()).isEqualTo(quoted("WITH_COLLECTIONS_KEY"));
assertThat(listProperty.getReverseColumnName(path)).isEqualTo(quoted("some_value"));
}
@Test // DATAJDBC-331
@@ -88,9 +89,18 @@ public class BasicJdbcPersistentPropertyUnitTests {
RelationalPersistentProperty listProperty = context //
.getRequiredPersistentEntity(WithCollections.class) //
.getRequiredPersistentProperty("overrideList");
PersistentPropertyPathExtension path = getPersistentPropertyPath(WithCollections.class, "overrideList");
assertThat(listProperty.getKeyColumn()).isEqualTo(quoted("override_key"));
assertThat(listProperty.getReverseColumnName()).isEqualTo(quoted("override_id"));
assertThat(listProperty.getReverseColumnName(path)).isEqualTo(quoted("override_id"));
}
private PersistentPropertyPathExtension getPersistentPropertyPath(Class<?> type, String propertyName) {
PersistentPropertyPath<RelationalPersistentProperty> path = context
.findPersistentPropertyPaths(type, p -> p.getName().equals(propertyName)).getFirst()
.orElseThrow(() -> new AssertionFailedError(String.format("Couldn't find path for '%s'", propertyName)));
return new PersistentPropertyPathExtension(context, path);
}
@SuppressWarnings("unused")
@@ -133,8 +143,10 @@ public class BasicJdbcPersistentPropertyUnitTests {
@Data
private static class WithCollections {
@Column(value = "some_value", keyColumn = "some_key") List<Integer> someList;
@Column(value = "some_value", keyColumn = "some_key") @MappedCollection(idColumn = "override_id",
keyColumn = "override_key") List<Integer> overrideList;
@Column(value = "some_value") List<Integer> someList;
@Column(value = "some_value") //
@MappedCollection(idColumn = "override_id", keyColumn = "override_key") //
List<Integer> overrideList;
}
}

View File

@@ -37,9 +37,6 @@ public class DependencyTests {
classpath() //
.noJars() //
.including("org.springframework.data.jdbc.**") //
// the following exclusion exclude deprecated classes necessary for backward compatibility.
.excluding("org.springframework.data.jdbc.core.EntityRowMapper") //
.excluding("org.springframework.data.jdbc.core.DefaultDataAccessStrategy") //
.filterClasspath("*target/classes") // exclude test code
.printOnFailure("degraph-jdbc.graphml"),
JCheck.violationFree());
@@ -52,9 +49,6 @@ public class DependencyTests {
classpath() //
// include only Spring Data related classes (for example no JDK code)
.including("org.springframework.data.**") //
// the following exclusion exclude deprecated classes necessary for backward compatibility.
.excluding("org.springframework.data.jdbc.core.EntityRowMapper") //
.excluding("org.springframework.data.jdbc.core.DefaultDataAccessStrategy") //
.filterClasspath(new AbstractFunction1<String, Object>() {
@Override
public Object apply(String s) { //

View File

@@ -22,14 +22,10 @@ import static org.mockito.ArgumentMatchers.*;
import static org.mockito.Mockito.*;
import static org.springframework.data.relational.core.sql.SqlIdentifier.*;
import java.util.Collections;
import org.apache.ibatis.exceptions.PersistenceException;
import org.apache.ibatis.session.SqlSession;
import org.junit.Before;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
import org.mockito.Mockito;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;
import org.springframework.data.jdbc.core.PropertyPathTestingUtils;
@@ -39,8 +35,8 @@ import org.springframework.data.jdbc.core.mapping.JdbcMappingContext;
import org.springframework.data.mapping.PersistentPropertyPath;
import org.springframework.data.relational.core.mapping.RelationalMappingContext;
import org.springframework.data.relational.core.mapping.RelationalPersistentProperty;
import org.springframework.data.relational.domain.Identifier;
import org.springframework.data.relational.core.sql.IdentifierProcessing;
import org.springframework.data.relational.domain.Identifier;
/**
* Unit tests for the {@link MyBatisDataAccessStrategy}, mainly ensuring that the correct statements get's looked up.
@@ -71,7 +67,7 @@ public class MyBatisDataAccessStrategyUnitTests {
@Test // DATAJDBC-123
public void insert() {
accessStrategy.insert("x", String.class, Collections.singletonMap(unquoted("key"), "value"));
accessStrategy.insert("x", String.class, Identifier.from(singletonMap(unquoted("key"), "value")));
verify(session).insert(eq("java.lang.StringMapper.insert"), captor.capture());
@@ -268,35 +264,6 @@ public class MyBatisDataAccessStrategyUnitTests {
);
}
@SuppressWarnings("unchecked")
@Test // DATAJDBC-123
public void findAllByProperty() {
RelationalPersistentProperty property = mock(RelationalPersistentProperty.class, Mockito.RETURNS_DEEP_STUBS);
when(property.getOwner().getType()).thenReturn((Class) String.class);
doReturn(Number.class).when(property).getType();
doReturn("propertyName").when(property).getName();
accessStrategy.findAllByProperty("id", property);
verify(session).selectList(eq("java.lang.StringMapper.findAllByProperty-propertyName"), captor.capture());
assertThat(captor.getValue()) //
.isNotNull() //
.extracting( //
MyBatisContext::getInstance, //
MyBatisContext::getId, //
MyBatisContext::getDomainType, //
c -> c.get("key") //
).containsExactly( //
null, //
"id", //
Number.class, //
null //
);
}
@SuppressWarnings("unchecked")
@Test // DATAJDBC-384
public void findAllByPath() {
@@ -333,29 +300,6 @@ public class MyBatisDataAccessStrategyUnitTests {
);
}
@SuppressWarnings("unchecked")
@Test // DATAJDBC-384
public void findAllByPathFallsBackToFindAllByProperty() {
RelationalPersistentProperty property = mock(RelationalPersistentProperty.class, RETURNS_DEEP_STUBS);
PersistentPropertyPath path = mock(PersistentPropertyPath.class, RETURNS_DEEP_STUBS);
when(path.getBaseProperty()).thenReturn(property);
when(property.getOwner().getType()).thenReturn((Class) String.class);
when(path.getRequiredLeafProperty()).thenReturn(property);
when(property.getType()).thenReturn((Class) Number.class);
when(path.toDotPath()).thenReturn("dot.path");
when(session.selectList(any(), any())).thenThrow(PersistenceException.class).thenReturn(emptyList());
accessStrategy.findAllByPath(Identifier.empty(), path);
verify(session, times(2)).selectList(any(), any());
}
@Test // DATAJDBC-123
public void existsById() {

View File

@@ -104,8 +104,7 @@ public class BasicRelationalPersistentProperty extends AnnotationBasedPersistent
.map(this::createSqlIdentifier)); //
this.collectionKeyColumnName = Lazy.of(() -> Optionals //
.toStream(Optional.ofNullable(findAnnotation(MappedCollection.class)).map(MappedCollection::keyColumn), //
Optional.ofNullable(findAnnotation(Column.class)).map(Column::keyColumn)) //
.toStream(Optional.ofNullable(findAnnotation(MappedCollection.class)).map(MappedCollection::keyColumn)) //
.filter(StringUtils::hasText).findFirst() //
.map(this::createSqlIdentifier) //
.orElseGet(() -> createDerivedSqlIdentifier(namingStrategy.getKeyColumn(this))));
@@ -164,16 +163,6 @@ public class BasicRelationalPersistentProperty extends AnnotationBasedPersistent
return (RelationalPersistentEntity<?>) super.getOwner();
}
/*
* (non-Javadoc)
* @see org.springframework.data.relational.core.mapping.RelationalPersistentProperty#getReverseColumnName()
*/
@Override
public SqlIdentifier getReverseColumnName() {
return collectionIdColumnName.get()
.orElseGet(() -> createDerivedSqlIdentifier(this.namingStrategy.getReverseColumnName(this)));
}
/*
* (non-Javadoc)
* @see org.springframework.data.relational.core.mapping.RelationalPersistentProperty#getReverseColumnName(org.springframework.data.relational.core.mapping.PersistentPropertyPathExtension)

View File

@@ -38,11 +38,4 @@ public @interface Column {
*/
String value() default "";
/**
* The column name for key columns of List or Map collections.
*
* @deprecated since 1.1, was used for collection mapping. Use {@link MappedCollection} instead of this.
*/
@Deprecated
String keyColumn() default "";
}

View File

@@ -40,16 +40,7 @@ public interface RelationalPersistentProperty extends PersistentProperty<Relatio
@Override
RelationalPersistentEntity<?> getOwner();
/**
* @return
* @deprecated Use {@link #getReverseColumnName(PersistentPropertyPathExtension)} instead.
*/
@Deprecated
SqlIdentifier getReverseColumnName();
default SqlIdentifier getReverseColumnName(PersistentPropertyPathExtension path) {
return getReverseColumnName();
}
SqlIdentifier getReverseColumnName(PersistentPropertyPathExtension path);
@Nullable
SqlIdentifier getKeyColumn();

View File

@@ -1,66 +0,0 @@
/*
* Copyright 2018-2020 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.relational.domain.support;
import lombok.RequiredArgsConstructor;
import org.springframework.context.ApplicationListener;
import org.springframework.core.Ordered;
import org.springframework.data.auditing.IsNewAwareAuditingHandler;
import org.springframework.data.relational.core.mapping.event.BeforeSaveEvent;
/**
* Spring JDBC event listener to capture auditing information on persisting and updating entities.
*
* @author Kazuki Shimizu
* @author Jens Schauder
* @author Oliver Gierke
* @deprecated since 1.1, use {@link RelationalAuditingCallback} instead.
*/
@Deprecated
@RequiredArgsConstructor
public class RelationalAuditingEventListener implements ApplicationListener<BeforeSaveEvent>, Ordered {
/**
* The order used for this {@link org.springframework.context.event.EventListener}. Ordering ensures that this
* {@link ApplicationListener} will run before other listeners without a specified priority.
*
* @see org.springframework.core.annotation.Order
* @see Ordered
*/
public static final int AUDITING_ORDER = 100;
private final IsNewAwareAuditingHandler handler;
/**
* {@inheritDoc}
*
* @param event a notification event for indicating before save
*/
@Override
public void onApplicationEvent(BeforeSaveEvent event) {
handler.markAudited(event.getEntity());
}
/*
* (non-Javadoc)
* @see org.springframework.core.Ordered#getOrder()
*/
@Override
public int getOrder() {
return AUDITING_ORDER;
}
}

View File

@@ -18,6 +18,7 @@ package org.springframework.data.relational.core.mapping;
import static org.assertj.core.api.Assertions.*;
import static org.springframework.data.relational.core.sql.SqlIdentifier.*;
import junit.framework.AssertionFailedError;
import lombok.Data;
import java.time.LocalDateTime;
@@ -27,9 +28,11 @@ import java.util.List;
import java.util.UUID;
import java.util.function.BiConsumer;
import org.assertj.core.api.Assertions;
import org.assertj.core.api.SoftAssertions;
import org.junit.Test;
import org.springframework.data.annotation.Id;
import org.springframework.data.mapping.PersistentPropertyPath;
import org.springframework.data.mapping.PropertyHandler;
import org.springframework.data.relational.core.mapping.Embedded.OnEmpty;
@@ -60,7 +63,9 @@ public class BasicRelationalPersistentPropertyUnitTests {
RelationalPersistentProperty listProperty = entity.getRequiredPersistentProperty("someList");
assertThat(listProperty.getReverseColumnName()).isEqualTo(quoted("dummy_column_name"));
PersistentPropertyPath<RelationalPersistentProperty> path = context.findPersistentPropertyPaths(DummyEntity.class, p -> p.getName().equals("someList")).getFirst().orElseThrow(() -> new AssertionFailedError("Couldn't find path for 'someList'"));
assertThat(listProperty.getReverseColumnName(new PersistentPropertyPathExtension(context, path))).isEqualTo(quoted("dummy_column_name"));
assertThat(listProperty.getKeyColumn()).isEqualTo(quoted("dummy_key_column_name"));
}