|
17 | 17 | *
|
18 | 18 | * {@include.example example.ExamplesTest#queryPredicateVariableArray()}
|
19 | 19 | *
|
| 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 | + * |
20 | 86 | * <h3 id="get-by-id">Get by id/key</h3>
|
21 | 87 | *
|
22 | 88 | * {@include.example example.ExamplesTest#getByIdOrKey()}
|
|
0 commit comments