Skip to content

Commit f143391

Browse files
authored
Merge pull request #25 from quinnandrews/24-specification-builder-add-update-documentation
Add/Update Documentation.
2 parents a93b9a8 + 2c47350 commit f143391

File tree

5 files changed

+622
-31
lines changed

5 files changed

+622
-31
lines changed

README.md

Lines changed: 37 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3,35 +3,46 @@
33
## Description
44
Provides a variety of components that reduce the overhead of composing and maintaining Specifications.
55

6-
SpecificationFactory is used to generate Specification instances. It encapsulates anonymous Specification subclasses and provides null-safe handling.
6+
[SpecificationFactory ](https://github.com/quinnandrews/spring-data-specification-builder/blob/a93b9a84805d3c20b1461ca634abd3a50695d245/src/main/java/io/github/quinnandrews/spring/data/specification/builder/SpecificationFactory.java)is used to generate Specification instances. It encapsulates anonymous Specification subclasses and provides null-safe handling.
77

8-
SpecificationBuilder puts a fluent API on top of SpecificationFactory to compose compound Specifications with ease.
8+
[SpecificationBuilder](https://github.com/quinnandrews/spring-data-specification-builder/blob/a93b9a84805d3c20b1461ca634abd3a50695d245/src/main/java/io/github/quinnandrews/spring/data/specification/builder/SpecificationBuilder.java) puts a fluent API on top of SpecificationFactory to compose compound Specifications with ease.
99

10-
SpecificationUtil is used by SpecificationFactory to assist with null checking, wildcard detection and String conversions, etc.
10+
[SpecificationUtil](https://github.com/quinnandrews/spring-data-specification-builder/blob/a93b9a84805d3c20b1461ca634abd3a50695d245/src/main/java/io/github/quinnandrews/spring/data/specification/builder/SpecificationUtil.java) is used by SpecificationFactory to assist with null checking, wildcard detection and String conversions, etc.
1111

12-
The Specifications Annotation is available as a convenience, an alias of Spring's Component Annotation to mark Specification Beans as a distinct type.
12+
The [Specifications Annotation](https://github.com/quinnandrews/spring-data-specification-builder/blob/a93b9a84805d3c20b1461ca634abd3a50695d245/src/main/java/io/github/quinnandrews/spring/data/specification/annotations/Specifications.java) is available as a convenience, an alias of Spring's Component Annotation to mark Specification Beans as a particular kind of Bean.
1313

1414
SpecificationFactory and SpecificationUtil may be used independently, if desired. However, the intent is to use SpecificationBuilder exclusively, without being aware of either SpecificationFactory or SpecificationUtil, but it is not mandatory. Both SpecificationFactory and SpecificationUtil are declared with public access.
1515

1616
## Features
1717

1818
- Built-in null handling makes conditional query composition simple and easy – no need to wrap Specification conjunctions with a check for parameter state when parameters are optional.
1919
- Built-in support for efficient eager fetching provides query optimization – an entire Aggregate can be loaded with one query instead of many.
20-
- A fluent API encapsulating boilerplate code makes queries that are both strongly typed and easy to read – the risk of error is reduced while comprehension of query logic is enhanced.
21-
- A `@Specifications` Annotation complements Spring's `@Controller`, `@Service` and `@Repository` Annotations, allowing one to declare Specification Beans in a similar fashion and being able to identify these kinds of Beans for special use cases, like when defining rules with ArchUnit, for example.
20+
- A fluent API encapsulating boilerplate code makes queries that are both strongly typed and easy to read – the risk of error is reduced while query logic is more coherent.
21+
- A `@Specifications` Annotation complements Spring's `@Controller`, `@Service` and `@Repository` AnnotationsSpecification Beans can be identified as a special kind of Bean by both developers and processes (like the execution of rules with [ArchUnit](https://github.com/TNG/ArchUnit), for example).
2222

2323
## Requirements
2424
### Java 17
2525
https://adoptium.net/temurin/releases/?version=17
2626

2727
### Hibernate JPA Metamodel Generator (or equivalent)
2828
https://hibernate.org/orm/tooling/
29+
30+
Add the Hibernate JPA Metamodel Generator to the Maven Compiler Plugin as an Annotation Processor:
2931
```xml
30-
<dependency>
31-
<groupId>org.hibernate.orm</groupId>
32-
<artifactId>hibernate-jpamodelgen</artifactId>
33-
<version>6.3.1.Final</version>
34-
</dependency>
32+
<plugin>
33+
<groupId>org.apache.maven.plugins</groupId>
34+
<artifactId>maven-compiler-plugin</artifactId>
35+
<version>3.11.0</version>
36+
<configuration>
37+
<annotationProcessorPaths>
38+
<path>
39+
<groupId>org.hibernate.orm</groupId>
40+
<artifactId>hibernate-jpamodelgen</artifactId>
41+
<version>6.3.1.Final</version>
42+
</path>
43+
</annotationProcessorPaths>
44+
</configuration>
45+
</plugin>
3546
```
3647

3748
## Dependencies
@@ -44,12 +55,12 @@ Add this project's artifact to your project as a dependency:
4455
<dependency>
4556
<groupId>io.github.quinnandrews</groupId>
4657
<artifactId>spring-data-specification-builder</artifactId>
47-
<version>1.0.0</version>
58+
<version>2.0.0</version>
4859
</dependency>
4960
```
5061
(NOTE: This project's artifact is NOT yet available in Maven Central, but is available from GitHub Packages.)
5162

52-
Then extend your Repository Interfaces with JPASpecificationExecutor:
63+
Then extend your Repository Interfaces with JPASpecificationExecutor so that Specification methods are available:
5364
```java
5465
import io.github.quinnandrews.spring.data.specification.builder.application.data.guitarpedals.GuitarPedal;
5566
import org.springframework.data.jpa.repository.JpaRepository;
@@ -61,7 +72,7 @@ public interface GuitarPedalRepository extends JpaRepository<GuitarPedal, Long>,
6172
JpaSpecificationExecutor<GuitarPedal> {
6273
}
6374
```
64-
Next, define your Specifications:
75+
Next, define your Specifications in a Specifications Bean (this is optional – you can also define Specification queries where they are used, in a Service, a Test, etc.)
6576

6677
```java
6778
import io.github.quinnandrews.spring.data.specification.annotations.Specifications;
@@ -111,26 +122,26 @@ public class GuitarPedalService {
111122
```
112123

113124
## Examples
114-
The examples and tests use the Domain of Guitar Pedals (I'm also a musician and I enjoy exploring the vast array of sounds offered by the world of guitar pedals). It was simply more fun than using the Domains of TODOs or Employees, for example.
125+
The examples and tests use the Domain of Guitar Pedals (I'm a musician). It was simply more fun than using the Domains of TODOs or Employees.
115126

116127
### GuitarPedalSpecifications.class
117-
GuitarPedalSpecifications contains the most comprehensive set of examples. It compares defining the same queries with and without the SpecificationBuilder, details gotchas and goes into more complex things like working with collections, for instance. Begin from the top and work your way down.
128+
[GuitarPedalSpecifications](https://github.com/quinnandrews/spring-data-specification-builder/blob/a93b9a84805d3c20b1461ca634abd3a50695d245/src/test/java/io/github/quinnandrews/spring/data/specification/builder/application/data/guitarpedals/specifications/GuitarPedalSpecifications.java) contains the most comprehensive set of examples. It compares defining the same queries with and without the SpecificationBuilder, details gotchas and goes into more complex things like working with collections, for instance. Begin from the top and work your way down.
118129

119130
### GuitarPedalSpecificationsIntegrationTest.class
120-
GuitarPedalSpecificationsIntegrationTest contains the Integrations Tests of the examples in GuitarPedalSpecifications. This may be useful to look at as well, or to run the examples yourself and see the sql output with your own eyes.
131+
[GuitarPedalSpecificationsIntegrationTest](https://github.com/quinnandrews/spring-data-specification-builder/blob/a93b9a84805d3c20b1461ca634abd3a50695d245/src/test/java/io/github/quinnandrews/spring/data/specification/builder/GuitarPedalSpecificationsIntegrationTest.java) contains the Integrations Tests of the examples in GuitarPedalSpecifications. This may be useful to look at as well, or to run the examples yourself and see the sql output with your own eyes.
121132

122133
### SpecificationBuilderIntegrationTest.class
123-
SpecificationBuilderIntegrationTest contains Integration Tests for the methods in SpecificationBuilder. Some of these tests cover cases that are not included in GuitarPedalSpecifications.
134+
[SpecificationBuilderIntegrationTest](https://github.com/quinnandrews/spring-data-specification-builder/blob/a93b9a84805d3c20b1461ca634abd3a50695d245/src/test/java/io/github/quinnandrews/spring/data/specification/builder/SpecificationBuilderIntegrationTest.java) contains Integration Tests for the methods in SpecificationBuilder. Some of these tests cover cases that are not included in GuitarPedalSpecifications.
124135

125136
### Other Test Classes
126-
SpecificationBuilderTest, SpecificationFactoryTest and SpecificationUtilTest contain Unit Tests for the methods in their corresponding Classes. These may useful to look at as well, in order to understand more about how things work under the hood, but it is not necessary.
137+
[SpecificationBuilderTest](https://github.com/quinnandrews/spring-data-specification-builder/blob/a93b9a84805d3c20b1461ca634abd3a50695d245/src/test/java/io/github/quinnandrews/spring/data/specification/builder/SpecificationBuilderTest.java), [SpecificationFactoryTest](https://github.com/quinnandrews/spring-data-specification-builder/blob/a93b9a84805d3c20b1461ca634abd3a50695d245/src/test/java/io/github/quinnandrews/spring/data/specification/builder/SpecificationFactoryTest.java) and [SpecificationUtilTest](https://github.com/quinnandrews/spring-data-specification-builder/blob/a93b9a84805d3c20b1461ca634abd3a50695d245/src/test/java/io/github/quinnandrews/spring/data/specification/builder/SpecificationUtilTest.java) contain Unit Tests for the methods in their corresponding Classes. These may be useful to look at as well, in order to understand more about how things work under the hood, but it is not necessary.
127138

128139
## Roadmap
129-
1) ~~**Add `and()` Methods in the Builder**<br>
130-
Add `and()` Methods to make the fluent-API more fluent & legible, and to better resemble the Specification Interface.~~
131-
2) **Build Specifications on Associations**<br>
140+
1) **Build Specifications on Associations**<br>
132141
Add versions of `where` methods that operate on Associations. It is expected the builder will need to maintain an instance variable containing Joins already created, so that they can be re-used during the build process if there is more than one Specification to apply to an Association.
133-
3) **Define JoinType of Associations**<br>
134-
Add versions of `withFetch()` that allow definition of JoinType. Should it be applied to `where` methods on Associations as well?
135-
4) **Consider Adding a `not()` Method in the Builder**
136-
5) **Consider Adding a `clear()` Method in the Builder**
142+
2) **Define JoinType of Associations**<br>
143+
Add versions of `fetchOf()` that allow definition of JoinType. (Should it be applied to `where` methods on Associations as well?)
144+
3) **Add a `not()` Method in the Builder**
145+
4) **Add a `clear()` Method in the Builder**
146+
5) **Implement a SortBuilder to complement the SpecificationBuilder**<br/>
147+
Implement with the same sort of fluent-api and require Attributes instead of Strings for type safety.

src/main/java/io/github/quinnandrews/spring/data/specification/annotations/Specifications.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,19 @@
55

66
import java.lang.annotation.*;
77

8+
/**
9+
* An alias of {@link Component @Component} indicating that the
10+
* annotated class contains Specifications. Complements
11+
* {@link org.springframework.stereotype.Controller @Controller},
12+
* {@link org.springframework.stereotype.Service @Service}, and
13+
* {@link org.springframework.stereotype.Repository @Repository}.
14+
*
15+
* @author Quinn Andrews
16+
* @see Component
17+
* @see org.springframework.stereotype.Controller
18+
* @see org.springframework.stereotype.Service
19+
* @see org.springframework.stereotype.Repository
20+
*/
821
@Target(ElementType.TYPE)
922
@Retention(RetentionPolicy.RUNTIME)
1023
@Documented

0 commit comments

Comments
 (0)