Adds DB2 support
Provides the files and enum constants for Spring Cloud Task to work with a DB2 database.
This commit is contained in:
committed by
Thomas Risberg
parent
8e8a5c927a
commit
c61a6e9c35
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Copyright 2016 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
|
||||
*
|
||||
* http://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.database.support;
|
||||
|
||||
import org.springframework.data.domain.Pageable;
|
||||
|
||||
/**
|
||||
* IBM DB2 implementation of a {@link org.springframework.cloud.task.repository.database.PagingQueryProvider} using database
|
||||
* specific features.
|
||||
*
|
||||
* @author Thomas Schuettel
|
||||
*/
|
||||
public class Db2PagingQueryProvider extends AbstractSqlPagingQueryProvider {
|
||||
|
||||
@Override
|
||||
public String getPageQuery(Pageable pageable) {
|
||||
int offset = pageable.getOffset() + 1;
|
||||
return generateRowNumSqlQueryWithNesting(getSelectClause(), false,
|
||||
"TMP_ROW_NUM BETWEEN " + offset + " AND " + (offset + pageable.getPageSize()));
|
||||
}
|
||||
|
||||
private String generateRowNumSqlQueryWithNesting(String selectClause, boolean remainingPageQuery,
|
||||
String rowNumClause) {
|
||||
StringBuilder sql = new StringBuilder();
|
||||
sql.append("SELECT ").append(selectClause).append(" FROM (SELECT ").append(selectClause).append(", ")
|
||||
.append("ROW_NUMBER() OVER() as TMP_ROW_NUM");
|
||||
sql.append(" FROM (SELECT ").append(selectClause).append(" FROM ").append(this.getFromClause());
|
||||
SqlPagingQueryUtils.buildWhereClause(this, remainingPageQuery, sql);
|
||||
sql.append(" ORDER BY ").append(SqlPagingQueryUtils.buildSortClause(this));
|
||||
sql.append(")) WHERE ").append(rowNumClause);
|
||||
|
||||
return sql.toString();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
package org.springframework.cloud.task.repository.database.support;
|
||||
|
||||
|
||||
import static org.springframework.cloud.task.repository.support.DatabaseType.DB2;
|
||||
import static org.springframework.cloud.task.repository.support.DatabaseType.HSQL;
|
||||
import static org.springframework.cloud.task.repository.support.DatabaseType.H2;
|
||||
import static org.springframework.cloud.task.repository.support.DatabaseType.MYSQL;
|
||||
@@ -68,6 +68,7 @@ public class SqlPagingQueryProviderFactoryBean implements FactoryBean<PagingQuer
|
||||
providers.put(POSTGRES, new PostgresPagingQueryProvider());
|
||||
providers.put(ORACLE, new OraclePagingQueryProvider());
|
||||
providers.put(SQLSERVER, new SqlServerPagingQueryProvider());
|
||||
providers.put(DB2, new Db2PagingQueryProvider());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -40,7 +40,8 @@ public enum DatabaseType {
|
||||
ORACLE("Oracle"),
|
||||
MYSQL("MySQL"),
|
||||
POSTGRES("PostgreSQL"),
|
||||
SQLSERVER("Microsoft SQL Server");
|
||||
SQLSERVER("Microsoft SQL Server"),
|
||||
DB2("DB2");
|
||||
|
||||
private static final Map<String, DatabaseType> dbNameMap;
|
||||
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
|
||||
CREATE TABLE TASK_EXECUTION (
|
||||
TASK_EXECUTION_ID BIGINT NOT NULL PRIMARY KEY ,
|
||||
START_TIME TIMESTAMP DEFAULT NULL ,
|
||||
END_TIME TIMESTAMP DEFAULT NULL ,
|
||||
TASK_NAME VARCHAR(100) ,
|
||||
EXIT_CODE INTEGER ,
|
||||
EXIT_MESSAGE VARCHAR(2500) ,
|
||||
LAST_UPDATED TIMESTAMP
|
||||
);
|
||||
|
||||
CREATE TABLE TASK_EXECUTION_PARAMS (
|
||||
TASK_EXECUTION_ID BIGINT NOT NULL ,
|
||||
TASK_PARAM VARCHAR(2500) ,
|
||||
constraint TASK_EXEC_PARAMS_FK foreign key (TASK_EXECUTION_ID)
|
||||
references TASK_EXECUTION(TASK_EXECUTION_ID)
|
||||
) ;
|
||||
|
||||
CREATE TABLE TASK_TASK_BATCH (
|
||||
TASK_EXECUTION_ID BIGINT NOT NULL ,
|
||||
JOB_EXECUTION_ID BIGINT NOT NULL ,
|
||||
constraint TASK_EXEC_BATCH_FK foreign key (TASK_EXECUTION_ID)
|
||||
references TASK_EXECUTION(TASK_EXECUTION_ID)
|
||||
) ;
|
||||
|
||||
CREATE SEQUENCE TASK_SEQ AS BIGINT START WITH 0 MINVALUE 0 MAXVALUE 9223372036854775807 NOCACHE NOCYCLE;
|
||||
1
spring-cloud-task-docs/src/main/asciidoc/getting-started.adoc
Normal file → Executable file
1
spring-cloud-task-docs/src/main/asciidoc/getting-started.adoc
Normal file → Executable file
@@ -29,6 +29,7 @@ While you can begin developing a task without a database (the status of the task
|
||||
as part of the task repository's updates), for production environments, you'll want to
|
||||
utilize a supported database. Below is a list of the ones currently supported:
|
||||
|
||||
- DB2
|
||||
- H2
|
||||
- HSQLDB
|
||||
- MySql
|
||||
|
||||
Reference in New Issue
Block a user