diff --git a/docs/src/main/asciidoc/appendix-task-repository-schema.adoc b/docs/src/main/asciidoc/appendix-task-repository-schema.adoc index 6122f3be..2ef3de76 100644 --- a/docs/src/main/asciidoc/appendix-task-repository-schema.adoc +++ b/docs/src/main/asciidoc/appendix-task-repository-schema.adoc @@ -83,3 +83,16 @@ Used for the `single-instance-enabled` feature discussed < orderMap; - - private DataFieldMaxValueIncrementer taskIncrementer; - private static final Set validSortColumns = new HashSet<>(10); static { @@ -178,6 +167,12 @@ public class JdbcTaskExecutionDao implements TaskExecutionDao { validSortColumns.add("PARENT_EXECUTION_ID"); } + private final NamedParameterJdbcTemplate jdbcTemplate; + private String tablePrefix = TaskProperties.DEFAULT_TABLE_PREFIX; + private DataSource dataSource; + private LinkedHashMap orderMap; + private DataFieldMaxValueIncrementer taskIncrementer; + /** * Initializes the JdbcTaskExecutionDao. * @param dataSource used by the dao to execute queries and update the tables. @@ -530,10 +525,11 @@ public class JdbcTaskExecutionDao implements TaskExecutionDao { for (Sort.Order sortOrder : sort) { if (validSortColumns.contains(sortOrder.getProperty().toUpperCase())) { sortOrderMap.put(sortOrder.getProperty(), - sortOrder.isAscending() ? Order.ASCENDING : Order.DESCENDING); + sortOrder.isAscending() ? Order.ASCENDING : Order.DESCENDING); } else { - throw new IllegalArgumentException(String.format("Invalid sort option selected: %s", sortOrder.getProperty())); + throw new IllegalArgumentException( + String.format("Invalid sort option selected: %s", sortOrder.getProperty())); } } } @@ -576,8 +572,8 @@ public class JdbcTaskExecutionDao implements TaskExecutionDao { } /** - * Convenience method that inserts an individual records into the - * TASK_EXECUTION_PARAMS table. + * Convenience method that inserts an individual records into the TASK_EXECUTION_PARAMS + * table. * @param taskExecutionId id of a task execution * @param taskParam task parameters */ diff --git a/spring-cloud-task-core/src/main/java/org/springframework/cloud/task/repository/support/SqlServerSequenceMaxValueIncrementer.java b/spring-cloud-task-core/src/main/java/org/springframework/cloud/task/repository/support/SqlServerSequenceMaxValueIncrementer.java new file mode 100644 index 00000000..e876d1c1 --- /dev/null +++ b/spring-cloud-task-core/src/main/java/org/springframework/cloud/task/repository/support/SqlServerSequenceMaxValueIncrementer.java @@ -0,0 +1,37 @@ +/* + * Copyright 2021-2021 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. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.task.repository.support; + +import javax.sql.DataSource; + +import org.springframework.jdbc.support.incrementer.AbstractSequenceMaxValueIncrementer; + +/** + * Incrementer using SQL Server's sequence. + * @author Glenn Renfro + * @since 2.3.2 + */ +public class SqlServerSequenceMaxValueIncrementer extends AbstractSequenceMaxValueIncrementer { + + SqlServerSequenceMaxValueIncrementer(DataSource dataSource, String incrementerName) { + super(dataSource, incrementerName); + } + @Override + protected String getSequenceQuery() { + return "select next value for " + getIncrementerName(); + } +} diff --git a/spring-cloud-task-core/src/main/java/org/springframework/cloud/task/repository/support/TaskExecutionDaoFactoryBean.java b/spring-cloud-task-core/src/main/java/org/springframework/cloud/task/repository/support/TaskExecutionDaoFactoryBean.java index 7c870c0b..dc96860e 100644 --- a/spring-cloud-task-core/src/main/java/org/springframework/cloud/task/repository/support/TaskExecutionDaoFactoryBean.java +++ b/spring-cloud-task-core/src/main/java/org/springframework/cloud/task/repository/support/TaskExecutionDaoFactoryBean.java @@ -1,5 +1,5 @@ /* - * Copyright 2015-2019 the original author or authors. + * Copyright 2015-2021 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. @@ -16,17 +16,24 @@ package org.springframework.cloud.task.repository.support; +import java.sql.DatabaseMetaData; +import java.sql.ResultSet; +import java.sql.SQLException; + import javax.sql.DataSource; import org.springframework.batch.item.database.support.DataFieldMaxValueIncrementerFactory; import org.springframework.batch.item.database.support.DefaultDataFieldMaxValueIncrementerFactory; import org.springframework.beans.factory.FactoryBean; import org.springframework.cloud.task.configuration.TaskProperties; +import org.springframework.cloud.task.listener.TaskException; import org.springframework.cloud.task.repository.dao.JdbcTaskExecutionDao; import org.springframework.cloud.task.repository.dao.MapTaskExecutionDao; import org.springframework.cloud.task.repository.dao.TaskExecutionDao; import org.springframework.jdbc.support.MetaDataAccessException; +import org.springframework.jdbc.support.incrementer.DataFieldMaxValueIncrementer; import org.springframework.util.Assert; +import org.springframework.util.StringUtils; /** * A {@link FactoryBean} implementation that creates the appropriate @@ -81,7 +88,26 @@ public class TaskExecutionDaoFactoryBean implements FactoryBean