spring-data-relational icon indicating copy to clipboard operation
spring-data-relational copied to clipboard

Create Infrastructure so users can define custom predicates for query derivation

Open schauder opened this issue 4 years ago • 4 comments

This is inspired by #1185

schauder avatar Mar 01 '22 12:03 schauder

@schauder Happy to look into this - do you have an idea of what the predicates will look like?

Thanks

Shane

ShaneLee avatar Mar 04 '22 13:03 ShaneLee

@ShaneLee a quick pointer would be to look for "PartTree" related classes. You'll find lengthy if/else/switch conditions. Basically we would need to extract all the information of those into an interface which then could be implemented and registered by a user. Or (later) even a Dialect.

HTH.

schauder avatar Mar 04 '22 13:03 schauder

Would this allow for the use of custom criteria? My current problem is I want to use JSON operators in PostgreSQL with the criteria API.

stdreyer avatar Mar 11 '22 10:03 stdreyer

I wanted to implement org.springframework.data.relational.core.query.CriteriaDefinition for extending sql query functionality with json operators such '@?' or '?|' (and others), but cannot extend enum org.springframework.data.relational.core.query.CriteriaDefinition.Comparator.

I can suggest adding smth like interface IComparator, and then implements interface by enum Comparator. And change CriteriaDefinition method - Comparator getComparator(); with - IComparator getComparator(); And do smth with this throwing - 'default -> throw new UnsupportedOperationException("Comparator " + comparator + " not supported");' in org.springframework.data.jdbc.core.convert.QueryMapper.createCondition method (instead of throwing return smth like this Conditions.just(column_without_table_prefix + " " + comparator + " " + value))

If do this, it will be possible for developers to create custom Comparators and use them with custom Criteria which will implement CriteriaDefinition.

thanks

gkstms avatar Mar 15 '23 22:03 gkstms