Skip to content

Commit f0fddda

Browse files
zbw1231dbgroupdlmu
authored andcommitted
add support for kingbase
Signed-off-by: dbgroupdlmu <[email protected]>
1 parent ade546b commit f0fddda

File tree

5 files changed

+37
-44
lines changed

5 files changed

+37
-44
lines changed

spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/builder/JdbcPagingItemReaderBuilder.java

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,7 @@
2121
import org.springframework.batch.item.database.JdbcPagingItemReader;
2222
import org.springframework.batch.item.database.Order;
2323
import org.springframework.batch.item.database.PagingQueryProvider;
24-
import org.springframework.batch.item.database.support.AbstractSqlPagingQueryProvider;
25-
import org.springframework.batch.item.database.support.Db2PagingQueryProvider;
26-
import org.springframework.batch.item.database.support.DerbyPagingQueryProvider;
27-
import org.springframework.batch.item.database.support.H2PagingQueryProvider;
28-
import org.springframework.batch.item.database.support.HanaPagingQueryProvider;
29-
import org.springframework.batch.item.database.support.HsqlPagingQueryProvider;
30-
import org.springframework.batch.item.database.support.MariaDBPagingQueryProvider;
31-
import org.springframework.batch.item.database.support.MySqlPagingQueryProvider;
32-
import org.springframework.batch.item.database.support.OraclePagingQueryProvider;
33-
import org.springframework.batch.item.database.support.PostgresPagingQueryProvider;
34-
import org.springframework.batch.item.database.support.SqlServerPagingQueryProvider;
35-
import org.springframework.batch.item.database.support.SqlitePagingQueryProvider;
36-
import org.springframework.batch.item.database.support.SybasePagingQueryProvider;
24+
import org.springframework.batch.item.database.support.*;
3725
import org.springframework.batch.support.DatabaseType;
3826
import org.springframework.jdbc.core.BeanPropertyRowMapper;
3927
import org.springframework.jdbc.core.DataClassRowMapper;
@@ -361,6 +349,7 @@ protected PagingQueryProvider determineQueryProvider(DataSource dataSource) {
361349
case MARIADB -> new MariaDBPagingQueryProvider();
362350
case ORACLE -> new OraclePagingQueryProvider();
363351
case POSTGRES -> new PostgresPagingQueryProvider();
352+
case KINGBASE -> new KingbasePagingQueryProvider();
364353
case SYBASE -> new SybasePagingQueryProvider();
365354
case SQLITE -> new SqlitePagingQueryProvider();
366355
};

spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/support/DefaultDataFieldMaxValueIncrementerFactory.java

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -34,20 +34,7 @@
3434
import org.springframework.jdbc.support.incrementer.SybaseMaxValueIncrementer;
3535
import org.springframework.jdbc.support.incrementer.MariaDBSequenceMaxValueIncrementer;
3636

37-
import static org.springframework.batch.support.DatabaseType.DB2;
38-
import static org.springframework.batch.support.DatabaseType.DB2AS400;
39-
import static org.springframework.batch.support.DatabaseType.DB2ZOS;
40-
import static org.springframework.batch.support.DatabaseType.DERBY;
41-
import static org.springframework.batch.support.DatabaseType.H2;
42-
import static org.springframework.batch.support.DatabaseType.HANA;
43-
import static org.springframework.batch.support.DatabaseType.HSQL;
44-
import static org.springframework.batch.support.DatabaseType.MARIADB;
45-
import static org.springframework.batch.support.DatabaseType.MYSQL;
46-
import static org.springframework.batch.support.DatabaseType.ORACLE;
47-
import static org.springframework.batch.support.DatabaseType.POSTGRES;
48-
import static org.springframework.batch.support.DatabaseType.SQLITE;
49-
import static org.springframework.batch.support.DatabaseType.SQLSERVER;
50-
import static org.springframework.batch.support.DatabaseType.SYBASE;
37+
import static org.springframework.batch.support.DatabaseType.*;
5138

5239
/**
5340
* Default implementation of the {@link DataFieldMaxValueIncrementerFactory} interface.
@@ -120,6 +107,9 @@ else if (databaseType == ORACLE) {
120107
else if (databaseType == POSTGRES) {
121108
return new PostgresSequenceMaxValueIncrementer(dataSource, incrementerName);
122109
}
110+
else if (databaseType == KINGBASE) {
111+
return new PostgresSequenceMaxValueIncrementer(dataSource, incrementerName);
112+
}
123113
else if (databaseType == SQLITE) {
124114
return new SqliteMaxValueIncrementer(dataSource, incrementerName, incrementerColumnName);
125115
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package org.springframework.batch.item.database.support;
2+
3+
import org.springframework.util.StringUtils;
4+
5+
6+
public class KingbasePagingQueryProvider extends AbstractSqlPagingQueryProvider {
7+
8+
@Override
9+
public String generateFirstPageQuery(int pageSize) {
10+
return SqlPagingQueryUtils.generateLimitSqlQuery(this, false, buildLimitClause(pageSize));
11+
}
12+
13+
@Override
14+
public String generateRemainingPagesQuery(int pageSize) {
15+
if (StringUtils.hasText(getGroupClause())) {
16+
return SqlPagingQueryUtils.generateLimitGroupedSqlQuery(this, buildLimitClause(pageSize));
17+
}
18+
else {
19+
return SqlPagingQueryUtils.generateLimitSqlQuery(this, true, buildLimitClause(pageSize));
20+
}
21+
}
22+
23+
private String buildLimitClause(int pageSize) {
24+
return new StringBuilder().append("LIMIT ").append(pageSize).toString();
25+
}
26+
27+
}

spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/support/SqlPagingQueryProviderFactoryBean.java

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,22 +15,6 @@
1515
*/
1616
package org.springframework.batch.item.database.support;
1717

18-
import static org.springframework.batch.support.DatabaseType.DB2;
19-
import static org.springframework.batch.support.DatabaseType.DB2VSE;
20-
import static org.springframework.batch.support.DatabaseType.DB2ZOS;
21-
import static org.springframework.batch.support.DatabaseType.DB2AS400;
22-
import static org.springframework.batch.support.DatabaseType.DERBY;
23-
import static org.springframework.batch.support.DatabaseType.H2;
24-
import static org.springframework.batch.support.DatabaseType.HANA;
25-
import static org.springframework.batch.support.DatabaseType.HSQL;
26-
import static org.springframework.batch.support.DatabaseType.MARIADB;
27-
import static org.springframework.batch.support.DatabaseType.MYSQL;
28-
import static org.springframework.batch.support.DatabaseType.ORACLE;
29-
import static org.springframework.batch.support.DatabaseType.POSTGRES;
30-
import static org.springframework.batch.support.DatabaseType.SQLITE;
31-
import static org.springframework.batch.support.DatabaseType.SQLSERVER;
32-
import static org.springframework.batch.support.DatabaseType.SYBASE;
33-
3418
import java.util.HashMap;
3519
import java.util.LinkedHashMap;
3620
import java.util.Map;
@@ -45,6 +29,8 @@
4529
import org.springframework.util.Assert;
4630
import org.springframework.util.StringUtils;
4731

32+
import static org.springframework.batch.support.DatabaseType.*;
33+
4834
/**
4935
* Factory bean for {@link PagingQueryProvider} interface. The database type will be
5036
* determined from the data source if not provided explicitly. Valid types are given by
@@ -85,6 +71,7 @@ public class SqlPagingQueryProviderFactoryBean implements FactoryBean<PagingQuer
8571
providers.put(MARIADB, new MariaDBPagingQueryProvider());
8672
providers.put(ORACLE, new OraclePagingQueryProvider());
8773
providers.put(POSTGRES, new PostgresPagingQueryProvider());
74+
providers.put(KINGBASE, new KingbasePagingQueryProvider());
8875
providers.put(SQLITE, new SqlitePagingQueryProvider());
8976
providers.put(SQLSERVER, new SqlServerPagingQueryProvider());
9077
providers.put(SYBASE, new SybasePagingQueryProvider());

spring-batch-infrastructure/src/main/java/org/springframework/batch/support/DatabaseType.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public enum DatabaseType {
3838

3939
DERBY("Apache Derby"), DB2("DB2"), DB2VSE("DB2VSE"), DB2ZOS("DB2ZOS"), DB2AS400("DB2AS400"),
4040
HSQL("HSQL Database Engine"), SQLSERVER("Microsoft SQL Server"), MYSQL("MySQL"), ORACLE("Oracle"),
41-
POSTGRES("PostgreSQL"), SYBASE("Sybase"), H2("H2"), SQLITE("SQLite"), HANA("HDB"), MARIADB("MariaDB");
41+
POSTGRES("PostgreSQL"), KINGBASE("KingbaseES"),SYBASE("Sybase"), H2("H2"), SQLITE("SQLite"), HANA("HDB"), MARIADB("MariaDB");
4242

4343
private static final Map<String, DatabaseType> nameMap;
4444

0 commit comments

Comments
 (0)