Add support for mariadb

resolves #833

PagingProvider and integration tests added
This commit is contained in:
Glenn Renfro
2022-03-15 08:32:39 -04:00
parent be2be98814
commit f857359196
10 changed files with 526 additions and 11 deletions

View File

@@ -0,0 +1,37 @@
/*
* Copyright 2022-2022 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.database.support;
import org.springframework.cloud.task.repository.database.PagingQueryProvider;
import org.springframework.data.domain.Pageable;
/**
* MariaDB implementation of a {@link PagingQueryProvider} using database specific
* features.
*
* @author Glenn Renfro
*/
public class MariaDbPagingQueryProvider extends AbstractSqlPagingQueryProvider {
@Override
public String getPageQuery(Pageable pageable) {
String topClause = new StringBuilder().append("LIMIT ").append(pageable.getOffset()).append(", ")
.append(pageable.getPageSize()).toString();
return SqlPagingQueryUtils.generateLimitJumpToQuery(this, topClause);
}
}

View File

@@ -35,6 +35,7 @@ import static org.springframework.cloud.task.repository.support.DatabaseType.DB2
import static org.springframework.cloud.task.repository.support.DatabaseType.DB2ZOS;
import static org.springframework.cloud.task.repository.support.DatabaseType.H2;
import static org.springframework.cloud.task.repository.support.DatabaseType.HSQL;
import static org.springframework.cloud.task.repository.support.DatabaseType.MARIADB;
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;
@@ -67,6 +68,7 @@ public class SqlPagingQueryProviderFactoryBean implements FactoryBean<PagingQuer
this.providers.put(HSQL, new HsqlPagingQueryProvider());
this.providers.put(H2, new H2PagingQueryProvider());
this.providers.put(MYSQL, new MySqlPagingQueryProvider());
this.providers.put(MARIADB, new MariaDbPagingQueryProvider());
this.providers.put(POSTGRES, new PostgresPagingQueryProvider());
this.providers.put(ORACLE, new OraclePagingQueryProvider());
this.providers.put(SQLSERVER, new SqlServerPagingQueryProvider());

View File

@@ -57,6 +57,11 @@ public enum DatabaseType {
*/
MYSQL("MySQL"),
/**
* MySQL DB.
*/
MARIADB("MariaDB"),
/**
* PostgreSQL DB.
*/
@@ -145,7 +150,9 @@ public enum DatabaseType {
}
}
else {
databaseProductName = JdbcUtils.commonDatabaseName(databaseProductName);
if (!databaseProductName.equals(MARIADB.getProductName())) {
databaseProductName = JdbcUtils.commonDatabaseName(databaseProductName);
}
}
return fromProductName(databaseProductName);
}
@@ -157,9 +164,6 @@ public enum DatabaseType {
* @throws IllegalArgumentException if none is found.
*/
public static DatabaseType fromProductName(String productName) {
if (productName.equals("MariaDB")) {
productName = "MySQL";
}
if (!dbNameMap.containsKey(productName)) {
throw new IllegalArgumentException("DatabaseType not found for product name: [" + productName + "]");
}

View File

@@ -0,0 +1,37 @@
CREATE TABLE TASK_EXECUTION (
TASK_EXECUTION_ID BIGINT NOT NULL PRIMARY KEY ,
START_TIME DATETIME(6) DEFAULT NULL ,
END_TIME DATETIME(6) DEFAULT NULL ,
TASK_NAME VARCHAR(100) ,
EXIT_CODE INTEGER ,
EXIT_MESSAGE VARCHAR(2500) ,
ERROR_MESSAGE VARCHAR(2500) ,
LAST_UPDATED TIMESTAMP,
EXTERNAL_EXECUTION_ID VARCHAR(255),
PARENT_EXECUTION_ID BIGINT
) ENGINE=InnoDB;
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)
) ENGINE=InnoDB;
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)
) ENGINE=InnoDB;
CREATE TABLE TASK_LOCK (
LOCK_KEY CHAR(36) NOT NULL,
REGION VARCHAR(100) NOT NULL,
CLIENT_ID CHAR(36),
CREATED_DATE DATETIME(6) NOT NULL,
constraint LOCK_PK primary key (LOCK_KEY, REGION)
) ENGINE=InnoDB;
CREATE SEQUENCE TASK_SEQ START WITH 1 MINVALUE 1 MAXVALUE 9223372036854775806 INCREMENT BY 1 NOCACHE NOCYCLE ENGINE=InnoDB;