### RSQL Syntax Examples Source: https://github.com/perplexhub/rsql-jpa-specification/blob/master/rsql-support/README.md Illustrates various RSQL query syntaxes for filtering, including between, not between, like, ignore case, and logical operators. ```java filter = "id=bt=(2,4)";// id>=2 && id<=4 //between filter = "id=nb=(2,4)";// id<2 || id>4 //not between filter = "company.code=like=em"; //like %em% filter = "company.code=ilike=EM"; //ignore case like %EM% filter = "company.code=icase=EM"; //ignore case equal EM filter = "company.code=notlike=em"; //not like %em% filter = "company.code=inotlike=EM"; //ignore case not like %EM% filter = "company.code=ke=e*m"; //like %e*m% filter = "company.code=ik=E*M"; //ignore case like %E*M% filter = "company.code=nk=e*m"; //not like %e*m% filter = "company.code=ni=E*M"; //ignore case not like %E*M% filter = "company.code=ic=E^^M"; //ignore case equal E^^M filter = "company.code==demo"; //equal filter = "company.code=='demo'"; //equal filter = "company.code==''"; //equal to empty string filter = "company.code==dem*"; //like dem% filter = "company.code==*emo"; //like %emo filter = "company.code==*em*"; //like %em% filter = "company.code==^EM"; //ignore case equal EM filter = "company.code==^*EM*"; //ignore case like %EM% filter = "company.code=='^*EM*'"; //ignore case like %EM% filter = "company.code!=demo"; //not equal filter = "company.code=in=(\*)"; //equal to * filter = "company.code=in=(\^)"; //equal to ^ filter = "company.code=in=(demo,real)"; //in filter = "company.code=out=(demo,real)"; //not in filter = "company.id=gt=100"; //greater than filter = "company.id=lt=100"; //less than filter = "company.id=ge=100"; //greater than or equal filter = "company.id=le=100"; //less than or equal filter = "company.id>100"; //greater than filter = "company.id<100"; //less than filter = "company.id>=100"; //greater than or equal filter = "company.id<=100"; //less than or equal filter = "company.code=isnull=''"; //is null filter = "company.code=null=''"; //is null filter = "company.code=na=''"; //is null filter = "company.code=nn=''"; //is not null filter = "company.code=notnull=''"; //is not null filter = "company.code=isnotnull=''"; //is not null filter = "company.code=='demo';company.id>100"; //and filter = "company.code=='demo' and company.id>100"; //and filter = "company.code=='demo',company.id>100"; //or filter = "company.code=='demo' or company.id>100"; //or ``` -------------------------------- ### Search query using @concat, @upper, and constant Source: https://github.com/perplexhub/rsql-jpa-specification/blob/master/README.md Example of using '@concat' and '@upper' with a constant value for a search query. ```java String rsql3 = "@concat[@upper[code]|#123]==HELLO123"; ``` -------------------------------- ### Sort query using @concat, @upper, and constant Source: https://github.com/perplexhub/rsql-jpa-specification/blob/master/README.md Example of using '@concat' and '@upper' with a constant value for sorting. ```java String sort3 = "@concat[@upper[code]|#123],asc"; ``` -------------------------------- ### RSQL Syntax Examples for Filtering Source: https://github.com/perplexhub/rsql-jpa-specification/blob/master/README.md Demonstrates various RSQL syntaxes for filtering data, including between, not between, like, ignore case, null checks, and logical operators. ```java filter = "id=bt=(2,4)";// id>=2 && id<=4 //between filter = "id=nb=(2,4)";// id<2 || id>4 //not between filter = "company.code=like=em"; //like %em% filter = "company.code=ilike=EM"; //ignore case like %EM% filter = "company.code=icase=EM"; //ignore case equal EM filter = "company.code=notlike=em"; //not like %em% filter = "company.code=inotlike=EM"; //ignore case not like %EM% filter = "company.code=ke=e*m"; //like %e*m% filter = "company.code=ik=E*M"; //ignore case like %E*M% filter = "company.code=nk=e*m"; //not like %e*m% filter = "company.code=ni=E*M"; //ignore case not like %E*M% filter = "company.code=ic=E^^M"; //ignore case equal E^^M filter = "company.code==demo"; //equal filter = "company.code=='demo'"; //equal filter = "company.code==''"; //equal to empty string filter = "company.code==dem*"; //like dem% filter = "company.code==*emo"; //like %emo filter = "company.code==*em*"; //like %em% filter = "company.code==^EM"; //ignore case equal EM filter = "company.code==^*EM*"; //ignore case like %EM% filter = "company.code=='^*EM*'"; //ignore case like %EM% filter = "company.code!=demo"; //not equal filter = "company.code=in=(*)"; //equal to * filter = "company.code=in=(^)"; //equal to ^ filter = "company.code=in=(demo,real)"; //in filter = "company.code=out=(demo,real)"; //not in filter = "company.id=gt=100"; //greater than filter = "company.id=lt=100"; //less than filter = "company.id=ge=100"; //greater than or equal filter = "company.id=le=100"; //less than or equal filter = "company.id>100"; //greater than filter = "company.id<100"; //less than filter = "company.id>=100"; //greater than or equal filter = "company.id<=100"; //less than or equal filter = "company.code=isnull="; //is null filter = "company.code=null="; //is null filter = "company.code=na="; //is null filter = "company.code=nn="; //is not null filter = "company.code=notnull="; //is not null filter = "company.code=isnotnull="; //is not null filter = "company.code=='demo';company.id>100"; //and filter = "company.code=='demo' and company.id>100"; //and filter = "company.code=='demo',company.id>100"; //or filter = "company.code=='demo' or company.id>100"; //or ``` -------------------------------- ### Sort query using @upper procedure Source: https://github.com/perplexhub/rsql-jpa-specification/blob/master/README.md Example of using the '@upper' stored procedure for sorting a 'code' column in ascending order. ```java String sort1 = "@upper[code],asc"; ``` -------------------------------- ### Sort query using @concat and @upper procedures Source: https://github.com/perplexhub/rsql-jpa-specification/blob/master/README.md Example of using '@concat' and '@upper' procedures for sorting based on combined and transformed column values. ```java String sort2 = "@concat[@upper[code]|name],asc"; ``` -------------------------------- ### Search query using @concat and @upper procedures Source: https://github.com/perplexhub/rsql-jpa-specification/blob/master/README.md Example of using '@concat' and '@upper' procedures to combine and transform column values for a search query. ```java String rsql2 = "@concat[@upper[code]|name]==TESTTest Lab"; ``` -------------------------------- ### Search query using @upper procedure Source: https://github.com/perplexhub/rsql-jpa-specification/blob/master/README.md Example of using the '@upper' stored procedure to convert a 'code' column to uppercase for a search query. ```java String rsql1 = "@upper[code]==HELLO"; ``` -------------------------------- ### Querying JSONB field by name Source: https://github.com/perplexhub/rsql-jpa-specification/blob/master/README.md Example of querying a JSONB field 'data' by its nested 'name' property. Assumes 'data' is a JSONB field in the User entity. ```java String rsql = "data.name==demo"; List users = userRepository.findAll(toSpecification(rsql)); ``` -------------------------------- ### Querying JSONB field by nested user ID Source: https://github.com/perplexhub/rsql-jpa-specification/blob/master/README.md Example of querying a JSONB field 'data' by a nested 'id' within the 'user' object. Assumes 'data.user.id' path exists. ```java String rsql = "data.user.id==1"; List users = userRepository.findAll(toSpecification(rsql)); ``` -------------------------------- ### Querying JSONB field by nested array element ID Source: https://github.com/perplexhub/rsql-jpa-specification/blob/master/README.md Example of querying a JSONB field 'data' by the 'id' of an element within the 'roles' array. Assumes 'data.roles.id' path exists. ```java String rsql = "data.roles.id==1"; List users = userRepository.findAll(toSpecification(rsql)); ``` -------------------------------- ### Sample Spring Boot Application Configuration Source: https://github.com/perplexhub/rsql-jpa-specification/blob/master/README.md Configure your Spring Boot application to enable JPA repositories and transaction management. Ensure the base packages for your repositories are correctly specified. ```java package io.github.perplexhub.rsql; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.data.jpa.repository.config.EnableJpaRepositories; import org.springframework.transaction.annotation.EnableTransactionManagement; @EnableJpaRepositories(basePackages = { "io.github.xxx.yyy.repository" }) @EnableTransactionManagement @SpringBootApplication public class Application { public static void main(String[] args) throws Exception { SpringApplication.run(Application.class, args); } } ``` -------------------------------- ### Import RSQL Configuration Source: https://github.com/perplexhub/rsql-jpa-specification/blob/master/rsql-support/README.md Import the RSQLConfig class to enable RSQL support within your Spring application context. ```java @Import(io.github.perplexhub.rsql.RSQLConfig.class) ``` -------------------------------- ### Calling a whitelisted stored procedure for search Source: https://github.com/perplexhub/rsql-jpa-specification/blob/master/README.md Demonstrates calling a stored procedure '@concat' with arguments for searching. Requires whitelisting the procedure. ```java String rsql = "@concat[greetings|#123]==HELLO123"; QuerySupport querySupport = QuerySupport.builder() .rsqlQuery(rsql) .procedureWhiteList(List.of("concat", "upper")) .build(); List companies = itemRepository.findAll(toSpecification(querySupport)); ``` -------------------------------- ### Maven Dependency for rsql-jpa-spring-boot-starter Source: https://github.com/perplexhub/rsql-jpa-specification/blob/master/README.md Add this dependency to your Maven project to enable RSQL to Spring JPA translation. Replace X.X.X with the desired version. ```xml io.github.perplexhub rsql-jpa-spring-boot-starter X.X.X ``` -------------------------------- ### Maven Dependency for rsql-querydsl-spring-boot-starter Source: https://github.com/perplexhub/rsql-jpa-specification/blob/master/README.md Add this dependency to your Maven project for RSQL to Spring JPA and QueryDSL translation. Replace X.X.X with the desired version. ```xml io.github.perplexhub rsql-querydsl-spring-boot-starter X.X.X ``` -------------------------------- ### Add QueryDSL Core Dependency Source: https://github.com/perplexhub/rsql-jpa-specification/blob/master/rsql-support/README.md Include the QueryDSL core dependency if you plan to use the RSQLSupport.toPredicate method for QueryDSL integration. ```xml com.querydsl querydsl-core x.y.z ``` -------------------------------- ### QueryDSL Predicate with Property Path Remapping Source: https://github.com/perplexhub/rsql-jpa-specification/blob/master/rsql-support/README.md Remap RSQL property names to domain model property paths for more flexible filtering with QueryDSL Predicates. Supports basic filtering and pagination. ```java // property path remap filter = "compCode=='demo';compId>100"; // "company.code=='demo';company.id>100" - protect our domain model #10 Map propertyPathMapper = new HashMap<>(); propertyPathMapper.put("compId", "company.id"); propertyPathMapper.put("compCode", "company.code"); repository.findAll(toPredicate(filter, QUser.user, propertyPathMapper)); repository.findAll(toPredicate(filter, QUser.user, propertyPathMapper), pageable); ``` -------------------------------- ### QueryDSL Predicate with RSQL Source: https://github.com/perplexhub/rsql-jpa-specification/blob/master/README.md Integrate RSQL with QueryDSL by converting RSQL filters into BooleanExpressions. Supports pagination and property path remapping for flexible querying. ```java Pageable pageable = PageRequest.of(0, 5); //page 1 and page size is 5 repository.findAll(RSQLSupport.toPredicate(filter, QUser.user)); repository.findAll(RSQLSupport.toPredicate(filter, QUser.user), pageable); ``` ```java import static io.github.perplexhub.rsql.RSQLSupport.*; repository.findAll(toPredicate(filter, QUser.user)); repository.findAll(toPredicate(filter, QUser.user), pageable); ``` ```java filter = "compCode=='demo';compId>100"; // "company.code=='demo';company.id>100" - protect our domain model #10 Map propertyPathMapper = new HashMap<>(); propertyPathMapper.put("compId", "company.id"); propertyPathMapper.put("compCode", "company.code"); repository.findAll(toPredicate(filter, QUser.user, propertyPathMapper)); repository.findAll(toPredicate(filter, QUser.user, propertyPathMapper), pageable); ``` -------------------------------- ### QueryDSL Predicate with RSQL Source: https://github.com/perplexhub/rsql-jpa-specification/blob/master/rsql-support/README.md Use RSQLSupport.toPredicate to convert RSQL filters into QueryDSL BooleanExpressions for repository queries. Supports basic filtering and pagination. ```java Pageable pageable = PageRequest.of(0, 5); //page 1 and page size is 5 repository.findAll(RSQLSupport.toPredicate(filter, QUser.user)); repository.findAll(RSQLSupport.toPredicate(filter, QUser.user), pageable); // use static import import static io.github.perplexhub.rsql.RSQLSupport.*; repository.findAll(toPredicate(filter, QUser.user)); repository.findAll(toPredicate(filter, QUser.user), pageable); ``` -------------------------------- ### RSQL Sort Syntax Reference Source: https://github.com/perplexhub/rsql-jpa-specification/blob/master/README.md Defines the syntax for specifying sort orders in RSQL, including single and multiple fields, ascending/descending, and case-insensitive sorting. ```java sort = "id"; // order by id asc sort = "id,asc"; // order by id asc sort = "id,asc;company.id,desc"; // order by id asc, company.id desc sort = "name,asc,ic" // order by name ascending ignore case ``` -------------------------------- ### Sorting with JPA Specifications using RSQL Source: https://github.com/perplexhub/rsql-jpa-specification/blob/master/README.md Apply RSQL-defined sorting to repository queries using RSQLSupport.toSort, with support for custom property mapping. ```java repository.findAll(RSQLSupport.toSort("id,asc;company.id,desc")); // sort with custom field mapping Map propertyMapping = new HashMap<>(); propertyMapping.put("userID", "id"); propertyMapping.put("companyID", "company.id"); repository.findAll(RSQLSupport.toSort("userID,asc;companyID,desc", propertyMapping)); // same as id,asc;company.id,desc ``` -------------------------------- ### Filter and Sort with JPA Specification Source: https://github.com/perplexhub/rsql-jpa-specification/blob/master/README.md Use RSQLSupport to convert RSQL queries into JPA Specifications for filtering and sorting. This is useful for dynamic query generation based on user input. ```java Specification specification = RSQLSupport.toSpecification("company.name==name") .and(RSQLSupport.toSort("company.name,asc,ic;user.id,desc")); repository.findAll(specification); ``` -------------------------------- ### Configure JPA Repository Interface Source: https://github.com/perplexhub/rsql-jpa-specification/blob/master/rsql-support/README.md Extend JpaRepository, JpaSpecificationExecutor, and QuerydslPredicateExecutor in your JPA repository interface to support RSQL queries. ```java package com.perplexhub.repository; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaSpecificationExecutor; import org.springframework.data.querydsl.QuerydslPredicateExecutor; import com.perplexhub.model.User; public interface UserRepository extends JpaRepository, JpaSpecificationExecutor, QuerydslPredicateExecutor { } ``` -------------------------------- ### Maven Properties for Spring Boot, Spring Data, and QueryDSL Versions Source: https://github.com/perplexhub/rsql-jpa-specification/blob/master/README.md Control the versions of Spring Boot, Spring Data, and QueryDSL used in your project by defining these properties in your Maven pom.xml. ```xml 4.0.3 2025.1.3 4.1.4 ``` -------------------------------- ### Custom RSQL Operator for Day of Week Source: https://github.com/perplexhub/rsql-jpa-specification/blob/master/README.md Define and use custom RSQL operators for complex criteria, such as checking the day of the week. This involves creating a RSQLCustomPredicate with a custom ComparisonOperator and a lambda expression for the predicate logic. ```java String rsql = "createDate=dayofweek='2'"; RSQLCustomPredicate customPredicate = new RSQLCustomPredicate<>(new ComparisonOperator("=dayofweek="), Long.class, input -> { Expression function = input.getCriteriaBuilder().function("ISO_DAY_OF_WEEK", Long.class, input.getPath()); return input.getCriteriaBuilder().lessThan(function, (Long) input.getArguments().get(0)); }); List users = userRepository.findAll(toSpecification(rsql, Arrays.asList(customPredicate))); ``` -------------------------------- ### Custom RSQL Operator for Range Queries Source: https://github.com/perplexhub/rsql-jpa-specification/blob/master/README.md Create custom RSQL operators for range-based queries, such as 'between'. This involves defining a RSQLCustomPredicate with a ComparisonOperator that supports range arguments and implementing the JPA Criteria API logic for range checks. ```java String rsql = "company.id=between=(2,3)"; RSQLCustomPredicate customPredicate = new RSQLCustomPredicate<>(new ComparisonOperator("=between=", true), Long.class, input -> { return input.getCriteriaBuilder().between(input.getPath().as(Long.class), (Long) input.getArguments().get(0), (Long) input.getArguments().get(1)); }); List users = userRepository.findAll(toSpecification(rsql, Arrays.asList(customPredicate))); ``` -------------------------------- ### Spring Data JPA Specification with RSQL Source: https://github.com/perplexhub/rsql-jpa-specification/blob/master/rsql-support/README.md Use RSQLSupport.toSpecification to convert RSQL filters into Spring Data JPA Specifications for repository queries. Supports basic filtering and pagination. ```java Pageable pageable = PageRequest.of(0, 5); //page 1 and page size is 5 repository.findAll(RSQLSupport.toSpecification(filter)); repository.findAll(RSQLSupport.toSpecification(filter), pageable); repository.findAll(RSQLSupport.toSpecification(filter, true)); // select distinct repository.findAll(RSQLSupport.toSpecification(filter, true), pageable); ``` ```java // use static import import static io.github.perplexhub.rsql.RSQLSupport.*; repository.findAll(toSpecification(filter)); repository.findAll(toSpecification(filter), pageable); repository.findAll(toSpecification(filter, true)); // select distinct repository.findAll(toSpecification(filter, true), pageable); ``` -------------------------------- ### Spring Data JPA Specification Usage with RSQL Source: https://github.com/perplexhub/rsql-jpa-specification/blob/master/README.md Utilize the RSQLSupport class to convert RSQL filters into Spring Data JPA Specifications for querying repositories. ```java Pageable pageable = PageRequest.of(0, 5); //page 1 and page size is 5 repository.findAll(RSQLSupport.toSpecification(filter)); repository.findAll(RSQLSupport.toSpecification(filter), pageable); repository.findAll(RSQLSupport.toSpecification(filter, true)); // select distinct repository.findAll(RSQLSupport.toSpecification(filter, true), pageable); // use static import import static io.github.perplexhub.rsql.RSQLSupport.*; repository.findAll(toSpecification(filter)); repository.findAll(toSpecification(filter), pageable); repository.findAll(toSpecification(filter, true)); // select distinct repository.findAll(toSpecification(filter, true), pageable); // property path remap filter = "compCode=='demo';compId>100"; // "company.code=='demo';company.id>100" - protect our domain model #10 Map propertyPathMapper = new HashMap<>(); propertyPathMapper.put("compId", "company.id"); propertyPathMapper.put("compCode", "company.code"); repository.findAll(toSpecification(filter, propertyPathMapper)); repository.findAll(toSpecification(filter, propertyPathMapper), pageable); ``` -------------------------------- ### Escaping Special Characters in LIKE Predicate Source: https://github.com/perplexhub/rsql-jpa-specification/blob/master/README.md Configure an escape character for RSQL LIKE predicates to correctly handle special characters like '%' and '_' in search terms. This ensures that these characters are treated literally rather than as wildcards in the generated SQL. ```java char escapeChar = '$'; QuerySupport query = QuerySupport.builder() .rsqlQuery("name=like='" + escapeChar + "%'") .likeEscapeCharacter(escapeChar) .build(); List users = companyRepository.findAll(toSpecification(query)); ``` -------------------------------- ### Configure JpaSpecificationExecutor in Repository Source: https://github.com/perplexhub/rsql-jpa-specification/blob/master/README.md Extend JpaSpecificationExecutor in your JPA repository interfaces to allow RSQL query translation. This enables the use of Specifications for dynamic query building. ```java package com.perplexhub.repository; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaSpecificationExecutor; import com.perplexhub.model.User; public interface UserRepository extends JpaRepository, JpaSpecificationExecutor { } ``` -------------------------------- ### Spring Data JPA Specification with Property Path Remapping Source: https://github.com/perplexhub/rsql-jpa-specification/blob/master/rsql-support/README.md Remap RSQL property names to domain model property paths for more flexible filtering with Spring Data JPA Specifications. Supports basic filtering and pagination. ```java // property path remap filter = "compCode=='demo';compId>100"; // "company.code=='demo';company.id>100" - protect our domain model #10 Map propertyPathMapper = new HashMap<>(); propertyPathMapper.put("compId", "company.id"); propertyPathMapper.put("compCode", "company.code"); repository.findAll(toSpecification(filter, propertyPathMapper)); repository.findAll(toSpecification(filter, propertyPathMapper), pageable); ``` -------------------------------- ### Custom Value Converter for Date Type Source: https://github.com/perplexhub/rsql-jpa-specification/blob/master/README.md Register a custom converter for specific data types like Date to handle RSQL string parsing. This allows RSQL to correctly interpret and convert string representations of custom types. ```java SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss"); RSQLJPASupport.addConverter(Date.class, s -> { try { return sdf.parse(s); } catch (ParseException e) { return null; } }); ``` -------------------------------- ### Custom RSQL Operator for String Matching Source: https://github.com/perplexhub/rsql-jpa-specification/blob/master/README.md Implement custom RSQL operators for specific string matching logic, like checking if a string is within a predefined list. This uses RSQLCustomPredicate to define the operator and its corresponding JPA Criteria API logic. ```java String rsql = "name=around='May'"; RSQLCustomPredicate customPredicate = new RSQLCustomPredicate<>(new ComparisonOperator("=around="), String.class, input -> { if ("May".equals(input.getArguments().get(0))) { return input.getPath().in(Arrays.asList("April", "May", "June")); } return input.getCriteriaBuilder().equal(input.getPath(), (String) input.getArguments().get(0)); }); List users = userRepository.findAll(toSpecification(rsql, Arrays.asList(customPredicate))); ``` -------------------------------- ### Add Spring Data JPA Dependency Source: https://github.com/perplexhub/rsql-jpa-specification/blob/master/rsql-support/README.md Include the Spring Data JPA dependency in your pom.xml to enable JPA repository functionalities. ```xml org.springframework.data spring-data-jpa x.y.z ``` -------------------------------- ### Custom RSQL Operator for Null Checks Source: https://github.com/perplexhub/rsql-jpa-specification/blob/master/README.md Implement custom RSQL operators to specifically check for null values in a database column. This is achieved using RSQLCustomPredicate to define an operator like '=notAssigned=' and mapping it to a JPA Criteria API isNull check. ```java String rsql = "city=notAssigned=''"; RSQLCustomPredicate customPredicate = new RSQLCustomPredicate<>(new ComparisonOperator("=notAssigned="), String.class, input -> { return input.getCriteriaBuilder().isNull(input.getRoot().get("city")); }); List users = userRepository.findAll(toSpecification(rsql, Arrays.asList(customPredicate))); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.