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 * @return 046 * @deprecated since 8.1 (misspelled), use {@link #mustBeClosed} instead 047 */ 048 @Deprecated 049 boolean isLife(); 050 051 /** 052 * Indicates if the query result must be closed (because it holds resources). 053 * 054 * @return {@code true} if the query result must be closed, {@code false} otherwise 055 * @since 8.1 056 */ 057 boolean mustBeClosed(); 058 059 /** 060 * Gets the total size of the query result. 061 * <p> 062 * Note that this may be costly, and that some backends may not be able to do this operation, in which case 063 * {@code -1} will be returned. 064 * 065 * @return the size, or {@code -1} for an unknown size 066 */ 067 long size(); 068 069 /** 070 * Gets the current position in the iterator. 071 * <p> 072 * Positions start at {@code 0}. 073 * 074 * @return the position 075 */ 076 long pos(); 077 078 /** 079 * Skips to a given position in the iterator. 080 * <p> 081 * Positions start at {@code 0}. 082 */ 083 void skipTo(long pos); 084 085}