Skip to content

Commit 22cd1d3

Browse files
authored
Merge pull request #874 from commercetools/query-predicate-javadoc
DEVX-588 adding query predicate builder documentation
2 parents 31a9408 + b3fa25e commit 22cd1d3

File tree

1 file changed

+66
-0
lines changed
  • commercetools/internal-docs/src/main/java/com/commercetools/docs/meta

1 file changed

+66
-0
lines changed

commercetools/internal-docs/src/main/java/com/commercetools/docs/meta/Querying.java

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,72 @@
1717
*
1818
* {@include.example example.ExamplesTest#queryPredicateVariableArray()}
1919
*
20+
<h3 id="query-predicate-builder">Query Predicate Builder</h3>
21+
*
22+
* <p>The <a href="https://docs.commercetools.com/sdk/java-sdk-predicates">
23+
* Query Predicate Builder</a> offers a fluent, type-safe interface for building Query Predicates.</p>
24+
*
25+
* <h4>Basic Usage</h4>
26+
*
27+
* <pre>{@code
28+
* import static com.commercetools.api.predicates.query.CustomerQueryBuilderDsl.*;
29+
*
30+
* String predicate = CustomerQueryBuilderDsl.of()
31+
* .firstName().is("John")
32+
* .and()
33+
* .lastName().is("Doe")
34+
* .build();
35+
* }</pre>
36+
*
37+
* <h4>Examples of Query Predicates</h4>
38+
*
39+
* <p>The following examples demonstrate how to use the Query Predicate builder for different scenarios. More examples can be found
40+
* <a href="https://github.com/commercetools/commercetools-sdk-java-v2/tree/main/commercetools/commercetools-sdk-java-api/src/test/java/com/commercetools/api/predicates/query">here</a>.</p>
41+
*
42+
* <h5>Equality Comparisons</h5>
43+
* <pre>{@code
44+
* CartQueryBuilderDsl.of().id().is("abc");
45+
* CustomerQueryBuilderDsl.of().dateOfBirth().is(LocalDate.parse("2018-10-12"));
46+
* TaxRateQueryBuilderDsl.of().amount().is(0.19);
47+
* }</pre>
48+
*
49+
* <h5>Logical Operators</h5>
50+
* <pre>{@code
51+
* CartQueryBuilderDsl.of().id().is("abc").not();
52+
* CartQueryBuilderDsl.of().id().is("abc").and(p -> p.customerId().is("def"));
53+
* CartQueryBuilderDsl.of().id().is("abc").or(p -> p.customerId().is("def"));
54+
* }</pre>
55+
*
56+
* <h5>Range Comparisons</h5>
57+
* <pre>{@code
58+
* CartQueryBuilderDsl.of().version().isLessThan(10L);
59+
* CartQueryBuilderDsl.of().version().isGreaterThan(10L);
60+
* TaxRateQueryBuilderDsl.of().amount().isLessThan(0.19);
61+
* CustomerQueryBuilderDsl.of().dateOfBirth().isGreaterThan(LocalDate.parse("2018-10-12"));
62+
* }</pre>
63+
*
64+
* <h5>Collection Queries</h5>
65+
* <pre>{@code
66+
* CartQueryBuilderDsl.of().key().isIn(Arrays.asList("foo", "bar"));
67+
* TaxRateQueryBuilderDsl.of().amount().isIn(Arrays.asList(0.19, 0.20));
68+
* }</pre>
69+
*
70+
* <h5>Nested Queries</h5>
71+
* <pre>{@code
72+
* ProductQueryBuilderDsl.of()
73+
* .masterData(m -> m.current(c -> c.slug(l -> l.with(Locale.ENGLISH).is("super-product"))
74+
* .and(t -> t.name(l -> l.with(Locale.ENGLISH).is("Super Product")))));
75+
* }</pre>
76+
*
77+
* <h5>Special Cases</h5>
78+
* <pre>{@code
79+
* CartQueryBuilderDsl.of().key().isDefined();
80+
* CartQueryBuilderDsl.of().key().isNotDefined();
81+
* CartQueryBuilderDsl.of().lineItems().isEmpty();
82+
* TypeQueryBuilderDsl.of().resourceTypeIds().containsAnyVar("approval-flow");
83+
* }</pre>
84+
*
85+
*
2086
* <h3 id="get-by-id">Get by id/key</h3>
2187
*
2288
* {@include.example example.ExamplesTest#getByIdOrKey()}

0 commit comments

Comments
 (0)