From b8238908df32d4f062204f5f1b07ddb2ea082739 Mon Sep 17 00:00:00 2001 From: Michael Minella Date: Fri, 17 Oct 2014 10:53:26 -0500 Subject: [PATCH] Updated sequence initalization insert to be idempotent BATCH-2159 provides a tweak to the insert statement used for initializing the sequence tables used in the job repository database so that they don't error if run multiple times as well as don't insert multiple rows. --- .../org/springframework/batch/core/schema-mysql.sql | 6 +++--- spring-batch-core/src/main/sql/mysql.vpp | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) 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 da8a22352..0d7cea879 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 @@ -82,7 +82,7 @@ CREATE TABLE BATCH_STEP_EXECUTION_SEQ ( constraint UNIQUE_KEY_UN unique (UNIQUE_KEY) ) ENGINE=MYISAM; -INSERT INTO BATCH_STEP_EXECUTION_SEQ values(0, '0'); +INSERT INTO BATCH_STEP_EXECUTION_SEQ (ID, UNIQUE_KEY) select * from (select 0 as ID, '0' as UNIQUE_KEY) as tmp where not exists(select * from BATCH_STEP_EXECUTION_SEQ); CREATE TABLE BATCH_JOB_EXECUTION_SEQ ( ID BIGINT NOT NULL, @@ -90,7 +90,7 @@ CREATE TABLE BATCH_JOB_EXECUTION_SEQ ( constraint UNIQUE_KEY_UN unique (UNIQUE_KEY) ) ENGINE=MYISAM; -INSERT INTO BATCH_JOB_EXECUTION_SEQ values(0, '0'); +INSERT INTO BATCH_JOB_EXECUTION_SEQ (ID, UNIQUE_KEY) select * from (select 0 as ID, '0' as UNIQUE_KEY) as tmp where not exists(select * from BATCH_JOB_EXECUTION_SEQ); CREATE TABLE BATCH_JOB_SEQ ( ID BIGINT NOT NULL, @@ -98,4 +98,4 @@ CREATE TABLE BATCH_JOB_SEQ ( constraint UNIQUE_KEY_UN unique (UNIQUE_KEY) ) ENGINE=MYISAM; -INSERT INTO BATCH_JOB_SEQ values(0, '0'); +INSERT INTO BATCH_JOB_SEQ (ID, UNIQUE_KEY) select * from (select 0 as ID, '0' as UNIQUE_KEY) as tmp where not exists(select * from BATCH_JOB_SEQ); diff --git a/spring-batch-core/src/main/sql/mysql.vpp b/spring-batch-core/src/main/sql/mysql.vpp index d49adb54b..084565f76 100644 --- a/spring-batch-core/src/main/sql/mysql.vpp +++ b/spring-batch-core/src/main/sql/mysql.vpp @@ -1,6 +1,6 @@ #macro (sequence $name $value)CREATE TABLE ${name} (ID BIGINT NOT NULL, UNIQUE_KEY CHAR(1) NOT NULL, constraint ${name}_UN unique (UNIQUE_KEY)) ENGINE=MYISAM; -INSERT INTO ${name} values(0, '0'); +INSERT INTO ${name} (ID, UNIQUE_KEY) select * from (select 0 as ID, '0' as UNIQUE_KEY) as tmp where not exists(select * from ${name}); #end #macro (notnull $name $type)MODIFY COLUMN ${name} ${type} NOT NULL#end