1 /* 2 * Copyright (C) 2019, HuntLabs 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 */ 17 18 module hunt.database.base.Cursor; 19 20 import hunt.database.base.AsyncResult; 21 import hunt.database.base.Common; 22 import hunt.database.base.RowSet; 23 24 import hunt.logging; 25 26 27 28 /** 29 * A cursor that reads progressively rows from the database, it is useful for reading very large result sets. 30 */ 31 interface Cursor { 32 33 /** 34 * Read rows from the cursor, the result is provided asynchronously to the {@code handler}. 35 * 36 * @param count the amount of rows to read 37 * @param handler the handler for the result 38 */ 39 void read(int count, RowSetHandler handler); 40 41 /** 42 * Returns {@code true} when the cursor has results in progress and the {@link #read} should be called to retrieve 43 * them. 44 * 45 * @return whether the cursor has more results, 46 */ 47 bool hasMore(); 48 49 /** 50 * Release the cursor. 51 * <p/> 52 * It should be called for prepared queries executed with a fetch size. 53 */ 54 final void close() { 55 close((ar) { 56 warning("do nothing..."); 57 }); 58 } 59 60 /** 61 * Like {@link #close()} but with a {@code completionHandler} called when the cursor has been released. 62 */ 63 void close(AsyncVoidHandler completionHandler); 64 65 }