-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ChennuruAkhil#8 Refactored code with Query… (#1148)
* ChennuruAkhil#8 Refactored code with Query Hints * ChennuruAkhil#8 Fixed Sonar issues * ChennuruAkhil#8 Refactored code as per the comments
- Loading branch information
1 parent
3427916
commit dddf633
Showing
5 changed files
with
37 additions
and
133 deletions.
There are no files selected for viewing
27 changes: 25 additions & 2 deletions
27
jpa/boot-jpa-locks/src/main/java/com/example/locks/repositories/ActorRepository.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,6 +1,29 @@ | ||
package com.example.locks.repositories; | ||
|
||
import com.example.locks.entities.Actor; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import jakarta.persistence.LockModeType; | ||
import jakarta.persistence.QueryHint; | ||
import java.util.Optional; | ||
import org.springframework.data.jpa.repository.*; | ||
import org.springframework.data.repository.query.Param; | ||
|
||
public interface ActorRepository extends JpaRepository<Actor, Long>, CustomizedActorRepository {} | ||
public interface ActorRepository extends JpaRepository<Actor, Long> { | ||
|
||
@Query(value = "SELECT actor FROM Actor actor WHERE actor.actorId = :actorId") | ||
@QueryHints( | ||
value = { | ||
@QueryHint(name = "jakarta.persistence.lock.timeout", value = "5000"), | ||
@QueryHint(name = "jakarta.persistence.query.timeout", value = "3000"), | ||
}) | ||
@Lock(LockModeType.PESSIMISTIC_WRITE) | ||
Optional<Actor> findByIdWithPessimisticWriteLock(@Param("actorId") Long actorId); | ||
|
||
@Query(value = "SELECT actor FROM Actor actor WHERE actor.actorId = :actorId") | ||
@QueryHints( | ||
value = { | ||
@QueryHint(name = "jakarta.persistence.lock.timeout", value = "5000"), | ||
@QueryHint(name = "jakarta.persistence.query.timeout", value = "3000"), | ||
}) | ||
@Lock(LockModeType.PESSIMISTIC_READ) | ||
Optional<Actor> findByIdWithPessimisticReadLock(@Param("actorId") Long actorId); | ||
} |
13 changes: 0 additions & 13 deletions
13
...oot-jpa-locks/src/main/java/com/example/locks/repositories/CustomizedActorRepository.java
This file was deleted.
Oops, something went wrong.
112 changes: 0 additions & 112 deletions
112
...jpa-locks/src/main/java/com/example/locks/repositories/CustomizedActorRepositoryImpl.java
This file was deleted.
Oops, something went wrong.
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
3 changes: 3 additions & 0 deletions
3
jpa/boot-jpa-locks/src/main/java/com/example/locks/utils/AppConstants.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