View Javadoc
1   /*
2    *    Copyright 2016-2025 the original author or authors.
3    *
4    *    Licensed under the Apache License, Version 2.0 (the "License");
5    *    you may not use this file except in compliance with the License.
6    *    You may obtain a copy of the License at
7    *
8    *       https://www.apache.org/licenses/LICENSE-2.0
9    *
10   *    Unless required by applicable law or agreed to in writing, software
11   *    distributed under the License is distributed on an "AS IS" BASIS,
12   *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   *    See the License for the specific language governing permissions and
14   *    limitations under the License.
15   */
16  package org.mybatis.dynamic.sql.util.springbatch;
17  
18  import java.util.HashMap;
19  import java.util.Map;
20  
21  import org.mybatis.dynamic.sql.render.RenderingStrategy;
22  import org.mybatis.dynamic.sql.select.render.SelectStatementProvider;
23  
24  public class SpringBatchUtility {
25      private SpringBatchUtility() {}
26  
27      static final String PARAMETER_KEY = "mybatis3_dsql_query"; //$NON-NLS-1$
28  
29      /**
30       * Constant for use in a query intended for use with the MyBatisPagingItemReader.
31       * This value will not be used in the query at runtime because MyBatis Spring integration
32       * will supply a value for _skiprows.
33       *
34       * <p>This value can be used as a parameter for the "offset" method in a query to make the intention
35       * clear that the actual runtime value will be supplied by MyBatis Spring integration.
36       *
37       * <p>See <a href="https://mybatis.org/spring/batch.html">https://mybatis.org/spring/batch.html</a> for details.
38       */
39      public static final long MYBATIS_SPRING_BATCH_SKIPROWS = -437L;
40  
41      /**
42       * Constant for use in a query intended for use with the MyBatisPagingItemReader.
43       * This value will not be used in the query at runtime because MyBatis Spring integration
44       * will supply a value for _pagesize.
45       *
46       * <p>This value can be used as a parameter for the "limit" or "fetchFirst" method in a query to make the intention
47       * clear that the actual runtime value will be supplied by MyBatis Spring integration.
48       *
49       * <p>See <a href="https://mybatis.org/spring/batch.html">https://mybatis.org/spring/batch.html</a> for details.
50       */
51      public static final long MYBATIS_SPRING_BATCH_PAGESIZE = -439L;
52  
53      public static final RenderingStrategy SPRING_BATCH_PAGING_ITEM_READER_RENDERING_STRATEGY =
54              new SpringBatchPagingItemReaderRenderingStrategy();
55  
56      public static Map<String, Object> toParameterValues(SelectStatementProvider selectStatement) {
57          var parameterValues = new HashMap<String, Object>();
58          parameterValues.put(PARAMETER_KEY, selectStatement.getSelectStatement());
59          parameterValues.put(RenderingStrategy.DEFAULT_PARAMETER_PREFIX, selectStatement.getParameters());
60          return parameterValues;
61      }
62  }