diff --git a/pom.xml b/pom.xml index f6359158d4..19031b843c 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ org.springframework.data spring-data-relational-parent - 2.0.0.BUILD-SNAPSHOT + 2.0.0.DATAJDBC-480-SNAPSHOT pom Spring Data Relational Parent diff --git a/spring-data-jdbc-distribution/pom.xml b/spring-data-jdbc-distribution/pom.xml index 858a5f4b4b..eba94ea761 100644 --- a/spring-data-jdbc-distribution/pom.xml +++ b/spring-data-jdbc-distribution/pom.xml @@ -14,7 +14,7 @@ org.springframework.data spring-data-relational-parent - 2.0.0.BUILD-SNAPSHOT + 2.0.0.DATAJDBC-480-SNAPSHOT ../pom.xml diff --git a/spring-data-jdbc/pom.xml b/spring-data-jdbc/pom.xml index 1fdf3e615a..0a92fc2142 100644 --- a/spring-data-jdbc/pom.xml +++ b/spring-data-jdbc/pom.xml @@ -6,7 +6,7 @@ 4.0.0 spring-data-jdbc - 2.0.0.BUILD-SNAPSHOT + 2.0.0.DATAJDBC-480-SNAPSHOT Spring Data JDBC Spring Data module for JDBC repositories. @@ -15,7 +15,7 @@ org.springframework.data spring-data-relational-parent - 2.0.0.BUILD-SNAPSHOT + 2.0.0.DATAJDBC-480-SNAPSHOT diff --git a/spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/CascadingDataAccessStrategy.java b/spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/CascadingDataAccessStrategy.java deleted file mode 100644 index 98b6763563..0000000000 --- a/spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/CascadingDataAccessStrategy.java +++ /dev/null @@ -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 strategies) { - super(strategies); - } - -} diff --git a/spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/DataAccessStrategy.java b/spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/DataAccessStrategy.java deleted file mode 100644 index ee713ca097..0000000000 --- a/spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/DataAccessStrategy.java +++ /dev/null @@ -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 {} diff --git a/spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/DefaultDataAccessStrategy.java b/spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/DefaultDataAccessStrategy.java deleted file mode 100644 index 1af4398746..0000000000 --- a/spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/DefaultDataAccessStrategy.java +++ /dev/null @@ -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); - } - -} diff --git a/spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/DelegatingDataAccessStrategy.java b/spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/DelegatingDataAccessStrategy.java deleted file mode 100644 index 17fea71273..0000000000 --- a/spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/DelegatingDataAccessStrategy.java +++ /dev/null @@ -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 {} diff --git a/spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/EntityRowMapper.java b/spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/EntityRowMapper.java deleted file mode 100644 index b2d1c6dcbc..0000000000 --- a/spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/EntityRowMapper.java +++ /dev/null @@ -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 extends org.springframework.data.jdbc.core.convert.EntityRowMapper { - - public EntityRowMapper(RelationalPersistentEntity entity, JdbcConverter converter, - DataAccessStrategy accessStrategy) { - super(entity, converter); - } -} diff --git a/spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/convert/CascadingDataAccessStrategy.java b/spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/convert/CascadingDataAccessStrategy.java index a3dea2da3e..703f292227 100644 --- a/spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/convert/CascadingDataAccessStrategy.java +++ b/spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/convert/CascadingDataAccessStrategy.java @@ -17,7 +17,6 @@ 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.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 CascadingDataAccessStrategy(List strategies) { 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 Object insert(T instance, Class domainType, Map 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 Iterable findAllByPath(Identifier identifier, 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 Iterable 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) diff --git a/spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/convert/DataAccessStrategy.java b/spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/convert/DataAccessStrategy.java index f30a97cdc7..3adb0c7a47 100644 --- a/spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/convert/DataAccessStrategy.java +++ b/spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/convert/DataAccessStrategy.java @@ -23,7 +23,6 @@ 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 @@ */ 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 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 - Object insert(T instance, Class domainType, Map 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 Object insert(T instance, Class domainType, Identifier identifier) { - return insert(instance, domainType, identifier.toMap()); - } + Object insert(T instance, Class domainType, Identifier identifier); /** * Updates the data of a single entity in the database. Referenced entities don't get handled. @@ -192,22 +174,8 @@ default Object insert(T instance, Class domainType, Identifier identifier * @see org.springframework.data.jdbc.core.RelationResolver#findAllByPath(org.springframework.data.relational.domain.Identifier, org.springframework.data.mapping.PersistentPropertyPath) */ @Override - default Iterable findAllByPath(Identifier identifier, - PersistentPropertyPath 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 - Iterable findAllByProperty(Object rootId, RelationalPersistentProperty property); + Iterable findAllByPath(Identifier identifier, + PersistentPropertyPath path); /** * returns if a row with the given id exists for the given type. diff --git a/spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/convert/DefaultDataAccessStrategy.java b/spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/convert/DefaultDataAccessStrategy.java index 30ea26f4c3..630c4ac42b 100644 --- a/spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/convert/DefaultDataAccessStrategy.java +++ b/spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/convert/DefaultDataAccessStrategy.java @@ -95,16 +95,6 @@ public DefaultDataAccessStrategy(SqlGeneratorSource sqlGeneratorSource, Relation 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 Object insert(T instance, Class domainType, Map 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 @@ private SqlParameterSource createParameterSource(Identifier identifier, Identifi 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 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) diff --git a/spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/convert/DelegatingDataAccessStrategy.java b/spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/convert/DelegatingDataAccessStrategy.java index 611cecb428..f61e41a016 100644 --- a/spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/convert/DelegatingDataAccessStrategy.java +++ b/spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/convert/DelegatingDataAccessStrategy.java @@ -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 Object insert(T instance, Class domainType, Map 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 Iterable findAllByPath(Identifier identifier, 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 Iterable 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) diff --git a/spring-data-jdbc/src/main/java/org/springframework/data/jdbc/mybatis/MyBatisDataAccessStrategy.java b/spring-data-jdbc/src/main/java/org/springframework/data/jdbc/mybatis/MyBatisDataAccessStrategy.java index 48546c2321..c89bdd2a8f 100644 --- a/spring-data-jdbc/src/main/java/org/springframework/data/jdbc/mybatis/MyBatisDataAccessStrategy.java +++ b/spring-data-jdbc/src/main/java/org/springframework/data/jdbc/mybatis/MyBatisDataAccessStrategy.java @@ -22,7 +22,6 @@ 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 void setNamespaceStrategy(NamespaceStrategy namespaceStrategy) { this.namespaceStrategy = namespaceStrategy; } - /* - * (non-Javadoc) - * @see org.springframework.data.jdbc.core.DataAccessStrategy#insert(java.lang.Object, java.lang.Class, java.util.Map) - */ - @Override - public Object insert(T instance, Class domainType, Map 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 Iterable findAllByPath(Identifier identifier, 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) { - - 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 Iterable findAllByProperty(Object rootId, RelationalPersistentProperty property) { + return sqlSession().selectList(statementName, + new MyBatisContext(identifier, null, path.getRequiredLeafProperty().getType())); - String statement = namespace(property.getOwner().getType()) + ".findAllByProperty-" + property.getName(); - MyBatisContext parameter = new MyBatisContext(rootId, null, property.getType(), Collections.emptyMap()); - return sqlSession().selectList(statement, parameter); } /* diff --git a/spring-data-jdbc/src/main/java/org/springframework/data/jdbc/repository/RowMapperMap.java b/spring-data-jdbc/src/main/java/org/springframework/data/jdbc/repository/RowMapperMap.java deleted file mode 100644 index 710699fd6e..0000000000 --- a/spring-data-jdbc/src/main/java/org/springframework/data/jdbc/repository/RowMapperMap.java +++ /dev/null @@ -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 RowMapper rowMapperFor(Class type) { - return null; - } - - @Override - public RowMapper getRowMapper(Class type) { - return null; - } - }; - - @Nullable - RowMapper rowMapperFor(Class type); - - @Override - default RowMapper getRowMapper(Class type) { - return rowMapperFor(type); - } -} diff --git a/spring-data-jdbc/src/main/java/org/springframework/data/jdbc/repository/config/ConfigurableRowMapperMap.java b/spring-data-jdbc/src/main/java/org/springframework/data/jdbc/repository/config/ConfigurableRowMapperMap.java deleted file mode 100644 index a71c19929b..0000000000 --- a/spring-data-jdbc/src/main/java/org/springframework/data/jdbc/repository/config/ConfigurableRowMapperMap.java +++ /dev/null @@ -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, 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 ConfigurableRowMapperMap register(Class type, RowMapper 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 the type to be produced by the returned {@link RowMapper}. - * @return Guaranteed to be not {@code null}. - */ - @SuppressWarnings("unchecked") - @Nullable - public RowMapper rowMapperFor(Class type) { - - Assert.notNull(type, "Type must not be null"); - - RowMapper candidate = (RowMapper) rowMappers.get(type); - - if (candidate == null) { - - for (Map.Entry, RowMapper> entry : rowMappers.entrySet()) { - - if (type.isAssignableFrom(entry.getKey())) { - candidate = (RowMapper) entry.getValue(); - } - } - } - - return candidate; - } -} diff --git a/spring-data-jdbc/src/main/java/org/springframework/data/jdbc/repository/config/JdbcAuditingRegistrar.java b/spring-data-jdbc/src/main/java/org/springframework/data/jdbc/repository/config/JdbcAuditingRegistrar.java index 4100ae3a84..0a9c488bf5 100644 --- a/spring-data-jdbc/src/main/java/org/springframework/data/jdbc/repository/config/JdbcAuditingRegistrar.java +++ b/spring-data-jdbc/src/main/java/org/springframework/data/jdbc/repository/config/JdbcAuditingRegistrar.java @@ -25,7 +25,6 @@ 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 @@ protected BeanDefinitionBuilder getAuditHandlerBeanDefinitionBuilder(AuditingCon } /** - * Register the bean definition of {@link RelationalAuditingEventListener}. {@inheritDoc} + * Register the bean definition of {@link RelationalAuditingCallback}. {@inheritDoc} * * @see AuditingBeanDefinitionRegistrarSupport#registerAuditListenerBeanDefinition(BeanDefinition, * BeanDefinitionRegistry) diff --git a/spring-data-jdbc/src/main/java/org/springframework/data/jdbc/repository/config/JdbcConfiguration.java b/spring-data-jdbc/src/main/java/org/springframework/data/jdbc/repository/config/JdbcConfiguration.java deleted file mode 100644 index 55d790f34b..0000000000 --- a/spring-data-jdbc/src/main/java/org/springframework/data/jdbc/repository/config/JdbcConfiguration.java +++ /dev/null @@ -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) { - - 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; - } -} diff --git a/spring-data-jdbc/src/main/java/org/springframework/data/jdbc/repository/support/JdbcQueryMethod.java b/spring-data-jdbc/src/main/java/org/springframework/data/jdbc/repository/support/JdbcQueryMethod.java index aad430612f..960103fa88 100644 --- a/spring-data-jdbc/src/main/java/org/springframework/data/jdbc/repository/support/JdbcQueryMethod.java +++ b/spring-data-jdbc/src/main/java/org/springframework/data/jdbc/repository/support/JdbcQueryMethod.java @@ -37,10 +37,8 @@ * @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; diff --git a/spring-data-jdbc/src/main/java/org/springframework/data/jdbc/repository/support/JdbcRepositoryFactory.java b/spring-data-jdbc/src/main/java/org/springframework/data/jdbc/repository/support/JdbcRepositoryFactory.java index a3a8dfbb6c..74a3fac8a5 100644 --- a/spring-data-jdbc/src/main/java/org/springframework/data/jdbc/repository/support/JdbcRepositoryFactory.java +++ b/spring-data-jdbc/src/main/java/org/springframework/data/jdbc/repository/support/JdbcRepositoryFactory.java @@ -22,7 +22,6 @@ 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 void setQueryMappingConfiguration(QueryMappingConfiguration queryMappingC 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 EntityInformation getEntityInformation(Class aClass) { diff --git a/spring-data-jdbc/src/main/java/org/springframework/data/jdbc/repository/support/JdbcRepositoryFactoryBean.java b/spring-data-jdbc/src/main/java/org/springframework/data/jdbc/repository/support/JdbcRepositoryFactoryBean.java index 5335b04159..d7b591b323 100644 --- a/spring-data-jdbc/src/main/java/org/springframework/data/jdbc/repository/support/JdbcRepositoryFactoryBean.java +++ b/spring-data-jdbc/src/main/java/org/springframework/data/jdbc/repository/support/JdbcRepositoryFactoryBean.java @@ -26,7 +26,6 @@ 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 void setQueryMappingConfiguration(QueryMappingConfiguration queryMappingC 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; } diff --git a/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/core/convert/CascadingDataAccessStrategyUnitTests.java b/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/core/convert/CascadingDataAccessStrategyUnitTests.java index aa7e41284d..bb231ee67a 100644 --- a/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/core/convert/CascadingDataAccessStrategyUnitTests.java +++ b/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/core/convert/CascadingDataAccessStrategyUnitTests.java @@ -24,9 +24,10 @@ 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 void findByFailsIfAllStrategiesFail() { @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 findAll = access.findAllByProperty(23L, mock(RelationalPersistentProperty.class)); + Iterable findAll = access.findAllByPath(identifier, mock(PersistentPropertyPath.class)); assertThat(findAll).containsExactly("success"); } diff --git a/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/core/convert/DefaultDataAccessStrategyUnitTests.java b/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/core/convert/DefaultDataAccessStrategyUnitTests.java index 348864dd62..273b0a79dc 100644 --- a/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/core/convert/DefaultDataAccessStrategyUnitTests.java +++ b/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/core/convert/DefaultDataAccessStrategyUnitTests.java @@ -39,6 +39,7 @@ 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 void additionalParameterForIdDoesNotLeadToDuplicateParameters() { 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 void additionalParametersGetAddedToStatement() { 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 void considersConfiguredWriteConverter() { 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)); diff --git a/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/core/convert/EntityRowMapperUnitTests.java b/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/core/convert/EntityRowMapperUnitTests.java index b9d1d7c189..b13d55f1b6 100644 --- a/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/core/convert/EntityRowMapperUnitTests.java +++ b/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/core/convert/EntityRowMapperUnitTests.java @@ -874,14 +874,14 @@ private EntityRowMapper createRowMapper(Class type, NamingStrategy nam Set> 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)); diff --git a/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/core/mapping/BasicJdbcPersistentPropertyUnitTests.java b/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/core/mapping/BasicJdbcPersistentPropertyUnitTests.java index 095e695067..04b897f740 100644 --- a/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/core/mapping/BasicJdbcPersistentPropertyUnitTests.java +++ b/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/core/mapping/BasicJdbcPersistentPropertyUnitTests.java @@ -18,6 +18,7 @@ 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.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 void detectsAnnotatedColumnName() { @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 void detectsKeyColumnOverrideNameFromMappedCollectionAnnotation() { 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 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 List getListGetter() { @Data private static class WithCollections { - @Column(value = "some_value", keyColumn = "some_key") List someList; - @Column(value = "some_value", keyColumn = "some_key") @MappedCollection(idColumn = "override_id", - keyColumn = "override_key") List overrideList; + @Column(value = "some_value") List someList; + + @Column(value = "some_value") // + @MappedCollection(idColumn = "override_id", keyColumn = "override_key") // + List overrideList; } } diff --git a/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/degraph/DependencyTests.java b/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/degraph/DependencyTests.java index c1da6307d7..fdebafa51c 100644 --- a/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/degraph/DependencyTests.java +++ b/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/degraph/DependencyTests.java @@ -37,9 +37,6 @@ public void cycleFree() { 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 void acrossModules() { 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() { @Override public Object apply(String s) { // diff --git a/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/mybatis/MyBatisDataAccessStrategyUnitTests.java b/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/mybatis/MyBatisDataAccessStrategyUnitTests.java index 7d4c436bbc..9f393923a1 100644 --- a/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/mybatis/MyBatisDataAccessStrategyUnitTests.java +++ b/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/mybatis/MyBatisDataAccessStrategyUnitTests.java @@ -22,14 +22,10 @@ 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.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 void before() { @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 void findAllById() { ); } - @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 void findAllByPath() { ); } - @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() { diff --git a/spring-data-relational/pom.xml b/spring-data-relational/pom.xml index 0a529399c3..ca57d806d2 100644 --- a/spring-data-relational/pom.xml +++ b/spring-data-relational/pom.xml @@ -6,7 +6,7 @@ 4.0.0 spring-data-relational - 2.0.0.BUILD-SNAPSHOT + 2.0.0.DATAJDBC-480-SNAPSHOT Spring Data Relational Spring Data Relational support @@ -14,7 +14,7 @@ org.springframework.data spring-data-relational-parent - 2.0.0.BUILD-SNAPSHOT + 2.0.0.DATAJDBC-480-SNAPSHOT diff --git a/spring-data-relational/src/main/java/org/springframework/data/relational/core/conversion/BasicRelationalConverter.java b/spring-data-relational/src/main/java/org/springframework/data/relational/core/conversion/BasicRelationalConverter.java index c288e03b0f..efbd006967 100644 --- a/spring-data-relational/src/main/java/org/springframework/data/relational/core/conversion/BasicRelationalConverter.java +++ b/spring-data-relational/src/main/java/org/springframework/data/relational/core/conversion/BasicRelationalConverter.java @@ -26,13 +26,13 @@ import org.springframework.core.convert.support.DefaultConversionService; import org.springframework.data.convert.CustomConversions; import org.springframework.data.convert.CustomConversions.StoreConversions; -import org.springframework.data.convert.EntityInstantiators; import org.springframework.data.mapping.PersistentEntity; import org.springframework.data.mapping.PersistentProperty; import org.springframework.data.mapping.PersistentPropertyAccessor; import org.springframework.data.mapping.PreferredConstructor.Parameter; import org.springframework.data.mapping.context.MappingContext; import org.springframework.data.mapping.model.ConvertingPropertyAccessor; +import org.springframework.data.mapping.model.EntityInstantiators; import org.springframework.data.mapping.model.ParameterValueProvider; import org.springframework.data.mapping.model.SimpleTypeHolder; import org.springframework.data.relational.core.mapping.RelationalPersistentEntity; diff --git a/spring-data-relational/src/main/java/org/springframework/data/relational/core/mapping/BasicRelationalPersistentProperty.java b/spring-data-relational/src/main/java/org/springframework/data/relational/core/mapping/BasicRelationalPersistentProperty.java index 68bd4896a7..d218391118 100644 --- a/spring-data-relational/src/main/java/org/springframework/data/relational/core/mapping/BasicRelationalPersistentProperty.java +++ b/spring-data-relational/src/main/java/org/springframework/data/relational/core/mapping/BasicRelationalPersistentProperty.java @@ -104,8 +104,7 @@ public BasicRelationalPersistentProperty(Property property, PersistentEntity 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 RelationalPersistentEntity getOwner() { 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) diff --git a/spring-data-relational/src/main/java/org/springframework/data/relational/core/mapping/Column.java b/spring-data-relational/src/main/java/org/springframework/data/relational/core/mapping/Column.java index 3a81753f3f..1016b67f7e 100644 --- a/spring-data-relational/src/main/java/org/springframework/data/relational/core/mapping/Column.java +++ b/spring-data-relational/src/main/java/org/springframework/data/relational/core/mapping/Column.java @@ -38,11 +38,4 @@ */ 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 ""; } diff --git a/spring-data-relational/src/main/java/org/springframework/data/relational/core/mapping/RelationalPersistentProperty.java b/spring-data-relational/src/main/java/org/springframework/data/relational/core/mapping/RelationalPersistentProperty.java index 92d6c9cf9c..42c20f00a1 100644 --- a/spring-data-relational/src/main/java/org/springframework/data/relational/core/mapping/RelationalPersistentProperty.java +++ b/spring-data-relational/src/main/java/org/springframework/data/relational/core/mapping/RelationalPersistentProperty.java @@ -40,16 +40,7 @@ public interface RelationalPersistentProperty extends PersistentProperty 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(); diff --git a/spring-data-relational/src/main/java/org/springframework/data/relational/domain/support/RelationalAuditingEventListener.java b/spring-data-relational/src/main/java/org/springframework/data/relational/domain/support/RelationalAuditingEventListener.java deleted file mode 100644 index e236b3b820..0000000000 --- a/spring-data-relational/src/main/java/org/springframework/data/relational/domain/support/RelationalAuditingEventListener.java +++ /dev/null @@ -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, 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; - } -} diff --git a/spring-data-relational/src/main/java/org/springframework/data/relational/repository/query/DtoInstantiatingConverter.java b/spring-data-relational/src/main/java/org/springframework/data/relational/repository/query/DtoInstantiatingConverter.java index 81e5d906f1..2a1e5cb0aa 100755 --- a/spring-data-relational/src/main/java/org/springframework/data/relational/repository/query/DtoInstantiatingConverter.java +++ b/spring-data-relational/src/main/java/org/springframework/data/relational/repository/query/DtoInstantiatingConverter.java @@ -16,8 +16,6 @@ package org.springframework.data.relational.repository.query; import org.springframework.core.convert.converter.Converter; -import org.springframework.data.convert.EntityInstantiator; -import org.springframework.data.convert.EntityInstantiators; import org.springframework.data.mapping.PersistentEntity; import org.springframework.data.mapping.PersistentProperty; import org.springframework.data.mapping.PersistentPropertyAccessor; @@ -25,6 +23,8 @@ import org.springframework.data.mapping.PreferredConstructor.Parameter; import org.springframework.data.mapping.SimplePropertyHandler; import org.springframework.data.mapping.context.MappingContext; +import org.springframework.data.mapping.model.EntityInstantiator; +import org.springframework.data.mapping.model.EntityInstantiators; import org.springframework.data.mapping.model.ParameterValueProvider; import org.springframework.data.relational.core.mapping.RelationalPersistentEntity; import org.springframework.data.relational.core.mapping.RelationalPersistentProperty; @@ -46,7 +46,7 @@ public class DtoInstantiatingConverter implements Converter { * * @param dtoType must not be {@literal null}. * @param context must not be {@literal null}. - * @param instantiators must not be {@literal null}. + * @param instantiator must not be {@literal null}. */ public DtoInstantiatingConverter(Class dtoType, MappingContext, ? extends RelationalPersistentProperty> context, diff --git a/spring-data-relational/src/test/java/org/springframework/data/relational/core/mapping/BasicRelationalPersistentPropertyUnitTests.java b/spring-data-relational/src/test/java/org/springframework/data/relational/core/mapping/BasicRelationalPersistentPropertyUnitTests.java index d7b5b4439f..2d0e4686f8 100644 --- a/spring-data-relational/src/test/java/org/springframework/data/relational/core/mapping/BasicRelationalPersistentPropertyUnitTests.java +++ b/spring-data-relational/src/test/java/org/springframework/data/relational/core/mapping/BasicRelationalPersistentPropertyUnitTests.java @@ -18,6 +18,7 @@ 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.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 void detectsAnnotatedColumnAndKeyName() { RelationalPersistentProperty listProperty = entity.getRequiredPersistentProperty("someList"); - assertThat(listProperty.getReverseColumnName()).isEqualTo(quoted("dummy_column_name")); + PersistentPropertyPath 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")); }