001/* 002 * (C) Copyright 2017 Nuxeo (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 * Kevin Leturc 018 */ 019package org.nuxeo.ecm.core.storage.marklogic; 020 021import org.nuxeo.ecm.core.api.CursorResult; 022 023import com.marklogic.xcc.ResultItem; 024import com.marklogic.xcc.ResultSequence; 025import com.marklogic.xcc.Session; 026 027/** 028 * {@link CursorResult} for MarkLogic which handles the session close. 029 * 030 * @since 9.1 031 */ 032public class MarkLogicCursorResult extends CursorResult<ResultSequence, ResultItem> { 033 034 protected final Session session; 035 036 public MarkLogicCursorResult(Session session, ResultSequence cursor, int batchSize, int keepAliveSeconds) { 037 super(cursor, batchSize, keepAliveSeconds); 038 this.session = session; 039 } 040 041 @Override 042 public boolean hasNext() { 043 return cursor != null && cursor.hasNext(); 044 } 045 046 @Override 047 public ResultItem next() { 048 return cursor.next(); 049 } 050 051 @Override 052 public void close() { 053 // session close will close automatically the cursor (ie: result sequence) 054 session.close(); 055 // Call super close to clear cursor 056 super.close(); 057 } 058 059}