### Execute REST API Queries Source: https://context7.com/queritylib/querity/llms.txt Examples of using curl to perform filtering, pagination, sorting, and aggregation via the Querity REST API. ```bash curl 'http://localhost:8080/api/products?q={"filter":{"propertyName":"category","operator":"EQUALS","value":"Electronics"}}' ``` ```bash curl 'http://localhost:8080/api/products?q={"filter":{"and":[{"propertyName":"price","operator":"LESSER_THAN","value":100},{"propertyName":"inStock","operator":"EQUALS","value":true}]},"sort":[{"propertyName":"price","direction":"ASC"}],"pagination":{"page":1,"pageSize":20}}' ``` ```bash curl 'http://localhost:8080/api/products/report?q={"select":{"expressions":[{"propertyName":"category"},{"function":"COUNT","arguments":[{"propertyName":"id"}],"alias":"count"},{"function":"AVG","arguments":[{"propertyName":"price"}],"alias":"avgPrice"}]},"groupBy":{"propertyNames":["category"]}}' ``` ```bash curl 'http://localhost:8080/api/products/count?filter={"propertyName":"status","operator":"EQUALS","value":"ACTIVE"}' ``` -------------------------------- ### Install Querity Spring Data JPA Dependency Source: https://github.com/queritylib/querity/blob/main/README.md Add the required dependency to your project build configuration to use Querity with Spring Data JPA. ```xml io.github.queritylib querity-spring-data-jpa ${querity.version} ``` ```groovy implementation "io.github.queritylib:querity-spring-data-jpa:${querityVersion}" ``` -------------------------------- ### JUnit 5 Test Method for Filtering Entities Source: https://github.com/queritylib/querity/blob/main/AGENTS.md An example of a JUnit 5 test method using the Querity builder to filter entities by ID. It demonstrates building a query with a filter condition and asserting the result. ```java @Test void givenFilterByIdEqualsCondition_whenFindAll_thenReturnOnlyFilteredElements() { Query query = Querity.query() .filter(filterBy("id", EQUALS, entity1.getId())) .build(); List result = querity.findAll(getEntityClass(), query); assertThat(result).containsExactly(entity1); } ``` -------------------------------- ### Static Imports for Querity API and Assertions Source: https://github.com/queritylib/querity/blob/main/AGENTS.md Demonstrates recommended static imports for using Querity's fluent API and AssertJ for testing. Avoids verbose qualification. ```java import static io.github.queritylib.querity.api.Operator.*; import static io.github.queritylib.querity.api.Querity.*; import static org.assertj.core.api.Assertions.assertThat; ``` -------------------------------- ### Build and Run All Tests with Maven Wrapper Source: https://github.com/queritylib/querity/blob/main/AGENTS.md Execute all project tests using the Maven wrapper. Ensure you are in the 'querity/' directory. ```bash ./mvnw verify ``` -------------------------------- ### Configure Spring Boot dependencies Source: https://context7.com/queritylib/querity/llms.txt Add the appropriate starter dependency based on your database technology. ```xml io.github.queritylib querity-spring-data-jpa 3.6.2 io.github.queritylib querity-spring-data-mongodb 3.6.2 io.github.queritylib querity-spring-data-elasticsearch 3.6.2 io.github.queritylib querity-spring-web 3.6.2 ``` -------------------------------- ### Run Project Tests Source: https://github.com/queritylib/querity/blob/main/README.md Execute the project test suite using the Maven wrapper. ```bash ./mvnw test ``` -------------------------------- ### Apply Filter Conditions and Operators Source: https://context7.com/queritylib/querity/llms.txt Demonstrates various filtering techniques including equality, logical combinations, IN operators, null checks, and nested property access. ```java import static io.github.queritylib.querity.api.Querity.*; import static io.github.queritylib.querity.api.Operator.*; // Simple equality filter Query query1 = Querity.query() .filter(filterBy("lastName", EQUALS, "Skywalker")) .build(); // Shorthand for EQUALS (default operator) Query query2 = Querity.query() .filter(filterBy("lastName", "Skywalker")) .build(); // Complex nested conditions Query query3 = Querity.query() .filter( and( filterBy("status", EQUALS, "ACTIVE"), or( filterBy("role", EQUALS, "ADMIN"), filterBy("role", EQUALS, "MANAGER") ), not(filterBy("deleted", EQUALS, true)) ) ) .build(); // IN operator for multiple values Query query4 = Querity.query() .filter(filterBy("category", IN, List.of("ELECTRONICS", "BOOKS", "CLOTHING"))) .build(); // Null checking Query query5 = Querity.query() .filter(filterBy("email", IS_NOT_NULL)) .build(); // Nested property filtering Query query6 = Querity.query() .filter(filterBy("address.city", EQUALS, "New York")) .build(); ``` -------------------------------- ### Clean and Rebuild Project with Maven Wrapper Source: https://github.com/queritylib/querity/blob/main/AGENTS.md Perform a clean build of the project, including running all tests. This command removes compiled artifacts before rebuilding. ```bash ./mvnw clean verify ``` -------------------------------- ### Build and Execute Queries Programmatically Source: https://github.com/queritylib/querity/blob/main/README.md Use the Querity API to construct complex queries with filters, sorting, and pagination, then execute them against a data source. ```java import static io.github.queritylib.querity.api.Querity.*; import static io.github.queritylib.querity.api.Operator.*; import static io.github.queritylib.querity.api.Sort.Direction.*; @Service public class MyService { @Autowired Querity querity; public List getPeople() { Query query = Querity.query() .filter( and( filterBy("lastName", EQUALS, "Skywalker"), filterBy("age", GREATER_THAN, 18) ) ) .sort(sortBy("lastName"), sortBy("birthDate", DESC)) .pagination(1, 10) .build(); return querity.findAll(Person.class, query); } } ``` -------------------------------- ### Implement Spring Boot service Source: https://context7.com/queritylib/querity/llms.txt Inject the auto-configured Querity bean to perform database operations. ```java @Service public class ProductService { @Autowired private Querity querity; // Auto-configured based on your database public List search(String category, BigDecimal maxPrice) { Query query = Querity.query() .filter( and( filterBy("category", EQUALS, category), filterBy("price", LESSER_THAN_EQUALS, maxPrice), filterBy("inStock", EQUALS, true) ) ) .sort(sortBy("price")) .build(); return querity.findAll(Product.class, query); } } ``` -------------------------------- ### Build Simple Entity Queries Source: https://context7.com/queritylib/querity/llms.txt Constructs a standard entity query with filtering, sorting, and pagination using the Querity builder pattern. ```java import static io.github.queritylib.querity.api.Querity.*; import static io.github.queritylib.querity.api.Operator.*; import static io.github.queritylib.querity.api.SimpleSort.Direction.*; @Service public class PersonService { @Autowired private Querity querity; public List findActiveAdults() { Query query = Querity.query() .filter( and( filterBy("status", EQUALS, "ACTIVE"), filterBy("age", GREATER_THAN_EQUALS, 18) ) ) .sort(sortBy("lastName"), sortBy("firstName", DESC)) .pagination(1, 20) .build(); return querity.findAll(Person.class, query); } } ``` -------------------------------- ### Run Tests for a Specific Module with Maven Wrapper Source: https://github.com/queritylib/querity/blob/main/AGENTS.md Execute tests only for a designated module. Replace 'querity-api' with the desired module name. ```bash ./mvnw test -pl querity-api ``` ```bash ./mvnw test -pl querity-jpa-common ``` ```bash ./mvnw test -pl querity-spring-data-jpa ``` -------------------------------- ### Configure Gradle Repository for Snapshots Source: https://github.com/queritylib/querity/blob/main/README.md Add this repository block to your build.gradle file to enable access to snapshot builds. ```groovy repositories { maven { name = 'Central Portal Snapshots' url = 'https://central.sonatype.com/repository/maven-snapshots/' mavenContent { snapshotsOnly() } } } ``` -------------------------------- ### Configure Maven Repository for Snapshots Source: https://github.com/queritylib/querity/blob/main/README.md Add this repository configuration to your pom.xml to enable access to snapshot builds. ```xml Central Portal Snapshots central-portal-snapshots https://central.sonatype.com/repository/maven-snapshots/ false true ``` -------------------------------- ### Constructing a Query with Fluent Builder Source: https://github.com/queritylib/querity/blob/main/AGENTS.md Use the fluent builder pattern to define filters, sorting, and pagination in a single chain. ```java Query query = Querity.query() .filter(filterBy("status", EQUALS, "ACTIVE")) .sort(sortBy("lastName", DESC)) .pagination(1, 10) .build(); ``` -------------------------------- ### Configure Pagination Source: https://context7.com/queritylib/querity/llms.txt Define result set pagination using page numbers and page sizes. ```java import static io.github.queritylib.querity.api.Querity.*; // Using pagination builder method Query query1 = Querity.query() .filter(filterBy("status", "ACTIVE")) .pagination(1, 25) // Page 1, 25 items per page .build(); // Using Pagination object Query query2 = Querity.query() .pagination(paged(2, 50)) // Page 2, 50 items per page .build(); ``` -------------------------------- ### Count records with Querity Source: https://context7.com/queritylib/querity/llms.txt Use the count method to retrieve the number of matching entities without loading them into memory. ```java import static io.github.queritylib.querity.api.Querity.*; import static io.github.queritylib.querity.api.Operator.*; @Service public class StatisticsService { @Autowired private Querity querity; public Long countActiveUsers() { return querity.count( User.class, and( filterBy("status", EQUALS, "ACTIVE"), filterBy("lastLoginDate", GREATER_THAN, "2024-01-01") ) ); } } ``` -------------------------------- ### Run a Single Test Class with Maven Wrapper Source: https://github.com/queritylib/querity/blob/main/AGENTS.md Execute all tests within a specific test class in a given module. Specify the module with '-pl' and the test class with '-Dtest'. ```bash ./mvnw test -pl querity-api -Dtest=ConditionTests ``` -------------------------------- ### Run a Single Test Method with Maven Wrapper Source: https://github.com/queritylib/querity/blob/main/AGENTS.md Execute a single test method within a specific test class. Use '-pl' for the module and '-Dtest' for the class and method. ```bash ./mvnw test -pl querity-api -Dtest=ConditionTests#givenNoOperator_whenBuildSimpleCondition_thenReturnEqualsCondition ``` -------------------------------- ### Integrate with Spring Web REST API Source: https://context7.com/queritylib/querity/llms.txt Use the querity-spring-web module to automatically deserialize Query objects from request parameters. ```java import io.github.queritylib.querity.api.Query; import io.github.queritylib.querity.api.AdvancedQuery; import io.github.queritylib.querity.api.Condition; import org.springframework.web.bind.annotation.*; @RestController @RequestMapping("/api/products") public class ProductController { @Autowired private Querity querity; // Accept Query as JSON in query parameter @GetMapping public List findAll(@RequestParam(required = false) Query q) { return querity.findAll(Product.class, q); } // Accept AdvancedQuery for projections @GetMapping("/report") public List> getReport(@RequestParam(required = false) AdvancedQuery q) { return querity.findAllProjected(Product.class, q); } // Accept Condition for count endpoint @GetMapping("/count") public Long count(@RequestParam(required = false) Condition filter) { return querity.count(Product.class, filter); } } ``` -------------------------------- ### Apply Aggregate Functions Source: https://context7.com/queritylib/querity/llms.txt Perform calculations like COUNT, SUM, and AVG within projection queries. ```java import static io.github.queritylib.querity.api.Querity.*; // Simple aggregation without grouping AdvancedQuery query1 = Querity.advancedQuery() .select( count(prop("id")).as("totalOrders"), sum(prop("amount")).as("revenue"), min(prop("amount")).as("minOrder"), max(prop("amount")).as("maxOrder") ) .filter(filterBy("year", EQUALS, 2024)) .build(); // Aggregation with GROUP BY and HAVING AdvancedQuery query2 = Querity.advancedQuery() .select( prop("department"), prop("region"), count(prop("employeeId")).as("headcount"), avg(prop("salary")).as("avgSalary") ) .groupBy("department", "region") .having(filterBy(count(prop("employeeId")), GREATER_THAN_EQUALS, 5)) .sort(sortBy("headcount", DESC)) .build(); List> results = querity.findAllProjected(Employee.class, query2); ``` -------------------------------- ### Compile Project Excluding Tests with Maven Wrapper Source: https://github.com/queritylib/querity/blob/main/AGENTS.md Compile the project without running tests. Use this for faster builds when tests are not immediately needed. ```bash ./mvnw compile -DskipTests ``` -------------------------------- ### Sort with Properties and Expressions Source: https://context7.com/queritylib/querity/llms.txt Apply ascending or descending sort orders to simple properties or function results. ```java import static io.github.queritylib.querity.api.Querity.*; import static io.github.queritylib.querity.api.SimpleSort.Direction.*; // Simple property sorting Query query1 = Querity.query() .sort(sortBy("lastName"), sortBy("firstName", DESC)) .build(); // Sorting by function expression Query query2 = Querity.query() .sort( sortBy(length(prop("lastName")), DESC), sortBy(upper(prop("firstName"))) ) .build(); ``` -------------------------------- ### Execute Advanced Projection Queries Source: https://context7.com/queritylib/querity/llms.txt Use AdvancedQuery to select specific fields and perform aggregations with grouping. ```java import static io.github.queritylib.querity.api.Querity.*; import static io.github.queritylib.querity.api.Operator.*; @Service public class ReportService { @Autowired private Querity querity; public List> getSalesByCategory() { AdvancedQuery query = Querity.advancedQuery() .select( prop("category"), count(prop("id")).as("orderCount"), sum(prop("amount")).as("totalAmount"), avg(prop("amount")).as("avgAmount") ) .filter(filterBy("status", EQUALS, "COMPLETED")) .groupBy("category") .having(filterBy(count(prop("id")), GREATER_THAN, 10)) .sort(sortBy("totalAmount", DESC)) .pagination(1, 10) .build(); return querity.findAllProjected(Order.class, query); // Returns: [{category: "Electronics", orderCount: 150, totalAmount: 45000.00, avgAmount: 300.00}, ...] } } ``` -------------------------------- ### Parse Textual Queries Source: https://github.com/queritylib/querity/blob/main/README.md Convert a simple string representation of a query into a Query object using the querity-parser module. ```java Query query = QuerityParser.parseQuery( "and(lastName=\"Skywalker\", age>18) sort by lastName, birthDate desc page 1,10" ); ``` -------------------------------- ### Parse textual queries Source: https://context7.com/queritylib/querity/llms.txt The QuerityParser module converts query strings into QueryDefinition objects, supporting complex filters, projections, and grouping. ```java import io.github.queritylib.querity.parser.QuerityParser; import io.github.queritylib.querity.api.QueryDefinition; import io.github.queritylib.querity.api.Query; import io.github.queritylib.querity.api.AdvancedQuery; // Simple query parsing QueryDefinition query1 = QuerityParser.parseQuery( "lastName=\"Skywalker\" sort by lastName, firstName desc page 1,20" ); // Complex filter with AND/OR QueryDefinition query2 = QuerityParser.parseQuery( "and(status=\"ACTIVE\", or(role=\"ADMIN\", role=\"MANAGER\")) sort by createdAt desc" ); // Filter with comparison operators QueryDefinition query3 = QuerityParser.parseQuery( "and(age>=18, age<65, salary>50000)" ); // Using functions in filters QueryDefinition query4 = QuerityParser.parseQuery( "UPPER(lastName)=\"SKYWALKER\" sort by LENGTH(lastName) desc" ); // Advanced query with SELECT and GROUP BY QueryDefinition query5 = QuerityParser.parseQuery( "select category, COUNT(id) as orderCount, SUM(amount) as total " + "where status=\"COMPLETED\" " + "group by category " + "having COUNT(id)>10 " + "sort by total desc page 1,10" ); // Cast to appropriate type based on query features if (query5 instanceof AdvancedQuery advQuery) { List> results = querity.findAllProjected(Order.class, advQuery); } ``` -------------------------------- ### Perform Field-to-Field Comparisons Source: https://context7.com/queritylib/querity/llms.txt Compares two fields directly within a query using FieldReference to avoid hardcoded values. ```java import static io.github.queritylib.querity.api.Querity.*; import static io.github.queritylib.querity.api.Operator.*; // Compare two fields directly Query query = Querity.query() .filter( and( // Find products where sale price is less than original price filterByField("salePrice", LESSER_THAN, field("originalPrice")), // And shipping address differs from billing address filterByField("shipping.city", NOT_EQUALS, field("billing.city")) ) ) .build(); List productsOnSale = querity.findAll(Product.class, query); ``` -------------------------------- ### Execute Distinct Queries Source: https://context7.com/queritylib/querity/llms.txt Set the distinct flag to true to filter out duplicate results from the query execution. ```java import static io.github.queritylib.querity.api.Querity.*; Query query = Querity.query() .filter(filterBy("category", IN, List.of("A", "B", "C"))) .distinct(true) .build(); List uniqueProducts = querity.findAll(Product.class, query); ``` -------------------------------- ### Implement Native Database Expressions Source: https://context7.com/queritylib/querity/llms.txt Use JpaNativeConditionWrapper to inject custom JPA CriteriaBuilder logic into a Querity query. ```java import static io.github.queritylib.querity.api.Querity.*; import io.github.queritylib.querity.jpa.JpaNativeConditionWrapper; import jakarta.persistence.criteria.*; // JPA native condition using CriteriaBuilder Query query = Querity.query() .filter( and( filterBy("status", EQUALS, "ACTIVE"), filterByNative(new JpaNativeConditionWrapper() { @Override public Predicate toNativePredicate(Root root, CriteriaQuery query, CriteriaBuilder cb) { return cb.like(cb.lower(root.get("description")), "%keyword%"); } }) ) ) .build(); ``` -------------------------------- ### Filter with Function Expressions Source: https://context7.com/queritylib/querity/llms.txt Apply string, arithmetic, date, and conditional functions within filter criteria. ```java import static io.github.queritylib.querity.api.Querity.*; import static io.github.queritylib.querity.api.Operator.*; // Filter using UPPER function for case-insensitive search Query query1 = Querity.query() .filter(filterBy(upper(prop("lastName")), EQUALS, "SKYWALKER")) .build(); // Filter by string length Query query2 = Querity.query() .filter(filterBy(length(prop("username")), GREATER_THAN, 5)) .build(); // Nested function calls Query query3 = Querity.query() .filter(filterBy(upper(trim(prop("email"))), ENDS_WITH, "@EXAMPLE.COM")) .build(); // Using COALESCE for null handling Query query4 = Querity.query() .filter(filterBy(coalesce(prop("nickname"), lit("Anonymous")), NOT_EQUALS, "Anonymous")) .build(); // Date comparison with CURRENT_DATE Query query5 = Querity.query() .filter(filterBy(prop("expirationDate"), GREATER_THAN, currentDate())) .build(); ``` -------------------------------- ### Implementing Native Expressions in JPA Source: https://github.com/queritylib/querity/blob/main/AGENTS.md Utilize functional interfaces to define custom JPA order specifications for native expressions. ```java OrderSpecification spec = (root, cb) -> cb.asc(cb.length(root.get("name"))); Query query = Querity.query().sort(sortByNative(spec)).build(); ``` -------------------------------- ### Map DTO Properties to Entities Source: https://context7.com/queritylib/querity/llms.txt Use SimplePropertyNameMapper to translate DTO property names to database entity fields before query execution. ```java import io.github.queritylib.querity.common.mapping.SimplePropertyNameMapper; import io.github.queritylib.querity.common.mapping.PropertyNameMappingPreprocessor; // Create a mapper for DTO to Entity property translation SimplePropertyNameMapper mapper = SimplePropertyNameMapper.builder() .mapping("customerName", "customer.fullName") .mapping("orderTotal", "totalAmount") .mapping("shippingAddress", "delivery.address") .recursive(true) // Enables nested property mapping .build(); PropertyNameMappingPreprocessor preprocessor = new PropertyNameMappingPreprocessor(mapper); // Query using DTO property names Query query = Querity.query() .filter(filterBy("customerName", STARTS_WITH, "John")) .sort(sortBy("orderTotal", DESC)) .withPreprocessor(preprocessor) .build(); // Preprocessor transforms to entity property names before execution List orders = querity.findAll(Order.class, query.preprocess()); ``` -------------------------------- ### Suppressing Unchecked Cast Warnings in Java Source: https://github.com/queritylib/querity/blob/main/AGENTS.md Use the @SuppressWarnings annotation to explicitly handle and suppress 'unchecked' and 'rawtypes' warnings when necessary, such as with generic types. ```java @SuppressWarnings({"unchecked", "rawtypes"}) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.