From d5558d9def2d22e0d96737fea471b6d360ae9731 Mon Sep 17 00:00:00 2001 From: Jens Schauder Date: Tue, 15 Jan 2019 09:27:46 +0100 Subject: [PATCH] DATAJDBC-282 - Removed JdbcRepository. The decision was made not to offer `insert` and `update` as part of the repository interface. It stays available as part of the `JdbcAggregateTemplate` which may be used directly or inside of a custom method implementation. --- .../data/jdbc/core/JdbcRepository.java | 38 ------- .../support/SimpleJdbcRepository.java | 21 +--- ...ositoryInsertExistingIntegrationTests.java | 102 ------------------ .../JdbcRepositoryIntegrationTests.java | 13 +-- 4 files changed, 3 insertions(+), 171 deletions(-) delete mode 100644 spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/JdbcRepository.java delete mode 100644 spring-data-jdbc/src/test/java/org/springframework/data/jdbc/repository/JdbcRepositoryInsertExistingIntegrationTests.java diff --git a/spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/JdbcRepository.java b/spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/JdbcRepository.java deleted file mode 100644 index 2c2a7bc61..000000000 --- a/spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/JdbcRepository.java +++ /dev/null @@ -1,38 +0,0 @@ -package org.springframework.data.jdbc.core; - -import org.springframework.data.repository.Repository; - -/** - * Jdbc repository for dedicated insert(), update() and upsert() sql functions. Other than - * {@link org.springframework.data.jdbc.repository.support.SimpleJdbcRepository} there should be bypassing of the isNew - * check. - * - * @author Thomas Lang - * @since 1.1 - */ -public interface JdbcRepository extends Repository { - - /** - * Dedicated insert function. This skips the test if the aggregate root is new and makes an insert. - *

- * This is useful if the client provides an id for new aggregate roots. - *

- * - * @param aggregateRoot the aggregate root to be saved in the database. Must not be {@code null}. - * @param Type of the aggregate root. - * @return the saved aggregate root. If the provided aggregate root was immutable and a value needed changing, e.g. - * the id this will be a new instance. - */ - S insert(S aggregateRoot); - - /** - * Dedicated update function. This skips the test if the aggregate root is new or not and always performs an update - * operation. - * - * @param aggregateRoot the aggregate root to be saved in the database. Must not be {@code null}. - * @param Type of the aggregate root. - * @return the saved aggregate root. If the provided aggregate root was immutable and a value needed changing, e.g. - * the id this will be a new instance. - */ - S update(S aggregateRoot); -} diff --git a/spring-data-jdbc/src/main/java/org/springframework/data/jdbc/repository/support/SimpleJdbcRepository.java b/spring-data-jdbc/src/main/java/org/springframework/data/jdbc/repository/support/SimpleJdbcRepository.java index 836de3992..36d88c072 100644 --- a/spring-data-jdbc/src/main/java/org/springframework/data/jdbc/repository/support/SimpleJdbcRepository.java +++ b/spring-data-jdbc/src/main/java/org/springframework/data/jdbc/repository/support/SimpleJdbcRepository.java @@ -22,7 +22,6 @@ import java.util.Optional; import java.util.stream.Collectors; import org.springframework.data.jdbc.core.JdbcAggregateOperations; -import org.springframework.data.jdbc.core.JdbcRepository; import org.springframework.data.mapping.PersistentEntity; import org.springframework.data.repository.CrudRepository; import org.springframework.data.util.Streamable; @@ -32,7 +31,7 @@ import org.springframework.data.util.Streamable; * @author Oliver Gierke */ @RequiredArgsConstructor -public class SimpleJdbcRepository implements CrudRepository, JdbcRepository { +public class SimpleJdbcRepository implements CrudRepository { private final @NonNull JdbcAggregateOperations entityOperations; @@ -137,22 +136,4 @@ public class SimpleJdbcRepository implements CrudRepository, JdbcR public void deleteAll() { entityOperations.deleteAll(entity.getType()); } - - /* - * (non-Javadoc) - * @see org.springframework.data.repository.JdbcRepository#insert(T t) - */ - @Override - public S insert(S var1) { - return entityOperations.insert(var1); - } - - /* - * (non-Javadoc) - * @see org.springframework.data.repository.JdbcRepository#update(T t) - */ - @Override - public S update(S aggregateRoot) { - return entityOperations.update(aggregateRoot); - } } diff --git a/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/repository/JdbcRepositoryInsertExistingIntegrationTests.java b/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/repository/JdbcRepositoryInsertExistingIntegrationTests.java deleted file mode 100644 index 6b88949ca..000000000 --- a/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/repository/JdbcRepositoryInsertExistingIntegrationTests.java +++ /dev/null @@ -1,102 +0,0 @@ -/* - * Copyright 2017-2019 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 - * - * http://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 static org.assertj.core.api.Assertions.*; - -import lombok.Data; - -import org.junit.ClassRule; -import org.junit.Rule; -import org.junit.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.Import; -import org.springframework.data.annotation.Id; -import org.springframework.data.jdbc.core.JdbcRepository; -import org.springframework.data.jdbc.repository.support.JdbcRepositoryFactory; -import org.springframework.data.jdbc.testing.TestConfiguration; -import org.springframework.data.repository.CrudRepository; -import org.springframework.jdbc.core.JdbcTemplate; -import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.rules.SpringClassRule; -import org.springframework.test.context.junit4.rules.SpringMethodRule; -import org.springframework.test.jdbc.JdbcTestUtils; -import org.springframework.transaction.annotation.Transactional; - -/** - * Very simple use cases for creation and usage of JdbcRepositories. - * - * @author Jens Schauder - */ -@ContextConfiguration -@Transactional -public class JdbcRepositoryInsertExistingIntegrationTests { - - @Configuration - @Import(TestConfiguration.class) - static class Config { - - @Autowired JdbcRepositoryFactory factory; - - @Bean - Class testClass() { - return JdbcRepositoryInsertExistingIntegrationTests.class; - } - - @Bean - DummyEntityRepository dummyEntityRepository() { - return factory.getRepository(DummyEntityRepository.class); - } - - } - - @ClassRule public static final SpringClassRule classRule = new SpringClassRule(); - @Rule public SpringMethodRule methodRule = new SpringMethodRule(); - - @Autowired NamedParameterJdbcTemplate template; - @Autowired DummyEntityRepository repository; - - @Test // DATAJDBC-282 - public void insertAnExistingEntity() { - - DummyEntity existingDummyEntity = createDummyEntity(); - existingDummyEntity.idProp = 123L; - - DummyEntity entity = repository.insert(existingDummyEntity); - - assertThat(JdbcTestUtils.countRowsInTableWhere((JdbcTemplate) template.getJdbcOperations(), "dummy_entity", - "id_Prop = " + existingDummyEntity.getIdProp())).isEqualTo(1); - } - - private static DummyEntity createDummyEntity() { - - DummyEntity entity = new DummyEntity(); - entity.setName("Entity Name"); - return entity; - } - - interface DummyEntityRepository extends CrudRepository, JdbcRepository {} - - @Data - static class DummyEntity { - - String name; - @Id private Long idProp; - } -} diff --git a/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/repository/JdbcRepositoryIntegrationTests.java b/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/repository/JdbcRepositoryIntegrationTests.java index daf0846ee..1c3461ff9 100644 --- a/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/repository/JdbcRepositoryIntegrationTests.java +++ b/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/repository/JdbcRepositoryIntegrationTests.java @@ -28,7 +28,6 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Import; import org.springframework.data.annotation.Id; -import org.springframework.data.jdbc.core.JdbcRepository; import org.springframework.data.jdbc.repository.support.JdbcRepositoryFactory; import org.springframework.data.jdbc.testing.TestConfiguration; import org.springframework.data.repository.CrudRepository; @@ -84,15 +83,6 @@ public class JdbcRepositoryIntegrationTests { "id_Prop = " + entity.getIdProp())).isEqualTo(1); } - @Test // DATAJDBC-282 - public void insertAnEntity() { - - DummyEntity entity = repository.insert(createDummyEntity()); - - assertThat(JdbcTestUtils.countRowsInTableWhere((JdbcTemplate) template.getJdbcOperations(), "dummy_entity", - "id_Prop = " + entity.getIdProp())).isEqualTo(1); - } - @Test // DATAJDBC-95 public void saveAndLoadAnEntity() { @@ -261,7 +251,8 @@ public class JdbcRepositoryIntegrationTests { return entity; } - interface DummyEntityRepository extends CrudRepository, JdbcRepository {} + interface DummyEntityRepository extends CrudRepository { + } @Data static class DummyEntity {