Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
81 commits
Select commit Hold shift + click to select a range
633365d
Compatibility with 1.10.4.RELEASE
reda-alaoui Nov 23, 2016
8051f38
Compatibility with 1.10.5.RELEASE
reda-alaoui Nov 23, 2016
0b9bd2b
Rename EntityGraph methods to make them more generic.
reda-alaoui Nov 23, 2016
1dfd923
Add the concept of empty Entitygraph
reda-alaoui Nov 23, 2016
cee4478
Add test on pagination
reda-alaoui Nov 23, 2016
74adc88
Error on count query triggered by page query
reda-alaoui Nov 23, 2016
1f4f957
Refactor proxy injector for performance
reda-alaoui Nov 23, 2016
6bf82df
Refactor
reda-alaoui Nov 23, 2016
eb19b6a
Refactor imports
reda-alaoui Nov 23, 2016
c145b12
Add default EntityGraph concept
reda-alaoui Nov 23, 2016
6a983af
Complete README
reda-alaoui Nov 23, 2016
e04b6a4
Add unique constraint on default method
reda-alaoui Nov 24, 2016
9faae0d
Change version in README
reda-alaoui Nov 24, 2016
14891e3
Add compatibility table
reda-alaoui Nov 24, 2016
dcb9d93
Add scm
reda-alaoui Nov 24, 2016
5bb8f29
[maven-release-plugin] prepare release spring-data-jpa-entity-graph-1…
reda-alaoui Nov 24, 2016
1cbe518
[maven-release-plugin] prepare for next development iteration
reda-alaoui Nov 24, 2016
1be969c
@EntityGraph must not be overridden by the default EntityGraph
reda-alaoui Nov 24, 2016
eea5079
[maven-release-plugin] prepare release spring-data-jpa-entity-graph-1…
reda-alaoui Nov 24, 2016
648f5cc
[maven-release-plugin] prepare for next development iteration
reda-alaoui Nov 24, 2016
626c147
Update README
reda-alaoui Nov 24, 2016
72faee8
Add license info
reda-alaoui Nov 24, 2016
4adab2f
Only gpg sign on release
reda-alaoui Nov 24, 2016
7105cb0
[maven-release-plugin] prepare release spring-data-jpa-entity-graph-1…
reda-alaoui Nov 24, 2016
d4dc003
[maven-release-plugin] prepare for next development iteration
reda-alaoui Nov 24, 2016
5e0e667
[maven-release-plugin] prepare release spring-data-jpa-entity-graph-1…
reda-alaoui Nov 24, 2016
1170398
[maven-release-plugin] prepare for next development iteration
reda-alaoui Nov 24, 2016
3571ebe
Add name, description and url to the pom
reda-alaoui Nov 24, 2016
cd4ce4a
[maven-release-plugin] prepare release spring-data-jpa-entity-graph-1…
reda-alaoui Nov 24, 2016
fe0a5ae
[maven-release-plugin] prepare for next development iteration
reda-alaoui Nov 24, 2016
f508ee0
Update README
reda-alaoui Nov 24, 2016
e8acdf0
QueryHints can be null
reda-alaoui Nov 24, 2016
bb5dd4f
[maven-release-plugin] prepare release spring-data-jpa-entity-graph-1…
reda-alaoui Nov 24, 2016
fa816e0
[maven-release-plugin] prepare for next development iteration
reda-alaoui Nov 24, 2016
eb5c652
Update README
reda-alaoui Nov 24, 2016
d97cb50
Manage raw returns
reda-alaoui Nov 24, 2016
1f99591
Add release script
reda-alaoui Nov 24, 2016
8a1cf01
Add release script
reda-alaoui Nov 24, 2016
e456b64
[maven-release-plugin] prepare release spring-data-jpa-entity-graph-1…
reda-alaoui Nov 24, 2016
3355d0f
[maven-release-plugin] prepare for next development iteration
reda-alaoui Nov 24, 2016
2242bc0
Update README
reda-alaoui Nov 24, 2016
ad438aa
NPE when there is no default EntityGraph
reda-alaoui Nov 24, 2016
145f3ac
[maven-release-plugin] prepare release spring-data-jpa-entity-graph-1…
reda-alaoui Nov 24, 2016
c15a651
[maven-release-plugin] prepare for next development iteration
reda-alaoui Nov 24, 2016
79a5c8a
Update README
reda-alaoui Nov 24, 2016
b705596
Update README.md
reda-alaoui Nov 25, 2016
216a111
Enhance README
reda-alaoui Nov 25, 2016
a738d58
Enhance README
reda-alaoui Nov 25, 2016
350a645
Type exceptions
reda-alaoui Nov 27, 2016
9192f36
Throw InapplicableEntityGraphException in case of mandatory EntityGra…
reda-alaoui Nov 27, 2016
bd359af
Fail when multiple EntityGraphs are detected on one repository method…
reda-alaoui Nov 27, 2016
a7b23ae
[maven-release-plugin] prepare release spring-data-jpa-entity-graph-1…
reda-alaoui Nov 27, 2016
ed4cf9d
[maven-release-plugin] prepare for next development iteration
reda-alaoui Nov 27, 2016
fb87d0c
Update README
reda-alaoui Nov 27, 2016
df1eba9
Don't fail on method returning void
reda-alaoui Nov 28, 2016
8261bd5
[maven-release-plugin] prepare release spring-data-jpa-entity-graph-1…
reda-alaoui Nov 28, 2016
41b446b
[maven-release-plugin] prepare for next development iteration
reda-alaoui Nov 28, 2016
4c05da6
Update README
reda-alaoui Nov 28, 2016
8facae4
Add the concept of optional EntityGraph
reda-alaoui Nov 28, 2016
b382aaf
[maven-release-plugin] prepare release spring-data-jpa-entity-graph-1…
reda-alaoui Nov 28, 2016
b4a963c
[maven-release-plugin] prepare for next development iteration
reda-alaoui Nov 28, 2016
6f7caec
Bump to 1.10.10
reda-alaoui Nov 28, 2016
9d48334
Primary EntityGraph should override any EntityGraph query hint
reda-alaoui Nov 28, 2016
6f678c1
[maven-release-plugin] prepare release spring-data-jpa-entity-graph-1…
reda-alaoui Nov 28, 2016
8a8198e
[maven-release-plugin] prepare for next development iteration
reda-alaoui Nov 28, 2016
69bdb1f
Bump to 1.10.11
reda-alaoui Nov 28, 2016
69e6945
Fix #1 EntityGraph applied on QueryDsl Pagination count query
reda-alaoui Dec 5, 2016
789cbd3
[maven-release-plugin] prepare release spring-data-jpa-entity-graph-1…
reda-alaoui Dec 5, 2016
4b92560
[maven-release-plugin] prepare for next development iteration
reda-alaoui Dec 5, 2016
8394b64
Bump to 1.10.12
reda-alaoui Dec 5, 2016
9c76b47
Add travis config
reda-alaoui Dec 5, 2016
7b4f555
Use oraclejdk8
reda-alaoui Dec 5, 2016
2e704a2
Fix #2 Wrong EntityGraph applied when nesting repositories method call
reda-alaoui Dec 6, 2016
2363836
[maven-release-plugin] prepare release spring-data-jpa-entity-graph-1…
reda-alaoui Dec 6, 2016
72f5b9d
[maven-release-plugin] prepare for next development iteration
reda-alaoui Dec 6, 2016
cd20329
Bump to 1.10.13
reda-alaoui Dec 6, 2016
cde7b67
Add badges
reda-alaoui Dec 6, 2016
189765c
Add codecov.io
reda-alaoui Dec 15, 2016
e6e0d95
Add codecov.io
reda-alaoui Dec 15, 2016
2a9a6da
Add codecov.io badge
reda-alaoui Dec 15, 2016
d0a47e8
Add codecov.io badge
reda-alaoui Dec 15, 2016
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
7 changes: 7 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
language: java
jdk:
- oraclejdk8
before_install:
- curl -o $HOME/.m2/settings.xml https://raw.githubusercontent.com/Cosium/spring-data-jpa-entity-graph/$TRAVIS_BRANCH/src/site/resources/settings.xml
after_success:
- bash <(curl -s https://codecov.io/bash)
68 changes: 58 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,37 @@
### Why?
[![Travis branch](https://img.shields.io/travis/Cosium/spring-data-jpa-entity-graph/1.10.x.svg)](https://travis-ci.org/Cosium/spring-data-jpa-entity-graph)
[![Codecov branch](https://img.shields.io/codecov/c/github/Cosium/spring-data-jpa-entity-graph/1.10.x.svg)](https://codecov.io/gh/Cosium/spring-data-jpa-entity-graph)
[![Maven Central](https://img.shields.io/maven-central/v/com.cosium.spring.data/spring-data-jpa-entity-graph.svg)](http://search.maven.org/#search%7Cgav%7C1%7Cg%3A%22com.cosium.spring.data%22%20AND%20a%3A%22spring-data-jpa-entity-graph%22)

Today, Spring Data JPA supports EntityGraph exlusively through annotations.
# Spring Data JPA EntityGraph

Today, [Spring Data JPA](https://github.com/spring-projects/spring-data-jpa) supports EntityGraph exlusively through annotations.
Thus, for a method, the choice of EntityGraph must be made before compilation.

This library gives the ability to pass EntityGraph on any Spring Data JPA repository method as an argument, making the EntityGraph choice fully dynamic.
This extension gives the ability to pass EntityGraph on any Spring Data JPA repository method as an argument, making the EntityGraph choice fully dynamic.

Example:
```java
productRepository.findByName("foo", EntityGraphUtils.fromName("Product.brand"));
```

## Compatibility

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

### Quick start in 3 steps
## Quick start

1. Add the dependency :
1. In addition to spring-data-jpa, add the library dependency :

```xml
<dependency>
<groupId>com.cosium.spring.data</groupId>
<artifactId>spring-data-jpa-entity-graph</artifactId>
<version>1.11.00-SNAPSHOT</version>
<version>1.10.13</version>
</dependency>
```
2. In your Spring configuration, set the repository factory bean class to `JpaEntityGraphRepositoryFactoryBean` :
Expand All @@ -27,7 +45,7 @@ This library gives the ability to pass EntityGraph on any Spring Data JPA reposi
```
3. Make sure your repositories extend `JpaEntityGraphRepository`, `JpaEntityGraphSpecificationExecutor` and/or `JpaEntityGraphQueryDslPredicateExecutor`

##Usage
## Basic Usage

Let's consider the following entities and repository :
```java
Expand Down Expand Up @@ -63,14 +81,44 @@ public interface ProductRepository extends JpaEntityGraphRepository<Product, Lon

You can pass the entity graph to the `findByName` method :
```java
productRepository.findByName("MyProduct", EntityGraphUtils.fromName("Product.brand");
// This will apply 'Product.brand' named EntityGraph to findByName
productRepository.findByName("MyProduct", EntityGraphUtils.fromName("Product.brand"));
```

Or to the `findOne` method :
```java
productRepository.findOne(1L, EntityGraphUtils.fromName("Product.brand");
// 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 implementation.
You can also pass a dynamically built EntityGraph by using `DynamicEntityGraph` implementation.

## 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);
```
104 changes: 81 additions & 23 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<name>Spring Data JPA EntityGraph</name>
<description>A Spring Data JPA extension allowing full usage of JPA EntityGraph on repositories</description>
<url>https://github.com/Cosium/spring-data-jpa-entity-graph</url>

<groupId>com.cosium.spring.data</groupId>
<artifactId>spring-data-jpa-entity-graph</artifactId>
<version>1.11.00-SNAPSHOT</version>
<version>1.10.14-SNAPSHOT</version>

<properties>
<source.level>1.6</source.level>
<spring.data.jpa>1.11.0.BUILD-SNAPSHOT</spring.data.jpa>
<spring.data.jpa>1.10.5.RELEASE</spring.data.jpa>
<eclipselink>2.6.2</eclipselink>
<querydsl>4.1.3</querydsl>

<!--Test-->
<dbunit>2.5.3</dbunit>
<spring-test-dbunit>1.3.0</spring-test-dbunit>
<spring.boot>1.4.1.RELEASE</spring.boot>
<spring.boot>1.3.8.RELEASE</spring.boot>
<h2>1.4.193</h2>
</properties>

Expand Down Expand Up @@ -86,6 +88,12 @@
<version>${dbunit}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>3.3.0</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down Expand Up @@ -146,7 +154,7 @@
<pushChanges>false</pushChanges>
<localCheckout>true</localCheckout>
<autoVersionSubmodules>true</autoVersionSubmodules>
<useReleaseProfile>false</useReleaseProfile>
<useReleaseProfile>true</useReleaseProfile>
<releaseProfiles>release</releaseProfiles>
<goals>deploy</goals>
</configuration>
Expand All @@ -168,22 +176,75 @@
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
<version>1.6</version>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.7.7.201606060606</version>
<executions>
<execution>
<id>sign-artifacts</id>
<phase>deploy</phase>
<goals>
<goal>sign</goal>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>report</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

<profiles>
<profile>
<id>release-sign-artifacts</id>
<activation>
<property>
<name>performRelease</name>
<value>true</value>
</property>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
<version>1.6</version>
<executions>
<execution>
<id>sign-artifacts</id>
<phase>verify</phase>
<goals>
<goal>sign</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>

<distributionManagement>
<snapshotRepository>
<id>ossrh</id>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
</snapshotRepository>
<repository>
<id>ossrh</id>
<url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>
</repository>
</distributionManagement>

<scm>
<connection>scm:git:https://github.com/Cosium/spring-data-jpa-entity-graph</connection>
<developerConnection>scm:git:https://github.com/Cosium/spring-data-jpa-entity-graph</developerConnection>
<url>https://github.com/Cosium/spring-data-jpa-entity-graph</url>
<tag>HEAD</tag>
</scm>

<organization>
<name>Cosium</name>
<url>http://www.cosium.com</url>
Expand All @@ -198,15 +259,12 @@
</developer>
</developers>

<distributionManagement>
<snapshotRepository>
<id>ossrh</id>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
</snapshotRepository>
<repository>
<id>ossrh</id>
<url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>
</repository>
</distributionManagement>
<licenses>
<license>
<name>MIT License</name>
<url>http://www.opensource.org/licenses/mit-license.php</url>
<distribution>repo</distribution>
</license>
</licenses>

</project>
2 changes: 2 additions & 0 deletions release.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/usr/bin/env bash
mvn --batch-mode clean release:prepare release:perform && git push && git push --tags
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.cosium.spring.data.jpa.entity.graph.domain;

import com.google.common.base.MoreObjects;
import org.springframework.util.Assert;

/**
Expand All @@ -9,22 +10,52 @@
*/
public abstract class AbstractEntityGraph implements EntityGraph{

private EntityGraphType type = EntityGraphType.FETCH;
protected static final EntityGraphType DEFAULT_ENTITY_GRAPH_TYPE = EntityGraphType.FETCH;
private EntityGraphType entityGraphType = DEFAULT_ENTITY_GRAPH_TYPE;
private boolean optional;

public AbstractEntityGraph(){}

public AbstractEntityGraph(EntityGraphType type){
Assert.notNull(type);
this.type = type;
public AbstractEntityGraph(EntityGraphType entityGraphType){
this(entityGraphType, false);
}

public AbstractEntityGraph(EntityGraphType entityGraphType, boolean optional){
Assert.notNull(entityGraphType);
this.entityGraphType = entityGraphType;
this.optional = optional;
}

@Override
public EntityGraphType getType() {
return type;
public EntityGraphType getEntityGraphType() {
return entityGraphType;
}

public void setEntityGraphType(EntityGraphType entityGraphType) {
Assert.notNull(entityGraphType);
this.entityGraphType = entityGraphType;
}

public void setType(EntityGraphType type) {
Assert.notNull(type);
this.type = type;
/**
* False by default
* @return True if the EntityGraph is optional.<br>
* Passing an optional EntityGraph to an unsupported method will not trigger {@link com.cosium.spring.data.jpa.entity.graph.repository.exception.InapplicableEntityGraphException}.
*/
@Override
public boolean isOptional() {
return optional;
}

public void setOptional(boolean optional) {
this.optional = optional;
}

@Override
public String toString() {
return MoreObjects.toStringHelper(this)
.add("entityGraphType", entityGraphType)
.add("optional", optional)
.toString();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import java.util.Collections;
import java.util.List;

import com.google.common.base.MoreObjects;

/**
* Created on 22/11/16.
*
Expand All @@ -22,12 +24,20 @@ public DynamicEntityGraph(EntityGraphType type, List<String> attributePaths){
}

@Override
public List<String> getAttributePaths() {
public List<String> getEntityGraphAttributePaths() {
return attributePaths;
}

@Override
public final String getName() {
public final String getEntityGraphName() {
return null;
}


@Override
public String toString() {
return MoreObjects.toStringHelper(this)
.add("attributePaths", attributePaths)
.toString();
}
}
Loading