SCT-59 Add Support for H2 database
resolves spring-cloud/spring-cloud-task#59
This commit is contained in:
@@ -54,8 +54,8 @@
|
|||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.hsqldb</groupId>
|
<groupId>com.h2database</groupId>
|
||||||
<artifactId>hsqldb</artifactId>
|
<artifactId>h2</artifactId>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
|
|||||||
@@ -0,0 +1,37 @@
|
|||||||
|
/*
|
||||||
|
* 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.cloud.task.repository.database.PagingQueryProvider;
|
||||||
|
import org.springframework.data.domain.Pageable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* H2 implementation of a {@link PagingQueryProvider} using database specific features.
|
||||||
|
*
|
||||||
|
* @author Glenn Renfro
|
||||||
|
*/
|
||||||
|
public class H2PagingQueryProvider extends AbstractSqlPagingQueryProvider {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getPageQuery(Pageable pageable) {
|
||||||
|
String topClause = new StringBuilder().append("LIMIT ")
|
||||||
|
.append(pageable.getOffset()).append(" ")
|
||||||
|
.append(pageable.getPageSize()).toString();
|
||||||
|
return SqlPagingQueryUtils.generateTopJumpToQuery(this, topClause);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -18,6 +18,7 @@ package org.springframework.cloud.task.repository.database.support;
|
|||||||
|
|
||||||
|
|
||||||
import static org.springframework.cloud.task.repository.support.DatabaseType.HSQL;
|
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;
|
import static org.springframework.cloud.task.repository.support.DatabaseType.MYSQL;
|
||||||
import static org.springframework.cloud.task.repository.support.DatabaseType.ORACLE;
|
import static org.springframework.cloud.task.repository.support.DatabaseType.ORACLE;
|
||||||
import static org.springframework.cloud.task.repository.support.DatabaseType.POSTGRES;
|
import static org.springframework.cloud.task.repository.support.DatabaseType.POSTGRES;
|
||||||
@@ -61,6 +62,7 @@ public class SqlPagingQueryProviderFactoryBean implements FactoryBean<PagingQuer
|
|||||||
|
|
||||||
{
|
{
|
||||||
providers.put(HSQL, new HsqlPagingQueryProvider());
|
providers.put(HSQL, new HsqlPagingQueryProvider());
|
||||||
|
providers.put(H2, new H2PagingQueryProvider());
|
||||||
providers.put(MYSQL, new MySqlPagingQueryProvider());
|
providers.put(MYSQL, new MySqlPagingQueryProvider());
|
||||||
providers.put(POSTGRES, new PostgresPagingQueryProvider());
|
providers.put(POSTGRES, new PostgresPagingQueryProvider());
|
||||||
providers.put(ORACLE, new OraclePagingQueryProvider());
|
providers.put(ORACLE, new OraclePagingQueryProvider());
|
||||||
|
|||||||
@@ -36,6 +36,7 @@ import org.springframework.util.StringUtils;
|
|||||||
public enum DatabaseType {
|
public enum DatabaseType {
|
||||||
|
|
||||||
HSQL("HSQL Database Engine"),
|
HSQL("HSQL Database Engine"),
|
||||||
|
H2("H2"),
|
||||||
ORACLE("Oracle"),
|
ORACLE("Oracle"),
|
||||||
MYSQL("MySQL"),
|
MYSQL("MySQL"),
|
||||||
POSTGRES("PostgreSQL");
|
POSTGRES("PostgreSQL");
|
||||||
|
|||||||
@@ -0,0 +1,21 @@
|
|||||||
|
|
||||||
|
CREATE TABLE TASK_EXECUTION (
|
||||||
|
TASK_EXECUTION_ID BIGINT NOT NULL PRIMARY KEY ,
|
||||||
|
TASK_EXTERNAL_EXECUTION_ID VARCHAR(100) ,
|
||||||
|
START_TIME TIMESTAMP DEFAULT NULL ,
|
||||||
|
END_TIME TIMESTAMP DEFAULT NULL ,
|
||||||
|
TASK_NAME VARCHAR(100) ,
|
||||||
|
EXIT_CODE INTEGER ,
|
||||||
|
EXIT_MESSAGE VARCHAR(2500) ,
|
||||||
|
LAST_UPDATED TIMESTAMP ,
|
||||||
|
STATUS_CODE VARCHAR(10)
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE TASK_EXECUTION_PARAMS (
|
||||||
|
TASK_EXECUTION_ID BIGINT NOT NULL ,
|
||||||
|
TASK_PARAM VARCHAR(250) ,
|
||||||
|
constraint TASK_EXEC_PARAMS_FK foreign key (TASK_EXECUTION_ID)
|
||||||
|
references TASK_EXECUTION(TASK_EXECUTION_ID)
|
||||||
|
) ;
|
||||||
|
|
||||||
|
CREATE SEQUENCE TASK_SEQ ;
|
||||||
@@ -42,8 +42,8 @@
|
|||||||
<artifactId>spring-boot-starter-jdbc</artifactId>
|
<artifactId>spring-boot-starter-jdbc</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.hsqldb</groupId>
|
<groupId>com.h2database</groupId>
|
||||||
<artifactId>hsqldb</artifactId>
|
<artifactId>h2</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
|||||||
Reference in New Issue
Block a user