Skip to content
This repository has been archived by the owner on Apr 17, 2023. It is now read-only.

Commit

Permalink
Enabled hibernate cache and cached most used queries
Browse files Browse the repository at this point in the history
  • Loading branch information
ziccardi committed Dec 7, 2017
1 parent 9d6e792 commit 0953c1b
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ public PageResult<PushApplication, Count> findAllForDeveloper(String loginName,
.setParameter("developer", loginName).getSingleResult();
List<PushApplication> entities = entityManager.createQuery("select pa " + select, PushApplication.class)
.setFirstResult(page * pageSize).setMaxResults(pageSize)
.setParameter("developer", loginName).getResultList();
.setParameter("developer", loginName)
.setHint("org.hibernate.cacheable", true).getResultList();

return new PageResult<>(entities, new Count(count));
}
Expand All @@ -59,7 +60,8 @@ public PageResult<PushApplication, Count> findAllForDeveloper(String loginName,
@Override
public List<String> findAllPushApplicationIDsForDeveloper (String loginName) {
return createQuery("select pa.pushApplicationID from PushApplication pa where pa.developer = :developer", String.class)
.setParameter("developer", loginName).getResultList();
.setParameter("developer", loginName)
.setHint("org.hibernate.cacheable", true).getResultList();
}

@Override
Expand All @@ -73,7 +75,8 @@ public PushApplication findByPushApplicationIDForDeveloper(String pushApplicatio
@Override
public PushApplication findByPushApplicationID(String pushApplicationID) {
return getSingleResultForQuery(createQuery("select pa from PushApplication pa where pa.pushApplicationID = :pushApplicationID")
.setParameter("pushApplicationID", pushApplicationID));
.setParameter("pushApplicationID", pushApplicationID)
.setHint("org.hibernate.cacheable", true));
}

@Override
Expand Down Expand Up @@ -110,7 +113,8 @@ public long getNumberOfPushApplicationsForDeveloper(String name) {
public List<PushApplication> findByVariantIds(List<String> variantIDs) {
final String jpql = "select pa from PushApplication pa left join fetch pa.variants v where v.variantID in (:variantIDs)";

return createQuery(jpql).setParameter("variantIDs", variantIDs).getResultList();
return createQuery(jpql).setParameter("variantIDs", variantIDs)
.setHint("org.hibernate.cacheable", true).getResultList();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ public void delete(Variant variant) {
@Override
public Variant findByVariantID(String variantID) {
return getSingleResultForQuery(createQuery("select t from Variant t where t.variantID = :variantID")
.setParameter("variantID", variantID));
.setParameter("variantID", variantID)
.setHint("org.hibernate.cacheable", true));
}

@Override
Expand Down Expand Up @@ -67,7 +68,8 @@ public List<Variant> findAllVariantsByIDs(List<String> variantIDs) {
}

return createQuery("select t from Variant t where t.variantID IN :variantIDs")
.setParameter("variantIDs", variantIDs).getResultList();
.setParameter("variantIDs", variantIDs)
.setHint("org.hibernate.cacheable", true).getResultList();
}

//Admin queries
Expand Down
6 changes: 6 additions & 0 deletions model/jpa/src/main/resources/META-INF/persistence.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,19 @@
<jta-data-source>java:jboss/datasources/UnifiedPushDS</jta-data-source>

<mapping-file>META-INF/orm.xml</mapping-file>
<shared-cache-mode>ALL</shared-cache-mode>

<properties>
<property name="hibernate.dialect_resolvers" value="org.jboss.aerogear.unifiedpush.jpa.MysqlDialectResolver"/>
<property name="hibernate.hbm2ddl.auto" value="${ups.ddl_value}"/>
<property name="hibernate.show_sql" value="false"/>
<property name="hibernate.format_sql" value="false"/>
<property name="hibernate.id.new_generator_mappings" value="true"/>

<property name="hibernate.cache.use_query_cache" value="true"/>
<property name="hibernate.cache.use_second_level_cache" value="true"/>

<property name="hibernate.cache.infinispan.statistics" value="true"/>
</properties>
</persistence-unit>

Expand Down

2 comments on commit 0953c1b

@matzew
Copy link
Contributor

@matzew matzew commented on 0953c1b Dec 10, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ziccardi let's not use RHMAP-xxx JIRA names here, on the branch - we should have AGPUSH JIRAs for the work on AGPUSH server ;-)

@ziccardi
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@matzew Currently this branch is about issue https://issues.jboss.org/browse/RHMAP-16817, hence the name.
Do you think I should change it?

Please sign in to comment.