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.
This commit is contained in:
@@ -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<T, ID> extends Repository<T, ID> {
|
||||
|
||||
/**
|
||||
* Dedicated insert function. This skips the test if the aggregate root is new and makes an insert.
|
||||
* <p>
|
||||
* This is useful if the client provides an id for new aggregate roots.
|
||||
* </p>
|
||||
*
|
||||
* @param aggregateRoot the aggregate root to be saved in the database. Must not be {@code null}.
|
||||
* @param <S> 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 extends T> 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 <S> 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 extends T> S update(S aggregateRoot);
|
||||
}
|
||||
@@ -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<T, ID> implements CrudRepository<T, ID>, JdbcRepository<T, ID> {
|
||||
public class SimpleJdbcRepository<T, ID> implements CrudRepository<T, ID> {
|
||||
|
||||
private final @NonNull
|
||||
JdbcAggregateOperations entityOperations;
|
||||
@@ -137,22 +136,4 @@ public class SimpleJdbcRepository<T, ID> implements CrudRepository<T, ID>, JdbcR
|
||||
public void deleteAll() {
|
||||
entityOperations.deleteAll(entity.getType());
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.repository.JdbcRepository#insert(T t)
|
||||
*/
|
||||
@Override
|
||||
public <S extends T> S insert(S var1) {
|
||||
return entityOperations.insert(var1);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.repository.JdbcRepository#update(T t)
|
||||
*/
|
||||
@Override
|
||||
public <S extends T> S update(S aggregateRoot) {
|
||||
return entityOperations.update(aggregateRoot);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<DummyEntity, Long>, JdbcRepository<DummyEntity, Long> {}
|
||||
|
||||
@Data
|
||||
static class DummyEntity {
|
||||
|
||||
String name;
|
||||
@Id private Long idProp;
|
||||
}
|
||||
}
|
||||
@@ -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<DummyEntity, Long>, JdbcRepository<DummyEntity, Long> {}
|
||||
interface DummyEntityRepository extends CrudRepository<DummyEntity, Long> {
|
||||
}
|
||||
|
||||
@Data
|
||||
static class DummyEntity {
|
||||
|
||||
Reference in New Issue
Block a user