View Javadoc
1   /*
2    *    Copyright 2009-2023 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.apache.ibatis.cursor;
17  
18  import java.io.Closeable;
19  
20  /**
21   * Cursor contract to handle fetching items lazily using an Iterator. Cursors are a perfect fit to handle millions of
22   * items queries that would not normally fit in memory. If you use collections in resultMaps then cursor SQL queries
23   * must be ordered (resultOrdered="true") using the id columns of the resultMap.
24   *
25   * @author Guillaume Darmont / guillaume@dropinocean.com
26   */
27  public interface Cursor<T> extends Closeable, Iterable<T> {
28  
29    /**
30     * @return true if the cursor has started to fetch items from database.
31     */
32    boolean isOpen();
33  
34    /**
35     * @return true if the cursor is fully consumed and has returned all elements matching the query.
36     */
37    boolean isConsumed();
38  
39    /**
40     * Get the current item index. The first item has the index 0.
41     *
42     * @return -1 if the first cursor item has not been retrieved. The index of the current item retrieved.
43     */
44    int getCurrentIndex();
45  }