Skip to content

Commit

Permalink
Merge pull request #452 from bcgov/feature/GRAD2-2430
Browse files Browse the repository at this point in the history
GRAD2-2430: bug fix on LocalDateTime compatible with native query.
  • Loading branch information
kamal-mohammed authored Dec 20, 2023
2 parents 773a974 + 8990377 commit 9299125
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
public class BatchJobExecutionContextEntity {
@Id
@Column(name = "JOB_EXECUTION_ID", nullable = false)
private Long id;
private Long jobExecutionId;

@Column(name = "SHORT_CONTEXT", nullable = false, length = 2500)
private String shortContext;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class BatchStepExecutionContextEntity {

@Id
@Column(name = "STEP_EXECUTION_ID", nullable = false)
private Long id;
private Long stepExecutionId;

@Column(name = "SHORT_CONTEXT", length = 2500)
private String shortContext;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class BatchStepExecutionEntity {

@Id
@Column(name = "STEP_EXECUTION_ID", nullable = false)
private Long id;
private Long stepExecutionId;

@Column(name = "JOB_EXECUTION_ID", nullable = false)
private Long jobExecutionId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,28 +18,24 @@ public interface BatchJobExecutionRepository extends JpaRepository<BatchJobExecu

@Transactional
@Modifying
@Query(value = "DELETE FROM BATCH_JOB_EXECUTION_PARAMS WHERE JOB_EXECUTION_ID IN (\n" +
"SELECT JOB_EXECUTION_ID FROM BATCH_JOB_EXECUTION WHERE CREATE_TIME <= :createDate);",
nativeQuery = true)
@Query(value = "DELETE FROM BatchJobExecutionParamEntity bjep WHERE bjep.jobExecutionId IN (\n" +
"SELECT bje.jobExecutionId FROM BatchJobExecutionEntity bje WHERE bje.createTime <= :createDate)")
void deleteBatchParamsByCreateTimeBefore(LocalDateTime createDate);

@Transactional
@Modifying
@Query(value = "DELETE FROM BATCH_JOB_EXECUTION_CONTEXT WHERE JOB_EXECUTION_ID IN (\n" +
"SELECT JOB_EXECUTION_ID FROM BATCH_JOB_EXECUTION WHERE CREATE_TIME <= :createDate);",
nativeQuery = true)
@Query(value = "DELETE FROM BatchJobExecutionContextEntity bjec WHERE bjec.jobExecutionId IN (\n" +
"SELECT bje.jobExecutionId FROM BatchJobExecutionEntity bje WHERE bje.createTime <= :createDate)")
void deleteBatchContextsByCreateTimeBefore(LocalDateTime createDate);

@Transactional
@Modifying
@Query(value = "DELETE FROM BATCH_JOB_INSTANCE WHERE JOB_INSTANCE_ID NOT IN (\n" +
"SELECT JOB_INSTANCE_ID FROM BATCH_JOB_EXECUTION);",
nativeQuery = true)
@Query(value = "DELETE FROM BatchJobInstanceEntity bji WHERE bji.id NOT IN (\n" +
"SELECT bje.id FROM BatchJobExecutionEntity bje)")
void deleteBatchInstancesNotInBatchJobs();

@Transactional
@Modifying
@Query(value = "DELETE FROM BATCH_JOB_EXECUTION WHERE CREATE_TIME <= :createDate;",
nativeQuery = true)
@Query(value = "DELETE FROM BatchJobExecutionEntity bje WHERE bje.createTime <= :createDate")
void deleteBatchJobsByCreateTimeBefore(LocalDateTime createDate);
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,15 @@ public interface BatchStepExecutionRepository extends JpaRepository<BatchStepExe

@Transactional
@Modifying
@Query(value = "DELETE FROM BATCH_STEP_EXECUTION_CONTEXT WHERE STEP_EXECUTION_ID IN (\n" +
"SELECT BATCH_STEP_EXECUTION.STEP_EXECUTION_ID FROM BATCH_STEP_EXECUTION WHERE JOB_EXECUTION_ID IN (\n" +
" SELECT JOB_EXECUTION_ID FROM BATCH_JOB_EXECUTION WHERE CREATE_TIME <= :createDate\n" +
"));\n",
nativeQuery = true)
@Query(value = "DELETE FROM BatchStepExecutionContextEntity bsec WHERE bsec.stepExecutionId IN (\n" +
"SELECT bse.stepExecutionId FROM BatchStepExecutionEntity bse WHERE bse.jobExecutionId IN (\n" +
" SELECT bje.jobExecutionId FROM BatchJobExecutionEntity bje WHERE bje.createTime <= :createDate))")
void deleteBatchStepContextsByCreateTimeBefore(LocalDateTime createDate);

@Transactional
@Modifying
@Query(value = "DELETE FROM BATCH_STEP_EXECUTION WHERE JOB_EXECUTION_ID IN (\n" +
" SELECT JOB_EXECUTION_ID FROM BATCH_JOB_EXECUTION WHERE CREATE_TIME <= :createDate);",
nativeQuery = true)
@Query(value = "DELETE FROM BatchStepExecutionEntity bse WHERE bse.jobExecutionId IN (\n" +
" SELECT bje.jobExecutionId FROM BatchJobExecutionEntity bje WHERE bje.createTime <= :createDate)")
void deleteBatchStepsByCreateTimeBefore(LocalDateTime createDate);

}
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ public void testGetDashboardInfo_whenLastUpdatedDate_isOlderThan5hours_thenUpdat
BatchStepExecutionEntity step = new BatchStepExecutionEntity();
step.setStepName("test-partition12");
step.setJobExecutionId(hist.getJobExecutionId());
step.setId(Long.valueOf("123"));
step.setStepExecutionId(Long.valueOf("123"));
step.setStatus("STARTED");
step.setStartTime(ca.bc.gov.educ.api.batchgraduation.util.DateUtils.toLocalDateTime(startedDateTime));
Date lastUpdatedDateTime = DateUtils.addHours(today, -6);
Expand Down

0 comments on commit 9299125

Please sign in to comment.