-
Notifications
You must be signed in to change notification settings - Fork 191
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add JpaSpecificationEntityGraphExecutor (#2120)
Provides option to find entities by Specificaton with EntityGraph filter in order to load some LAZY attributes Signed-off-by: Avgustin Marinov <[email protected]>
- Loading branch information
1 parent
39861e7
commit efc6d05
Showing
8 changed files
with
181 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
...va/org/eclipse/hawkbit/repository/jpa/repository/JpaSpecificationEntityGraphExecutor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
/** | ||
* Copyright (c) 2024 Contributors to the Eclipse Foundation | ||
* | ||
* This program and the accompanying materials are made | ||
* available under the terms of the Eclipse Public License 2.0 | ||
* which is available at https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
*/ | ||
package org.eclipse.hawkbit.repository.jpa.repository; | ||
|
||
import java.util.List; | ||
import java.util.Optional; | ||
import java.util.function.Function; | ||
|
||
import jakarta.persistence.criteria.CriteriaBuilder; | ||
import jakarta.persistence.criteria.CriteriaQuery; | ||
import jakarta.persistence.criteria.Root; | ||
|
||
import org.eclipse.hawkbit.repository.model.BaseEntity; | ||
import org.springframework.data.domain.Page; | ||
import org.springframework.data.domain.Pageable; | ||
import org.springframework.data.domain.Slice; | ||
import org.springframework.data.domain.Sort; | ||
import org.springframework.data.jpa.domain.Specification; | ||
import org.springframework.data.repository.query.FluentQuery; | ||
import org.springframework.lang.Nullable; | ||
|
||
/** | ||
* Repository interface that offers JpaSpecificationExecutor#findOne/All methods with entity graph loading | ||
* | ||
* @param <T> entity type | ||
*/ | ||
public interface JpaSpecificationEntityGraphExecutor<T> { | ||
|
||
/** | ||
* Returns a single entity matching the given {@link Specification} with the entity graph hint or {@link Optional#empty()} if none found. | ||
* @see org.springframework.data.jpa.repository.JpaSpecificationExecutor#findOne(Specification) | ||
* | ||
* @param spec must not be {@literal null}. | ||
* @param entityGraph the entity graph hint to use | ||
* @return never {@literal null}. | ||
* @throws org.springframework.dao.IncorrectResultSizeDataAccessException if more than one entity found. | ||
*/ | ||
Optional<T> findOne(Specification<T> spec, String entityGraph); | ||
|
||
/** | ||
* Returns all entities matching the given {@link Specification} with the entity graph hint. | ||
* <p> | ||
* @see org.springframework.data.jpa.repository.JpaSpecificationExecutor#findAll(Specification) | ||
* | ||
* @param spec can be {@literal null}. | ||
* @param entityGraph the entity graph hint to use | ||
* @return never {@literal null}. | ||
*/ | ||
List<T> findAll(@Nullable Specification<T> spec, String entityGraph); | ||
|
||
/** | ||
* Returns a {@link Page} of entities matching the given {@link Specification} with the entity graph hint. | ||
* <p> | ||
* @see org.springframework.data.jpa.repository.JpaSpecificationExecutor#findAll(Specification, Pageable) | ||
* | ||
* @param spec can be {@literal null}. | ||
* @param entityGraph the entity graph hint to use | ||
* @param pageable must not be {@literal null}. | ||
* @return never {@literal null}. | ||
*/ | ||
Page<T> findAll(@Nullable Specification<T> spec, String entityGraph, Pageable pageable); | ||
|
||
/** | ||
* Returns all entities matching the given {@link Specification} and {@link Sort} with the entity graph hint. | ||
* <p> | ||
* @see org.springframework.data.jpa.repository.JpaSpecificationExecutor#findAll(Specification, Sort) | ||
* | ||
* @param spec can be {@literal null}. | ||
* @param entityGraph the entity graph hint to use | ||
* @param sort must not be {@literal null}. | ||
* @return never {@literal null}. | ||
*/ | ||
List<T> findAll(@Nullable Specification<T> spec, String entityGraph, Sort sort); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters