Skip to content

Commit

Permalink
[Wen Hao] - add docs.
Browse files Browse the repository at this point in the history
  • Loading branch information
wenhao committed Mar 7, 2017
1 parent 223e8ba commit d65a357
Show file tree
Hide file tree
Showing 12 changed files with 1,682 additions and 78 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,5 @@ jpa-spec.ipr
jpa-spec.iws
jpa-spec.iml
src/.DS_Store

.java-version
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,20 @@ but it still productive and easily understandable. Build on Spring Data JPA and
* Builder style specification creator.
* Support pagination and sort builder.

### Docs

English Version:

[Latest]

[3.0.0]

Chinese Version:

[最新]

[3.0.0_cn]

### Gradle

```groovy
Expand Down Expand Up @@ -335,6 +349,11 @@ Copyright © 2016-2017 Wen Hao

Licensed under [Apache License]


[Latest]: ./docs/3.1.0.md
[3.0.0]: ./docs/3.0.0.md
[最新]: ./docs/3.1.0_cn.md
[3.0.0_cn]: ./docs/3.0.0_cn.md
[Legacy Hibernate Criteria Queries]: https://docs.jboss.org/hibernate/orm/5.2/userguide/html_single/Hibernate_User_Guide.html#appendix-legacy-criteria
[EqualTest.java]: ./src/test/java/com/github/wenhao/jpa/integration/EqualTest.java
[NotEqualTest.java]: ./src/test/java/com/github/wenhao/jpa/integration/NotEqualTest.java
Expand Down
73 changes: 36 additions & 37 deletions README_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ repositories {
}
dependencies {
compile 'com.github.wenhao:jpa-spec:3.0.0'
compile 'com.github.wenhao:jpa-spec:3.1.0'
}
```

Expand All @@ -49,7 +49,7 @@ dependencies {
<dependency>
<groupId>com.github.wenhao</groupId>
<artifactId>jpa-spec</artifactId>
<version>3.0.0</version>
<version>3.1.0</version>
</dependency>
```

Expand Down Expand Up @@ -89,14 +89,14 @@ public interface PersonRepository extends JpaRepository<Person, Long>, JpaSpecif

```java
public Page<Person> findAll(SearchRequest request) {
Specification<Person> specification = Specifications.<Person>builder()
Specification<Person> specification = Specifications.<Person>and()
.eq(StringUtils.isNotBlank(request.getName()), "name", request.getName())
.gt(Objects.nonNull(request.getAge()), "age", 18)
.between("birthday", new Range<>(new Date(), new Date()))
.like("nickName", "%og%", "%me")
.build();
return personRepository.findAll(specification, new PageRequest(0, 15));

return personRepository.findAll(specification, new PageRequest(0, 15));
}
```

Expand All @@ -117,13 +117,13 @@ find any person nickName equals to "dog" and name equals to "Jack"/"Eric" or nul

```java
public List<Person> findAll(SearchRequest request) {
Specification<Person> specification = Specifications.<Person>builder()
Specification<Person> specification = Specifications.<Person>and()
.eq("nickName", "dog")
.eq(StringUtils.isNotBlank(request.getName()), "name", "Jack", "Eric", null)
.eq("company", null) //or eq("company", (Object) null)
.build();
return personRepository.findAll(specification);

return personRepository.findAll(specification);
}
```

Expand All @@ -141,12 +141,12 @@ find any person name in "Jack" or "Eric" and company not in "ThoughtWorks" or "I

```java
public List<Person> findAll(SearchRequest request) {
Specification<Person> specification = Specifications.<Person>builder()
Specification<Person> specification = Specifications.<Person>and()
.in("name", request.getNames().toArray()) //or in("name", "Jack", "Eric")
.notIn("company", "ThoughtWorks", "IBM")
.build();
return personRepository.findAll(specification);

return personRepository.findAll(specification);
}
```

Expand All @@ -164,11 +164,11 @@ find any people age bigger than 18.

```java
public List<Person> findAll(SearchRequest request) {
Specification<Person> specification = Specifications.<Person>builder()
Specification<Person> specification = Specifications.<Person>and()
.gt(Objects.nonNull(request.getAge()), "age", 18)
.build();
return personRepository.findAll(specification);

return personRepository.findAll(specification);
}
```

Expand All @@ -186,12 +186,12 @@ find any person age between 18 and 25, birthday between someday and someday.

```java
public List<Person> findAll(SearchRequest request) {
Specification<Person> specification = Specifications.<Person>builder()
Specification<Person> specification = Specifications.<Person>and()
.between(Objects.nonNull(request.getAge(), "age", new Range<>(18, 25))
.between("birthday", new Range<>(new Date(), new Date()))
.build();
return personRepository.findAll(specification);

return personRepository.findAll(specification);
}
```

Expand All @@ -212,12 +212,12 @@ find any person name like %ac% or %og%, company not like %ec%.

```java
public Page<Person> findAll(SearchRequest request) {
Specification<Person> specification = Specifications.<Person>builder()
Specification<Person> specification = Specifications.<Person>and()
.like("name", "ac", "%og%")
.notLike("company", "ec")
.build();
return personRepository.findAll(specification);

return personRepository.findAll(specification);
}
```

Expand All @@ -235,12 +235,10 @@ support or specifications.

```java
public List<Phone> findAll(SearchRequest request) {
Specification<Person> specification = Specifications.<Person>builder()
.and(OrSpecifications.<Person>builder()
Specification<Person> specification = Specifications.<Person>or()
.like("name", "%ac%")
.gt("age", 19)
.build())
.build();
.build();

return phoneRepository.findAll(specification);
}
Expand All @@ -265,7 +263,7 @@ each specification support association query as left join.

```java
public List<Phone> findAll(SearchRequest request) {
Specification<Phone> specification = Specifications.<Phone>builder()
Specification<Phone> specification = Specifications.<Phone>and()
.eq(StringUtils.isNotBlank(request.getBrand()), "brand", "HuaWei")
.eq(StringUtils.isNotBlank(request.getPersonName()), "person.name", "Jack")
.build();
Expand All @@ -281,7 +279,7 @@ public List<Phone> findAll(SearchRequest request) {

```java
public List<Phone> findAll(SearchRequest request) {
Specification<Person> specification = Specifications.<Person>builder()
Specification<Person> specification = Specifications.<Person>and()
.between("age", new Range<>(10, 35))
.eq(StringUtils.isNotBlank(jack.getName()), "addresses.street", "Chengdu")
.build();
Expand Down Expand Up @@ -309,9 +307,9 @@ You can custom specification to do the @ManyToOne and @ManyToMany as well.

```java
public List<Phone> findAll(SearchRequest request) {
Specification<Phone> specification = Specifications.<Phone>builder()
Specification<Phone> specification = Specifications.<Phone>and()
.eq(StringUtils.isNotBlank(request.getBrand()), "brand", "HuaWei")
.and(StringUtils.isNotBlank(request.getPersonName()), (root, query, cb) -> {
.predicate(StringUtils.isNotBlank(request.getPersonName()), (root, query, cb) -> {
Path<Person> person = root.get("person");
return cb.equal(person.get("name"), "Jack");
})
Expand All @@ -330,9 +328,9 @@ public List<Phone> findAll(SearchRequest request) {

```java
public List<Phone> findAll(SearchRequest request) {
Specification<Person> specification = Specifications.<Person>builder()
Specification<Person> specification = Specifications.<Person>and()
.between("age", new Range<>(10, 35))
.and(StringUtils.isNotBlank(jack.getName()), ((root, query, cb) -> {
.predicate(StringUtils.isNotBlank(jack.getName()), ((root, query, cb) -> {
Join address = root.join("addresses", JoinType.LEFT);
return cb.equal(address.get("street"), "Chengdu");
}))
Expand All @@ -341,6 +339,7 @@ public List<Phone> findAll(SearchRequest request) {
return phoneRepository.findAll(specification);
}
```

<!--
####Sort
-->
Expand All @@ -350,7 +349,7 @@ public List<Phone> findAll(SearchRequest request) {

```java
public List<Person> findAll(SearchRequest request) {
Specification<Person> specification = Specifications.<Person>builder()
Specification<Person> specification = Specifications.<Person>and()
.eq(StringUtils.isNotBlank(request.getName()), "name", request.getName())
.gt("age", 18)
.between("birthday", new Range<>(new Date(), new Date()))
Expand Down Expand Up @@ -378,18 +377,18 @@ find person by pagination and sort by name desc and birthday asc.

```java
public Page<Person> findAll(SearchRequest request) {
Specification<Person> specification = Specifications.<Person>builder()
Specification<Person> specification = Specifications.<Person>and()
.eq(StringUtils.isNotBlank(request.getName()), "name", request.getName())
.gt("age", 18)
.between("birthday", new Range<>(new Date(), new Date()))
.like("nickName", "%og%")
.build();

Sort sort = Sorts.builder()
.desc(StringUtils.isNotBlank(request.getName()), "name")
.asc("birthday")
.build();

return personRepository.findAll(specification, new PageRequest(0, 15, sort));
}
```
Expand Down Expand Up @@ -431,11 +430,11 @@ public class PersonIdCard {
```java
public List<PersonIdCard> findAll(SearchRequest request) {
Specification<PersonIdCard> specification = Specifications.<PersonIdCard>builder()
Specification<PersonIdCard> specification = Specifications.<PersonIdCard>and()
.gt(Objects.nonNull(request.getAge()), "age", 18)
.build();
return personIdCardRepository.findAll(specification);
return personIdCardRepository.findAll(specification);
}
```
Expand Down
12 changes: 6 additions & 6 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ repositories {
}

group = 'com.github.wenhao'
version = '3.0.0'
version = '3.1.0'

idea {
project {
Expand Down Expand Up @@ -102,10 +102,10 @@ bintray {
githubRepo = 'wenhao/jpa-spec'
githubReleaseNotesFile = 'README.md'
version {
name = '3.0.0'
desc = 'A JAP Query By Specification framework 3.0.0'
name = '3.1.0'
desc = 'A JAP Query By Specification framework 3.1.0'
released = new Date()
vcsTag = '3.0.0'
vcsTag = '3.1.0'
}
}
}
Expand All @@ -121,7 +121,7 @@ install {
packaging 'jar'
groupId 'com.github.wenhao'
artifactId 'jpa-spec'
version '3.0.0'
version '3.1.0'

licenses {
license {
Expand Down Expand Up @@ -175,7 +175,7 @@ uploadArchives {
packaging 'jar'
groupId 'com.github.wenhao'
artifactId 'jpa-spec'
version '3.0.0'
version '3.1.0'

scm {
url 'scm:git@github.com:wenhao/jpa-spec.git'
Expand Down
Loading

0 comments on commit d65a357

Please sign in to comment.