ca.gc.aafc.dina.jpa.JsonbValueSpecification Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of dina-base-api Show documentation
Show all versions of dina-base-api Show documentation
Base DINA API package for Java built on SpringBoot and Crnk
The newest version!
package ca.gc.aafc.dina.jpa;
import lombok.RequiredArgsConstructor;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;
/**
* Allows to create JPA Predicate matching a value on a specific jsonb key.
* PostgreSQL specific.
* @param
*/
@RequiredArgsConstructor
public class JsonbValueSpecification {
static final String JSONB_EXTRACT_PATH_PG_FUNCTION_NAME = "jsonb_extract_path_text";
private final String columnName;
private final String keyName;
public Predicate toPredicate(Root root, CriteriaBuilder builder, String value) {
return builder.equal(builder
.function(JSONB_EXTRACT_PATH_PG_FUNCTION_NAME,
String.class,
root.get(this.columnName),
builder.literal(this.keyName)),
value);
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy