diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/AbstractPagingItemReader.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/AbstractPagingItemReader.java index 18ba8f8a8..56a6e9db0 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/AbstractPagingItemReader.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/AbstractPagingItemReader.java @@ -1,3 +1,18 @@ +/* + * 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; import org.springframework.batch.item.support.AbstractItemReaderItemStream; diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/IbatisPagingItemReader.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/IbatisPagingItemReader.java index 44f49cf22..bf8426d48 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/IbatisPagingItemReader.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/IbatisPagingItemReader.java @@ -1,3 +1,19 @@ +/* + * 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; import org.springframework.util.ClassUtils; diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/JdbcPagingItemReader.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/JdbcPagingItemReader.java index 68c5cf260..565828692 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/JdbcPagingItemReader.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/JdbcPagingItemReader.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.batch.item.database; import org.springframework.batch.item.database.support.PagingQueryProvider; diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/JpaAwareItemWriter.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/JpaAwareItemWriter.java index 08f8c60e6..7bf50ad1e 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/JpaAwareItemWriter.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/JpaAwareItemWriter.java @@ -1,3 +1,19 @@ +/* + * 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; import java.util.List; diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/support/AbstractSqlPagingQueryProvider.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/support/AbstractSqlPagingQueryProvider.java index 9b84ad5af..0ba33a68f 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/support/AbstractSqlPagingQueryProvider.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/support/AbstractSqlPagingQueryProvider.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.batch.item.database.support; import javax.sql.DataSource; @@ -62,7 +63,7 @@ public abstract class AbstractSqlPagingQueryProvider implements PagingQueryProvi /** * - * @return the + * @return SQL SELECT clause part of SQL query string */ protected String getSelectClause() { return selectClause; @@ -77,7 +78,7 @@ public abstract class AbstractSqlPagingQueryProvider implements PagingQueryProvi /** * - * @return SQL "from" clause + * @return SQL FROM clause part of SQL query string */ protected String getFromClause() { return fromClause; @@ -97,7 +98,7 @@ public abstract class AbstractSqlPagingQueryProvider implements PagingQueryProvi /** * - * @return WHERE clause part of SQL query string + * @return SQL WHERE clause part of SQL query string */ protected String getWhereClause() { return whereClause; @@ -128,9 +129,10 @@ public abstract class AbstractSqlPagingQueryProvider implements PagingQueryProvi } /** - * - * @return place holder for sortKey. Will vary depending on whethernamed parameters or traditional placeholders + * The sort key placegholder will vary depending on whether named parameters or traditional placeholders * are used in query strings. + * + * @return place holder for sortKey. */ protected String getSortKeyPlaceHolder() { return usingNamedParameters ? ":_sortKey" : "?"; @@ -161,10 +163,32 @@ public abstract class AbstractSqlPagingQueryProvider implements PagingQueryProvi } } + /** + * Method generating the query string to be used for retrieving the first page. + * This method must be implemented in sub classes. + * + * @param pageSize number of rows to read per page + * @return query string + */ public abstract String generateFirstPageQuery(int pageSize); + /** + * Method generating the query string to be used for retrieving the pages following the first page. + * This method must be implemented in sub classes. + * + * @param pageSize number of rows to read per page + * @return query string + */ public abstract String generateRemainingPagesQuery(int pageSize); + /** + * Method generating the query string to be used for jumping to a specific item position. + * This method must be implemented in sub classes. + * + * @param itemIndex the index of the item to jump to + * @param pageSize number of rows to read per page + * @return query string + */ public abstract String generateJumpToItemQuery(int itemIndex, int pageSize); private String removeKeyWord(String keyWord, String clause) { diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/support/Db2PagingQueryProvider.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/support/Db2PagingQueryProvider.java index e9b17b955..1d37f0fe7 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/support/Db2PagingQueryProvider.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/support/Db2PagingQueryProvider.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.batch.item.database.support; /** diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/support/DerbyPagingQueryProvider.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/support/DerbyPagingQueryProvider.java index 83d1867de..7b7a98187 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/support/DerbyPagingQueryProvider.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/support/DerbyPagingQueryProvider.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.batch.item.database.support; import org.springframework.jdbc.support.JdbcUtils; diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/support/HsqlPagingQueryProvider.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/support/HsqlPagingQueryProvider.java index c08977d86..cf4474795 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/support/HsqlPagingQueryProvider.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/support/HsqlPagingQueryProvider.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.batch.item.database.support; /** diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/support/MySqlPagingQueryProvider.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/support/MySqlPagingQueryProvider.java index cbc58b493..9a685516c 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/support/MySqlPagingQueryProvider.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/support/MySqlPagingQueryProvider.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.batch.item.database.support; /** diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/support/OraclePagingQueryProvider.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/support/OraclePagingQueryProvider.java index 04da47558..f8f75c92e 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/support/OraclePagingQueryProvider.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/support/OraclePagingQueryProvider.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.batch.item.database.support; /** diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/support/PagingQueryProvider.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/support/PagingQueryProvider.java index 3f868e0dd..e530a672f 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/support/PagingQueryProvider.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/support/PagingQueryProvider.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.batch.item.database.support; import javax.sql.DataSource; diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/support/PostgresPagingQueryProvider.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/support/PostgresPagingQueryProvider.java index bb35cf607..3098ae0eb 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/support/PostgresPagingQueryProvider.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/support/PostgresPagingQueryProvider.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.batch.item.database.support; /** diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/support/SimpleDelegatingPagingQueryProvider.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/support/SimpleDelegatingPagingQueryProvider.java index aeffdb2c3..0d134a3a3 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/support/SimpleDelegatingPagingQueryProvider.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/support/SimpleDelegatingPagingQueryProvider.java @@ -1,3 +1,18 @@ +/* + * 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; import static org.springframework.batch.support.DatabaseType.*; diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/support/SqlPagingQueryUtils.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/support/SqlPagingQueryUtils.java index 04087a3c8..d09231ae2 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/support/SqlPagingQueryUtils.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/support/SqlPagingQueryUtils.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.batch.item.database.support; /** @@ -23,6 +24,14 @@ package org.springframework.batch.item.database.support; */ public class SqlPagingQueryUtils { + /** + * Generate SQL query string using a LIMIT clause + * + * @param provider {@link AbstractSqlPagingQueryProvider} providing the implementation specifics + * @param remainingPageQuery is this query for the ramining pages (true) as opposed to the first page (false) + * @param limitClause the implementation specific limit clause to be used + * @return the generated query + */ public static String generateLimitSqlQuery(AbstractSqlPagingQueryProvider provider, boolean remainingPageQuery, String limitClause) { StringBuilder sql = new StringBuilder(); sql.append("SELECT ").append(provider.getSelectClause()); @@ -34,6 +43,14 @@ public class SqlPagingQueryUtils { return sql.toString(); } + /** + * Generate SQL query string using a TOP clause + * + * @param provider {@link AbstractSqlPagingQueryProvider} providing the implementation specifics + * @param remainingPageQuery is this query for the ramining pages (true) as opposed to the first page (false) + * @param topClause the implementation specific top clause to be used + * @return the generated query + */ public static String generateTopSqlQuery(AbstractSqlPagingQueryProvider provider, boolean remainingPageQuery, String topClause) { StringBuilder sql = new StringBuilder(); sql.append("SELECT ").append(topClause).append(" ").append(provider.getSelectClause()); @@ -44,6 +61,14 @@ public class SqlPagingQueryUtils { return sql.toString(); } + /** + * Generate SQL query string using a ROW_NUM condition + * + * @param provider {@link AbstractSqlPagingQueryProvider} providing the implementation specifics + * @param remainingPageQuery is this query for the ramining pages (true) as opposed to the first page (false) + * @param rowNumClause the implementation specific row num clause to be used + * @return the generated query + */ public static String generateRowNumSqlQuery(AbstractSqlPagingQueryProvider provider, boolean remainingPageQuery, String rowNumClause) { StringBuilder sql = new StringBuilder(); sql.append("SELECT ").append(provider.getSelectClause()); @@ -56,6 +81,41 @@ public class SqlPagingQueryUtils { } + /** + * Generate SQL query string using a LIMIT clause + * + * @param provider {@link AbstractSqlPagingQueryProvider} providing the implementation specifics + * @param limitClause the implementation specific top clause to be used + * @return the generated query + */ + public static String generateLimitJumpToQuery(AbstractSqlPagingQueryProvider provider, String limitClause) { + StringBuilder sql = new StringBuilder(); + sql.append("SELECT ").append(provider.getSortKey()).append(" AS SORT_KEY"); + sql.append(" FROM ").append(provider.getFromClause()); + sql.append(provider.getWhereClause() == null ? "" : " WHERE " + provider.getWhereClause()); + sql.append(" ORDER BY ").append(provider.getSortKey()).append(" ASC "); + sql.append( limitClause); + + return sql.toString(); + } + + /** + * Generate SQL query string using a TOP clause + * + * @param provider {@link AbstractSqlPagingQueryProvider} providing the implementation specifics + * @param topClause the implementation specific top clause to be used + * @return the generated query + */ + public static String generateTopJumpToQuery(AbstractSqlPagingQueryProvider provider, String topClause) { + StringBuilder sql = new StringBuilder(); + sql.append("SELECT ").append(topClause).append(" ").append(provider.getSortKey()).append(" AS SORT_KEY"); + sql.append(" FROM ").append(provider.getFromClause()); + sql.append(provider.getWhereClause() == null ? "" : " WHERE " + provider.getWhereClause()); + sql.append(" ORDER BY ").append(provider.getSortKey()).append(" ASC"); + + return sql.toString(); + } + private static void buildWhereClause(AbstractSqlPagingQueryProvider provider, boolean remainingPageQuery, StringBuilder sql) { if (remainingPageQuery) { sql.append(" WHERE "); @@ -70,25 +130,4 @@ public class SqlPagingQueryUtils { } } - public static String generateTopJumpToQuery(AbstractSqlPagingQueryProvider provider, String topClause) { - StringBuilder sql = new StringBuilder(); - sql.append("SELECT ").append(topClause).append(" ").append(provider.getSortKey()).append(" AS SORT_KEY"); - sql.append(" FROM ").append(provider.getFromClause()); - sql.append(provider.getWhereClause() == null ? "" : " WHERE " + provider.getWhereClause()); - sql.append(" ORDER BY ").append(provider.getSortKey()).append(" ASC"); - - return sql.toString(); - } - - public static String generateLimitJumpToQuery(AbstractSqlPagingQueryProvider provider, String limitClause) { - StringBuilder sql = new StringBuilder(); - sql.append("SELECT ").append(provider.getSortKey()).append(" AS SORT_KEY"); - sql.append(" FROM ").append(provider.getFromClause()); - sql.append(provider.getWhereClause() == null ? "" : " WHERE " + provider.getWhereClause()); - sql.append(" ORDER BY ").append(provider.getSortKey()).append(" ASC "); - sql.append( limitClause); - - return sql.toString(); - } - } diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/support/SqlServerPagingQueryProvider.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/support/SqlServerPagingQueryProvider.java index 7bc171851..185ba9568 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/support/SqlServerPagingQueryProvider.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/support/SqlServerPagingQueryProvider.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.batch.item.database.support; /** diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/support/SqlWindowingPagingQueryProvider.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/support/SqlWindowingPagingQueryProvider.java index 03a06825d..a16d5227d 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/support/SqlWindowingPagingQueryProvider.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/support/SqlWindowingPagingQueryProvider.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.batch.item.database.support; /** diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/support/SybasePagingQueryProvider.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/support/SybasePagingQueryProvider.java index b19334b1f..b2bbd7856 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/support/SybasePagingQueryProvider.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/support/SybasePagingQueryProvider.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.batch.item.database.support; /**