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