Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GRAD2-2430: bug fix on LocalDateTime compatible with native query. #452

Merged
merged 2 commits into from
Dec 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading