001/* 002 * (C) Copyright 2006-2011 Nuxeo SA (http://nuxeo.com/) and others. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 * 016 * Contributors: 017 * Florent Guillaume 018 */ 019package org.nuxeo.ecm.core.api; 020 021import java.io.Closeable; 022import java.io.Serializable; 023import java.util.Map; 024 025/** 026 * An iterable query result based on a cursor. 027 * <p> 028 * The {@link #close()} method MUST be called when the query result is no more needed, otherwise underlying resources 029 * will be leaked. There is no auto-closing at the end of the iteration. 030 */ 031public interface IterableQueryResult extends Iterable<Map<String, Serializable>>, Closeable { 032 033 /** 034 * Closes the query result and releases the underlying resources held by the cursor. 035 * <p> 036 * This MUST be called when the query result is no more needed, otherwise underlying resources will be leaked. There 037 * is no auto-closing at the end of the iteration. 038 */ 039 @Override 040 void close(); 041 042 /** 043 * Indicates if the query result has not been closed 044 * 045 * @deprecated since 8.1 (misspelled), use {@link #mustBeClosed} instead 046 */ 047 @Deprecated 048 boolean isLife(); 049 050 /** 051 * Indicates if the query result must be closed (because it holds resources). 052 * 053 * @return {@code true} if the query result must be closed, {@code false} otherwise 054 * @since 8.1 055 */ 056 boolean mustBeClosed(); 057 058 /** 059 * Gets the total size of the query result. 060 * <p> 061 * Note that this may be costly, and that some backends may not be able to do this operation, in which case 062 * {@code -1} will be returned. 063 * 064 * @return the size, or {@code -1} for an unknown size 065 */ 066 long size(); 067 068 /** 069 * Gets the current position in the iterator. 070 * <p> 071 * Positions start at {@code 0}. 072 * 073 * @return the position 074 */ 075 long pos(); 076 077 /** 078 * Skips to a given position in the iterator. 079 * <p> 080 * Positions start at {@code 0}. 081 */ 082 void skipTo(long pos); 083 084}