diff --git a/README.md b/README.md
index e7d10a7..df00223 100644
--- a/README.md
+++ b/README.md
@@ -1,10 +1,11 @@
+[](https://gitter.im/Cosium/spring-data-jpa-entity-graph?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge)
[](https://travis-ci.org/Cosium/spring-data-jpa-entity-graph)
[](https://codecov.io/gh/Cosium/spring-data-jpa-entity-graph)
[](http://search.maven.org/#search%7Cgav%7C1%7Cg%3A%22com.cosium.spring.data%22%20AND%20a%3A%22spring-data-jpa-entity-graph%22)
# Spring Data JPA EntityGraph
-Today, [Spring Data JPA](https://github.com/spring-projects/spring-data-jpa) supports EntityGraph exlusively through annotations.
+Today, [Spring Data JPA](https://github.com/spring-projects/spring-data-jpa) supports EntityGraph exclusively through annotations.
Thus, for a method, the choice of EntityGraph must be made before compilation.
This extension gives the ability to pass EntityGraph on any Spring Data JPA repository method as an argument, making the EntityGraph choice fully dynamic.
@@ -14,122 +15,18 @@ Example:
productRepository.findByName("foo", EntityGraphUtils.fromName("Product.brand"));
```
-## Compatibility
+## Documentation
This library follows the Spring Data JPA versionning semantic.
-spring-data-jpa-entity-graph | spring-data-jpa
----------------------------- | ---------------
-1.11.x | 1.11.y
-1.10.x | 1.10.y
+spring-data-jpa branches | Latest spring-data-jpa-entity-graph version | Documentation
+---------------------------- | --------------- | -----------------
+1.12.x | Not released yet | [1.12.x documentation](https://github.com/Cosium/spring-data-jpa-entity-graph/blob/master/doc/MAIN.md)
+1.11.x | 1.11.03 | [1.11.x documentation](doc/MAIN.md)
+1.10.x | 1.10.15 | [1.10.x documentation](https://github.com/Cosium/spring-data-jpa-entity-graph/blob/1.10.x/doc/MAIN.md)
-## Quick start
+Example: if you were using `spring-data-jpa 1.10.13` in your project, you would need to select any `spring-data-jpa-entity-graph 1.10.x`. Thus `spring-data-jpa-entity-graph 1.10.14` would be eligible.
-1. In addition to spring-data-jpa, add the library dependency :
-
- ```xml
-
- com.cosium.spring.data
- spring-data-jpa-entity-graph
- 1.10.14
-
- ```
-2. In your Spring configuration, set the repository factory bean class to `JpaEntityGraphRepositoryFactoryBean` :
-
- ```java
- @Configuration
- @EnableJpaRepositories(repositoryFactoryBeanClass = JpaEntityGraphRepositoryFactoryBean.class)
- public class DataRepositoryConfiguration {
- ...
- }
- ```
-3. Make sure your repositories extend `JpaEntityGraphRepository`, `JpaEntityGraphSpecificationExecutor` and/or `JpaEntityGraphQueryDslPredicateExecutor`
+## Genesis
-## Basic Usage
-
-Let's consider the following entities and repository :
-```java
-@Entity
-public class Brand {
- @Id
- private long id = 0;
- private String name;
- //...
-}
-```
-```java
-@NamedEntityGraphs(value = {
- @NamedEntityGraph(name = "Product.brand", attributeNodes = {
- @NamedAttributeNode("brand")
- })
-})
-@Entity
-public class Product {
- @Id
- private long id = 0;
- private String name;
- @ManyToOne(fetch = FetchType.LAZY)
- private Brand brand;
- //...
-}
-```
-```java
-public interface ProductRepository extends JpaEntityGraphRepository {
- List findByName(String name, EntityGraph entityGraph);
-}
-```
-
-You can pass the entity graph to the `findByName` method :
-```java
-// This will apply 'Product.brand' named EntityGraph to findByName
-productRepository.findByName("MyProduct", EntityGraphUtils.fromName("Product.brand"));
-```
-
-Or to the `findOne` method :
-```java
-// This will apply 'Product.brand' named EntityGraph to findOne
-productRepository.findOne(1L, EntityGraphUtils.fromName("Product.brand"));
-```
-
-Or any method you like.
-
-You can also pass a dynamically built EntityGraph by using `DynamicEntityGraph`, it's also accessible through a helper method:
-
-```java
-productRepository.findOne(1L, EntityGraphUtils.fromAttributePaths("brand", "maker"));
-```
-
-This is similar to [Spring's ad-hoc attribute paths](http://docs.spring.io/spring-data/jpa/docs/current/reference/html/#repositories.query-methods.query-property-expressions),
-and equivalent to writing this in your repository's interface:
-```java
-@EntityGraph(attributePaths = { "brand", "maker" })
-Product findOne(Long id);
-```
-
-## Default EntityGraph
-
-For an Entity, you can define its default EntityGraph.
-An Entity default EntityGraph will be used each time the Entity repository method is called without EntityGraph.
-
-A default EntityGraph name must end with `.default`.
-
-```java
-@NamedEntityGraphs(value = {
- @NamedEntityGraph(name = "Product.default", attributeNodes = {
- @NamedAttributeNode("brand")
- })
-})
-@Entity
-public class Product {
- @Id
- private long id = 0;
- private String name;
- @ManyToOne(fetch = FetchType.LAZY)
- private Brand brand;
- //...
-}
-```
-```java
-// This call will make use of "Product.default" EntityGraph.
-productRepository.findOne(1L);
-```
+This project was created following the discussion in Spring Data Tracker issue [DATAJPA-749 - Context enabled JPA 2.1 @EntityGraph](https://jira.spring.io/browse/DATAJPA-749) .
\ No newline at end of file
diff --git a/doc/MAIN.md b/doc/MAIN.md
new file mode 100644
index 0000000..7d58875
--- /dev/null
+++ b/doc/MAIN.md
@@ -0,0 +1,115 @@
+## Quick start
+1. In addition to `spring-data-jpa`, add the library dependency :
+
+ ```xml
+
+ com.cosium.spring.data
+ spring-data-jpa-entity-graph
+ 1.11.03
+
+ ```
+2. In your Spring configuration, set the repository factory bean class to `EntityGraphJpaRepositoryFactoryBean` :
+
+ ```java
+ @Configuration
+ @EnableJpaRepositories(repositoryFactoryBeanClass = EntityGraphJpaRepositoryFactoryBean.class)
+ public class DataRepositoryConfiguration {
+ //...
+ }
+ ```
+3. Make sure your repositories extend the Spring Data standard ones or the library provided repositories:
+- `EntityGraphJpaRepository` which is equivalent to standard `JpaRepository`
+- `EntityGraphJpaSpecificationExecutor` which is equivalent to standard `JpaSpecificationExecutor`
+- `EntityGraphQueryDslPredicateExecutor` which is equivalent to standard `QueryDslPredicateExecutor`
+- `EntityGraphCrudRepository` which is equivalent to standard `CrudRepository`
+- `EntityGraphPagingAndSortingRepository` which is equivalent to standard `PagingAndSortingRepository`
+- `EntityGraphQueryByExampleExecutor` which is equivalent to standard `QueryByExampleExecutor`
+
+## Basic Usage
+
+Let's consider the following entities and repository :
+```java
+@Entity
+public class Brand {
+ @Id
+ private long id = 0;
+ private String name;
+ //...
+}
+```
+```java
+@NamedEntityGraphs(value = {
+ @NamedEntityGraph(name = "Product.brand", attributeNodes = {
+ @NamedAttributeNode("brand")
+ })
+})
+@Entity
+public class Product {
+ @Id
+ private long id = 0;
+ private String name;
+ @ManyToOne(fetch = FetchType.LAZY)
+ private Brand brand;
+ //...
+}
+```
+```java
+public interface ProductRepository extends EntityGraphJpaRepository {
+ List findByName(String name, EntityGraph entityGraph);
+}
+```
+
+You can pass the entity graph to the `findByName` method :
+```java
+// This will apply 'Product.brand' named EntityGraph to findByName
+productRepository.findByName("MyProduct", EntityGraphUtils.fromName("Product.brand"));
+```
+
+Or to the `findOne` method :
+```java
+// This will apply 'Product.brand' named EntityGraph to findOne
+productRepository.findOne(1L, EntityGraphUtils.fromName("Product.brand"));
+```
+
+Or any method you like.
+
+You can also pass a dynamically built EntityGraph by using `DynamicEntityGraph`, it's also accessible through a helper method:
+
+```java
+productRepository.findOne(1L, EntityGraphUtils.fromAttributePaths("brand", "maker"));
+```
+
+This is similar to [Spring's ad-hoc attribute paths](http://docs.spring.io/spring-data/jpa/docs/current/reference/html/#repositories.query-methods.query-property-expressions),
+and equivalent to writing this in your repository's interface:
+```java
+@EntityGraph(attributePaths = { "brand", "maker" })
+Product findOne(Long id);
+```
+
+## Default EntityGraph
+
+For an Entity, you can define its default EntityGraph.
+An Entity default EntityGraph will be used each time the Entity repository method is called without EntityGraph.
+
+A default EntityGraph name must end with `.default`.
+
+```java
+@NamedEntityGraphs(value = {
+ @NamedEntityGraph(name = "Product.default", attributeNodes = {
+ @NamedAttributeNode("brand")
+ })
+})
+@Entity
+public class Product {
+ @Id
+ private long id = 0;
+ private String name;
+ @ManyToOne(fetch = FetchType.LAZY)
+ private Brand brand;
+ //...
+}
+```
+```java
+// This call will make use of "Product.default" EntityGraph.
+productRepository.findOne(1L);
+```
diff --git a/pom.xml b/pom.xml
index c3fed9b..da35de3 100644
--- a/pom.xml
+++ b/pom.xml
@@ -1,7 +1,5 @@
-
+
4.0.0
Spring Data JPA EntityGraph
@@ -10,11 +8,11 @@
com.cosium.spring.data
spring-data-jpa-entity-graph
- 1.11.00-SNAPSHOT
+ 1.11.04-SNAPSHOT
1.6
- 1.11.0.BUILD-SNAPSHOT
+ 1.11.0.RELEASE
2.6.2
4.1.3
@@ -238,7 +236,8 @@
scm:git:https://github.com/Cosium/spring-data-jpa-entity-graph
scm:git:https://github.com/Cosium/spring-data-jpa-entity-graph
https://github.com/Cosium/spring-data-jpa-entity-graph
-
+ HEAD
+
Cosium
diff --git a/src/main/java/com/cosium/spring/data/jpa/entity/graph/domain/EntityGraphUtils.java b/src/main/java/com/cosium/spring/data/jpa/entity/graph/domain/EntityGraphUtils.java
index 70a3718..f2f3fd6 100644
--- a/src/main/java/com/cosium/spring/data/jpa/entity/graph/domain/EntityGraphUtils.java
+++ b/src/main/java/com/cosium/spring/data/jpa/entity/graph/domain/EntityGraphUtils.java
@@ -1,10 +1,10 @@
package com.cosium.spring.data.jpa.entity.graph.domain;
-import com.mysema.commons.lang.Assert;
-
import java.util.Arrays;
import java.util.List;
+import org.springframework.util.Assert;
+
/**
* Created on 22/11/16.
*
diff --git a/src/main/java/com/cosium/spring/data/jpa/entity/graph/repository/EntityGraphCrudRepository.java b/src/main/java/com/cosium/spring/data/jpa/entity/graph/repository/EntityGraphCrudRepository.java
new file mode 100644
index 0000000..247fa0a
--- /dev/null
+++ b/src/main/java/com/cosium/spring/data/jpa/entity/graph/repository/EntityGraphCrudRepository.java
@@ -0,0 +1,44 @@
+package com.cosium.spring.data.jpa.entity.graph.repository;
+
+import java.io.Serializable;
+import java.util.List;
+
+import com.cosium.spring.data.jpa.entity.graph.domain.EntityGraph;
+import org.springframework.data.repository.CrudRepository;
+import org.springframework.data.repository.NoRepositoryBean;
+
+/**
+ * Created on 18/03/17.
+ *
+ * @author Reda.Housni-Alaoui
+ */
+@NoRepositoryBean
+public interface EntityGraphCrudRepository extends CrudRepository{
+
+ /**
+ * Retrieves an entity by its id.
+ *
+ * @param id must not be {@literal null}.
+ * @param entityGraph can be {@literal null}.
+ * @return the entity with the given id or {@literal null} if none found
+ * @throws IllegalArgumentException if {@code id} is {@literal null}
+ */
+ T findOne(ID id, EntityGraph entityGraph);
+
+ /**
+ * Returns all instances of the type with the given IDs.
+ *
+ * @param ids
+ * @param entityGraph can be {@literal null}.
+ * @return
+ */
+ List findAll(Iterable ids, EntityGraph entityGraph);
+
+ /**
+ * Returns all instances of the type.
+ *
+ * @param entityGraph can be {@literal null}.
+ * @return all entities
+ */
+ List findAll(EntityGraph entityGraph);
+}
diff --git a/src/main/java/com/cosium/spring/data/jpa/entity/graph/repository/EntityGraphJpaRepository.java b/src/main/java/com/cosium/spring/data/jpa/entity/graph/repository/EntityGraphJpaRepository.java
new file mode 100644
index 0000000..4e4d6fb
--- /dev/null
+++ b/src/main/java/com/cosium/spring/data/jpa/entity/graph/repository/EntityGraphJpaRepository.java
@@ -0,0 +1,18 @@
+package com.cosium.spring.data.jpa.entity.graph.repository;
+
+import java.io.Serializable;
+
+import org.springframework.data.jpa.repository.JpaRepository;
+import org.springframework.data.repository.NoRepositoryBean;
+
+/**
+ * Created on 22/11/16.
+ *
+ * @author Reda.Housni-Alaoui
+ */
+@NoRepositoryBean
+public interface EntityGraphJpaRepository
+ extends JpaRepository, EntityGraphPagingAndSortingRepository, EntityGraphQueryByExampleExecutor {
+
+
+}
diff --git a/src/main/java/com/cosium/spring/data/jpa/entity/graph/repository/EntityGraphJpaSpecificationExecutor.java b/src/main/java/com/cosium/spring/data/jpa/entity/graph/repository/EntityGraphJpaSpecificationExecutor.java
new file mode 100644
index 0000000..a081fde
--- /dev/null
+++ b/src/main/java/com/cosium/spring/data/jpa/entity/graph/repository/EntityGraphJpaSpecificationExecutor.java
@@ -0,0 +1,59 @@
+package com.cosium.spring.data.jpa.entity.graph.repository;
+
+import java.util.List;
+
+import com.cosium.spring.data.jpa.entity.graph.domain.EntityGraph;
+import org.springframework.data.domain.Page;
+import org.springframework.data.domain.Pageable;
+import org.springframework.data.domain.Sort;
+import org.springframework.data.jpa.domain.Specification;
+import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
+import org.springframework.data.repository.NoRepositoryBean;
+
+/**
+ * Created on 23/11/16.
+ *
+ * @author Reda.Housni-Alaoui
+ */
+@NoRepositoryBean
+public interface EntityGraphJpaSpecificationExecutor extends JpaSpecificationExecutor {
+
+ /**
+ * Returns a single entity matching the given {@link Specification}.
+ *
+ * @param spec
+ * @param entityGraph
+ * @return
+ */
+ T findOne(Specification spec, EntityGraph entityGraph);
+
+ /**
+ * Returns all entities matching the given {@link Specification}.
+ *
+ * @param spec
+ * @param entityGraph
+ * @return
+ */
+ List findAll(Specification spec, EntityGraph entityGraph);
+
+ /**
+ * Returns a {@link Page} of entities matching the given {@link Specification}.
+ *
+ * @param spec
+ * @param pageable
+ * @param entityGraph
+ * @return
+ */
+ Page findAll(Specification spec, Pageable pageable, EntityGraph entityGraph);
+
+ /**
+ * Returns all entities matching the given {@link Specification} and {@link Sort}.
+ *
+ * @param spec
+ * @param sort
+ * @param entityGraph
+ * @return
+ */
+ List findAll(Specification spec, Sort sort, EntityGraph entityGraph);
+
+}
diff --git a/src/main/java/com/cosium/spring/data/jpa/entity/graph/repository/EntityGraphPagingAndSortingRepository.java b/src/main/java/com/cosium/spring/data/jpa/entity/graph/repository/EntityGraphPagingAndSortingRepository.java
new file mode 100644
index 0000000..89cb668
--- /dev/null
+++ b/src/main/java/com/cosium/spring/data/jpa/entity/graph/repository/EntityGraphPagingAndSortingRepository.java
@@ -0,0 +1,40 @@
+package com.cosium.spring.data.jpa.entity.graph.repository;
+
+import java.io.Serializable;
+import java.util.List;
+
+import com.cosium.spring.data.jpa.entity.graph.domain.EntityGraph;
+import org.springframework.data.domain.Page;
+import org.springframework.data.domain.Pageable;
+import org.springframework.data.domain.Sort;
+import org.springframework.data.repository.NoRepositoryBean;
+import org.springframework.data.repository.PagingAndSortingRepository;
+
+/**
+ * Created on 18/03/17.
+ *
+ * @author Reda.Housni-Alaoui
+ */
+@NoRepositoryBean
+public interface EntityGraphPagingAndSortingRepository
+ extends PagingAndSortingRepository, EntityGraphCrudRepository {
+
+ /**
+ * Returns a {@link Page} of entities meeting the paging restriction provided in the {@code Pageable} object.
+ *
+ * @param pageable
+ * @param entityGraph can be {@literal null}.
+ * @return a page of entities
+ */
+ Page findAll(Pageable pageable, EntityGraph entityGraph);
+
+ /**
+ * Returns all entities sorted by the given options.
+ *
+ * @param sort
+ * @param entityGraph can be {@literal null}.
+ * @return all entities sorted by the given options
+ */
+ List findAll(Sort sort, EntityGraph entityGraph);
+
+}
diff --git a/src/main/java/com/cosium/spring/data/jpa/entity/graph/repository/EntityGraphQueryByExampleExecutor.java b/src/main/java/com/cosium/spring/data/jpa/entity/graph/repository/EntityGraphQueryByExampleExecutor.java
new file mode 100644
index 0000000..8bb8701
--- /dev/null
+++ b/src/main/java/com/cosium/spring/data/jpa/entity/graph/repository/EntityGraphQueryByExampleExecutor.java
@@ -0,0 +1,62 @@
+package com.cosium.spring.data.jpa.entity.graph.repository;
+
+import java.util.List;
+
+import com.cosium.spring.data.jpa.entity.graph.domain.EntityGraph;
+import org.springframework.data.domain.Example;
+import org.springframework.data.domain.Page;
+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;
+
+/**
+ * Created on 18/03/17.
+ *
+ * @author Reda.Housni-Alaoui
+ */
+@NoRepositoryBean
+public interface EntityGraphQueryByExampleExecutor extends QueryByExampleExecutor {
+
+ /**
+ * Returns a {@link Page} of entities matching the given {@link Example}. In case no match could be found, an empty
+ * {@link Page} is returned.
+ *
+ * @param example can be {@literal null}.
+ * @param pageable can be {@literal null}.
+ * @param entityGraph can be {@literal null}.
+ * @return a {@link Page} of entities matching the given {@link Example}.
+ */
+ Page findAll(Example example, Pageable pageable, EntityGraph entityGraph);
+
+ /**
+ * Returns a single entity matching the given {@link Example} or {@literal null} if none was found.
+ *
+ * @param example can be {@literal null}.
+ * @param entityGraph can be {@literal null}.
+ * @return a single entity matching the given {@link Example} or {@literal null} if none was found.
+ * @throws org.springframework.dao.IncorrectResultSizeDataAccessException if the Example yields more than one result.
+ */
+ S findOne(Example example, EntityGraph entityGraph);
+
+ /**
+ * Returns all entities matching the given {@link Example} applying the given {@link Sort}. In case no match could be
+ * found an empty {@link Iterable} is returned.
+ *
+ * @param example can be {@literal null}.
+ * @param sort the {@link Sort} specification to sort the results by, must not be {@literal null}.
+ * @param entityGraph can be {@literal null}.
+ * @return all entities matching the given {@link Example}.
+ */
+ List findAll(Example example, Sort sort, EntityGraph entityGraph);
+
+ /**
+ * Returns the number of instances matching the given {@link Example}.
+ *
+ * @param example the {@link Example} to count instances for, can be {@literal null}.
+ * @param entityGraph can be {@literal null}.
+ * @return the number of instances matching the {@link Example}.
+ */
+ List findAll(Example example, EntityGraph entityGraph);
+
+}
diff --git a/src/main/java/com/cosium/spring/data/jpa/entity/graph/repository/EntityGraphQueryDslPredicateExecutor.java b/src/main/java/com/cosium/spring/data/jpa/entity/graph/repository/EntityGraphQueryDslPredicateExecutor.java
new file mode 100644
index 0000000..31ed337
--- /dev/null
+++ b/src/main/java/com/cosium/spring/data/jpa/entity/graph/repository/EntityGraphQueryDslPredicateExecutor.java
@@ -0,0 +1,84 @@
+package com.cosium.spring.data.jpa.entity.graph.repository;
+
+import com.cosium.spring.data.jpa.entity.graph.domain.EntityGraph;
+import com.querydsl.core.types.OrderSpecifier;
+import com.querydsl.core.types.Predicate;
+import org.springframework.data.domain.Page;
+import org.springframework.data.domain.Pageable;
+import org.springframework.data.domain.Sort;
+import org.springframework.data.querydsl.QueryDslPredicateExecutor;
+import org.springframework.data.repository.NoRepositoryBean;
+
+/**
+ * Created on 23/11/16.
+ *
+ * @author Reda.Housni-Alaoui
+ */
+@NoRepositoryBean
+public interface EntityGraphQueryDslPredicateExecutor extends QueryDslPredicateExecutor {
+
+ /**
+ * Returns a single entity matching the given {@link Predicate} or {@literal null} if none was found.
+ *
+ * @param predicate can be {@literal null}.
+ * @param entityGraph can be {@literal null}.
+ * @return a single entity matching the given {@link Predicate} or {@literal null} if none was found.
+ * @throws org.springframework.dao.IncorrectResultSizeDataAccessException if the predicate yields more than one
+ * result.
+ */
+ T findOne(Predicate predicate, EntityGraph entityGraph);
+
+ /**
+ * Returns all entities matching the given {@link Predicate}. In case no match could be found an empty
+ * {@link Iterable} is returned.
+ *
+ * @param predicate can be {@literal null}.
+ * @param entityGraph can be {@literal null}.
+ * @return all entities matching the given {@link Predicate}.
+ */
+ Iterable findAll(Predicate predicate, EntityGraph entityGraph);
+
+ /**
+ * Returns all entities matching the given {@link Predicate} applying the given {@link Sort}. In case no match could
+ * be found an empty {@link Iterable} is returned.
+ *
+ * @param predicate can be {@literal null}.
+ * @param sort the {@link Sort} specification to sort the results by, must not be {@literal null}.
+ * @param entityGraph can be {@literal null}.
+ * @return all entities matching the given {@link Predicate}.
+ * @since 1.10
+ */
+ Iterable findAll(Predicate predicate, Sort sort, EntityGraph entityGraph);
+
+ /**
+ * Returns all entities matching the given {@link Predicate} applying the given {@link OrderSpecifier}s. In case no
+ * match could be found an empty {@link Iterable} is returned.
+ *
+ * @param predicate can be {@literal null}.
+ * @param entityGraph can be {@literal null}.
+ * @param orders the {@link OrderSpecifier}s to sort the results by
+ * @return all entities matching the given {@link Predicate} applying the given {@link OrderSpecifier}s.
+ */
+ Iterable findAll(Predicate predicate, EntityGraph entityGraph, OrderSpecifier>... orders);
+
+ /**
+ * Returns all entities ordered by the given {@link OrderSpecifier}s.
+ *
+ * @param orders the {@link OrderSpecifier}s to sort the results by.
+ * @param entityGraph can be {@literal null}.
+ * @return all entities ordered by the given {@link OrderSpecifier}s.
+ */
+ Iterable findAll(EntityGraph entityGraph, OrderSpecifier>... orders);
+
+ /**
+ * Returns a {@link Page} of entities matching the given {@link Predicate}. In case no match could be found, an empty
+ * {@link Page} is returned.
+ *
+ * @param predicate can be {@literal null}.
+ * @param pageable can be {@literal null}.
+ * @param entityGraph can be {@literal null}.
+ * @return a {@link Page} of entities matching the given {@link Predicate}.
+ */
+ Page findAll(Predicate predicate, Pageable pageable, EntityGraph entityGraph);
+
+}
diff --git a/src/main/java/com/cosium/spring/data/jpa/entity/graph/repository/JpaEntityGraphQueryDslPredicateExecutor.java b/src/main/java/com/cosium/spring/data/jpa/entity/graph/repository/JpaEntityGraphQueryDslPredicateExecutor.java
index d28cc0a..2578c85 100644
--- a/src/main/java/com/cosium/spring/data/jpa/entity/graph/repository/JpaEntityGraphQueryDslPredicateExecutor.java
+++ b/src/main/java/com/cosium/spring/data/jpa/entity/graph/repository/JpaEntityGraphQueryDslPredicateExecutor.java
@@ -1,82 +1,15 @@
package com.cosium.spring.data.jpa.entity.graph.repository;
-import com.cosium.spring.data.jpa.entity.graph.domain.EntityGraph;
-import com.querydsl.core.types.OrderSpecifier;
-import com.querydsl.core.types.Predicate;
-import org.springframework.data.domain.Page;
-import org.springframework.data.domain.Pageable;
-import org.springframework.data.domain.Sort;
-import org.springframework.data.querydsl.QueryDslPredicateExecutor;
+import org.springframework.data.repository.NoRepositoryBean;
/**
* Created on 23/11/16.
*
* @author Reda.Housni-Alaoui
+ * @deprecated Use {@link EntityGraphQueryDslPredicateExecutor} instead
*/
-public interface JpaEntityGraphQueryDslPredicateExecutor extends QueryDslPredicateExecutor {
-
- /**
- * Returns a single entity matching the given {@link Predicate} or {@literal null} if none was found.
- *
- * @param predicate can be {@literal null}.
- * @param entityGraph can be {@literal null}.
- * @return a single entity matching the given {@link Predicate} or {@literal null} if none was found.
- * @throws org.springframework.dao.IncorrectResultSizeDataAccessException if the predicate yields more than one
- * result.
- */
- T findOne(Predicate predicate, EntityGraph entityGraph);
-
- /**
- * Returns all entities matching the given {@link Predicate}. In case no match could be found an empty
- * {@link Iterable} is returned.
- *
- * @param predicate can be {@literal null}.
- * @param entityGraph can be {@literal null}.
- * @return all entities matching the given {@link Predicate}.
- */
- Iterable findAll(Predicate predicate, EntityGraph entityGraph);
-
- /**
- * Returns all entities matching the given {@link Predicate} applying the given {@link Sort}. In case no match could
- * be found an empty {@link Iterable} is returned.
- *
- * @param predicate can be {@literal null}.
- * @param sort the {@link Sort} specification to sort the results by, must not be {@literal null}.
- * @param entityGraph can be {@literal null}.
- * @return all entities matching the given {@link Predicate}.
- * @since 1.10
- */
- Iterable findAll(Predicate predicate, Sort sort, EntityGraph entityGraph);
-
- /**
- * Returns all entities matching the given {@link Predicate} applying the given {@link OrderSpecifier}s. In case no
- * match could be found an empty {@link Iterable} is returned.
- *
- * @param predicate can be {@literal null}.
- * @param entityGraph can be {@literal null}.
- * @param orders the {@link OrderSpecifier}s to sort the results by
- * @return all entities matching the given {@link Predicate} applying the given {@link OrderSpecifier}s.
- */
- Iterable findAll(Predicate predicate, EntityGraph entityGraph, OrderSpecifier>... orders);
-
- /**
- * Returns all entities ordered by the given {@link OrderSpecifier}s.
- *
- * @param orders the {@link OrderSpecifier}s to sort the results by.
- * @param entityGraph can be {@literal null}.
- * @return all entities ordered by the given {@link OrderSpecifier}s.
- */
- Iterable findAll(EntityGraph entityGraph, OrderSpecifier>... orders);
-
- /**
- * Returns a {@link Page} of entities matching the given {@link Predicate}. In case no match could be found, an empty
- * {@link Page} is returned.
- *
- * @param predicate can be {@literal null}.
- * @param pageable can be {@literal null}.
- * @param entityGraph can be {@literal null}.
- * @return a {@link Page} of entities matching the given {@link Predicate}.
- */
- Page findAll(Predicate predicate, Pageable pageable, EntityGraph entityGraph);
+@Deprecated
+@NoRepositoryBean
+public interface JpaEntityGraphQueryDslPredicateExecutor extends EntityGraphQueryDslPredicateExecutor{
}
diff --git a/src/main/java/com/cosium/spring/data/jpa/entity/graph/repository/JpaEntityGraphRepository.java b/src/main/java/com/cosium/spring/data/jpa/entity/graph/repository/JpaEntityGraphRepository.java
index 895a79c..7b13241 100644
--- a/src/main/java/com/cosium/spring/data/jpa/entity/graph/repository/JpaEntityGraphRepository.java
+++ b/src/main/java/com/cosium/spring/data/jpa/entity/graph/repository/JpaEntityGraphRepository.java
@@ -1,109 +1,17 @@
package com.cosium.spring.data.jpa.entity.graph.repository;
import java.io.Serializable;
-import java.util.List;
-import com.cosium.spring.data.jpa.entity.graph.domain.EntityGraph;
-import org.springframework.data.domain.Example;
-import org.springframework.data.domain.Page;
-import org.springframework.data.domain.Pageable;
-import org.springframework.data.domain.Sort;
-import org.springframework.data.jpa.domain.Specification;
-import org.springframework.data.jpa.repository.JpaRepository;
-import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.repository.NoRepositoryBean;
/**
- * Created on 22/11/16.
+ * Created on 23/11/16.
*
* @author Reda.Housni-Alaoui
+ * @deprecated Use {@link EntityGraphJpaRepository} instead
*/
+@Deprecated
@NoRepositoryBean
-public interface JpaEntityGraphRepository extends JpaRepository {
+public interface JpaEntityGraphRepository extends EntityGraphJpaRepository{
- /**
- * Returns a {@link Page} of entities matching the given {@link Example}. In case no match could be found, an empty
- * {@link Page} is returned.
- *
- * @param example can be {@literal null}.
- * @param pageable can be {@literal null}.
- * @param entityGraph can be {@literal null}.
- * @return a {@link Page} of entities matching the given {@link Example}.
- */
- Page findAll(Example example, Pageable pageable, EntityGraph entityGraph);
-
- /**
- * Returns a single entity matching the given {@link Example} or {@literal null} if none was found.
- *
- * @param example can be {@literal null}.
- * @param entityGraph can be {@literal null}.
- * @return a single entity matching the given {@link Example} or {@literal null} if none was found.
- * @throws org.springframework.dao.IncorrectResultSizeDataAccessException if the Example yields more than one result.
- */
- S findOne(Example example, EntityGraph entityGraph);
-
- /**
- * Retrieves an entity by its id.
- *
- * @param id must not be {@literal null}.
- * @param entityGraph can be {@literal null}.
- * @return the entity with the given id or {@literal null} if none found
- * @throws IllegalArgumentException if {@code id} is {@literal null}
- */
- T findOne(ID id, EntityGraph entityGraph);
-
- /**
- * Returns a {@link Page} of entities meeting the paging restriction provided in the {@code Pageable} object.
- *
- * @param pageable
- * @param entityGraph can be {@literal null}.
- * @return a page of entities
- */
- Page findAll(Pageable pageable, EntityGraph entityGraph);
-
- /**
- * Returns all entities matching the given {@link Example} applying the given {@link Sort}. In case no match could be
- * found an empty {@link Iterable} is returned.
- *
- * @param example can be {@literal null}.
- * @param sort the {@link Sort} specification to sort the results by, must not be {@literal null}.
- * @param entityGraph can be {@literal null}.
- * @return all entities matching the given {@link Example}.
- */
- List findAll(Example example, Sort sort, EntityGraph entityGraph);
-
- /**
- * Returns the number of instances matching the given {@link Example}.
- *
- * @param example the {@link Example} to count instances for, can be {@literal null}.
- * @param entityGraph can be {@literal null}.
- * @return the number of instances matching the {@link Example}.
- */
- List findAll(Example example, EntityGraph entityGraph);
-
- /**
- * Returns all instances of the type with the given IDs.
- *
- * @param ids
- * @param entityGraph can be {@literal null}.
- * @return
- */
- List findAll(Iterable ids, EntityGraph entityGraph);
-
- /**
- * Returns all entities sorted by the given options.
- *
- * @param sort
- * @param entityGraph can be {@literal null}.
- * @return all entities sorted by the given options
- */
- List findAll(Sort sort, EntityGraph entityGraph);
-
- /**
- * Returns all instances of the type.
- *
- * @param entityGraph can be {@literal null}.
- * @return all entities
- */
- List findAll(EntityGraph entityGraph);
}
diff --git a/src/main/java/com/cosium/spring/data/jpa/entity/graph/repository/JpaEntityGraphSpecificationExecutor.java b/src/main/java/com/cosium/spring/data/jpa/entity/graph/repository/JpaEntityGraphSpecificationExecutor.java
index b645031..63858f7 100644
--- a/src/main/java/com/cosium/spring/data/jpa/entity/graph/repository/JpaEntityGraphSpecificationExecutor.java
+++ b/src/main/java/com/cosium/spring/data/jpa/entity/graph/repository/JpaEntityGraphSpecificationExecutor.java
@@ -1,57 +1,15 @@
package com.cosium.spring.data.jpa.entity.graph.repository;
-import java.util.List;
-
-import com.cosium.spring.data.jpa.entity.graph.domain.EntityGraph;
-import org.springframework.data.domain.Page;
-import org.springframework.data.domain.Pageable;
-import org.springframework.data.domain.Sort;
-import org.springframework.data.jpa.domain.Specification;
-import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
+import org.springframework.data.repository.NoRepositoryBean;
/**
* Created on 23/11/16.
*
* @author Reda.Housni-Alaoui
+ * @deprecated Use {@link EntityGraphJpaSpecificationExecutor} instead
*/
-public interface JpaEntityGraphSpecificationExecutor extends JpaSpecificationExecutor {
-
- /**
- * Returns a single entity matching the given {@link Specification}.
- *
- * @param spec
- * @param entityGraph
- * @return
- */
- T findOne(Specification spec, EntityGraph entityGraph);
-
- /**
- * Returns all entities matching the given {@link Specification}.
- *
- * @param spec
- * @param entityGraph
- * @return
- */
- List findAll(Specification spec, EntityGraph entityGraph);
-
- /**
- * Returns a {@link Page} of entities matching the given {@link Specification}.
- *
- * @param spec
- * @param pageable
- * @param entityGraph
- * @return
- */
- Page findAll(Specification spec, Pageable pageable, EntityGraph entityGraph);
-
- /**
- * Returns all entities matching the given {@link Specification} and {@link Sort}.
- *
- * @param spec
- * @param sort
- * @param entityGraph
- * @return
- */
- List findAll(Specification spec, Sort sort, EntityGraph entityGraph);
+@Deprecated
+@NoRepositoryBean
+public interface JpaEntityGraphSpecificationExecutor extends EntityGraphJpaSpecificationExecutor {
}
diff --git a/src/main/java/com/cosium/spring/data/jpa/entity/graph/repository/support/JpaEntityGraphRepositoryFactory.java b/src/main/java/com/cosium/spring/data/jpa/entity/graph/repository/support/EntityGraphJpaRepositoryFactory.java
similarity index 89%
rename from src/main/java/com/cosium/spring/data/jpa/entity/graph/repository/support/JpaEntityGraphRepositoryFactory.java
rename to src/main/java/com/cosium/spring/data/jpa/entity/graph/repository/support/EntityGraphJpaRepositoryFactory.java
index b93f684..b1fbc56 100644
--- a/src/main/java/com/cosium/spring/data/jpa/entity/graph/repository/support/JpaEntityGraphRepositoryFactory.java
+++ b/src/main/java/com/cosium/spring/data/jpa/entity/graph/repository/support/EntityGraphJpaRepositoryFactory.java
@@ -1,6 +1,6 @@
package com.cosium.spring.data.jpa.entity.graph.repository.support;
-import static org.springframework.data.querydsl.QueryDslUtils.QUERY_DSL_PRESENT;
+import static org.springframework.data.querydsl.QueryDslUtils.*;
import javax.persistence.EntityManager;
import java.lang.reflect.Field;
@@ -22,7 +22,7 @@
*
* @author Reda.Housni-Alaoui
*/
-public class JpaEntityGraphRepositoryFactory extends JpaRepositoryFactory {
+public class EntityGraphJpaRepositoryFactory extends JpaRepositoryFactory {
static {
addEntityGraphToSpecialTypes();
@@ -59,7 +59,7 @@ private static void addEntityGraphToSpecialTypes(Class> clazz, String fieldNam
*
* @param entityManager must not be {@literal null}
*/
- public JpaEntityGraphRepositoryFactory(EntityManager entityManager) {
+ public EntityGraphJpaRepositoryFactory(EntityManager entityManager) {
super(entityManager);
addRepositoryProxyPostProcessor(new RepositoryMethodEntityGraphExtractor(entityManager));
}
@@ -67,9 +67,9 @@ public JpaEntityGraphRepositoryFactory(EntityManager entityManager) {
@Override
protected Class> getRepositoryBaseClass(RepositoryMetadata metadata) {
if (isQueryDslExecutor(metadata.getRepositoryInterface())) {
- return QueryDslJpaEntityGraphRepository.class;
+ return QueryDslEntityGraphRepository.class;
} else {
- return SimpleJpaEntityGraphRepository.class;
+ return EntityGraphSimpleJpaRepository.class;
}
}
diff --git a/src/main/java/com/cosium/spring/data/jpa/entity/graph/repository/support/EntityGraphJpaRepositoryFactoryBean.java b/src/main/java/com/cosium/spring/data/jpa/entity/graph/repository/support/EntityGraphJpaRepositoryFactoryBean.java
new file mode 100644
index 0000000..1ab03a4
--- /dev/null
+++ b/src/main/java/com/cosium/spring/data/jpa/entity/graph/repository/support/EntityGraphJpaRepositoryFactoryBean.java
@@ -0,0 +1,39 @@
+package com.cosium.spring.data.jpa.entity.graph.repository.support;
+
+import javax.persistence.EntityManager;
+import java.io.Serializable;
+
+import org.springframework.data.jpa.repository.support.JpaRepositoryFactoryBean;
+import org.springframework.data.repository.Repository;
+import org.springframework.data.repository.core.support.RepositoryFactorySupport;
+
+/**
+ * Forces the use of {@link RepositoryEntityManagerEntityGraphInjector} while targeting {@link EntityGraphJpaRepositoryFactory}.
+ *
+ * Created on 18/03/17.
+ *
+ * @author Reda.Housni-Alaoui
+ */
+public class EntityGraphJpaRepositoryFactoryBean, T, I extends Serializable>
+ extends JpaRepositoryFactoryBean {
+
+ /**
+ * Creates a new {@link JpaRepositoryFactoryBean} for the given repository interface.
+ *
+ * @param repositoryInterface must not be {@literal null}.
+ */
+ public EntityGraphJpaRepositoryFactoryBean(Class extends R> repositoryInterface) {
+ super(repositoryInterface);
+ }
+
+ @Override
+ public void setEntityManager(EntityManager entityManager) {
+ /* Make sure to use the EntityManager able to inject captured EntityGraphs */
+ super.setEntityManager(RepositoryEntityManagerEntityGraphInjector.proxy(entityManager));
+ }
+
+ @Override
+ protected RepositoryFactorySupport createRepositoryFactory(EntityManager entityManager) {
+ return new EntityGraphJpaRepositoryFactory(entityManager);
+ }
+}
diff --git a/src/main/java/com/cosium/spring/data/jpa/entity/graph/repository/support/SimpleJpaEntityGraphRepository.java b/src/main/java/com/cosium/spring/data/jpa/entity/graph/repository/support/EntityGraphSimpleJpaRepository.java
similarity index 85%
rename from src/main/java/com/cosium/spring/data/jpa/entity/graph/repository/support/SimpleJpaEntityGraphRepository.java
rename to src/main/java/com/cosium/spring/data/jpa/entity/graph/repository/support/EntityGraphSimpleJpaRepository.java
index 098ebeb..1492973 100644
--- a/src/main/java/com/cosium/spring/data/jpa/entity/graph/repository/support/SimpleJpaEntityGraphRepository.java
+++ b/src/main/java/com/cosium/spring/data/jpa/entity/graph/repository/support/EntityGraphSimpleJpaRepository.java
@@ -5,8 +5,8 @@
import java.util.List;
import com.cosium.spring.data.jpa.entity.graph.domain.EntityGraph;
-import com.cosium.spring.data.jpa.entity.graph.repository.JpaEntityGraphRepository;
-import com.cosium.spring.data.jpa.entity.graph.repository.JpaEntityGraphSpecificationExecutor;
+import com.cosium.spring.data.jpa.entity.graph.repository.EntityGraphJpaRepository;
+import com.cosium.spring.data.jpa.entity.graph.repository.EntityGraphJpaSpecificationExecutor;
import org.springframework.data.domain.Example;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
@@ -22,15 +22,15 @@
*
* @author Reda.Housni-Alaoui
*/
-public class SimpleJpaEntityGraphRepository
+public class EntityGraphSimpleJpaRepository
extends SimpleJpaRepository
- implements JpaEntityGraphRepository, JpaEntityGraphSpecificationExecutor {
+ implements EntityGraphJpaRepository, EntityGraphJpaSpecificationExecutor {
- public SimpleJpaEntityGraphRepository(JpaEntityInformation entityInformation, EntityManager entityManager) {
+ public EntityGraphSimpleJpaRepository(JpaEntityInformation entityInformation, EntityManager entityManager) {
super(entityInformation, entityManager);
}
- public SimpleJpaEntityGraphRepository(Class domainClass, EntityManager em) {
+ public EntityGraphSimpleJpaRepository(Class domainClass, EntityManager em) {
super(domainClass, em);
}
diff --git a/src/main/java/com/cosium/spring/data/jpa/entity/graph/repository/support/JpaEntityGraphRepositoryFactoryBean.java b/src/main/java/com/cosium/spring/data/jpa/entity/graph/repository/support/JpaEntityGraphRepositoryFactoryBean.java
index eb5c942..172d70e 100644
--- a/src/main/java/com/cosium/spring/data/jpa/entity/graph/repository/support/JpaEntityGraphRepositoryFactoryBean.java
+++ b/src/main/java/com/cosium/spring/data/jpa/entity/graph/repository/support/JpaEntityGraphRepositoryFactoryBean.java
@@ -1,40 +1,23 @@
package com.cosium.spring.data.jpa.entity.graph.repository.support;
-import javax.persistence.EntityManager;
import java.io.Serializable;
-import org.springframework.data.jpa.repository.JpaRepository;
-import org.springframework.data.jpa.repository.support.JpaRepositoryFactoryBean;
import org.springframework.data.repository.Repository;
-import org.springframework.data.repository.core.support.RepositoryFactorySupport;
/**
- * Forces the use of {@link RepositoryEntityManagerEntityGraphInjector} while targeting {@link JpaEntityGraphRepositoryFactory}.
+ * Forces the use of {@link RepositoryEntityManagerEntityGraphInjector} while targeting {@link EntityGraphJpaRepositoryFactory}.
*
* Created on 22/11/16.
*
* @author Reda.Housni-Alaoui
+ * @deprecated Use {@link EntityGraphJpaRepositoryFactoryBean} instead
*/
+@Deprecated
public class JpaEntityGraphRepositoryFactoryBean, T, I extends Serializable>
- extends JpaRepositoryFactoryBean{
+ extends EntityGraphJpaRepositoryFactoryBean{
- /**
- * Creates a new {@link JpaRepositoryFactoryBean} for the given repository interface.
- *
- * @param repositoryInterface must not be {@literal null}.
- */
public JpaEntityGraphRepositoryFactoryBean(Class extends R> repositoryInterface) {
super(repositoryInterface);
}
- @Override
- public void setEntityManager(EntityManager entityManager) {
- /* Make sure to use the EntityManager able to inject captured EntityGraphs */
- super.setEntityManager(RepositoryEntityManagerEntityGraphInjector.proxy(entityManager));
- }
-
- @Override
- protected RepositoryFactorySupport createRepositoryFactory(EntityManager entityManager) {
- return new JpaEntityGraphRepositoryFactory(entityManager);
- }
}
diff --git a/src/main/java/com/cosium/spring/data/jpa/entity/graph/repository/support/QueryDslJpaEntityGraphRepository.java b/src/main/java/com/cosium/spring/data/jpa/entity/graph/repository/support/QueryDslEntityGraphRepository.java
similarity index 85%
rename from src/main/java/com/cosium/spring/data/jpa/entity/graph/repository/support/QueryDslJpaEntityGraphRepository.java
rename to src/main/java/com/cosium/spring/data/jpa/entity/graph/repository/support/QueryDslEntityGraphRepository.java
index ff98722..addf589 100644
--- a/src/main/java/com/cosium/spring/data/jpa/entity/graph/repository/support/QueryDslJpaEntityGraphRepository.java
+++ b/src/main/java/com/cosium/spring/data/jpa/entity/graph/repository/support/QueryDslEntityGraphRepository.java
@@ -4,7 +4,7 @@
import java.io.Serializable;
import com.cosium.spring.data.jpa.entity.graph.domain.EntityGraph;
-import com.cosium.spring.data.jpa.entity.graph.repository.JpaEntityGraphQueryDslPredicateExecutor;
+import com.cosium.spring.data.jpa.entity.graph.repository.EntityGraphQueryDslPredicateExecutor;
import com.querydsl.core.types.OrderSpecifier;
import com.querydsl.core.types.Predicate;
import org.springframework.data.domain.Page;
@@ -21,18 +21,18 @@
*
* @author Reda.Housni-Alaoui
*/
-public class QueryDslJpaEntityGraphRepository
- extends SimpleJpaEntityGraphRepository implements JpaEntityGraphQueryDslPredicateExecutor {
+public class QueryDslEntityGraphRepository
+ extends EntityGraphSimpleJpaRepository implements EntityGraphQueryDslPredicateExecutor {
private QueryDslJpaRepository queryDslJpaRepositoryDelegate;
- public QueryDslJpaEntityGraphRepository(JpaEntityInformation entityInformation, EntityManager entityManager) {
+ public QueryDslEntityGraphRepository(JpaEntityInformation entityInformation, EntityManager entityManager) {
super(entityInformation, entityManager);
this.queryDslJpaRepositoryDelegate = new EntityGraphAwareQueryDslJpaRepository((JpaEntityInformation) entityInformation, entityManager);
}
- public QueryDslJpaEntityGraphRepository(JpaEntityInformation entityInformation, EntityManager entityManager,
- EntityPathResolver resolver) {
+ public QueryDslEntityGraphRepository(JpaEntityInformation entityInformation, EntityManager entityManager,
+ EntityPathResolver resolver) {
super(entityInformation, entityManager);
this.queryDslJpaRepositoryDelegate = new EntityGraphAwareQueryDslJpaRepository(entityInformation, entityManager, resolver);
}
diff --git a/src/site/resources/settings.xml b/src/site/resources/settings.xml
index 3756550..335188c 100644
--- a/src/site/resources/settings.xml
+++ b/src/site/resources/settings.xml
@@ -10,7 +10,7 @@
central
central
- http://repo1.maven.org/maven2
+ https://repo1.maven.org/maven2
spring-snapshot-local
diff --git a/src/test/java/com/cosium/spring/data/jpa/entity/graph/BaseTest.java b/src/test/java/com/cosium/spring/data/jpa/entity/graph/BaseTest.java
index ab538bd..000070b 100644
--- a/src/test/java/com/cosium/spring/data/jpa/entity/graph/BaseTest.java
+++ b/src/test/java/com/cosium/spring/data/jpa/entity/graph/BaseTest.java
@@ -1,8 +1,6 @@
package com.cosium.spring.data.jpa.entity.graph;
import com.github.springtestdbunit.DbUnitTestExecutionListener;
-import com.github.springtestdbunit.annotation.DatabaseSetup;
-import com.github.springtestdbunit.annotation.DatabaseTearDown;
import org.junit.runner.RunWith;
import org.springframework.boot.test.autoconfigure.orm.jpa.AutoConfigureDataJpa;
import org.springframework.test.annotation.DirtiesContext;
diff --git a/src/test/java/com/cosium/spring/data/jpa/entity/graph/DataRepositoryConfiguration.java b/src/test/java/com/cosium/spring/data/jpa/entity/graph/DataRepositoryConfiguration.java
index ff5108f..fba7a6f 100644
--- a/src/test/java/com/cosium/spring/data/jpa/entity/graph/DataRepositoryConfiguration.java
+++ b/src/test/java/com/cosium/spring/data/jpa/entity/graph/DataRepositoryConfiguration.java
@@ -1,6 +1,6 @@
package com.cosium.spring.data.jpa.entity.graph;
-import com.cosium.spring.data.jpa.entity.graph.repository.support.JpaEntityGraphRepositoryFactoryBean;
+import com.cosium.spring.data.jpa.entity.graph.repository.support.EntityGraphJpaRepositoryFactoryBean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
@@ -10,7 +10,7 @@
* @author Reda.Housni-Alaoui
*/
@Configuration
-@EnableJpaRepositories(repositoryFactoryBeanClass = JpaEntityGraphRepositoryFactoryBean.class)
+@EnableJpaRepositories(repositoryFactoryBeanClass = EntityGraphJpaRepositoryFactoryBean.class)
public class DataRepositoryConfiguration {
}
diff --git a/src/test/java/com/cosium/spring/data/jpa/entity/graph/repository/JpaEntityGraphCustomRepositoryTest.java b/src/test/java/com/cosium/spring/data/jpa/entity/graph/repository/EntityGraphCustomJpaRepositoryTest.java
similarity index 92%
rename from src/test/java/com/cosium/spring/data/jpa/entity/graph/repository/JpaEntityGraphCustomRepositoryTest.java
rename to src/test/java/com/cosium/spring/data/jpa/entity/graph/repository/EntityGraphCustomJpaRepositoryTest.java
index 301e9d9..78dac73 100644
--- a/src/test/java/com/cosium/spring/data/jpa/entity/graph/repository/JpaEntityGraphCustomRepositoryTest.java
+++ b/src/test/java/com/cosium/spring/data/jpa/entity/graph/repository/EntityGraphCustomJpaRepositoryTest.java
@@ -1,9 +1,8 @@
package com.cosium.spring.data.jpa.entity.graph.repository;
-import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.*;
import javax.inject.Inject;
-
import java.util.List;
import com.cosium.spring.data.jpa.entity.graph.BaseTest;
@@ -23,7 +22,7 @@
*/
@DatabaseSetup(BaseTest.DATASET)
@DatabaseTearDown
-public class JpaEntityGraphCustomRepositoryTest extends BaseTest {
+public class EntityGraphCustomJpaRepositoryTest extends BaseTest {
@Inject
private ProductRepository productRepository;
diff --git a/src/test/java/com/cosium/spring/data/jpa/entity/graph/repository/JpaEntityGraphRepositoryTest.java b/src/test/java/com/cosium/spring/data/jpa/entity/graph/repository/EntityGraphJpaRepositoryTest.java
similarity index 99%
rename from src/test/java/com/cosium/spring/data/jpa/entity/graph/repository/JpaEntityGraphRepositoryTest.java
rename to src/test/java/com/cosium/spring/data/jpa/entity/graph/repository/EntityGraphJpaRepositoryTest.java
index f90da23..a858250 100644
--- a/src/test/java/com/cosium/spring/data/jpa/entity/graph/repository/JpaEntityGraphRepositoryTest.java
+++ b/src/test/java/com/cosium/spring/data/jpa/entity/graph/repository/EntityGraphJpaRepositoryTest.java
@@ -7,7 +7,6 @@
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;
-
import java.util.List;
import com.cosium.spring.data.jpa.entity.graph.BaseTest;
@@ -30,7 +29,7 @@
*/
@DatabaseSetup(BaseTest.DATASET)
@DatabaseTearDown
-public class JpaEntityGraphRepositoryTest extends BaseTest {
+public class EntityGraphJpaRepositoryTest extends BaseTest {
@Inject
private ProductRepository productRepository;
diff --git a/src/test/java/com/cosium/spring/data/jpa/entity/graph/repository/JpaEntityGraphSpecificationExecutorTest.java b/src/test/java/com/cosium/spring/data/jpa/entity/graph/repository/EntityGraphJpaSpecificationExecutorTest.java
similarity index 98%
rename from src/test/java/com/cosium/spring/data/jpa/entity/graph/repository/JpaEntityGraphSpecificationExecutorTest.java
rename to src/test/java/com/cosium/spring/data/jpa/entity/graph/repository/EntityGraphJpaSpecificationExecutorTest.java
index 57d7034..a20ec34 100644
--- a/src/test/java/com/cosium/spring/data/jpa/entity/graph/repository/JpaEntityGraphSpecificationExecutorTest.java
+++ b/src/test/java/com/cosium/spring/data/jpa/entity/graph/repository/EntityGraphJpaSpecificationExecutorTest.java
@@ -30,7 +30,7 @@
*/
@DatabaseSetup(BaseTest.DATASET)
@DatabaseTearDown
-public class JpaEntityGraphSpecificationExecutorTest extends BaseTest {
+public class EntityGraphJpaSpecificationExecutorTest extends BaseTest {
@Inject
private ProductRepository productRepository;
diff --git a/src/test/java/com/cosium/spring/data/jpa/entity/graph/repository/JpaEntityGraphQueryDslPredicateExecutorTest.java b/src/test/java/com/cosium/spring/data/jpa/entity/graph/repository/EntityGraphQueryDslPredicateExecutorTest.java
similarity index 96%
rename from src/test/java/com/cosium/spring/data/jpa/entity/graph/repository/JpaEntityGraphQueryDslPredicateExecutorTest.java
rename to src/test/java/com/cosium/spring/data/jpa/entity/graph/repository/EntityGraphQueryDslPredicateExecutorTest.java
index 2bdaa1a..ce04506 100644
--- a/src/test/java/com/cosium/spring/data/jpa/entity/graph/repository/JpaEntityGraphQueryDslPredicateExecutorTest.java
+++ b/src/test/java/com/cosium/spring/data/jpa/entity/graph/repository/EntityGraphQueryDslPredicateExecutorTest.java
@@ -26,7 +26,7 @@
*/
@DatabaseSetup(BaseTest.DATASET)
@DatabaseTearDown
-public class JpaEntityGraphQueryDslPredicateExecutorTest extends BaseTest {
+public class EntityGraphQueryDslPredicateExecutorTest extends BaseTest {
@Inject
private ProductRepository productRepository;
diff --git a/src/test/java/com/cosium/spring/data/jpa/entity/graph/repository/RepositoryTest.java b/src/test/java/com/cosium/spring/data/jpa/entity/graph/repository/RepositoryTest.java
new file mode 100644
index 0000000..5fb890a
--- /dev/null
+++ b/src/test/java/com/cosium/spring/data/jpa/entity/graph/repository/RepositoryTest.java
@@ -0,0 +1,49 @@
+package com.cosium.spring.data.jpa.entity.graph.repository;
+
+import static org.assertj.core.api.Assertions.*;
+
+import javax.inject.Inject;
+import java.util.List;
+
+import com.cosium.spring.data.jpa.entity.graph.BaseTest;
+import com.cosium.spring.data.jpa.entity.graph.domain.EntityGraphUtils;
+import com.cosium.spring.data.jpa.entity.graph.repository.sample.Maker;
+import com.cosium.spring.data.jpa.entity.graph.repository.sample.MakerRepository;
+import com.github.springtestdbunit.annotation.DatabaseSetup;
+import com.github.springtestdbunit.annotation.DatabaseTearDown;
+import org.hibernate.Hibernate;
+import org.junit.Test;
+import org.springframework.transaction.annotation.Transactional;
+
+/**
+ * Created on 17/03/17.
+ *
+ * @author Reda.Housni-Alaoui
+ */
+@DatabaseSetup(BaseTest.DATASET)
+@DatabaseTearDown
+public class RepositoryTest extends BaseTest {
+
+ @Inject
+ private MakerRepository makerRepository;
+
+ @Transactional
+ @Test
+ public void given_empty_eg_when_finding_makers_then_country_should_not_be_initialized() {
+ List makers = makerRepository.findByName("Maker 1", EntityGraphUtils.empty());
+ assertThat(makers).isNotEmpty();
+ for (Maker maker : makers) {
+ assertThat(Hibernate.isInitialized(maker.getCountry())).isFalse();
+ }
+ }
+
+ @Transactional
+ @Test
+ public void given_country_eg_when_finding_makers_then_country_should_be_initialized() {
+ List makers = makerRepository.findByName("Maker 1", EntityGraphUtils.fromName(Maker.COUNTRY_EG));
+ assertThat(makers).isNotEmpty();
+ for (Maker maker : makers) {
+ assertThat(Hibernate.isInitialized(maker.getCountry())).isTrue();
+ }
+ }
+}
diff --git a/src/test/java/com/cosium/spring/data/jpa/entity/graph/repository/sample/BrandRepository.java b/src/test/java/com/cosium/spring/data/jpa/entity/graph/repository/sample/BrandRepository.java
index c785f0a..6f1ff58 100644
--- a/src/test/java/com/cosium/spring/data/jpa/entity/graph/repository/sample/BrandRepository.java
+++ b/src/test/java/com/cosium/spring/data/jpa/entity/graph/repository/sample/BrandRepository.java
@@ -1,12 +1,12 @@
package com.cosium.spring.data.jpa.entity.graph.repository.sample;
-import com.cosium.spring.data.jpa.entity.graph.repository.JpaEntityGraphRepository;
+import com.cosium.spring.data.jpa.entity.graph.repository.EntityGraphJpaRepository;
/**
* Created on 24/11/16.
*
* @author Reda.Housni-Alaoui
*/
-public interface BrandRepository extends JpaEntityGraphRepository {
+public interface BrandRepository extends EntityGraphJpaRepository {
}
diff --git a/src/test/java/com/cosium/spring/data/jpa/entity/graph/repository/sample/Country.java b/src/test/java/com/cosium/spring/data/jpa/entity/graph/repository/sample/Country.java
new file mode 100644
index 0000000..de87850
--- /dev/null
+++ b/src/test/java/com/cosium/spring/data/jpa/entity/graph/repository/sample/Country.java
@@ -0,0 +1,36 @@
+package com.cosium.spring.data.jpa.entity.graph.repository.sample;
+
+import javax.persistence.*;
+
+/**
+ * Created on 17/03/17.
+ *
+ * @author Reda.Housni-Alaoui
+ */
+@Entity
+public class Country {
+
+ @Id
+ @GeneratedValue(strategy = GenerationType.IDENTITY)
+ @Access(value = AccessType.PROPERTY)
+ private long id = 0;
+
+ private String name;
+
+ public long getId() {
+ return id;
+ }
+
+ public void setId(long id) {
+ this.id = id;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+}
diff --git a/src/test/java/com/cosium/spring/data/jpa/entity/graph/repository/sample/Maker.java b/src/test/java/com/cosium/spring/data/jpa/entity/graph/repository/sample/Maker.java
index 3cf877a..0516c77 100644
--- a/src/test/java/com/cosium/spring/data/jpa/entity/graph/repository/sample/Maker.java
+++ b/src/test/java/com/cosium/spring/data/jpa/entity/graph/repository/sample/Maker.java
@@ -7,8 +7,14 @@
*
* @author Reda.Housni-Alaoui
*/
+@NamedEntityGraphs({
+ @NamedEntityGraph(name = Maker.COUNTRY_EG, attributeNodes = {@NamedAttributeNode("country")})
+})
@Entity
public class Maker {
+
+ public static final String COUNTRY_EG = "Marker.country";
+
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Access(value = AccessType.PROPERTY)
@@ -16,6 +22,10 @@ public class Maker {
private String name;
+ @ManyToOne(fetch = FetchType.LAZY)
+ @JoinColumn(nullable = false)
+ private Country country;
+
public long getId() {
return id;
}
@@ -31,4 +41,12 @@ public String getName() {
public void setName(String name) {
this.name = name;
}
+
+ public Country getCountry() {
+ return country;
+ }
+
+ public void setCountry(Country country) {
+ this.country = country;
+ }
}
diff --git a/src/test/java/com/cosium/spring/data/jpa/entity/graph/repository/sample/MakerRepository.java b/src/test/java/com/cosium/spring/data/jpa/entity/graph/repository/sample/MakerRepository.java
new file mode 100644
index 0000000..57c22eb
--- /dev/null
+++ b/src/test/java/com/cosium/spring/data/jpa/entity/graph/repository/sample/MakerRepository.java
@@ -0,0 +1,17 @@
+package com.cosium.spring.data.jpa.entity.graph.repository.sample;
+
+import java.util.List;
+
+import com.cosium.spring.data.jpa.entity.graph.domain.EntityGraph;
+import org.springframework.data.repository.Repository;
+
+/**
+ * Created on 17/03/17.
+ *
+ * @author Reda.Housni-Alaoui
+ */
+public interface MakerRepository extends Repository {
+
+ List findByName(String name, EntityGraph entityGraph);
+
+}
diff --git a/src/test/java/com/cosium/spring/data/jpa/entity/graph/repository/sample/ProductRepository.java b/src/test/java/com/cosium/spring/data/jpa/entity/graph/repository/sample/ProductRepository.java
index 721bb06..99d518a 100644
--- a/src/test/java/com/cosium/spring/data/jpa/entity/graph/repository/sample/ProductRepository.java
+++ b/src/test/java/com/cosium/spring/data/jpa/entity/graph/repository/sample/ProductRepository.java
@@ -3,9 +3,9 @@
import java.util.List;
import com.cosium.spring.data.jpa.entity.graph.domain.EntityGraph;
-import com.cosium.spring.data.jpa.entity.graph.repository.JpaEntityGraphQueryDslPredicateExecutor;
-import com.cosium.spring.data.jpa.entity.graph.repository.JpaEntityGraphRepository;
-import com.cosium.spring.data.jpa.entity.graph.repository.JpaEntityGraphSpecificationExecutor;
+import com.cosium.spring.data.jpa.entity.graph.repository.EntityGraphJpaRepository;
+import com.cosium.spring.data.jpa.entity.graph.repository.EntityGraphJpaSpecificationExecutor;
+import com.cosium.spring.data.jpa.entity.graph.repository.EntityGraphQueryDslPredicateExecutor;
import org.springframework.data.jpa.repository.Query;
/**
@@ -14,9 +14,9 @@
* @author Reda.Housni-Alaoui
*/
public interface ProductRepository
- extends JpaEntityGraphRepository,
- JpaEntityGraphSpecificationExecutor,
- JpaEntityGraphQueryDslPredicateExecutor,
+ extends EntityGraphJpaRepository,
+ EntityGraphJpaSpecificationExecutor,
+ EntityGraphQueryDslPredicateExecutor,
ProductRepositoryCustom {
List findByName(String name, EntityGraph entityGraph);
diff --git a/src/test/resources/com/cosium/spring/data/jpa/entity/graph/dataset.xml b/src/test/resources/com/cosium/spring/data/jpa/entity/graph/dataset.xml
index a26fb53..c93b7ec 100644
--- a/src/test/resources/com/cosium/spring/data/jpa/entity/graph/dataset.xml
+++ b/src/test/resources/com/cosium/spring/data/jpa/entity/graph/dataset.xml
@@ -3,7 +3,9 @@
-
+
+
+