You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+37-26Lines changed: 37 additions & 26 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3,35 +3,46 @@
3
3
## Description
4
4
Provides a variety of components that reduce the overhead of composing and maintaining Specifications.
5
5
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.
7
7
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.
9
9
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.
11
11
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.
13
13
14
14
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.
15
15
16
16
## Features
17
17
18
18
- 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.
19
19
- 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` Annotations – Specification 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).
@@ -61,7 +72,7 @@ public interface GuitarPedalRepository extends JpaRepository<GuitarPedal, Long>,
61
72
JpaSpecificationExecutor<GuitarPedal> {
62
73
}
63
74
```
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.)
@@ -111,26 +122,26 @@ public class GuitarPedalService {
111
122
```
112
123
113
124
## 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.
115
126
116
127
### 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.
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.
121
132
122
133
### 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.
124
135
125
136
### 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.
127
138
128
139
## 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>
132
141
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.
0 commit comments