Skip to content
Open
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
60 changes: 32 additions & 28 deletions core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,55 +5,33 @@
<parent>
<groupId>com.cosium.spring.data</groupId>
<artifactId>spring-data-jpa-entity-graph-parent</artifactId>
<version>3.5.1-SNAPSHOT</version>
<version>4.0.0-SNAPSHOT</version>
</parent>

<name>Spring Data JPA EntityGraph</name>
<artifactId>spring-data-jpa-entity-graph</artifactId>

<dependencies>
<dependency>
<!--Needed by SpringHibernateJpaPersistenceProvider for spring-data-jpa while building with JDK 11-->
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.4.0-b180830.0359</version>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-jpa</artifactId>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-jpa</artifactId>
<groupId>jakarta.persistence</groupId>
<artifactId>jakarta.persistence-api</artifactId>
<scope>provided</scope>
</dependency>

<!--Needed by querydsl for @Generated annotation-->
<dependency>
<!--Needed by querydsl for @Generated annotation-->
<groupId>javax.annotation</groupId>
<artifactId>javax.annotation-api</artifactId>
<version>1.3.2</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>com.querydsl</groupId>
<artifactId>querydsl-apt</artifactId>
<classifier>jakarta</classifier>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.hibernate.orm</groupId>
<artifactId>hibernate-jpamodelgen</artifactId>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>spring-data-jpa-entity-graph-generator</artifactId>
<version>${project.version}</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>com.querydsl</groupId>
<artifactId>querydsl-jpa</artifactId>
Expand Down Expand Up @@ -118,6 +96,32 @@
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<annotationProcessorPaths>
<path>
<groupId>org.hibernate.orm</groupId>
<artifactId>hibernate-processor</artifactId>
<version>${hibernate.version}</version>
</path>
<path>
<groupId>com.querydsl</groupId>
<artifactId>querydsl-apt</artifactId>
<version>${querydsl}</version>
<classifier>jakarta</classifier>
</path>
<path>
<groupId>${project.groupId}</groupId>
<artifactId>spring-data-jpa-entity-graph-generator</artifactId>
<version>${project.version}</version>
</path>
</annotationProcessorPaths>
<generatedTestSourcesDirectory>target/generated-test-sources</generatedTestSourcesDirectory>
<generatedSourcesDirectory>target/generated-sources</generatedSourcesDirectory>
</configuration>
</plugin>
</plugins>
</build>

Expand Down
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>,
EntityGraphPagingAndSortingRepository<T, ID>,
EntityGraphListCrudRepository<T, ID>,
EntityGraphListPagingAndSortingRepository<T, ID>,
EntityGraphQueryByExampleExecutor<T> {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
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.repository.ListCrudRepository;
import org.springframework.data.repository.NoRepositoryBean;

/**
* @author Andreas Austing
*/
@NoRepositoryBean
public interface EntityGraphListCrudRepository<T, ID>
extends ListCrudRepository<T, ID>, EntityGraphCrudRepository<T, ID> {

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

/**
* @see ListCrudRepository#findAll()
*/
List<T> findAll(EntityGraph entityGraph);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
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.Sort;
import org.springframework.data.repository.ListPagingAndSortingRepository;
import org.springframework.data.repository.NoRepositoryBean;

/**
* @author Andreas Austing
*/
@NoRepositoryBean
public interface EntityGraphListPagingAndSortingRepository<T, ID>
extends ListPagingAndSortingRepository<T, ID>, EntityGraphPagingAndSortingRepository<T, ID> {

/**
* @see ListPagingAndSortingRepository#findAll(Sort)
*/
List<T> findAll(Sort sort, EntityGraph entityGraph);
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
*/
@NoRepositoryBean
public interface EntityGraphPagingAndSortingRepository<T, ID>
extends PagingAndSortingRepository<T, ID>, EntityGraphCrudRepository<T, ID> {
extends PagingAndSortingRepository<T, ID>, EntityGraphRepository<T, ID> {

/**
* @see PagingAndSortingRepository#findAll(Pageable)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

import com.cosium.spring.data.jpa.entity.graph.domain2.EntityGraph;
import org.springframework.core.MethodParameter;
import org.springframework.data.core.TypeInformation;
import org.springframework.data.jpa.repository.query.JpaParameters;
import org.springframework.data.repository.query.ParametersSource;
import org.springframework.data.util.TypeInformation;

/**
* @author Réda Housni Alaoui
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.cosium.spring.data.jpa.entity.graph.domain2.EntityGraph;
import com.cosium.spring.data.jpa.entity.graph.repository.query.EntityGraphAwareJpaQueryMethodFactory;
import jakarta.persistence.EntityManager;
import org.jspecify.annotations.Nullable;
import org.springframework.data.jpa.provider.PersistenceProvider;
import org.springframework.data.jpa.repository.support.JpaRepositoryFactory;
import org.springframework.data.querydsl.QuerydslPredicateExecutor;
Expand Down Expand Up @@ -33,9 +34,18 @@ public EntityGraphJpaRepositoryFactory(EntityManager entityManager) {
PersistenceProvider.fromEntityManager(entityManager)));
}

@Override
public void setRepositoryBaseClass(@Nullable Class<?> repositoryBaseClass) {
// ignore
}

@Override
protected Class<?> getRepositoryBaseClass(RepositoryMetadata metadata) {
if (isQueryDslExecutor(metadata.getRepositoryInterface())) {
return getRepositoryBaseClass(metadata.getRepositoryInterface());
}

protected Class<?> getRepositoryBaseClass(Class<?> repositoryInterface) {
if (isQueryDslExecutor(repositoryInterface)) {
return EntityGraphQuerydslRepository.class;
} else {
return EntityGraphSimpleJpaRepository.class;
Expand Down
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 @@ -23,7 +23,8 @@ class RepositoryQueryEntityGraphInjector implements MethodInterceptor {
LoggerFactory.getLogger(RepositoryQueryEntityGraphInjector.class);

private static final List<String> EXECUTE_QUERY_METHODS =
Arrays.asList("getResultList", "getSingleResult", "getResultStream", "scroll");
Arrays.asList(
"getResultList", "getSingleResult", "getSingleResultOrNull", "getResultStream", "scroll");
private static final String UNWRAP_METHOD = "unwrap";
private final EntityGraphQueryHintCandidate entityGraphCandidate;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
import jakarta.persistence.ManyToOne;
import jakarta.persistence.Table;
import java.util.Optional;
import javax.inject.Inject;
import org.hibernate.Hibernate;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

/**
Expand All @@ -29,7 +29,7 @@
@DatabaseSetup(BaseTest.DATASET)
class DefaultEntityGraphTest extends BaseTest {

@Inject private MyEntityRepository repository;
@Autowired private MyEntityRepository repository;

@Transactional
@Test
Expand Down Expand Up @@ -86,7 +86,7 @@ public void setMaker(Maker maker) {
}
}

interface MyEntityRepository extends EntityGraphCrudRepository<MyEntity, Long> {
interface MyEntityRepository extends EntityGraphListCrudRepository<MyEntity, Long> {

@Override
default Optional<EntityGraph> defaultEntityGraph() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
import jakarta.persistence.PersistenceContext;
import java.util.List;
import java.util.Optional;
import javax.inject.Inject;
import org.hibernate.Hibernate;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.repository.Repository;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
Expand All @@ -28,7 +28,7 @@
@DatabaseSetup(BaseTest.DATASET)
class EntityGraphCustomJpaRepositoryTest extends BaseTest {

@Inject private EntityGraphCustomJpaRepositoryTestProductRepository productRepository;
@Autowired private EntityGraphCustomJpaRepositoryTestProductRepository productRepository;

@Test
@Transactional
Expand Down Expand Up @@ -68,8 +68,10 @@ public interface ProductRepositoryCustom {
public static class EntityGraphCustomJpaRepositoryTestProductRepositoryImpl
implements ProductRepositoryCustom {

@Inject private BrandRepository brandRepository;
@Inject private EntityGraphCustomJpaRepositoryTestProductRepository productRepository;
@Autowired private BrandRepository brandRepository;

@Autowired private EntityGraphCustomJpaRepositoryTestProductRepository productRepository;

@PersistenceContext private EntityManager entityManager;

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@
import jakarta.persistence.criteria.Root;
import java.util.List;
import java.util.Optional;
import javax.inject.Inject;
import org.hibernate.Hibernate;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
Expand All @@ -42,8 +42,9 @@ class EntityGraphJpaRepositoryTest extends BaseTest {

@PersistenceContext private EntityManager entityManager;

@Inject private ProductRepository productRepository;
@Inject private BrandRepository brandRepository;
@Autowired private ProductRepository productRepository;

@Autowired private BrandRepository brandRepository;

@Transactional
@Test
Expand Down Expand Up @@ -355,7 +356,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
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
import jakarta.persistence.criteria.Root;
import java.util.List;
import java.util.Optional;
import javax.inject.Inject;
import org.hibernate.Hibernate;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.transaction.annotation.Transactional;

Expand All @@ -32,7 +32,7 @@
@DatabaseSetup(BaseTest.DATASET)
class EntityGraphJpaSpecificationExecutorTest extends BaseTest {

@Inject private ProductRepository productRepository;
@Autowired private ProductRepository productRepository;

@Transactional
@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
import com.cosium.spring.data.jpa.entity.graph.sample.QProduct;
import com.github.springtestdbunit.annotation.DatabaseSetup;
import java.util.Optional;
import javax.inject.Inject;
import org.hibernate.Hibernate;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.repository.Repository;
Expand All @@ -25,7 +25,7 @@
@DatabaseSetup(BaseTest.DATASET)
class EntityGraphQuerydslPredicateExecutorTest extends BaseTest {

@Inject private ProductRepository productRepository;
@Autowired private ProductRepository productRepository;

@Transactional
@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
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;
import javax.inject.Inject;
import org.hibernate.Hibernate;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

/**
Expand All @@ -18,7 +18,7 @@
@DatabaseSetup(BaseTest.DATASET)
class GeneratedEntityGraphTest extends BaseTest {

@Inject private ProductRepository productRepository;
@Autowired private ProductRepository productRepository;

@Transactional
@Test
Expand Down
Loading