Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

return List instead of Iterable and adapt to new interface-hierarchy #202

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package com.cosium.spring.data.jpa.entity.graph.repository;

import com.cosium.spring.data.jpa.entity.graph.domain2.EntityGraph;
import java.util.List;
import java.util.Optional;
import org.springframework.data.repository.CrudRepository;
import org.springframework.data.repository.ListCrudRepository;
import org.springframework.data.repository.NoRepositoryBean;

/**
Expand All @@ -12,20 +13,20 @@
*/
@NoRepositoryBean
public interface EntityGraphCrudRepository<T, ID>
extends CrudRepository<T, ID>, EntityGraphRepository<T, ID> {
extends ListCrudRepository<T, ID>, EntityGraphRepository<T, ID> {

/**
* @see CrudRepository#findById(Object)
* @see ListCrudRepository#findById(Object)
*/
Optional<T> findById(ID id, EntityGraph entityGraph);

/**
* @see CrudRepository#findAllById(Iterable)
* @see ListCrudRepository#findAllById(Iterable)
*/
Iterable<T> findAllById(Iterable<ID> ids, EntityGraph entityGraph);
List<T> findAllById(Iterable<ID> ids, EntityGraph entityGraph);

/**
* @see CrudRepository#findAll()
* @see ListCrudRepository#findAll()
*/
Iterable<T> findAll(EntityGraph entityGraph);
List<T> findAll(EntityGraph entityGraph);
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@
@NoRepositoryBean
public interface EntityGraphJpaRepository<T, ID>
extends JpaRepository<T, ID>,
EntityGraphCrudRepository<T, ID>,
EntityGraphPagingAndSortingRepository<T, ID>,
EntityGraphQueryByExampleExecutor<T> {}
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package com.cosium.spring.data.jpa.entity.graph.repository;

import com.cosium.spring.data.jpa.entity.graph.domain2.EntityGraph;
import java.util.List;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.repository.ListPagingAndSortingRepository;
import org.springframework.data.repository.NoRepositoryBean;
import org.springframework.data.repository.PagingAndSortingRepository;

/**
* Created on 18/03/17.
Expand All @@ -14,15 +15,15 @@
*/
@NoRepositoryBean
public interface EntityGraphPagingAndSortingRepository<T, ID>
extends PagingAndSortingRepository<T, ID>, EntityGraphCrudRepository<T, ID> {
extends ListPagingAndSortingRepository<T, ID>, EntityGraphRepository<T, ID> {

/**
* @see PagingAndSortingRepository#findAll(Pageable)
* @see ListPagingAndSortingRepository#findAll(Pageable)
*/
Page<T> findAll(Pageable pageable, EntityGraph entityGraph);

/**
* @see PagingAndSortingRepository#findAll(Sort)
* @see ListPagingAndSortingRepository#findAll(Sort)
*/
Iterable<T> findAll(Sort sort, EntityGraph entityGraph);
List<T> findAll(Sort sort, EntityGraph entityGraph);
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,33 +8,33 @@
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.repository.NoRepositoryBean;
import org.springframework.data.repository.query.QueryByExampleExecutor;
import org.springframework.data.repository.query.ListQueryByExampleExecutor;

/**
* Created on 18/03/17.
*
* @author Reda.Housni-Alaoui
*/
@NoRepositoryBean
public interface EntityGraphQueryByExampleExecutor<T> extends QueryByExampleExecutor<T> {
public interface EntityGraphQueryByExampleExecutor<T> extends ListQueryByExampleExecutor<T> {

/**
* @see QueryByExampleExecutor#findAll(Example, Pageable)
* @see ListQueryByExampleExecutor#findAll(Example, Pageable)
*/
<S extends T> Page<S> findAll(Example<S> example, Pageable pageable, EntityGraph entityGraph);

/**
* @see QueryByExampleExecutor#findOne(Example)
* @see ListQueryByExampleExecutor#findOne(Example)
*/
<S extends T> Optional<S> findOne(Example<S> example, EntityGraph entityGraph);

/**
* @see QueryByExampleExecutor#findAll(Example, Sort)
* @see ListQueryByExampleExecutor#findAll(Example, Sort)
*/
<S extends T> List<S> findAll(Example<S> example, Sort sort, EntityGraph entityGraph);

/**
* @see QueryByExampleExecutor#findAll(Example)
* @see ListQueryByExampleExecutor#findAll(Example)
*/
<S extends T> List<S> findAll(Example<S> example, EntityGraph entityGraph);
}
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,12 @@ public List<T> findAllById(Iterable<ID> ids, EntityGraph entityGraph) {
}

@Override
public Iterable<T> findAll(Sort sort, EntityGraph entityGraph) {
public List<T> findAll(Sort sort, EntityGraph entityGraph) {
return findAll(sort);
}

@Override
public Iterable<T> findAll(EntityGraph entityGraph) {
public List<T> findAll(EntityGraph entityGraph) {
return findAll();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import com.cosium.spring.data.jpa.entity.graph.domain2.NamedEntityGraph;
import com.cosium.spring.data.jpa.entity.graph.repository.exception.InapplicableEntityGraphException;
import com.cosium.spring.data.jpa.entity.graph.sample.Brand;
import com.cosium.spring.data.jpa.entity.graph.sample.BrandEntityGraph;
import com.cosium.spring.data.jpa.entity.graph.sample.Product;
import com.cosium.spring.data.jpa.entity.graph.sample.ProductEntityGraph;
import com.github.springtestdbunit.annotation.DatabaseSetup;
Expand Down Expand Up @@ -331,6 +332,22 @@ void test23() {
assertThat(productName).isNotNull();
}

@Transactional
@Test
@DisplayName(
"Given an EntityGraphJpaRepository when calling a standard findAll method then a List should be returned (no matter whether an entitygraph is provided or not)")
void test24() {
long brandId = 1;

List<Brand> brandsWithoutEntityGraph = brandRepository.findAllById(List.of(brandId));
assertThat(brandsWithoutEntityGraph).hasSize(1);

List<Brand> brandsWithEntityGraph =
brandRepository.findAllById(
List.of(brandId), BrandEntityGraph.____().products().____.____());
assertThat(brandsWithEntityGraph).hasSize(1);
}

private abstract static class EntityGraphSpecification<T>
implements Specification<T>, EntityGraph {

Expand All @@ -355,7 +372,7 @@ public interface ProductRepository

@org.springframework.data.jpa.repository.EntityGraph(attributePaths = "brand")
@Override
Iterable<Product> findAll(EntityGraph entityGraph);
List<Product> findAll(EntityGraph entityGraph);

@org.springframework.data.jpa.repository.EntityGraph(attributePaths = "brand")
List<Product> findByName(String name, EntityGraph entityGraph);
Expand Down
Loading