explain difference between and
The goal of Criteria module is to provide fluent java API (DSL) to query heterogeneous data-sources.
-#### Main Features
+### Features
1. **Expressive and type-safe API** Compile-type validation of the query.
2. **Dynamic** Combine predicates at runtime based on some logic
@@ -13,8 +13,8 @@ The goal of Criteria module is to provide fluent java API (DSL) to query heterog
Define your model using immutables interfaces
```java
@Value.Immutable
-@Criteria // means generate criteria
-@Criteria.Repository // means generate repository
+@Criteria // generate criteria
+@Criteria.Repository // means generate repository (different from @Criteria)
interface Person {
@Criteria.Id
String id();
@@ -25,11 +25,13 @@ interface Person {
}
```
-#### Write query
-Now you can write the following queries:
+#### Query
+Because of `@Criteria` annotation, `PersonCriteria` class is automatically generated by immutables. You can now leverage it to write queries similar to:
```java
+// basic query by id
PersonCriteria.person.id.isIn("id1", "id2", "id3");
+// query on Strings, Comparables and Optionals
person
.fullName.startsWith("John") // basic string conditions
.fullName.isEqualTo(3.1415D) // will not compile since fullName is String
@@ -57,9 +59,10 @@ Statement like `A and (B or C)` can be written as follows:
person.fullName.isEqualTo("John").and(person.age.isGreaterThan(22).or().nickName.isPresent())
```
+Not all entities require repository (`@Criteria.Repository`) but you need to add `@Criteria` to all classes you want to query by. For example, to filter on `Person.pets.name` `Pet` class needs to have `@Criteria` (otherwise `PersonCriteria.pets` will have a very generic Object matcher).
+
#### Use generated repository to query or update a datasource
-`@Criteria.Repository` instructs immutables to generate repository class with `find` / `insert` / `watch` operations.
-You are required to provide a valid [backend](https://github.com/immutables/immutables/blob/master/criteria/common/src/org/immutables/criteria/adapter/Backend.java)
+`@Criteria.Repository` instructs immutables to generate repository class with `find` / `insert` / `watch` operations. You are required to provide a valid [backend](https://github.com/immutables/immutables/blob/master/criteria/common/src/org/immutables/criteria/adapter/Backend.java)
instance (mongo, elastic, inmemory etc).
```java
