DATAJDBC-99 - Adapt changes in CrudRepository.

The method names in the CrudRepository have changed.

Related issue: DATACMNS-944
Original pull request: #5.
This commit is contained in:
Jens Schauder
2017-06-07 15:41:22 +02:00
committed by Oliver Gierke
parent 1af9146f4d
commit 95e033c3cf
7 changed files with 22 additions and 22 deletions

View File

@@ -112,7 +112,7 @@ public class SimpleJdbcRepository<T, ID extends Serializable> implements CrudRep
* @see org.springframework.data.repository.CrudRepository#save(java.lang.Iterable)
*/
@Override
public <S extends T> Iterable<S> save(Iterable<S> entities) {
public <S extends T> Iterable<S> saveAll(Iterable<S> entities) {
List<S> savedEntities = new ArrayList<>();
entities.forEach(e -> savedEntities.add(save(e)));
@@ -124,7 +124,7 @@ public class SimpleJdbcRepository<T, ID extends Serializable> implements CrudRep
* @see org.springframework.data.repository.CrudRepository#findOne(java.io.Serializable)
*/
@Override
public Optional<T> findOne(ID id) {
public Optional<T> findById(ID id) {
return Optional
.ofNullable(operations.queryForObject(sql.getFindOne(), new MapSqlParameterSource("id", id), entityRowMapper));
@@ -135,7 +135,7 @@ public class SimpleJdbcRepository<T, ID extends Serializable> implements CrudRep
* @see org.springframework.data.repository.CrudRepository#exists(java.io.Serializable)
*/
@Override
public boolean exists(ID id) {
public boolean existsById(ID id) {
return operations.queryForObject(sql.getExists(), new MapSqlParameterSource("id", id), Boolean.class);
}
@@ -153,7 +153,7 @@ public class SimpleJdbcRepository<T, ID extends Serializable> implements CrudRep
* @see org.springframework.data.repository.CrudRepository#findAll(java.lang.Iterable)
*/
@Override
public Iterable<T> findAll(Iterable<ID> ids) {
public Iterable<T> findAllById(Iterable<ID> ids) {
return operations.query(sql.getFindAllInList(), new MapSqlParameterSource("ids", ids), entityRowMapper);
}
@@ -171,7 +171,7 @@ public class SimpleJdbcRepository<T, ID extends Serializable> implements CrudRep
* @see org.springframework.data.repository.CrudRepository#delete(java.io.Serializable)
*/
@Override
public void delete(ID id) {
public void deleteById(ID id) {
doDelete(Identifier.of(id), Optional.empty());
}
@@ -189,7 +189,7 @@ public class SimpleJdbcRepository<T, ID extends Serializable> implements CrudRep
* @see org.springframework.data.repository.CrudRepository#delete(java.lang.Iterable)
*/
@Override
public void delete(Iterable<? extends T> entities) {
public void deleteAll(Iterable<? extends T> entities) {
List<ID> idList = Streamable.of(entities).stream() //
.map(e -> entityInformation.getRequiredId(e)) //

View File

@@ -25,7 +25,7 @@ import org.springframework.data.repository.core.support.PersistentEntityInformat
* @author Jens Schauder
* @since 2.0
*/
public class BasicJdbcPersistentEntityInformation<T, ID extends Serializable> extends PersistentEntityInformation<T, ID>
public class BasicJdbcPersistentEntityInformation<T, ID> extends PersistentEntityInformation<T, ID>
implements JdbcPersistentEntityInformation<T, ID> {
private final JdbcPersistentEntity<T> persistentEntity;

View File

@@ -24,7 +24,7 @@ import org.springframework.data.repository.core.EntityInformation;
* @author Jens Schauder
* @since 2.0
*/
public interface JdbcPersistentEntityInformation<T, ID extends Serializable> extends EntityInformation<T, ID> {
public interface JdbcPersistentEntityInformation<T, ID> extends EntityInformation<T, ID> {
void setId(T instance, Optional<Object> value);

View File

@@ -42,7 +42,7 @@ public class JdbcRepositoryFactory extends RepositoryFactorySupport {
@SuppressWarnings("unchecked")
@Override
public <T, ID extends Serializable> EntityInformation<T, ID> getEntityInformation(Class<T> aClass) {
public <T, ID> EntityInformation<T, ID> getEntityInformation(Class<T> aClass) {
return context.getPersistentEntity(aClass)
.map(e -> new BasicJdbcPersistentEntityInformation<T, ID>((JdbcPersistentEntity<T>) e)).orElseGet(null);

View File

@@ -80,7 +80,7 @@ public class JdbcRepositoryIdGenerationIntegrationTests {
assertThat(entity.getId()).isNotNull();
assertThat(readOnlyIdrepository.findOne(entity.getId())).hasValueSatisfying(it -> {
assertThat(readOnlyIdrepository.findById(entity.getId())).hasValueSatisfying(it -> {
assertThat(it.getId()).isEqualTo(entity.getId());
assertThat(it.getName()).isEqualTo(entity.getName());
@@ -97,7 +97,7 @@ public class JdbcRepositoryIdGenerationIntegrationTests {
assertThat(saved.getId()).isNotEqualTo(0L);
assertThat(primitiveIdRepository.findOne(saved.getId())).hasValueSatisfying(it -> {
assertThat(primitiveIdRepository.findById(saved.getId())).hasValueSatisfying(it -> {
assertThat(it.getId()).isEqualTo(saved.getId());
assertThat(it.getName()).isEqualTo(saved.getName());

View File

@@ -85,7 +85,7 @@ public class JdbcRepositoryIntegrationTests {
DummyEntity entity = repository.save(createDummyEntity());
assertThat(repository.findOne(entity.getIdProp())).hasValueSatisfying(it -> {
assertThat(repository.findById(entity.getIdProp())).hasValueSatisfying(it -> {
assertThat(it.getIdProp()).isEqualTo(entity.getIdProp());
assertThat(it.getName()).isEqualTo(entity.getName());
@@ -98,7 +98,7 @@ public class JdbcRepositoryIntegrationTests {
DummyEntity entity = createDummyEntity();
DummyEntity other = createDummyEntity();
repository.save(asList(entity, other));
repository.saveAll(asList(entity, other));
assertThat(repository.findAll()) //
.extracting(DummyEntity::getIdProp) //
@@ -110,8 +110,8 @@ public class JdbcRepositoryIntegrationTests {
DummyEntity entity = repository.save(createDummyEntity());
assertThat(repository.exists(entity.getIdProp())).isTrue();
assertThat(repository.exists(entity.getIdProp() + 1)).isFalse();
assertThat(repository.existsById(entity.getIdProp())).isTrue();
assertThat(repository.existsById(entity.getIdProp() + 1)).isFalse();
}
@Test // DATAJDBC-97
@@ -133,7 +133,7 @@ public class JdbcRepositoryIntegrationTests {
DummyEntity entity = repository.save(createDummyEntity());
DummyEntity other = repository.save(createDummyEntity());
assertThat(repository.findAll(asList(entity.getIdProp(), other.getIdProp())))//
assertThat(repository.findAllById(asList(entity.getIdProp(), other.getIdProp())))//
.extracting(DummyEntity::getIdProp)//
.containsExactlyInAnyOrder(entity.getIdProp(), other.getIdProp());
}
@@ -155,7 +155,7 @@ public class JdbcRepositoryIntegrationTests {
DummyEntity two = repository.save(createDummyEntity());
DummyEntity three = repository.save(createDummyEntity());
repository.delete(two.getIdProp());
repository.deleteById(two.getIdProp());
assertThat(repository.findAll()) //
.extracting(DummyEntity::getIdProp) //
@@ -183,7 +183,7 @@ public class JdbcRepositoryIntegrationTests {
DummyEntity two = repository.save(createDummyEntity());
DummyEntity three = repository.save(createDummyEntity());
repository.delete(asList(one, three));
repository.deleteAll(asList(one, three));
assertThat(repository.findAll()) //
.extracting(DummyEntity::getIdProp) //
@@ -212,7 +212,7 @@ public class JdbcRepositoryIntegrationTests {
entity.setName("something else");
DummyEntity saved = repository.save(entity);
assertThat(repository.findOne(entity.getIdProp())).hasValueSatisfying(it -> {
assertThat(repository.findById(entity.getIdProp())).hasValueSatisfying(it -> {
assertThat(it.getName()).isEqualTo(saved.getName());
});
}
@@ -226,7 +226,7 @@ public class JdbcRepositoryIntegrationTests {
entity.setName("something else");
other.setName("others Name");
repository.save(asList(entity, other));
repository.saveAll(asList(entity, other));
assertThat(repository.findAll()) //
.extracting(DummyEntity::getName) //

View File

@@ -64,7 +64,7 @@ public class SimpleJdbcRepositoryEventsUnitTests {
DummyEntity entity1 = new DummyEntity(null);
DummyEntity entity2 = new DummyEntity(23L);
repository.save(asList(entity1, entity2));
repository.saveAll(asList(entity1, entity2));
assertThat(publisher.events.get(0)).isInstanceOf(BeforeInsert.class);
assertThat(publisher.events.get(1)).isInstanceOf(AfterInsert.class);
@@ -92,7 +92,7 @@ public class SimpleJdbcRepositoryEventsUnitTests {
@Test // DATAJDBC-99
public void publishesEventsOnDeleteById() {
repository.delete(23L);
repository.deleteById(23L);
assertThat(publisher.events.get(0)).isInstanceOf(BeforeDelete.class);
assertThat(publisher.events.get(1)).isInstanceOf(AfterDelete.class);