Skip to content

Instantly share code, notes, and snippets.

View josergdev's full-sized avatar

José Rodríguez josergdev

  • Autentia
  • Madrid
View GitHub Profile
@josergdev
josergdev / CriteriaBuilderTupleIn.java
Last active October 6, 2024 21:54
CriteriaBuilder extension fort tuples IN feature
package dev.joserg.jpa;
import java.util.ArrayList;
import java.util.List;
import java.util.function.Function;
import jakarta.persistence.criteria.CriteriaBuilder;
import jakarta.persistence.criteria.Expression;
import jakarta.persistence.criteria.Predicate;
import lombok.extern.slf4j.Slf4j;
@josergdev
josergdev / SliceSpecificationExecutor.java
Last active September 30, 2024 10:36
JpaSpecificationExecutor extension to find All Slice by Specification
package dev.joserg.jpa;
import static org.springframework.data.domain.ScrollPosition.offset;
import java.util.function.Function;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.ScrollPosition;
import org.springframework.data.domain.Slice;
import org.springframework.data.domain.SliceImpl;
@josergdev
josergdev / SliceJpaRepositoryImpl.java
Last active August 24, 2024 12:00
SimpleJpaRepository extension to find All Slice by Specification
package dev.joserg.jpa;
import jakarta.persistence.EntityManager;
import org.jetbrains.annotations.Nullable;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Slice;
import org.springframework.data.domain.SliceImpl;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.data.jpa.repository.support.JpaEntityInformation;
import org.springframework.data.jpa.repository.support.SimpleJpaRepository;
@josergdev
josergdev / SimpleHttpCriteria.java
Last active August 24, 2024 10:51
This class maps http query parameters to the JPA specification with common convention behavior
package dev.joserg.jpa;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import jakarta.persistence.criteria.CriteriaBuilder;
import jakarta.persistence.criteria.CriteriaQuery;
import jakarta.persistence.criteria.JoinType;
@josergdev
josergdev / GenericSpecification.java
Last active August 24, 2024 12:03
Spring Data Specification to find data by pairs of attributes
package dev.joserg.util.jpa;
import static org.springframework.data.jpa.domain.Specification.allOf;
import static org.springframework.data.jpa.domain.Specification.anyOf;
import java.util.List;
import java.util.Optional;
import jakarta.annotation.Nonnull;
import jakarta.persistence.criteria.Root;