RESOLVED - issue BATCH-1459: H2 support
This commit is contained in:
@@ -18,6 +18,7 @@ package org.springframework.batch.item.database.support;
|
||||
import static org.springframework.batch.support.DatabaseType.DB2;
|
||||
import static org.springframework.batch.support.DatabaseType.DB2ZOS;
|
||||
import static org.springframework.batch.support.DatabaseType.DERBY;
|
||||
import static org.springframework.batch.support.DatabaseType.H2;
|
||||
import static org.springframework.batch.support.DatabaseType.HSQL;
|
||||
import static org.springframework.batch.support.DatabaseType.MYSQL;
|
||||
import static org.springframework.batch.support.DatabaseType.ORACLE;
|
||||
@@ -35,6 +36,7 @@ import org.springframework.jdbc.support.incrementer.DB2MainframeSequenceMaxValue
|
||||
import org.springframework.jdbc.support.incrementer.DB2SequenceMaxValueIncrementer;
|
||||
import org.springframework.jdbc.support.incrementer.DataFieldMaxValueIncrementer;
|
||||
import org.springframework.jdbc.support.incrementer.DerbyMaxValueIncrementer;
|
||||
import org.springframework.jdbc.support.incrementer.H2SequenceMaxValueIncrementer;
|
||||
import org.springframework.jdbc.support.incrementer.HsqlMaxValueIncrementer;
|
||||
import org.springframework.jdbc.support.incrementer.MySQLMaxValueIncrementer;
|
||||
import org.springframework.jdbc.support.incrementer.OracleSequenceMaxValueIncrementer;
|
||||
@@ -86,6 +88,9 @@ public class DefaultDataFieldMaxValueIncrementerFactory implements DataFieldMaxV
|
||||
else if (databaseType == HSQL) {
|
||||
return new HsqlMaxValueIncrementer(dataSource, incrementerName, incrementerColumnName);
|
||||
}
|
||||
else if (databaseType == H2) {
|
||||
return new H2SequenceMaxValueIncrementer(dataSource, incrementerName);
|
||||
}
|
||||
else if (databaseType == MYSQL) {
|
||||
return new MySQLMaxValueIncrementer(dataSource, incrementerName, incrementerColumnName);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
* Copyright 2006-2008 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.batch.item.database.support;
|
||||
|
||||
/**
|
||||
* H2 implementation of a {@link org.springframework.batch.item.database.PagingQueryProvider} using database specific features.
|
||||
*
|
||||
* @author Dave Syer
|
||||
* @since 2.1
|
||||
*/
|
||||
public class H2PagingQueryProvider extends AbstractSqlPagingQueryProvider {
|
||||
|
||||
@Override
|
||||
public String generateFirstPageQuery(int pageSize) {
|
||||
return SqlPagingQueryUtils.generateTopSqlQuery(this, false, buildTopClause(pageSize));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String generateRemainingPagesQuery(int pageSize) {
|
||||
return SqlPagingQueryUtils.generateTopSqlQuery(this, true, buildTopClause(pageSize));
|
||||
}
|
||||
|
||||
private String buildTopClause(int pageSize) {
|
||||
return new StringBuilder().append("TOP ").append(pageSize).toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String generateJumpToItemQuery(int itemIndex, int pageSize) {
|
||||
int page = itemIndex / pageSize;
|
||||
int offset = (page * pageSize) - 1;
|
||||
offset = offset<0 ? 0 : offset;
|
||||
|
||||
String topClause = new StringBuilder().append("LIMIT ").append(offset).append(" 1").toString();
|
||||
return SqlPagingQueryUtils.generateTopJumpToQuery(this, topClause);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -19,6 +19,7 @@ import static org.springframework.batch.support.DatabaseType.DB2;
|
||||
import static org.springframework.batch.support.DatabaseType.DB2ZOS;
|
||||
import static org.springframework.batch.support.DatabaseType.DERBY;
|
||||
import static org.springframework.batch.support.DatabaseType.HSQL;
|
||||
import static org.springframework.batch.support.DatabaseType.H2;
|
||||
import static org.springframework.batch.support.DatabaseType.MYSQL;
|
||||
import static org.springframework.batch.support.DatabaseType.ORACLE;
|
||||
import static org.springframework.batch.support.DatabaseType.POSTGRES;
|
||||
@@ -68,6 +69,7 @@ public class SqlPagingQueryProviderFactoryBean implements FactoryBean {
|
||||
providers.put(DB2ZOS, new Db2PagingQueryProvider());
|
||||
providers.put(DERBY,new DerbyPagingQueryProvider());
|
||||
providers.put(HSQL,new HsqlPagingQueryProvider());
|
||||
providers.put(H2,new H2PagingQueryProvider());
|
||||
providers.put(MYSQL,new MySqlPagingQueryProvider());
|
||||
providers.put(ORACLE,new OraclePagingQueryProvider());
|
||||
providers.put(POSTGRES,new PostgresPagingQueryProvider());
|
||||
|
||||
@@ -43,7 +43,7 @@ public enum DatabaseType {
|
||||
MYSQL("MySQL"),
|
||||
ORACLE("Oracle"),
|
||||
POSTGRES("PostgreSQL"),
|
||||
SYBASE("Sybase");
|
||||
SYBASE("Sybase"), H2("H2");
|
||||
|
||||
private static final Map<String, DatabaseType> nameMap;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user