Skip to content

Commit

Permalink
query optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
leandrofpk committed Apr 7, 2022
1 parent 0f4a686 commit 13247d5
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 5 deletions.
2 changes: 1 addition & 1 deletion beacon-engine/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>br.gov.inmetro.beacon</groupId>
<artifactId>beacon-engine</artifactId>
<version>1.0.3.RELEASE</version>
<version>1.0.4.RELEASE</version>
<packaging>jar</packaging>

<name>beacon-engine</name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class PulsesRepositoryImpl implements PulsesQueries {
@Transactional
public PulseEntity last(Long chainIndex){
Long lastPulseIndex = (Long) manager.createQuery(
"select max(p.pulseIndex) from PulseEntity p where p.chainIndex = :chainIndex")
"select max(p.id) from PulseEntity p where p.chainIndex = :chainIndex")
.setParameter("chainIndex", chainIndex)
.getSingleResult();

Expand All @@ -36,7 +36,7 @@ public PulseEntity last(Long chainIndex){
@Transactional
public PulseEntity first(Long chainIndex){
Long firstPulseIndex = (Long) manager.createQuery(
"select min(p.pulseIndex) from PulseEntity p where p.chainIndex = :chainIndex")
"select min(p.id) from PulseEntity p where p.chainIndex = :chainIndex")
.setParameter("chainIndex", chainIndex)
.getSingleResult();

Expand Down Expand Up @@ -73,6 +73,23 @@ public PulseEntity findByChainAndPulseIndex(Long chainIndex, Long pulseIndex){
}
}

@Transactional(readOnly = true)
public PulseEntity findByChainAndPulseId(Long chainIndex, Long pulseId){
try {
PulseEntity recordEntity = (PulseEntity) manager
.createQuery("from PulseEntity p " +
"join fetch p.listValueEntities lve " +
"where p.chainIndex = :chainIndex and p.pulseIndex = :pulseId")
.setParameter("chainIndex", chainIndex)
.setParameter("pulseId", pulseId)
.getSingleResult();

return recordEntity;
} catch (NoResultException e){
return null;
}
}

@Transactional(readOnly = true)
public Pulse findOldPulses(Long chainIndex, ZonedDateTime timeStamp){
try {
Expand Down
2 changes: 1 addition & 1 deletion beacon-interface/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
</parent>
<groupId>com.example</groupId>
<artifactId>beacon-interface</artifactId>
<version>1.0.0.RELEASE</version>
<version>1.0.1.RELEASE</version>
<name>beacon-interface</name>
<description>Demo project for Spring Boot</description>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public PulseEntity last(Long chainIndex){
@Transactional(readOnly = true)
public PulseEntity first(Long chainIndex){
Long firstPulseIndex = (Long) manager.createQuery(
"select min(p.pulseIndex) from PulseEntity p where p.chainIndex = :chainIndex")
"select min(p.id) from PulseEntity p where p.chainIndex = :chainIndex")
.setParameter("chainIndex", chainIndex)
.getSingleResult();

Expand Down

0 comments on commit 13247d5

Please sign in to comment.