From c844479daadc4f51cb19044ff8e764e9d9fada07 Mon Sep 17 00:00:00 2001 From: Michael Minella Date: Fri, 27 Jan 2017 14:37:46 -0600 Subject: [PATCH] Configured the MySQLMaxValueIncrementer to use a new connection --- build.gradle | 2 +- ...ltDataFieldMaxValueIncrementerFactory.java | 33 +++++++++++-------- 2 files changed, 20 insertions(+), 15 deletions(-) diff --git a/build.gradle b/build.gradle index 5a273767b..f2d5cf97e 100644 --- a/build.gradle +++ b/build.gradle @@ -48,7 +48,7 @@ allprojects { environmentProperty = project.hasProperty('environment') ? getProperty('environment') : 'hsql' - springVersionDefault = '5.0.0.M4' + springVersionDefault = '5.0.0.BUILD-SNAPSHOT' springVersion = project.hasProperty('springVersion') ? getProperty('springVersion') : springVersionDefault springRetryVersion = '1.1.3.RELEASE' springAmqpVersion = '1.5.6.RELEASE' diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/support/DefaultDataFieldMaxValueIncrementerFactory.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/support/DefaultDataFieldMaxValueIncrementerFactory.java index bf2d7d0bb..6167cb13d 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/support/DefaultDataFieldMaxValueIncrementerFactory.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/support/DefaultDataFieldMaxValueIncrementerFactory.java @@ -15,21 +15,8 @@ */ package org.springframework.batch.item.database.support; -import static org.springframework.batch.support.DatabaseType.DB2; -import static org.springframework.batch.support.DatabaseType.DB2ZOS; -import static org.springframework.batch.support.DatabaseType.DERBY; -import static org.springframework.batch.support.DatabaseType.H2; -import static org.springframework.batch.support.DatabaseType.HSQL; -import static org.springframework.batch.support.DatabaseType.MYSQL; -import static org.springframework.batch.support.DatabaseType.ORACLE; -import static org.springframework.batch.support.DatabaseType.POSTGRES; -import static org.springframework.batch.support.DatabaseType.SQLITE; -import static org.springframework.batch.support.DatabaseType.SQLSERVER; -import static org.springframework.batch.support.DatabaseType.SYBASE; - import java.util.ArrayList; import java.util.List; - import javax.sql.DataSource; import org.springframework.batch.support.DatabaseType; @@ -45,11 +32,27 @@ import org.springframework.jdbc.support.incrementer.PostgreSQLSequenceMaxValueIn import org.springframework.jdbc.support.incrementer.SqlServerMaxValueIncrementer; import org.springframework.jdbc.support.incrementer.SybaseMaxValueIncrementer; +import static org.springframework.batch.support.DatabaseType.DB2; +import static org.springframework.batch.support.DatabaseType.DB2ZOS; +import static org.springframework.batch.support.DatabaseType.DERBY; +import static org.springframework.batch.support.DatabaseType.H2; +import static org.springframework.batch.support.DatabaseType.HSQL; +import static org.springframework.batch.support.DatabaseType.MYSQL; +import static org.springframework.batch.support.DatabaseType.ORACLE; +import static org.springframework.batch.support.DatabaseType.POSTGRES; +import static org.springframework.batch.support.DatabaseType.SQLITE; +import static org.springframework.batch.support.DatabaseType.SQLSERVER; +import static org.springframework.batch.support.DatabaseType.SYBASE; + /** * Default implementation of the {@link DataFieldMaxValueIncrementerFactory} * interface. Valid database types are given by the {@link DatabaseType} enum. + * + * Note: For MySql databases, the + * {@link MySQLMaxValueIncrementer#setUseNewConnection(boolean)} will be set to true. * * @author Lucas Ward + * @author Michael Minella * @see DatabaseType */ public class DefaultDataFieldMaxValueIncrementerFactory implements DataFieldMaxValueIncrementerFactory { @@ -94,7 +97,9 @@ public class DefaultDataFieldMaxValueIncrementerFactory implements DataFieldMaxV return new H2SequenceMaxValueIncrementer(dataSource, incrementerName); } else if (databaseType == MYSQL) { - return new MySQLMaxValueIncrementer(dataSource, incrementerName, incrementerColumnName); + MySQLMaxValueIncrementer mySQLMaxValueIncrementer = new MySQLMaxValueIncrementer(dataSource, incrementerName, incrementerColumnName); + mySQLMaxValueIncrementer.setUseNewConnection(true); + return mySQLMaxValueIncrementer; } else if (databaseType == ORACLE) { return new OracleSequenceMaxValueIncrementer(dataSource, incrementerName);