SCT-59 Add Support for H2 database

resolves spring-cloud/spring-cloud-task#59
This commit is contained in:
Glenn Renfro
2016-01-14 14:07:20 -05:00
parent 30497e6258
commit d00925622b
6 changed files with 65 additions and 4 deletions

View File

@@ -54,8 +54,8 @@
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hsqldb</groupId>
<artifactId>hsqldb</artifactId>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>test</scope>
</dependency>
<dependency>

View File

@@ -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);
}
}

View File

@@ -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.H2;
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.POSTGRES;
@@ -61,6 +62,7 @@ public class SqlPagingQueryProviderFactoryBean implements FactoryBean<PagingQuer
{
providers.put(HSQL, new HsqlPagingQueryProvider());
providers.put(H2, new H2PagingQueryProvider());
providers.put(MYSQL, new MySqlPagingQueryProvider());
providers.put(POSTGRES, new PostgresPagingQueryProvider());
providers.put(ORACLE, new OraclePagingQueryProvider());

View File

@@ -36,6 +36,7 @@ import org.springframework.util.StringUtils;
public enum DatabaseType {
HSQL("HSQL Database Engine"),
H2("H2"),
ORACLE("Oracle"),
MYSQL("MySQL"),
POSTGRES("PostgreSQL");

View File

@@ -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 ;

View File

@@ -42,8 +42,8 @@
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<dependency>
<groupId>org.hsqldb</groupId>
<artifactId>hsqldb</artifactId>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>