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