diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/repository/support/SimpleJobRepository.java b/spring-batch-core/src/main/java/org/springframework/batch/core/repository/support/SimpleJobRepository.java index e98752c987..4f07e041e0 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/repository/support/SimpleJobRepository.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/repository/support/SimpleJobRepository.java @@ -54,6 +54,7 @@ * @author Baris Cubukcuoglu * @author Parikshit Dutta * @author Mark John Moreno + * @author UHyeon Jeong * @see JobRepository * @see JobInstanceDao * @see JobExecutionDao @@ -312,26 +313,16 @@ public JobExecution getLastJobExecution(String jobName, JobParameters jobParamet @Override public void deleteStepExecution(StepExecution stepExecution) { - this.ecDao.deleteExecutionContext(stepExecution); this.stepExecutionDao.deleteStepExecution(stepExecution); } @Override public void deleteJobExecution(JobExecution jobExecution) { - this.ecDao.deleteExecutionContext(jobExecution); - this.jobExecutionDao.deleteJobExecutionParameters(jobExecution); - for (StepExecution stepExecution : jobExecution.getStepExecutions()) { - deleteStepExecution(stepExecution); - } this.jobExecutionDao.deleteJobExecution(jobExecution); } @Override public void deleteJobInstance(JobInstance jobInstance) { - List jobExecutions = findJobExecutions(jobInstance); - for (JobExecution jobExecution : jobExecutions) { - deleteJobExecution(jobExecution); - } this.jobInstanceDao.deleteJobInstance(jobInstance); } diff --git a/spring-batch-core/src/main/resources/org/springframework/batch/core/schema-db2.sql b/spring-batch-core/src/main/resources/org/springframework/batch/core/schema-db2.sql index c883c354c9..5db07b3b9c 100644 --- a/spring-batch-core/src/main/resources/org/springframework/batch/core/schema-db2.sql +++ b/spring-batch-core/src/main/resources/org/springframework/batch/core/schema-db2.sql @@ -20,7 +20,7 @@ CREATE TABLE BATCH_JOB_EXECUTION ( EXIT_MESSAGE VARCHAR(2500) , LAST_UPDATED TIMESTAMP(9), constraint JOB_INST_EXEC_FK foreign key (JOB_INSTANCE_ID) - references BATCH_JOB_INSTANCE(JOB_INSTANCE_ID) + references BATCH_JOB_INSTANCE(JOB_INSTANCE_ID) ON DELETE CASCADE ) ; CREATE TABLE BATCH_JOB_EXECUTION_PARAMS ( @@ -30,7 +30,7 @@ CREATE TABLE BATCH_JOB_EXECUTION_PARAMS ( PARAMETER_VALUE VARCHAR(2500) , IDENTIFYING CHAR(1) NOT NULL , constraint JOB_EXEC_PARAMS_FK foreign key (JOB_EXECUTION_ID) - references BATCH_JOB_EXECUTION(JOB_EXECUTION_ID) + references BATCH_JOB_EXECUTION(JOB_EXECUTION_ID) ON DELETE CASCADE ) ; CREATE TABLE BATCH_STEP_EXECUTION ( @@ -54,7 +54,7 @@ CREATE TABLE BATCH_STEP_EXECUTION ( EXIT_MESSAGE VARCHAR(2500) , LAST_UPDATED TIMESTAMP(9), constraint JOB_EXEC_STEP_FK foreign key (JOB_EXECUTION_ID) - references BATCH_JOB_EXECUTION(JOB_EXECUTION_ID) + references BATCH_JOB_EXECUTION(JOB_EXECUTION_ID) ON DELETE CASCADE ) ; CREATE TABLE BATCH_STEP_EXECUTION_CONTEXT ( @@ -62,7 +62,7 @@ CREATE TABLE BATCH_STEP_EXECUTION_CONTEXT ( SHORT_CONTEXT VARCHAR(2500) NOT NULL, SERIALIZED_CONTEXT CLOB , constraint STEP_EXEC_CTX_FK foreign key (STEP_EXECUTION_ID) - references BATCH_STEP_EXECUTION(STEP_EXECUTION_ID) + references BATCH_STEP_EXECUTION(STEP_EXECUTION_ID) ON DELETE CASCADE ) ; CREATE TABLE BATCH_JOB_EXECUTION_CONTEXT ( @@ -70,7 +70,7 @@ CREATE TABLE BATCH_JOB_EXECUTION_CONTEXT ( SHORT_CONTEXT VARCHAR(2500) NOT NULL, SERIALIZED_CONTEXT CLOB , constraint JOB_EXEC_CTX_FK foreign key (JOB_EXECUTION_ID) - references BATCH_JOB_EXECUTION(JOB_EXECUTION_ID) + references BATCH_JOB_EXECUTION(JOB_EXECUTION_ID) ON DELETE CASCADE ) ; CREATE SEQUENCE BATCH_STEP_EXECUTION_SEQ AS BIGINT MAXVALUE 9223372036854775807 NO CYCLE; diff --git a/spring-batch-core/src/main/resources/org/springframework/batch/core/schema-derby.sql b/spring-batch-core/src/main/resources/org/springframework/batch/core/schema-derby.sql index c9510a5bc3..b6f2d14893 100644 --- a/spring-batch-core/src/main/resources/org/springframework/batch/core/schema-derby.sql +++ b/spring-batch-core/src/main/resources/org/springframework/batch/core/schema-derby.sql @@ -20,7 +20,7 @@ CREATE TABLE BATCH_JOB_EXECUTION ( EXIT_MESSAGE VARCHAR(2500) , LAST_UPDATED TIMESTAMP, constraint JOB_INST_EXEC_FK foreign key (JOB_INSTANCE_ID) - references BATCH_JOB_INSTANCE(JOB_INSTANCE_ID) + references BATCH_JOB_INSTANCE(JOB_INSTANCE_ID) ON DELETE CASCADE ) ; CREATE TABLE BATCH_JOB_EXECUTION_PARAMS ( @@ -30,7 +30,7 @@ CREATE TABLE BATCH_JOB_EXECUTION_PARAMS ( PARAMETER_VALUE VARCHAR(2500) , IDENTIFYING CHAR(1) NOT NULL , constraint JOB_EXEC_PARAMS_FK foreign key (JOB_EXECUTION_ID) - references BATCH_JOB_EXECUTION(JOB_EXECUTION_ID) + references BATCH_JOB_EXECUTION(JOB_EXECUTION_ID) ON DELETE CASCADE ) ; CREATE TABLE BATCH_STEP_EXECUTION ( @@ -54,7 +54,7 @@ CREATE TABLE BATCH_STEP_EXECUTION ( EXIT_MESSAGE VARCHAR(2500) , LAST_UPDATED TIMESTAMP, constraint JOB_EXEC_STEP_FK foreign key (JOB_EXECUTION_ID) - references BATCH_JOB_EXECUTION(JOB_EXECUTION_ID) + references BATCH_JOB_EXECUTION(JOB_EXECUTION_ID) ON DELETE CASCADE ) ; CREATE TABLE BATCH_STEP_EXECUTION_CONTEXT ( @@ -62,7 +62,7 @@ CREATE TABLE BATCH_STEP_EXECUTION_CONTEXT ( SHORT_CONTEXT VARCHAR(2500) NOT NULL, SERIALIZED_CONTEXT CLOB , constraint STEP_EXEC_CTX_FK foreign key (STEP_EXECUTION_ID) - references BATCH_STEP_EXECUTION(STEP_EXECUTION_ID) + references BATCH_STEP_EXECUTION(STEP_EXECUTION_ID) ON DELETE CASCADE ) ; CREATE TABLE BATCH_JOB_EXECUTION_CONTEXT ( @@ -70,7 +70,7 @@ CREATE TABLE BATCH_JOB_EXECUTION_CONTEXT ( SHORT_CONTEXT VARCHAR(2500) NOT NULL, SERIALIZED_CONTEXT CLOB , constraint JOB_EXEC_CTX_FK foreign key (JOB_EXECUTION_ID) - references BATCH_JOB_EXECUTION(JOB_EXECUTION_ID) + references BATCH_JOB_EXECUTION(JOB_EXECUTION_ID) ON DELETE CASCADE ) ; CREATE TABLE BATCH_STEP_EXECUTION_SEQ (ID BIGINT PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY, DUMMY VARCHAR(1)); diff --git a/spring-batch-core/src/main/resources/org/springframework/batch/core/schema-drop-sybase.sql b/spring-batch-core/src/main/resources/org/springframework/batch/core/schema-drop-sybase.sql index d217ec569b..12a369f99b 100644 --- a/spring-batch-core/src/main/resources/org/springframework/batch/core/schema-drop-sybase.sql +++ b/spring-batch-core/src/main/resources/org/springframework/batch/core/schema-drop-sybase.sql @@ -1,12 +1,19 @@ -- Autogenerated: do not edit this file - -DROP TABLE BATCH_STEP_EXECUTION_CONTEXT; +IF EXISTS (SELECT 1 FROM sysobjects WHERE name = 'BATCH_STEP_EXECUTION_CONTEXT' AND type = 'U') +drop table BATCH_STEP_EXECUTION_CONTEXT; +IF EXISTS (SELECT 1 FROM sysobjects WHERE name = 'BATCH_JOB_EXECUTION_CONTEXT' AND type = 'U') DROP TABLE BATCH_JOB_EXECUTION_CONTEXT; +IF EXISTS (SELECT 1 FROM sysobjects WHERE name = 'BATCH_STEP_EXECUTION' AND type = 'U') DROP TABLE BATCH_STEP_EXECUTION; +IF EXISTS (SELECT 1 FROM sysobjects WHERE name = 'BATCH_JOB_EXECUTION_PARAMS' AND type = 'U') DROP TABLE BATCH_JOB_EXECUTION_PARAMS; +IF EXISTS (SELECT 1 FROM sysobjects WHERE name = 'BATCH_JOB_EXECUTION' AND type = 'U') DROP TABLE BATCH_JOB_EXECUTION; +IF EXISTS (SELECT 1 FROM sysobjects WHERE name = 'BATCH_JOB_INSTANCE' AND type = 'U') DROP TABLE BATCH_JOB_INSTANCE; - +IF EXISTS (SELECT 1 FROM sysobjects WHERE name = 'BATCH_STEP_EXECUTION_SEQ' AND type = 'U') DROP TABLE BATCH_STEP_EXECUTION_SEQ; +IF EXISTS (SELECT 1 FROM sysobjects WHERE name = 'BATCH_JOB_EXECUTION_SEQ' AND type = 'U') DROP TABLE BATCH_JOB_EXECUTION_SEQ; +IF EXISTS (SELECT 1 FROM sysobjects WHERE name = 'BATCH_JOB_SEQ' AND type = 'U') DROP TABLE BATCH_JOB_SEQ; diff --git a/spring-batch-core/src/main/resources/org/springframework/batch/core/schema-h2.sql b/spring-batch-core/src/main/resources/org/springframework/batch/core/schema-h2.sql index dc51c373ca..939c406b19 100644 --- a/spring-batch-core/src/main/resources/org/springframework/batch/core/schema-h2.sql +++ b/spring-batch-core/src/main/resources/org/springframework/batch/core/schema-h2.sql @@ -20,7 +20,7 @@ CREATE TABLE BATCH_JOB_EXECUTION ( EXIT_MESSAGE VARCHAR(2500) , LAST_UPDATED TIMESTAMP(9), constraint JOB_INST_EXEC_FK foreign key (JOB_INSTANCE_ID) - references BATCH_JOB_INSTANCE(JOB_INSTANCE_ID) + references BATCH_JOB_INSTANCE(JOB_INSTANCE_ID) ON DELETE CASCADE ) ; CREATE TABLE BATCH_JOB_EXECUTION_PARAMS ( @@ -30,7 +30,7 @@ CREATE TABLE BATCH_JOB_EXECUTION_PARAMS ( PARAMETER_VALUE VARCHAR(2500) , IDENTIFYING CHAR(1) NOT NULL , constraint JOB_EXEC_PARAMS_FK foreign key (JOB_EXECUTION_ID) - references BATCH_JOB_EXECUTION(JOB_EXECUTION_ID) + references BATCH_JOB_EXECUTION(JOB_EXECUTION_ID) ON DELETE CASCADE ) ; CREATE TABLE BATCH_STEP_EXECUTION ( @@ -54,7 +54,7 @@ CREATE TABLE BATCH_STEP_EXECUTION ( EXIT_MESSAGE VARCHAR(2500) , LAST_UPDATED TIMESTAMP(9), constraint JOB_EXEC_STEP_FK foreign key (JOB_EXECUTION_ID) - references BATCH_JOB_EXECUTION(JOB_EXECUTION_ID) + references BATCH_JOB_EXECUTION(JOB_EXECUTION_ID) ON DELETE CASCADE ) ; CREATE TABLE BATCH_STEP_EXECUTION_CONTEXT ( @@ -62,7 +62,7 @@ CREATE TABLE BATCH_STEP_EXECUTION_CONTEXT ( SHORT_CONTEXT VARCHAR(2500) NOT NULL, SERIALIZED_CONTEXT LONGVARCHAR , constraint STEP_EXEC_CTX_FK foreign key (STEP_EXECUTION_ID) - references BATCH_STEP_EXECUTION(STEP_EXECUTION_ID) + references BATCH_STEP_EXECUTION(STEP_EXECUTION_ID) ON DELETE CASCADE ) ; CREATE TABLE BATCH_JOB_EXECUTION_CONTEXT ( @@ -70,7 +70,7 @@ CREATE TABLE BATCH_JOB_EXECUTION_CONTEXT ( SHORT_CONTEXT VARCHAR(2500) NOT NULL, SERIALIZED_CONTEXT LONGVARCHAR , constraint JOB_EXEC_CTX_FK foreign key (JOB_EXECUTION_ID) - references BATCH_JOB_EXECUTION(JOB_EXECUTION_ID) + references BATCH_JOB_EXECUTION(JOB_EXECUTION_ID) ON DELETE CASCADE ) ; CREATE SEQUENCE BATCH_STEP_EXECUTION_SEQ; diff --git a/spring-batch-core/src/main/resources/org/springframework/batch/core/schema-hana.sql b/spring-batch-core/src/main/resources/org/springframework/batch/core/schema-hana.sql index 8dc2dc843c..a9d4f963e6 100644 --- a/spring-batch-core/src/main/resources/org/springframework/batch/core/schema-hana.sql +++ b/spring-batch-core/src/main/resources/org/springframework/batch/core/schema-hana.sql @@ -20,7 +20,7 @@ CREATE TABLE BATCH_JOB_EXECUTION ( EXIT_MESSAGE VARCHAR(2500) , LAST_UPDATED TIMESTAMP, constraint JOB_INST_EXEC_FK foreign key (JOB_INSTANCE_ID) - references BATCH_JOB_INSTANCE(JOB_INSTANCE_ID) + references BATCH_JOB_INSTANCE(JOB_INSTANCE_ID) ON DELETE CASCADE ) ; CREATE TABLE BATCH_JOB_EXECUTION_PARAMS ( @@ -30,7 +30,7 @@ CREATE TABLE BATCH_JOB_EXECUTION_PARAMS ( PARAMETER_VALUE VARCHAR(2500) , IDENTIFYING VARCHAR(1) NOT NULL , constraint JOB_EXEC_PARAMS_FK foreign key (JOB_EXECUTION_ID) - references BATCH_JOB_EXECUTION(JOB_EXECUTION_ID) + references BATCH_JOB_EXECUTION(JOB_EXECUTION_ID) ON DELETE CASCADE ) ; CREATE TABLE BATCH_STEP_EXECUTION ( @@ -54,7 +54,7 @@ CREATE TABLE BATCH_STEP_EXECUTION ( EXIT_MESSAGE VARCHAR(2500) , LAST_UPDATED TIMESTAMP, constraint JOB_EXEC_STEP_FK foreign key (JOB_EXECUTION_ID) - references BATCH_JOB_EXECUTION(JOB_EXECUTION_ID) + references BATCH_JOB_EXECUTION(JOB_EXECUTION_ID) ON DELETE CASCADE ) ; CREATE TABLE BATCH_STEP_EXECUTION_CONTEXT ( @@ -62,7 +62,7 @@ CREATE TABLE BATCH_STEP_EXECUTION_CONTEXT ( SHORT_CONTEXT VARCHAR(2500) NOT NULL, SERIALIZED_CONTEXT CLOB , constraint STEP_EXEC_CTX_FK foreign key (STEP_EXECUTION_ID) - references BATCH_STEP_EXECUTION(STEP_EXECUTION_ID) + references BATCH_STEP_EXECUTION(STEP_EXECUTION_ID) ON DELETE CASCADE ) ; CREATE TABLE BATCH_JOB_EXECUTION_CONTEXT ( @@ -70,7 +70,7 @@ CREATE TABLE BATCH_JOB_EXECUTION_CONTEXT ( SHORT_CONTEXT VARCHAR(2500) NOT NULL, SERIALIZED_CONTEXT CLOB , constraint JOB_EXEC_CTX_FK foreign key (JOB_EXECUTION_ID) - references BATCH_JOB_EXECUTION(JOB_EXECUTION_ID) + references BATCH_JOB_EXECUTION(JOB_EXECUTION_ID) ON DELETE CASCADE ) ; CREATE SEQUENCE BATCH_STEP_EXECUTION_SEQ START WITH 0 MINVALUE 0 NO CYCLE; diff --git a/spring-batch-core/src/main/resources/org/springframework/batch/core/schema-hsqldb.sql b/spring-batch-core/src/main/resources/org/springframework/batch/core/schema-hsqldb.sql index 758699f152..b4c2501495 100644 --- a/spring-batch-core/src/main/resources/org/springframework/batch/core/schema-hsqldb.sql +++ b/spring-batch-core/src/main/resources/org/springframework/batch/core/schema-hsqldb.sql @@ -20,7 +20,7 @@ CREATE TABLE BATCH_JOB_EXECUTION ( EXIT_MESSAGE VARCHAR(2500) , LAST_UPDATED TIMESTAMP(9), constraint JOB_INST_EXEC_FK foreign key (JOB_INSTANCE_ID) - references BATCH_JOB_INSTANCE(JOB_INSTANCE_ID) + references BATCH_JOB_INSTANCE(JOB_INSTANCE_ID) ON DELETE CASCADE ) ; CREATE TABLE BATCH_JOB_EXECUTION_PARAMS ( @@ -30,7 +30,7 @@ CREATE TABLE BATCH_JOB_EXECUTION_PARAMS ( PARAMETER_VALUE VARCHAR(2500) , IDENTIFYING CHAR(1) NOT NULL , constraint JOB_EXEC_PARAMS_FK foreign key (JOB_EXECUTION_ID) - references BATCH_JOB_EXECUTION(JOB_EXECUTION_ID) + references BATCH_JOB_EXECUTION(JOB_EXECUTION_ID) ON DELETE CASCADE ) ; CREATE TABLE BATCH_STEP_EXECUTION ( @@ -54,7 +54,7 @@ CREATE TABLE BATCH_STEP_EXECUTION ( EXIT_MESSAGE VARCHAR(2500) , LAST_UPDATED TIMESTAMP(9), constraint JOB_EXEC_STEP_FK foreign key (JOB_EXECUTION_ID) - references BATCH_JOB_EXECUTION(JOB_EXECUTION_ID) + references BATCH_JOB_EXECUTION(JOB_EXECUTION_ID) ON DELETE CASCADE ) ; CREATE TABLE BATCH_STEP_EXECUTION_CONTEXT ( @@ -62,7 +62,7 @@ CREATE TABLE BATCH_STEP_EXECUTION_CONTEXT ( SHORT_CONTEXT VARCHAR(2500) NOT NULL, SERIALIZED_CONTEXT LONGVARCHAR , constraint STEP_EXEC_CTX_FK foreign key (STEP_EXECUTION_ID) - references BATCH_STEP_EXECUTION(STEP_EXECUTION_ID) + references BATCH_STEP_EXECUTION(STEP_EXECUTION_ID) ON DELETE CASCADE ) ; CREATE TABLE BATCH_JOB_EXECUTION_CONTEXT ( @@ -70,7 +70,7 @@ CREATE TABLE BATCH_JOB_EXECUTION_CONTEXT ( SHORT_CONTEXT VARCHAR(2500) NOT NULL, SERIALIZED_CONTEXT LONGVARCHAR , constraint JOB_EXEC_CTX_FK foreign key (JOB_EXECUTION_ID) - references BATCH_JOB_EXECUTION(JOB_EXECUTION_ID) + references BATCH_JOB_EXECUTION(JOB_EXECUTION_ID) ON DELETE CASCADE ) ; CREATE TABLE BATCH_STEP_EXECUTION_SEQ ( diff --git a/spring-batch-core/src/main/resources/org/springframework/batch/core/schema-mariadb.sql b/spring-batch-core/src/main/resources/org/springframework/batch/core/schema-mariadb.sql index 31f585fbc0..ffac18eec8 100644 --- a/spring-batch-core/src/main/resources/org/springframework/batch/core/schema-mariadb.sql +++ b/spring-batch-core/src/main/resources/org/springframework/batch/core/schema-mariadb.sql @@ -18,7 +18,7 @@ CREATE TABLE BATCH_JOB_EXECUTION ( EXIT_MESSAGE VARCHAR(2500) , LAST_UPDATED DATETIME(6), constraint JOB_INST_EXEC_FK foreign key (JOB_INSTANCE_ID) - references BATCH_JOB_INSTANCE(JOB_INSTANCE_ID) + references BATCH_JOB_INSTANCE(JOB_INSTANCE_ID) ON DELETE CASCADE ) ENGINE=InnoDB; CREATE TABLE BATCH_JOB_EXECUTION_PARAMS ( @@ -28,7 +28,7 @@ CREATE TABLE BATCH_JOB_EXECUTION_PARAMS ( PARAMETER_VALUE VARCHAR(2500) , IDENTIFYING CHAR(1) NOT NULL , constraint JOB_EXEC_PARAMS_FK foreign key (JOB_EXECUTION_ID) - references BATCH_JOB_EXECUTION(JOB_EXECUTION_ID) + references BATCH_JOB_EXECUTION(JOB_EXECUTION_ID) ON DELETE CASCADE ) ENGINE=InnoDB; CREATE TABLE BATCH_STEP_EXECUTION ( @@ -52,7 +52,7 @@ CREATE TABLE BATCH_STEP_EXECUTION ( EXIT_MESSAGE VARCHAR(2500) , LAST_UPDATED DATETIME(6), constraint JOB_EXEC_STEP_FK foreign key (JOB_EXECUTION_ID) - references BATCH_JOB_EXECUTION(JOB_EXECUTION_ID) + references BATCH_JOB_EXECUTION(JOB_EXECUTION_ID) ON DELETE CASCADE ) ENGINE=InnoDB; CREATE TABLE BATCH_STEP_EXECUTION_CONTEXT ( @@ -60,7 +60,7 @@ CREATE TABLE BATCH_STEP_EXECUTION_CONTEXT ( SHORT_CONTEXT VARCHAR(2500) NOT NULL, SERIALIZED_CONTEXT TEXT , constraint STEP_EXEC_CTX_FK foreign key (STEP_EXECUTION_ID) - references BATCH_STEP_EXECUTION(STEP_EXECUTION_ID) + references BATCH_STEP_EXECUTION(STEP_EXECUTION_ID) ON DELETE CASCADE ) ENGINE=InnoDB; CREATE TABLE BATCH_JOB_EXECUTION_CONTEXT ( @@ -68,7 +68,7 @@ CREATE TABLE BATCH_JOB_EXECUTION_CONTEXT ( SHORT_CONTEXT VARCHAR(2500) NOT NULL, SERIALIZED_CONTEXT TEXT , constraint JOB_EXEC_CTX_FK foreign key (JOB_EXECUTION_ID) - references BATCH_JOB_EXECUTION(JOB_EXECUTION_ID) + references BATCH_JOB_EXECUTION(JOB_EXECUTION_ID) ON DELETE CASCADE ) ENGINE=InnoDB; CREATE SEQUENCE BATCH_STEP_EXECUTION_SEQ START WITH 1 MINVALUE 1 MAXVALUE 9223372036854775806 INCREMENT BY 1 NOCACHE NOCYCLE ENGINE=InnoDB; diff --git a/spring-batch-core/src/main/resources/org/springframework/batch/core/schema-mysql.sql b/spring-batch-core/src/main/resources/org/springframework/batch/core/schema-mysql.sql index 197ef3ff02..73f3d207ec 100644 --- a/spring-batch-core/src/main/resources/org/springframework/batch/core/schema-mysql.sql +++ b/spring-batch-core/src/main/resources/org/springframework/batch/core/schema-mysql.sql @@ -20,7 +20,7 @@ CREATE TABLE BATCH_JOB_EXECUTION ( EXIT_MESSAGE VARCHAR(2500) , LAST_UPDATED DATETIME(6), constraint JOB_INST_EXEC_FK foreign key (JOB_INSTANCE_ID) - references BATCH_JOB_INSTANCE(JOB_INSTANCE_ID) + references BATCH_JOB_INSTANCE(JOB_INSTANCE_ID) ON DELETE CASCADE ) ENGINE=InnoDB; CREATE TABLE BATCH_JOB_EXECUTION_PARAMS ( @@ -30,7 +30,7 @@ CREATE TABLE BATCH_JOB_EXECUTION_PARAMS ( PARAMETER_VALUE VARCHAR(2500) , IDENTIFYING CHAR(1) NOT NULL , constraint JOB_EXEC_PARAMS_FK foreign key (JOB_EXECUTION_ID) - references BATCH_JOB_EXECUTION(JOB_EXECUTION_ID) + references BATCH_JOB_EXECUTION(JOB_EXECUTION_ID) ON DELETE CASCADE ) ENGINE=InnoDB; CREATE TABLE BATCH_STEP_EXECUTION ( @@ -54,7 +54,7 @@ CREATE TABLE BATCH_STEP_EXECUTION ( EXIT_MESSAGE VARCHAR(2500) , LAST_UPDATED DATETIME(6), constraint JOB_EXEC_STEP_FK foreign key (JOB_EXECUTION_ID) - references BATCH_JOB_EXECUTION(JOB_EXECUTION_ID) + references BATCH_JOB_EXECUTION(JOB_EXECUTION_ID) ON DELETE CASCADE ) ENGINE=InnoDB; CREATE TABLE BATCH_STEP_EXECUTION_CONTEXT ( @@ -62,7 +62,7 @@ CREATE TABLE BATCH_STEP_EXECUTION_CONTEXT ( SHORT_CONTEXT VARCHAR(2500) NOT NULL, SERIALIZED_CONTEXT TEXT , constraint STEP_EXEC_CTX_FK foreign key (STEP_EXECUTION_ID) - references BATCH_STEP_EXECUTION(STEP_EXECUTION_ID) + references BATCH_STEP_EXECUTION(STEP_EXECUTION_ID) ON DELETE CASCADE ) ENGINE=InnoDB; CREATE TABLE BATCH_JOB_EXECUTION_CONTEXT ( @@ -70,7 +70,7 @@ CREATE TABLE BATCH_JOB_EXECUTION_CONTEXT ( SHORT_CONTEXT VARCHAR(2500) NOT NULL, SERIALIZED_CONTEXT TEXT , constraint JOB_EXEC_CTX_FK foreign key (JOB_EXECUTION_ID) - references BATCH_JOB_EXECUTION(JOB_EXECUTION_ID) + references BATCH_JOB_EXECUTION(JOB_EXECUTION_ID) ON DELETE CASCADE ) ENGINE=InnoDB; CREATE TABLE BATCH_STEP_EXECUTION_SEQ ( diff --git a/spring-batch-core/src/main/resources/org/springframework/batch/core/schema-oracle.sql b/spring-batch-core/src/main/resources/org/springframework/batch/core/schema-oracle.sql index 73deea519e..d3d3ed16af 100644 --- a/spring-batch-core/src/main/resources/org/springframework/batch/core/schema-oracle.sql +++ b/spring-batch-core/src/main/resources/org/springframework/batch/core/schema-oracle.sql @@ -20,7 +20,7 @@ CREATE TABLE BATCH_JOB_EXECUTION ( EXIT_MESSAGE VARCHAR2(2500 char) , LAST_UPDATED TIMESTAMP(9), constraint JOB_INST_EXEC_FK foreign key (JOB_INSTANCE_ID) - references BATCH_JOB_INSTANCE(JOB_INSTANCE_ID) + references BATCH_JOB_INSTANCE(JOB_INSTANCE_ID) ON DELETE CASCADE ) SEGMENT CREATION IMMEDIATE; CREATE TABLE BATCH_JOB_EXECUTION_PARAMS ( @@ -30,7 +30,7 @@ CREATE TABLE BATCH_JOB_EXECUTION_PARAMS ( PARAMETER_VALUE VARCHAR(2500 char) , IDENTIFYING CHAR(1) NOT NULL , constraint JOB_EXEC_PARAMS_FK foreign key (JOB_EXECUTION_ID) - references BATCH_JOB_EXECUTION(JOB_EXECUTION_ID) + references BATCH_JOB_EXECUTION(JOB_EXECUTION_ID) ON DELETE CASCADE ) SEGMENT CREATION IMMEDIATE; CREATE TABLE BATCH_STEP_EXECUTION ( @@ -54,7 +54,7 @@ CREATE TABLE BATCH_STEP_EXECUTION ( EXIT_MESSAGE VARCHAR2(2500 char) , LAST_UPDATED TIMESTAMP(9), constraint JOB_EXEC_STEP_FK foreign key (JOB_EXECUTION_ID) - references BATCH_JOB_EXECUTION(JOB_EXECUTION_ID) + references BATCH_JOB_EXECUTION(JOB_EXECUTION_ID) ON DELETE CASCADE ) SEGMENT CREATION IMMEDIATE; CREATE TABLE BATCH_STEP_EXECUTION_CONTEXT ( @@ -62,7 +62,7 @@ CREATE TABLE BATCH_STEP_EXECUTION_CONTEXT ( SHORT_CONTEXT VARCHAR2(2500 char) NOT NULL, SERIALIZED_CONTEXT CLOB , constraint STEP_EXEC_CTX_FK foreign key (STEP_EXECUTION_ID) - references BATCH_STEP_EXECUTION(STEP_EXECUTION_ID) + references BATCH_STEP_EXECUTION(STEP_EXECUTION_ID) ON DELETE CASCADE ) SEGMENT CREATION IMMEDIATE; CREATE TABLE BATCH_JOB_EXECUTION_CONTEXT ( @@ -70,7 +70,7 @@ CREATE TABLE BATCH_JOB_EXECUTION_CONTEXT ( SHORT_CONTEXT VARCHAR2(2500 char) NOT NULL, SERIALIZED_CONTEXT CLOB , constraint JOB_EXEC_CTX_FK foreign key (JOB_EXECUTION_ID) - references BATCH_JOB_EXECUTION(JOB_EXECUTION_ID) + references BATCH_JOB_EXECUTION(JOB_EXECUTION_ID) ON DELETE CASCADE ) SEGMENT CREATION IMMEDIATE; CREATE SEQUENCE BATCH_STEP_EXECUTION_SEQ START WITH 0 MINVALUE 0 MAXVALUE 9223372036854775807 ORDER NOCYCLE; diff --git a/spring-batch-core/src/main/resources/org/springframework/batch/core/schema-postgresql.sql b/spring-batch-core/src/main/resources/org/springframework/batch/core/schema-postgresql.sql index dd146f1f0f..5c977a212e 100644 --- a/spring-batch-core/src/main/resources/org/springframework/batch/core/schema-postgresql.sql +++ b/spring-batch-core/src/main/resources/org/springframework/batch/core/schema-postgresql.sql @@ -20,7 +20,7 @@ CREATE TABLE BATCH_JOB_EXECUTION ( EXIT_MESSAGE VARCHAR(2500) , LAST_UPDATED TIMESTAMP, constraint JOB_INST_EXEC_FK foreign key (JOB_INSTANCE_ID) - references BATCH_JOB_INSTANCE(JOB_INSTANCE_ID) + references BATCH_JOB_INSTANCE(JOB_INSTANCE_ID) ON DELETE CASCADE ) ; CREATE TABLE BATCH_JOB_EXECUTION_PARAMS ( @@ -30,7 +30,7 @@ CREATE TABLE BATCH_JOB_EXECUTION_PARAMS ( PARAMETER_VALUE VARCHAR(2500) , IDENTIFYING CHAR(1) NOT NULL , constraint JOB_EXEC_PARAMS_FK foreign key (JOB_EXECUTION_ID) - references BATCH_JOB_EXECUTION(JOB_EXECUTION_ID) + references BATCH_JOB_EXECUTION(JOB_EXECUTION_ID) ON DELETE CASCADE ) ; CREATE TABLE BATCH_STEP_EXECUTION ( @@ -54,7 +54,7 @@ CREATE TABLE BATCH_STEP_EXECUTION ( EXIT_MESSAGE VARCHAR(2500) , LAST_UPDATED TIMESTAMP, constraint JOB_EXEC_STEP_FK foreign key (JOB_EXECUTION_ID) - references BATCH_JOB_EXECUTION(JOB_EXECUTION_ID) + references BATCH_JOB_EXECUTION(JOB_EXECUTION_ID) ON DELETE CASCADE ) ; CREATE TABLE BATCH_STEP_EXECUTION_CONTEXT ( @@ -62,7 +62,7 @@ CREATE TABLE BATCH_STEP_EXECUTION_CONTEXT ( SHORT_CONTEXT VARCHAR(2500) NOT NULL, SERIALIZED_CONTEXT TEXT , constraint STEP_EXEC_CTX_FK foreign key (STEP_EXECUTION_ID) - references BATCH_STEP_EXECUTION(STEP_EXECUTION_ID) + references BATCH_STEP_EXECUTION(STEP_EXECUTION_ID) ON DELETE CASCADE ) ; CREATE TABLE BATCH_JOB_EXECUTION_CONTEXT ( @@ -70,7 +70,7 @@ CREATE TABLE BATCH_JOB_EXECUTION_CONTEXT ( SHORT_CONTEXT VARCHAR(2500) NOT NULL, SERIALIZED_CONTEXT TEXT , constraint JOB_EXEC_CTX_FK foreign key (JOB_EXECUTION_ID) - references BATCH_JOB_EXECUTION(JOB_EXECUTION_ID) + references BATCH_JOB_EXECUTION(JOB_EXECUTION_ID) ON DELETE CASCADE ) ; CREATE SEQUENCE BATCH_STEP_EXECUTION_SEQ MAXVALUE 9223372036854775807 NO CYCLE; diff --git a/spring-batch-core/src/main/resources/org/springframework/batch/core/schema-sqlite.sql b/spring-batch-core/src/main/resources/org/springframework/batch/core/schema-sqlite.sql index 5a39c09e2a..d3594a0014 100644 --- a/spring-batch-core/src/main/resources/org/springframework/batch/core/schema-sqlite.sql +++ b/spring-batch-core/src/main/resources/org/springframework/batch/core/schema-sqlite.sql @@ -20,7 +20,7 @@ CREATE TABLE BATCH_JOB_EXECUTION ( EXIT_MESSAGE VARCHAR(2500) , LAST_UPDATED TIMESTAMP, constraint JOB_INST_EXEC_FK foreign key (JOB_INSTANCE_ID) - references BATCH_JOB_INSTANCE(JOB_INSTANCE_ID) + references BATCH_JOB_INSTANCE(JOB_INSTANCE_ID) ON DELETE CASCADE ) ; CREATE TABLE BATCH_JOB_EXECUTION_PARAMS ( @@ -30,7 +30,7 @@ CREATE TABLE BATCH_JOB_EXECUTION_PARAMS ( PARAMETER_VALUE VARCHAR(2500) , IDENTIFYING CHAR(1) NOT NULL , constraint JOB_EXEC_PARAMS_FK foreign key (JOB_EXECUTION_ID) - references BATCH_JOB_EXECUTION(JOB_EXECUTION_ID) + references BATCH_JOB_EXECUTION(JOB_EXECUTION_ID) ON DELETE CASCADE ) ; CREATE TABLE BATCH_STEP_EXECUTION ( @@ -54,7 +54,7 @@ CREATE TABLE BATCH_STEP_EXECUTION ( EXIT_MESSAGE VARCHAR(2500) , LAST_UPDATED TIMESTAMP, constraint JOB_EXEC_STEP_FK foreign key (JOB_EXECUTION_ID) - references BATCH_JOB_EXECUTION(JOB_EXECUTION_ID) + references BATCH_JOB_EXECUTION(JOB_EXECUTION_ID) ON DELETE CASCADE ) ; CREATE TABLE BATCH_STEP_EXECUTION_CONTEXT ( @@ -62,7 +62,7 @@ CREATE TABLE BATCH_STEP_EXECUTION_CONTEXT ( SHORT_CONTEXT VARCHAR(2500) NOT NULL, SERIALIZED_CONTEXT CLOB , constraint STEP_EXEC_CTX_FK foreign key (STEP_EXECUTION_ID) - references BATCH_STEP_EXECUTION(STEP_EXECUTION_ID) + references BATCH_STEP_EXECUTION(STEP_EXECUTION_ID) ON DELETE CASCADE ) ; CREATE TABLE BATCH_JOB_EXECUTION_CONTEXT ( @@ -70,7 +70,7 @@ CREATE TABLE BATCH_JOB_EXECUTION_CONTEXT ( SHORT_CONTEXT VARCHAR(2500) NOT NULL, SERIALIZED_CONTEXT CLOB , constraint JOB_EXEC_CTX_FK foreign key (JOB_EXECUTION_ID) - references BATCH_JOB_EXECUTION(JOB_EXECUTION_ID) + references BATCH_JOB_EXECUTION(JOB_EXECUTION_ID) ON DELETE CASCADE ) ; CREATE TABLE BATCH_STEP_EXECUTION_SEQ ( diff --git a/spring-batch-core/src/main/resources/org/springframework/batch/core/schema-sqlserver.sql b/spring-batch-core/src/main/resources/org/springframework/batch/core/schema-sqlserver.sql index 70c89664c0..5b9c4f4dc7 100644 --- a/spring-batch-core/src/main/resources/org/springframework/batch/core/schema-sqlserver.sql +++ b/spring-batch-core/src/main/resources/org/springframework/batch/core/schema-sqlserver.sql @@ -20,7 +20,7 @@ CREATE TABLE BATCH_JOB_EXECUTION ( EXIT_MESSAGE VARCHAR(2500) NULL, LAST_UPDATED DATETIME NULL, constraint JOB_INST_EXEC_FK foreign key (JOB_INSTANCE_ID) - references BATCH_JOB_INSTANCE(JOB_INSTANCE_ID) + references BATCH_JOB_INSTANCE(JOB_INSTANCE_ID) ON DELETE CASCADE ) ; CREATE TABLE BATCH_JOB_EXECUTION_PARAMS ( @@ -30,7 +30,7 @@ CREATE TABLE BATCH_JOB_EXECUTION_PARAMS ( PARAMETER_VALUE VARCHAR(2500) , IDENTIFYING CHAR(1) NOT NULL , constraint JOB_EXEC_PARAMS_FK foreign key (JOB_EXECUTION_ID) - references BATCH_JOB_EXECUTION(JOB_EXECUTION_ID) + references BATCH_JOB_EXECUTION(JOB_EXECUTION_ID) ON DELETE CASCADE ) ; CREATE TABLE BATCH_STEP_EXECUTION ( @@ -54,7 +54,7 @@ CREATE TABLE BATCH_STEP_EXECUTION ( EXIT_MESSAGE VARCHAR(2500) NULL, LAST_UPDATED DATETIME NULL, constraint JOB_EXEC_STEP_FK foreign key (JOB_EXECUTION_ID) - references BATCH_JOB_EXECUTION(JOB_EXECUTION_ID) + references BATCH_JOB_EXECUTION(JOB_EXECUTION_ID) ON DELETE CASCADE ) ; CREATE TABLE BATCH_STEP_EXECUTION_CONTEXT ( @@ -62,7 +62,7 @@ CREATE TABLE BATCH_STEP_EXECUTION_CONTEXT ( SHORT_CONTEXT VARCHAR(2500) NOT NULL, SERIALIZED_CONTEXT VARCHAR(MAX) NULL, constraint STEP_EXEC_CTX_FK foreign key (STEP_EXECUTION_ID) - references BATCH_STEP_EXECUTION(STEP_EXECUTION_ID) + references BATCH_STEP_EXECUTION(STEP_EXECUTION_ID) ON DELETE CASCADE ) ; CREATE TABLE BATCH_JOB_EXECUTION_CONTEXT ( @@ -70,7 +70,7 @@ CREATE TABLE BATCH_JOB_EXECUTION_CONTEXT ( SHORT_CONTEXT VARCHAR(2500) NOT NULL, SERIALIZED_CONTEXT VARCHAR(MAX) NULL, constraint JOB_EXEC_CTX_FK foreign key (JOB_EXECUTION_ID) - references BATCH_JOB_EXECUTION(JOB_EXECUTION_ID) + references BATCH_JOB_EXECUTION(JOB_EXECUTION_ID) ON DELETE CASCADE ) ; CREATE SEQUENCE BATCH_STEP_EXECUTION_SEQ START WITH 0 MINVALUE 0 MAXVALUE 9223372036854775807 NO CACHE NO CYCLE; diff --git a/spring-batch-core/src/main/resources/org/springframework/batch/core/schema-sybase.sql b/spring-batch-core/src/main/resources/org/springframework/batch/core/schema-sybase.sql index 15b221970e..b54639e939 100644 --- a/spring-batch-core/src/main/resources/org/springframework/batch/core/schema-sybase.sql +++ b/spring-batch-core/src/main/resources/org/springframework/batch/core/schema-sybase.sql @@ -18,9 +18,7 @@ CREATE TABLE BATCH_JOB_EXECUTION ( STATUS VARCHAR(10) NULL, EXIT_CODE VARCHAR(2500) NULL, EXIT_MESSAGE VARCHAR(2500) NULL, - LAST_UPDATED DATETIME, - constraint JOB_INST_EXEC_FK foreign key (JOB_INSTANCE_ID) - references BATCH_JOB_INSTANCE(JOB_INSTANCE_ID) + LAST_UPDATED DATETIME ) ; CREATE TABLE BATCH_JOB_EXECUTION_PARAMS ( @@ -28,9 +26,7 @@ CREATE TABLE BATCH_JOB_EXECUTION_PARAMS ( PARAMETER_NAME VARCHAR(100) NOT NULL , PARAMETER_TYPE VARCHAR(100) NOT NULL , PARAMETER_VALUE VARCHAR(2500) , - IDENTIFYING CHAR(1) NOT NULL , - constraint JOB_EXEC_PARAMS_FK foreign key (JOB_EXECUTION_ID) - references BATCH_JOB_EXECUTION(JOB_EXECUTION_ID) + IDENTIFYING CHAR(1) NOT NULL ) ; CREATE TABLE BATCH_STEP_EXECUTION ( @@ -52,27 +48,61 @@ CREATE TABLE BATCH_STEP_EXECUTION ( ROLLBACK_COUNT BIGINT NULL, EXIT_CODE VARCHAR(2500) NULL, EXIT_MESSAGE VARCHAR(2500) NULL, - LAST_UPDATED DATETIME, - constraint JOB_EXEC_STEP_FK foreign key (JOB_EXECUTION_ID) - references BATCH_JOB_EXECUTION(JOB_EXECUTION_ID) + LAST_UPDATED DATETIME ) ; CREATE TABLE BATCH_STEP_EXECUTION_CONTEXT ( STEP_EXECUTION_ID BIGINT NOT NULL PRIMARY KEY, SHORT_CONTEXT VARCHAR(2500) NOT NULL, - SERIALIZED_CONTEXT TEXT NULL, - constraint STEP_EXEC_CTX_FK foreign key (STEP_EXECUTION_ID) - references BATCH_STEP_EXECUTION(STEP_EXECUTION_ID) + SERIALIZED_CONTEXT TEXT NULL ) ; CREATE TABLE BATCH_JOB_EXECUTION_CONTEXT ( JOB_EXECUTION_ID BIGINT NOT NULL PRIMARY KEY, SHORT_CONTEXT VARCHAR(2500) NOT NULL, - SERIALIZED_CONTEXT TEXT NULL, - constraint JOB_EXEC_CTX_FK foreign key (JOB_EXECUTION_ID) - references BATCH_JOB_EXECUTION(JOB_EXECUTION_ID) + SERIALIZED_CONTEXT TEXT NULL ) ; CREATE TABLE BATCH_STEP_EXECUTION_SEQ (ID BIGINT IDENTITY); CREATE TABLE BATCH_JOB_EXECUTION_SEQ (ID BIGINT IDENTITY); CREATE TABLE BATCH_JOB_SEQ (ID BIGINT IDENTITY); + +CREATE TRIGGER BATCH_JOB_INSTANCE_DELETE_TRIGGER + ON BATCH_JOB_INSTANCE + FOR DELETE + AS + DELETE BATCH_JOB_EXECUTION + FROM BATCH_JOB_EXECUTION, deleted + WHERE BATCH_JOB_EXECUTION.JOB_INSTANCE_ID = deleted.JOB_INSTANCE_ID; + +CREATE TRIGGER BATCH_JOB_EXECUTION_DELETE_TRIGGER_DELETE_JOB_EXECUTION_CONTEXT + ON BATCH_JOB_EXECUTION + FOR DELETE + AS + DELETE BATCH_JOB_EXECUTION_CONTEXT + FROM BATCH_JOB_EXECUTION_CONTEXT, deleted + WHERE BATCH_JOB_EXECUTION_CONTEXT.JOB_EXECUTION_ID = deleted.JOB_INSTANCE_ID; + +CREATE TRIGGER BATCH_JOB_EXECUTION_DELETE_TRIGGER_DELETE_JOB_EXECUTION_PARAMS + ON BATCH_JOB_EXECUTION + FOR DELETE + AS + DELETE BATCH_JOB_EXECUTION_PARAMS + FROM BATCH_JOB_EXECUTION_PARAMS, deleted + WHERE BATCH_JOB_EXECUTION_PARAMS.JOB_EXECUTION_ID = deleted.JOB_EXECUTION_ID; + +CREATE TRIGGER BATCH_JOB_EXECUTION_DELETE_TRIGGER_DELETE_STEP_EXECUTION + ON BATCH_JOB_EXECUTION + FOR DELETE + AS + DELETE BATCH_STEP_EXECUTION + FROM BATCH_STEP_EXECUTION, deleted + WHERE BATCH_STEP_EXECUTION.JOB_EXECUTION_ID = deleted.JOB_EXECUTION_ID; + +CREATE TRIGGER BATCH_JOB_EXECUTION_DELETE_TRIGGER_DELETE_STEP_EXECUTION_CONTEXT + ON BATCH_STEP_EXECUTION + FOR DELETE + AS + DELETE BATCH_STEP_EXECUTION_CONTEXT + FROM BATCH_STEP_EXECUTION_CONTEXT, deleted + WHERE BATCH_STEP_EXECUTION_CONTEXT.STEP_EXECUTION_ID = deleted.STEP_EXECUTION_ID; diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/repository/support/SimpleJobRepositoryTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/repository/support/SimpleJobRepositoryTests.java index 5b903d0f14..bd4e2935d1 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/repository/support/SimpleJobRepositoryTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/repository/support/SimpleJobRepositoryTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2023 the original author or authors. + * Copyright 2006-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -61,6 +61,7 @@ * @author Baris Cubukcuoglu * @author Mahmoud Ben Hassine * @author Parikshit Dutta + * @author UHyeon Jeong * */ class SimpleJobRepositoryTests { @@ -348,39 +349,24 @@ public void testGetJobInstanceWithNameAndParameters() { @Test void testDeleteJobExecution() { // given - StepExecution stepExecution1 = mock(); - StepExecution stepExecution2 = mock(); JobExecution jobExecution = mock(); - when(jobExecution.getStepExecutions()).thenReturn(Arrays.asList(stepExecution1, stepExecution2)); // when this.jobRepository.deleteJobExecution(jobExecution); // then - verify(this.ecDao).deleteExecutionContext(jobExecution); - verify(this.jobExecutionDao).deleteJobExecutionParameters(jobExecution); - verify(this.ecDao).deleteExecutionContext(stepExecution1); - verify(this.stepExecutionDao).deleteStepExecution(stepExecution1); - verify(this.ecDao).deleteExecutionContext(stepExecution2); - verify(this.stepExecutionDao).deleteStepExecution(stepExecution2); verify(this.jobExecutionDao).deleteJobExecution(jobExecution); } @Test void testDeleteJobInstance() { // given - JobExecution jobExecution1 = mock(); - JobExecution jobExecution2 = mock(); JobInstance jobInstance = mock(); - when(this.jobExecutionDao.findJobExecutions(jobInstance)) - .thenReturn(Arrays.asList(jobExecution1, jobExecution2)); // when this.jobRepository.deleteJobInstance(jobInstance); // then - verify(this.jobExecutionDao).deleteJobExecution(jobExecution1); - verify(this.jobExecutionDao).deleteJobExecution(jobExecution2); verify(this.jobInstanceDao).deleteJobInstance(jobInstance); } diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/test/repository/SybaseJobRepositoryIntegrationTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/test/repository/SybaseJobRepositoryIntegrationTests.java index e8c4076d68..4c4425994f 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/test/repository/SybaseJobRepositoryIntegrationTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/test/repository/SybaseJobRepositoryIntegrationTests.java @@ -72,6 +72,7 @@ class SybaseJobRepositoryIntegrationTests { @BeforeEach void setUp() { ResourceDatabasePopulator databasePopulator = new ResourceDatabasePopulator(); + databasePopulator.addScript(new ClassPathResource("/org/springframework/batch/core/schema-drop-sybase.sql")); databasePopulator.addScript(new ClassPathResource("/org/springframework/batch/core/schema-sybase.sql")); databasePopulator.execute(this.dataSource); } @@ -93,6 +94,8 @@ void testJobExecution() throws Exception { @EnableBatchProcessing static class TestConfiguration { + private static final int SERVERTYPE_SYBASE = 2; + // FIXME Configuration parameters are hard-coded for the moment, to update once // testcontainers support is available @Bean @@ -102,6 +105,7 @@ public DataSource dataSource() throws Exception { dataSource.setPassword("sa"); dataSource.setServerName("172.17.0.2"); dataSource.setPortNumber(5000); + dataSource.setServerType(SERVERTYPE_SYBASE); dataSource.setDatabaseName("test"); return dataSource; } diff --git a/spring-batch-test/src/main/java/org/springframework/batch/test/JobRepositoryTestUtils.java b/spring-batch-test/src/main/java/org/springframework/batch/test/JobRepositoryTestUtils.java index d6a7b07327..7cdaa21eb8 100644 --- a/spring-batch-test/src/main/java/org/springframework/batch/test/JobRepositoryTestUtils.java +++ b/spring-batch-test/src/main/java/org/springframework/batch/test/JobRepositoryTestUtils.java @@ -135,8 +135,17 @@ public void removeJobExecutions(Collection jobExecutions) { for (JobExecution jobExecution : jobExecutions) { removeJobExecution(jobExecution); } - for (JobExecution jobExecution : jobExecutions) { - this.jobRepository.deleteJobInstance(jobExecution.getJobInstance()); + } + + /** + * Remove the {@link JobInstance} instances, and all associated {@link JobExecution} + * and {@link StepExecution} instances from the standard locations used by Spring + * Batch. + * @param jobInstances a collection of {@link JobInstance} + */ + public void removeJobInstances(Collection jobInstances) { + for (JobInstance jobInstance : jobInstances) { + this.jobRepository.deleteJobInstance(jobInstance); } } @@ -150,23 +159,18 @@ public void removeJobExecution(JobExecution jobExecution) { } /** - * Remove all the {@link JobExecution} instances, and all associated - * {@link JobInstance} and {@link StepExecution} instances from the standard locations + * Remove all the {@link JobInstance} instances, and all associated + * {@link JobExecution} and {@link StepExecution} instances from the standard locations * used by Spring Batch. */ - public void removeJobExecutions() { + public void removeJobInstances() { List jobNames = this.jobRepository.getJobNames(); for (String jobName : jobNames) { int start = 0; int count = 100; List jobInstances = this.jobRepository.findJobInstancesByName(jobName, start, count); while (!jobInstances.isEmpty()) { - for (JobInstance jobInstance : jobInstances) { - List jobExecutions = this.jobRepository.findJobExecutions(jobInstance); - if (jobExecutions != null && !jobExecutions.isEmpty()) { - removeJobExecutions(jobExecutions); - } - } + removeJobInstances(jobInstances); start += count; jobInstances = this.jobRepository.findJobInstancesByName(jobName, start, count); } diff --git a/spring-batch-test/src/test/java/org/springframework/batch/test/JobRepositoryTestUtilsTests.java b/spring-batch-test/src/test/java/org/springframework/batch/test/JobRepositoryTestUtilsTests.java index 3887f71ec1..5aed6e8725 100644 --- a/spring-batch-test/src/test/java/org/springframework/batch/test/JobRepositoryTestUtilsTests.java +++ b/spring-batch-test/src/test/java/org/springframework/batch/test/JobRepositoryTestUtilsTests.java @@ -72,7 +72,7 @@ void testCreateJobExecutions() throws Exception { assertEquals(3, list.size()); assertEquals(beforeJobs + 3, JdbcTestUtils.countRowsInTable(jdbcTemplate, "BATCH_JOB_EXECUTION")); assertEquals(beforeSteps + 3, JdbcTestUtils.countRowsInTable(jdbcTemplate, "BATCH_STEP_EXECUTION")); - utils.removeJobExecutions(list); + utils.removeJobInstances(list.stream().map(JobExecution::getJobInstance).toList()); assertEquals(beforeJobs, JdbcTestUtils.countRowsInTable(jdbcTemplate, "BATCH_JOB_EXECUTION")); assertEquals(beforeSteps, JdbcTestUtils.countRowsInTable(jdbcTemplate, "BATCH_STEP_EXECUTION")); } @@ -89,7 +89,7 @@ void testRemoveJobExecutionsWithSameJobInstance() throws Exception { jobExecution = jobRepository.createJobExecution("job", new JobParameters()); list.add(jobExecution); assertEquals(beforeJobs + 2, JdbcTestUtils.countRowsInTable(jdbcTemplate, "BATCH_JOB_EXECUTION")); - utils.removeJobExecutions(list); + utils.removeJobInstances(list.stream().map(JobExecution::getJobInstance).toList()); assertEquals(beforeJobs, JdbcTestUtils.countRowsInTable(jdbcTemplate, "BATCH_JOB_EXECUTION")); } @@ -100,7 +100,7 @@ void testCreateJobExecutionsByName() throws Exception { assertEquals(3, list.size()); assertEquals(beforeJobs + 3, JdbcTestUtils.countRowsInTable(jdbcTemplate, "BATCH_JOB_EXECUTION")); assertEquals(beforeSteps + 6, JdbcTestUtils.countRowsInTable(jdbcTemplate, "BATCH_STEP_EXECUTION")); - utils.removeJobExecutions(list); + utils.removeJobInstances(list.stream().map(JobExecution::getJobInstance).toList()); assertEquals(beforeJobs, JdbcTestUtils.countRowsInTable(jdbcTemplate, "BATCH_JOB_EXECUTION")); assertEquals(beforeSteps, JdbcTestUtils.countRowsInTable(jdbcTemplate, "BATCH_STEP_EXECUTION")); } @@ -111,9 +111,9 @@ void testRemoveJobExecutionsIncrementally() throws Exception { List list1 = utils.createJobExecutions(3); List list2 = utils.createJobExecutions(2); assertEquals(beforeJobs + 5, JdbcTestUtils.countRowsInTable(jdbcTemplate, "BATCH_JOB_EXECUTION")); - utils.removeJobExecutions(list2); + utils.removeJobInstances(list2.stream().map(JobExecution::getJobInstance).toList()); assertEquals(beforeJobs + 3, JdbcTestUtils.countRowsInTable(jdbcTemplate, "BATCH_JOB_EXECUTION")); - utils.removeJobExecutions(list1); + utils.removeJobInstances(list1.stream().map(JobExecution::getJobInstance).toList()); assertEquals(beforeJobs, JdbcTestUtils.countRowsInTable(jdbcTemplate, "BATCH_JOB_EXECUTION")); } @@ -125,7 +125,7 @@ void testCreateJobExecutionsWithIncrementer() throws Exception { List list = utils.createJobExecutions(1); assertEquals(1, list.size()); assertEquals("bar", list.get(0).getJobParameters().getString("foo")); - utils.removeJobExecutions(list); + utils.removeJobInstances(list.stream().map(JobExecution::getJobInstance).toList()); assertEquals(beforeJobs, JdbcTestUtils.countRowsInTable(jdbcTemplate, "BATCH_JOB_EXECUTION")); } @@ -138,7 +138,7 @@ void testRemoveJobExecutions() throws Exception { assertEquals(2, JdbcTestUtils.countRowsInTable(jdbcTemplate, "BATCH_STEP_EXECUTION")); // when - utils.removeJobExecutions(); + utils.removeJobInstances(); // then assertEquals(0, JdbcTestUtils.countRowsInTable(jdbcTemplate, "BATCH_STEP_EXECUTION")); diff --git a/spring-batch-test/src/test/java/org/springframework/batch/test/SpringBatchTestJUnit4Tests.java b/spring-batch-test/src/test/java/org/springframework/batch/test/SpringBatchTestJUnit4Tests.java index dbe3f22da7..fcb87fe891 100644 --- a/spring-batch-test/src/test/java/org/springframework/batch/test/SpringBatchTestJUnit4Tests.java +++ b/spring-batch-test/src/test/java/org/springframework/batch/test/SpringBatchTestJUnit4Tests.java @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 the original author or authors. + * Copyright 2018-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -51,6 +51,7 @@ * Test cases for usage of {@link SpringBatchTest} annotation with JUnit 4. * * @author Mahmoud Ben Hassine + * @author UHyeon Jeong */ @RunWith(SpringRunner.class) @SpringBatchTest @@ -98,7 +99,7 @@ public void testJobScopedItemReader() throws Exception { @Test public void testJob() throws Exception { // when - this.jobRepositoryTestUtils.removeJobExecutions(); + this.jobRepositoryTestUtils.removeJobInstances(); JobExecution jobExecution = this.jobLauncherTestUtils.launchJob(); // then diff --git a/spring-batch-test/src/test/java/org/springframework/batch/test/SpringBatchTestJUnit5Tests.java b/spring-batch-test/src/test/java/org/springframework/batch/test/SpringBatchTestJUnit5Tests.java index 924779cc11..7ae56dd84c 100644 --- a/spring-batch-test/src/test/java/org/springframework/batch/test/SpringBatchTestJUnit5Tests.java +++ b/spring-batch-test/src/test/java/org/springframework/batch/test/SpringBatchTestJUnit5Tests.java @@ -1,5 +1,5 @@ /* - * Copyright 2020-2022 the original author or authors. + * Copyright 2020-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -52,6 +52,7 @@ * Test cases for usage of {@link SpringBatchTest} annotation with JUnit 5. * * @author Mahmoud Ben Hassine + * @author UHyeon Jeong */ @SpringBatchTest @SpringJUnitConfig @@ -86,7 +87,7 @@ void testJobScopedItemReader() throws Exception { @Test void testJob() throws Exception { // given - this.jobRepositoryTestUtils.removeJobExecutions(); + this.jobRepositoryTestUtils.removeJobInstances(); JobParameters jobParameters = this.jobLauncherTestUtils.getUniqueJobParameters(); // when