-
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.
fix(): transaction only when saving report in db
- Loading branch information
Showing
2 changed files
with
49 additions
and
33 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
36 changes: 36 additions & 0 deletions
36
...ey/server/src/main/java/com/chutneytesting/migration/infra/ExecutionReportRepository.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,36 @@ | ||
/* | ||
* SPDX-FileCopyrightText: 2017-2024 Enedis | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
*/ | ||
|
||
package com.chutneytesting.migration.infra; | ||
|
||
import com.chutneytesting.execution.infra.storage.jpa.ScenarioExecutionReportEntity; | ||
import jakarta.persistence.EntityManager; | ||
import java.util.List; | ||
import org.springframework.stereotype.Component; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@Component | ||
public class ExecutionReportRepository { | ||
|
||
private final EntityManager entityManager; | ||
|
||
public ExecutionReportRepository(EntityManager entityManager ) { | ||
this.entityManager = entityManager; | ||
} | ||
|
||
@Transactional | ||
public void compressAndSaveInDb(List<ScenarioExecutionReportEntity> reportsInDb) { | ||
reportsInDb.forEach(report -> { | ||
entityManager.createQuery( | ||
"UPDATE SCENARIO_EXECUTIONS_REPORTS SET report = :report WHERE id = :id") | ||
.setParameter("report", report.getReport()) | ||
.setParameter("id", report.scenarioExecutionId()) | ||
.executeUpdate(); | ||
entityManager.detach(report); | ||
}); | ||
} | ||
} |