Skip to content

Commit d5d41cb

Browse files
author
Andreas Austing
committed
Support for spring-data 4.0.0
1 parent e76a36c commit d5d41cb

18 files changed

+137
-42
lines changed

core/pom.xml

Lines changed: 45 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,22 @@
55
<parent>
66
<groupId>com.cosium.spring.data</groupId>
77
<artifactId>spring-data-jpa-entity-graph-parent</artifactId>
8-
<version>3.5.1-SNAPSHOT</version>
8+
<version>4.0.0-SNAPSHOT</version>
99
</parent>
1010

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

1414
<dependencies>
15+
16+
<!--Needed by SpringHibernateJpaPersistenceProvider for spring-data-jpa while building with JDK 11
1517
<dependency>
16-
<!--Needed by SpringHibernateJpaPersistenceProvider for spring-data-jpa while building with JDK 11-->
1718
<groupId>javax.xml.bind</groupId>
1819
<artifactId>jaxb-api</artifactId>
1920
<version>2.4.0-b180830.0359</version>
2021
<scope>provided</scope>
2122
</dependency>
23+
-->
2224

2325
<dependency>
2426
<groupId>org.springframework.data</groupId>
@@ -27,13 +29,21 @@
2729
</dependency>
2830

2931
<dependency>
30-
<!--Needed by querydsl for @Generated annotation-->
32+
<groupId>jakarta.persistence</groupId>
33+
<artifactId>jakarta.persistence-api</artifactId>
34+
<version>3.2.0</version>
35+
<scope>provided</scope>
36+
</dependency>
37+
38+
<!--Needed by querydsl for @Generated annotation-->
39+
<dependency>
3140
<groupId>javax.annotation</groupId>
3241
<artifactId>javax.annotation-api</artifactId>
3342
<version>1.3.2</version>
3443
<scope>provided</scope>
3544
</dependency>
36-
45+
46+
<!--
3747
<dependency>
3848
<groupId>com.querydsl</groupId>
3949
<artifactId>querydsl-apt</artifactId>
@@ -43,7 +53,8 @@
4353
4454
<dependency>
4555
<groupId>org.hibernate.orm</groupId>
46-
<artifactId>hibernate-jpamodelgen</artifactId>
56+
<artifactId>hibernate-processor</artifactId>
57+
<version>${hibernate.version}</version>
4758
<scope>provided</scope>
4859
</dependency>
4960
@@ -53,6 +64,7 @@
5364
<version>${project.version}</version>
5465
<scope>provided</scope>
5566
</dependency>
67+
-->
5668

5769
<dependency>
5870
<groupId>com.querydsl</groupId>
@@ -118,6 +130,34 @@
118130
</archive>
119131
</configuration>
120132
</plugin>
133+
<plugin>
134+
<groupId>org.apache.maven.plugins</groupId>
135+
<artifactId>maven-compiler-plugin</artifactId>
136+
<configuration>
137+
<annotationProcessorPaths>
138+
<annotationProcessorPath>
139+
<groupId>com.querydsl</groupId>
140+
<artifactId>querydsl-apt</artifactId>
141+
<version>${querydsl}</version>
142+
<classifier>jakarta</classifier>
143+
</annotationProcessorPath>
144+
<annotationProcessorPath>
145+
<groupId>jakarta.persistence</groupId>
146+
<artifactId>jakarta.persistence-api</artifactId>
147+
</annotationProcessorPath>
148+
<path>
149+
<groupId>org.hibernate.orm</groupId>
150+
<artifactId>hibernate-processor</artifactId>
151+
<version>${hibernate.version}</version>
152+
</path>
153+
<path>
154+
<groupId>com.cosium.spring.data</groupId>
155+
<artifactId>spring-data-jpa-entity-graph-generator</artifactId>
156+
<version>3.5.0</version>
157+
</path>
158+
</annotationProcessorPaths>
159+
</configuration>
160+
</plugin>
121161
</plugins>
122162
</build>
123163

core/src/main/java/com/cosium/spring/data/jpa/entity/graph/repository/EntityGraphJpaRepository.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,6 @@
1111
@NoRepositoryBean
1212
public interface EntityGraphJpaRepository<T, ID>
1313
extends JpaRepository<T, ID>,
14-
EntityGraphPagingAndSortingRepository<T, ID>,
14+
EntityGraphListCrudRepository<T, ID>,
15+
EntityGraphListPagingAndSortingRepository<T, ID>,
1516
EntityGraphQueryByExampleExecutor<T> {}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package com.cosium.spring.data.jpa.entity.graph.repository;
2+
3+
import com.cosium.spring.data.jpa.entity.graph.domain2.EntityGraph;
4+
import java.util.List;
5+
import org.springframework.data.repository.ListCrudRepository;
6+
import org.springframework.data.repository.NoRepositoryBean;
7+
8+
/**
9+
* @author Andreas Austing
10+
*/
11+
@NoRepositoryBean
12+
public interface EntityGraphListCrudRepository<T, ID>
13+
extends ListCrudRepository<T, ID>, EntityGraphCrudRepository<T, ID> {
14+
15+
/**
16+
* @see ListCrudRepository#findAllById(Iterable)
17+
*/
18+
List<T> findAllById(Iterable<ID> ids, EntityGraph entityGraph);
19+
20+
/**
21+
* @see ListCrudRepository#findAll()
22+
*/
23+
List<T> findAll(EntityGraph entityGraph);
24+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package com.cosium.spring.data.jpa.entity.graph.repository;
2+
3+
import com.cosium.spring.data.jpa.entity.graph.domain2.EntityGraph;
4+
import java.util.List;
5+
import org.springframework.data.domain.Sort;
6+
import org.springframework.data.repository.ListPagingAndSortingRepository;
7+
import org.springframework.data.repository.NoRepositoryBean;
8+
9+
/**
10+
* @author Andreas Austing
11+
*/
12+
@NoRepositoryBean
13+
public interface EntityGraphListPagingAndSortingRepository<T, ID>
14+
extends ListPagingAndSortingRepository<T, ID>, EntityGraphPagingAndSortingRepository<T, ID> {
15+
16+
/**
17+
* @see ListPagingAndSortingRepository#findAll(Sort)
18+
*/
19+
List<T> findAll(Sort sort, EntityGraph entityGraph);
20+
}

core/src/main/java/com/cosium/spring/data/jpa/entity/graph/repository/EntityGraphPagingAndSortingRepository.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
*/
1515
@NoRepositoryBean
1616
public interface EntityGraphPagingAndSortingRepository<T, ID>
17-
extends PagingAndSortingRepository<T, ID>, EntityGraphCrudRepository<T, ID> {
17+
extends PagingAndSortingRepository<T, ID>, EntityGraphRepository<T, ID> {
1818

1919
/**
2020
* @see PagingAndSortingRepository#findAll(Pageable)

core/src/main/java/com/cosium/spring/data/jpa/entity/graph/repository/support/EntityGraphJpaRepositoryFactory.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import com.cosium.spring.data.jpa.entity.graph.domain2.EntityGraph;
66
import com.cosium.spring.data.jpa.entity.graph.repository.query.EntityGraphAwareJpaQueryMethodFactory;
77
import jakarta.persistence.EntityManager;
8+
import org.jspecify.annotations.Nullable;
89
import org.springframework.data.jpa.provider.PersistenceProvider;
910
import org.springframework.data.jpa.repository.support.JpaRepositoryFactory;
1011
import org.springframework.data.querydsl.QuerydslPredicateExecutor;
@@ -33,9 +34,18 @@ public EntityGraphJpaRepositoryFactory(EntityManager entityManager) {
3334
PersistenceProvider.fromEntityManager(entityManager)));
3435
}
3536

37+
@Override
38+
public void setRepositoryBaseClass(@Nullable Class<?> repositoryBaseClass) {
39+
// ignore
40+
}
41+
3642
@Override
3743
protected Class<?> getRepositoryBaseClass(RepositoryMetadata metadata) {
38-
if (isQueryDslExecutor(metadata.getRepositoryInterface())) {
44+
return getRepositoryBaseClass(metadata.getRepositoryInterface());
45+
}
46+
47+
protected Class<?> getRepositoryBaseClass(Class<?> repositoryInterface) {
48+
if (isQueryDslExecutor(repositoryInterface)) {
3949
return EntityGraphQuerydslRepository.class;
4050
} else {
4151
return EntityGraphSimpleJpaRepository.class;

core/src/main/java/com/cosium/spring/data/jpa/entity/graph/repository/support/EntityGraphSimpleJpaRepository.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,12 +90,12 @@ public List<T> findAllById(Iterable<ID> ids, EntityGraph entityGraph) {
9090
}
9191

9292
@Override
93-
public Iterable<T> findAll(Sort sort, EntityGraph entityGraph) {
93+
public List<T> findAll(Sort sort, EntityGraph entityGraph) {
9494
return findAll(sort);
9595
}
9696

9797
@Override
98-
public Iterable<T> findAll(EntityGraph entityGraph) {
98+
public List<T> findAll(EntityGraph entityGraph) {
9999
return findAll();
100100
}
101101
}

core/src/main/java/com/cosium/spring/data/jpa/entity/graph/repository/support/RepositoryQueryEntityGraphInjector.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ class RepositoryQueryEntityGraphInjector implements MethodInterceptor {
2323
LoggerFactory.getLogger(RepositoryQueryEntityGraphInjector.class);
2424

2525
private static final List<String> EXECUTE_QUERY_METHODS =
26-
Arrays.asList("getResultList", "getSingleResult", "getResultStream", "scroll");
26+
Arrays.asList(
27+
"getResultList", "getSingleResult", "getSingleResultOrNull", "getResultStream", "scroll");
2728
private static final String UNWRAP_METHOD = "unwrap";
2829
private final EntityGraphQueryHintCandidate entityGraphCandidate;
2930

core/src/test/java/com/cosium/spring/data/jpa/entity/graph/repository/DefaultEntityGraphTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@
1717
import jakarta.persistence.ManyToOne;
1818
import jakarta.persistence.Table;
1919
import java.util.Optional;
20-
import javax.inject.Inject;
2120
import org.hibernate.Hibernate;
2221
import org.junit.jupiter.api.DisplayName;
2322
import org.junit.jupiter.api.Test;
23+
import org.springframework.beans.factory.annotation.Autowired;
2424
import org.springframework.transaction.annotation.Transactional;
2525

2626
/**
@@ -29,7 +29,7 @@
2929
@DatabaseSetup(BaseTest.DATASET)
3030
class DefaultEntityGraphTest extends BaseTest {
3131

32-
@Inject private MyEntityRepository repository;
32+
@Autowired private MyEntityRepository repository;
3333

3434
@Transactional
3535
@Test
@@ -86,7 +86,7 @@ public void setMaker(Maker maker) {
8686
}
8787
}
8888

89-
interface MyEntityRepository extends EntityGraphCrudRepository<MyEntity, Long> {
89+
interface MyEntityRepository extends EntityGraphListCrudRepository<MyEntity, Long> {
9090

9191
@Override
9292
default Optional<EntityGraph> defaultEntityGraph() {

core/src/test/java/com/cosium/spring/data/jpa/entity/graph/repository/EntityGraphCustomJpaRepositoryTest.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@
1212
import jakarta.persistence.PersistenceContext;
1313
import java.util.List;
1414
import java.util.Optional;
15-
import javax.inject.Inject;
1615
import org.hibernate.Hibernate;
1716
import org.junit.jupiter.api.DisplayName;
1817
import org.junit.jupiter.api.Test;
18+
import org.springframework.beans.factory.annotation.Autowired;
1919
import org.springframework.data.repository.Repository;
2020
import org.springframework.stereotype.Component;
2121
import org.springframework.transaction.annotation.Transactional;
@@ -28,7 +28,7 @@
2828
@DatabaseSetup(BaseTest.DATASET)
2929
class EntityGraphCustomJpaRepositoryTest extends BaseTest {
3030

31-
@Inject private EntityGraphCustomJpaRepositoryTestProductRepository productRepository;
31+
@Autowired private EntityGraphCustomJpaRepositoryTestProductRepository productRepository;
3232

3333
@Test
3434
@Transactional
@@ -68,8 +68,10 @@ public interface ProductRepositoryCustom {
6868
public static class EntityGraphCustomJpaRepositoryTestProductRepositoryImpl
6969
implements ProductRepositoryCustom {
7070

71-
@Inject private BrandRepository brandRepository;
72-
@Inject private EntityGraphCustomJpaRepositoryTestProductRepository productRepository;
71+
@Autowired private BrandRepository brandRepository;
72+
73+
@Autowired private EntityGraphCustomJpaRepositoryTestProductRepository productRepository;
74+
7375
@PersistenceContext private EntityManager entityManager;
7476

7577
@Override

0 commit comments

Comments
 (0)