generated from ministryofjustice/template-repository
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* PI-1615 Move caseload rebuild into afterCommit hook * Added test
- Loading branch information
1 parent
b8fe289
commit bbdf52f
Showing
13 changed files
with
88 additions
and
35 deletions.
There are no files selected for viewing
27 changes: 27 additions & 0 deletions
27
libs/audit/src/main/kotlin/uk/gov/justice/digital/hmpps/audit/service/OptimisationTables.kt
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,27 @@ | ||
package uk.gov.justice.digital.hmpps.audit.service | ||
|
||
import org.springframework.context.annotation.Conditional | ||
import org.springframework.jdbc.core.JdbcTemplate | ||
import org.springframework.stereotype.Service | ||
import org.springframework.transaction.support.TransactionSynchronization | ||
import org.springframework.transaction.support.TransactionSynchronizationManager | ||
import uk.gov.justice.digital.hmpps.audit.config.OracleCondition | ||
|
||
@Service | ||
class OptimisationTables(private val optimisationTablesRebuild: OptimisationTablesRebuild?) { | ||
fun rebuild(personId: Long) { | ||
optimisationTablesRebuild?.rebuild(personId) | ||
} | ||
} | ||
|
||
@Service | ||
@Conditional(OracleCondition::class) | ||
class OptimisationTablesRebuild(private val jdbcTemplate: JdbcTemplate) { | ||
fun rebuild(personId: Long) { | ||
TransactionSynchronizationManager.registerSynchronization(object : TransactionSynchronization { | ||
override fun afterCommit() { | ||
jdbcTemplate.execute("call PKG_TRIGGERSUPPORT.PROCREBUILDOPTTABLES($personId)") | ||
} | ||
}) | ||
} | ||
} |
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
5 changes: 0 additions & 5 deletions
5
libs/audit/src/main/kotlin/uk/gov/justice/digital/hmpps/datasource/OptimisationContext.kt
This file was deleted.
Oops, something went wrong.
29 changes: 29 additions & 0 deletions
29
...udit/src/test/kotlin/uk/gov/justice/digital/hmpps/audit/service/OptimisationTablesTest.kt
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,29 @@ | ||
package uk.gov.justice.digital.hmpps.audit.service | ||
|
||
import org.hamcrest.MatcherAssert.assertThat | ||
import org.hamcrest.Matchers.hasSize | ||
import org.junit.jupiter.api.Assertions.assertDoesNotThrow | ||
import org.junit.jupiter.api.Test | ||
import org.mockito.Mockito.mock | ||
import org.mockito.Mockito.verify | ||
import org.springframework.jdbc.core.JdbcTemplate | ||
import org.springframework.transaction.support.TransactionSynchronizationManager | ||
|
||
class OptimisationTablesTest { | ||
@Test | ||
fun `handles non-Oracle database`() { | ||
assertDoesNotThrow { OptimisationTables(null).rebuild(123) } | ||
} | ||
|
||
@Test | ||
fun `creates afterCommit hook`() { | ||
val jdbcTemplate = mock(JdbcTemplate::class.java) | ||
TransactionSynchronizationManager.initSynchronization() | ||
|
||
OptimisationTables(OptimisationTablesRebuild(jdbcTemplate)).rebuild(123) | ||
|
||
assertThat(TransactionSynchronizationManager.getSynchronizations(), hasSize(1)) | ||
TransactionSynchronizationManager.getSynchronizations()[0].afterCommit() | ||
verify(jdbcTemplate).execute("call PKG_TRIGGERSUPPORT.PROCREBUILDOPTTABLES(123)") | ||
} | ||
} |
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
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