Class EmptyResultOnTypeMismatch<T>

java.lang.Object
net.kaczmarzyk.spring.data.jpa.domain.EmptyResultOnTypeMismatch<T>
All Implemented Interfaces:
Serializable, org.springframework.data.jpa.domain.Specification<T>
Direct Known Subclasses:
IgnoreOnTypeMismatch

public class EmptyResultOnTypeMismatch<T> extends Object implements org.springframework.data.jpa.domain.Specification<T>

Wrapper that turns a Specification into a one that always produces in an empty result (i.e. where 0 = 1) in case of a type mismatch (e.g. when type on path is Long and the value from the HTTP parameter is not a numeric.

It's useful for polymorphic "OR" queries such as where id = ? or name = ?. A spec will be wrapped with this decorator if onTypeMismatch property of @Spec is explicitly set to OnTypeMismatch.EMPTY_RESULT, i.e.: @Spec(path="id", onTypeMismatch=EMPTY_RESULT).

Author:
Tomasz Kaczmarzyk
See Also:
  • Constructor Summary

    Constructors
    Constructor
    Description
    EmptyResultOnTypeMismatch(org.springframework.data.jpa.domain.Specification<T> wrappedSpec)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
     
    org.springframework.data.jpa.domain.Specification<T>
     
    int
     
    jakarta.persistence.criteria.Predicate
    toPredicate(jakarta.persistence.criteria.Root<T> root, jakarta.persistence.criteria.CriteriaQuery<?> query, jakarta.persistence.criteria.CriteriaBuilder cb)
     
     

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait

    Methods inherited from interface org.springframework.data.jpa.domain.Specification

    and, or
  • Constructor Details

    • EmptyResultOnTypeMismatch

      public EmptyResultOnTypeMismatch(org.springframework.data.jpa.domain.Specification<T> wrappedSpec)
  • Method Details

    • toPredicate

      public jakarta.persistence.criteria.Predicate toPredicate(jakarta.persistence.criteria.Root<T> root, jakarta.persistence.criteria.CriteriaQuery<?> query, jakarta.persistence.criteria.CriteriaBuilder cb)
      Specified by:
      toPredicate in interface org.springframework.data.jpa.domain.Specification<T>
    • getWrappedSpec

      public org.springframework.data.jpa.domain.Specification<T> getWrappedSpec()
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object