Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 24549200D3E for ; Thu, 16 Nov 2017 22:32:17 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id 22D69160BEA; Thu, 16 Nov 2017 21:32:17 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 6C1891609EF for ; Thu, 16 Nov 2017 22:32:16 +0100 (CET) Received: (qmail 30027 invoked by uid 500); 16 Nov 2017 21:32:15 -0000 Mailing-List: contact dev-help@chemistry.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@chemistry.apache.org Delivered-To: mailing list dev@chemistry.apache.org Received: (qmail 30015 invoked by uid 99); 16 Nov 2017 21:32:15 -0000 Received: from mail-relay.apache.org (HELO mail-relay.apache.org) (140.211.11.15) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 16 Nov 2017 21:32:15 +0000 Received: from [192.168.178.42] (ip4d15fe51.dynamic.kabel-deutschland.de [77.21.254.81]) by mail-relay.apache.org (ASF Mail Server at mail-relay.apache.org) with ESMTPSA id 458151A0488; Thu, 16 Nov 2017 21:32:13 +0000 (UTC) Subject: Re: CMIS paging query result sample code To: dev@chemistry.apache.org, "Lu, Wentao" References: <095375566B6DA042AF27048A5083FFA6395C1DA3@KDCBCHMBX4.bchydro.adroot.bchydro.bc.ca> From: =?UTF-8?Q?Florian_M=c3=bcller?= Message-ID: <11f50d17-d1b6-575a-6343-52da2331948d@apache.org> Date: Thu, 16 Nov 2017 22:32:10 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.4.0 MIME-Version: 1.0 In-Reply-To: <095375566B6DA042AF27048A5083FFA6395C1DA3@KDCBCHMBX4.bchydro.adroot.bchydro.bc.ca> Content-Type: text/plain; charset=windows-1252 Content-Language: en-US Content-Transfer-Encoding: 7bit archived-at: Thu, 16 Nov 2017 21:32:17 -0000 Hi Wentao, If you are processing all query results, it's actually much simpler than you think. Please see: https://chemistry.apache.org/docs/cmis-samples/samples/operation-context/index.html#list-batch-size Use an Operation Context, set the maxItemsPerPage and just iterate over the query results: OperationContext oc = OperationContextUtils.createMinimumOperationContext(); oc.setMaxItemsPerPage(500); ItemIterable results = session.query(queryString, false, oc); for (QueryResult result : results) { System.out.println(result.getPropertyValueByQueryName("cmis:name")); } - Florian > Hi, > > Is there a sample code for OpenCMIS to paging query result? We have a query that will return large result set, we want to use paging query to avoid timeout if return all dataset in one query from backend FileNet repository, is there a sample code we can reference? I googled but get confused sample code especially after the first query call, > > while (results.getHasMoreItems()){ > PAGE_NUM ++; > //Should we do another session.query() call or just use the results.skipTo() from the first query result? > ItemIterable tmp_results = session.query(queryString, false).skipTo(PAGE_NUM * PAGE_SIZE).getPage(PAGE_SIZE); //this line or next line? > ItemIterable tmp_results = results.skipTo(PAGE_NUM * PAGE_SIZE).getPage(PAGE_SIZE); > > for (QueryResult result : tmp_results) { > System.out.println(result.getPropertyValueByQueryName("cmis:name")); > resultCount++; > } > } > > Here is the complete code snip > String queryString = "SELECT cmis:name FROM InformationSystem"; > > int PAGE_NUM = 0; > int PAGE_SIZE = 500; > > ItemIterable results = session.query(queryString, false).skipTo(PAGE_NUM * PAGE_SIZE).getPage(PAGE_SIZE); > int resultCount = 0; > for (QueryResult result : results) { > System.out.println(result.getPropertyValueByQueryName("cmis:name")); > resultCount ++; > } > System.out.println("resultCount="+resultCount); > > while (results.getHasMoreItems()){ > PAGE_NUM ++; > //Should we do another session.query() call or just use the results.skipTo() from the first query result? > ItemIterable tmp_results = session.query(queryString, false).skipTo(PAGE_NUM * PAGE_SIZE).getPage(PAGE_SIZE); > ItemIterable tmp_results = results.skipTo(PAGE_NUM * PAGE_SIZE).getPage(PAGE_SIZE); > > for (QueryResult result : tmp_results) { > System.out.println(result.getPropertyValueByQueryName("cmis:name")); > resultCount++; > } > System.out.println("resultCount="+resultCount); > } > > > > Thanks > Wentao > ________________________________ > This email and its attachments are intended solely for the personal use of the individual or entity named above. Any use of this communication by an unintended recipient is strictly prohibited. If you have received this email in error, any publication, use, reproduction, disclosure or dissemination of its contents is strictly prohibited. Please immediately delete this message and its attachments from your computer and servers. We would also appreciate if you would contact us by a collect call or return email to notify us of this error. Thank you for your cooperation. > -BCHydroDisclaimerID5.2.8.1541 >