-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #314 from devgateway/feature/jpa-query-cache-dgtkit3
#311 Cache hibernate queries from JPA repositories dgtkit-3
- Loading branch information
Showing
7 changed files
with
77 additions
and
6 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
19 changes: 19 additions & 0 deletions
19
...rc/main/java/org/devgateway/toolkit/persistence/repository/CacheHibernateQueryResult.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,19 @@ | ||
package org.devgateway.toolkit.persistence.repository; | ||
|
||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
import javax.persistence.QueryHint; | ||
|
||
import org.springframework.data.jpa.repository.QueryHints; | ||
|
||
/** | ||
* @author Octavian Ciubotaru | ||
*/ | ||
@Target({ ElementType.METHOD, ElementType.ANNOTATION_TYPE }) | ||
@Retention(RetentionPolicy.RUNTIME) | ||
@QueryHints({@QueryHint(name = "org.hibernate.cacheable", value = "true")}) | ||
public @interface CacheHibernateQueryResult { | ||
} |
48 changes: 48 additions & 0 deletions
48
...in/java/org/devgateway/toolkit/persistence/repository/norepository/BaseJpaRepository.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 |
---|---|---|
@@ -1,15 +1,63 @@ | ||
package org.devgateway.toolkit.persistence.repository.norepository; | ||
|
||
import org.devgateway.toolkit.persistence.repository.CacheHibernateQueryResult; | ||
import org.springframework.data.domain.Page; | ||
import org.springframework.data.domain.Pageable; | ||
import org.springframework.data.domain.Sort; | ||
import org.springframework.data.jpa.domain.Specification; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.data.jpa.repository.JpaSpecificationExecutor; | ||
import org.springframework.data.repository.NoRepositoryBean; | ||
import org.springframework.lang.Nullable; | ||
|
||
import java.io.Serializable; | ||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
/** | ||
* Created by Octavian on 01.07.2016. | ||
*/ | ||
@NoRepositoryBean | ||
public interface BaseJpaRepository<T, ID extends Serializable> | ||
extends JpaRepository<T, ID>, JpaSpecificationExecutor<T> { | ||
|
||
@Override | ||
@CacheHibernateQueryResult | ||
List<T> findAll(); | ||
|
||
@Override | ||
@CacheHibernateQueryResult | ||
List<T> findAll(Sort sort); | ||
|
||
@Override | ||
@CacheHibernateQueryResult | ||
List<T> findAll(Specification<T> spec); | ||
|
||
@Override | ||
@CacheHibernateQueryResult | ||
Page<T> findAll(Specification<T> spec, Pageable pageable); | ||
|
||
@Override | ||
@CacheHibernateQueryResult | ||
Page<T> findAll(Pageable pageable); | ||
|
||
@Override | ||
@CacheHibernateQueryResult | ||
List<T> findAll(Specification<T> spec, Sort sort); | ||
|
||
@Override | ||
@CacheHibernateQueryResult | ||
Optional<T> findOne(@Nullable Specification<T> spec); | ||
|
||
@Override | ||
@CacheHibernateQueryResult | ||
long count(Specification<T> spec); | ||
|
||
@Override | ||
@CacheHibernateQueryResult | ||
long count(); | ||
|
||
@Override | ||
@CacheHibernateQueryResult | ||
Optional<T> findById(ID id); | ||
} |
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,4 @@ | ||
|
||
# Uncomment for Hibernate SQL statements and parameters | ||
#logging.level.org.hibernate.SQL=DEBUG | ||
#logging.level.org.hibernate.type.descriptor.sql.BasicBinder=TRACE |
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