Return-Path: Delivered-To: apmail-incubator-chemistry-commits-archive@minotaur.apache.org Received: (qmail 84617 invoked from network); 16 Apr 2010 10:22:31 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 16 Apr 2010 10:22:31 -0000 Received: (qmail 30420 invoked by uid 500); 16 Apr 2010 10:22:31 -0000 Delivered-To: apmail-incubator-chemistry-commits-archive@incubator.apache.org Received: (qmail 30371 invoked by uid 500); 16 Apr 2010 10:22:31 -0000 Mailing-List: contact chemistry-commits-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: chemistry-dev@incubator.apache.org Delivered-To: mailing list chemistry-commits@incubator.apache.org Received: (qmail 30363 invoked by uid 99); 16 Apr 2010 10:22:30 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 16 Apr 2010 10:22:30 +0000 X-ASF-Spam-Status: No, hits=-1445.2 required=10.0 tests=ALL_TRUSTED,AWL X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 16 Apr 2010 10:22:28 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id D3AC8238897D; Fri, 16 Apr 2010 10:22:08 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r934730 - in /incubator/chemistry/opencmis/trunk/chemistry-opencmis-client: chemistry-opencmis-client-api/src/main/java/org/apache/chemistry/opencmis/client/api/util/ chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmi... Date: Fri, 16 Apr 2010 10:22:08 -0000 To: chemistry-commits@incubator.apache.org From: dcaruana@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20100416102208.D3AC8238897D@eris.apache.org> Author: dcaruana Date: Fri Apr 16 10:22:08 2010 New Revision: 934730 URL: http://svn.apache.org/viewvc?rev=934730&view=rev Log: First cut of paging list implementation refactor Added: incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/runtime/util/AbstractPageFetch.java (with props) incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/runtime/util/DefaultPagingIterable.java (with props) incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/runtime/util/DefaultPagingIterator.java (with props) Removed: incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/runtime/util/AbstractPagingIterable.java incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/runtime/util/DefaultPageIterator.java Modified: incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-api/src/main/java/org/apache/chemistry/opencmis/client/api/util/PagingIterable.java incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-api/src/main/java/org/apache/chemistry/opencmis/client/api/util/PagingIterator.java Modified: incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-api/src/main/java/org/apache/chemistry/opencmis/client/api/util/PagingIterable.java URL: http://svn.apache.org/viewvc/incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-api/src/main/java/org/apache/chemistry/opencmis/client/api/util/PagingIterable.java?rev=934730&r1=934729&r2=934730&view=diff ============================================================================== --- incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-api/src/main/java/org/apache/chemistry/opencmis/client/api/util/PagingIterable.java (original) +++ incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-api/src/main/java/org/apache/chemistry/opencmis/client/api/util/PagingIterable.java Fri Apr 16 10:22:08 2010 @@ -20,53 +20,18 @@ package org.apache.chemistry.opencmis.cl /** - * Basically this is a nested list of lists where the outer list represent pages and the inner list - * is the result set with items of type T. PagingList implementations can support lazy - * load of result sets. The first page has the page number 0. + * Iterable for CMIS collections that allows ability to skip to specific position. * * @param */ public interface PagingIterable extends Iterable { - PagingIterable skipTo(long position); - - /** - * Returns the maximum number of items in one page. The repository MUST NOT exceed this maximum. - */ -// int getMaxItemsPerPage(); - - /** - * Returns the maximum number of pages calculated from number of numItems and - * maxItemsPerPage. If the number of numItems is not known then -1 is - * returned. - * - * @return Number of pages or (-1) - */ -// int size(); - /** - * Return one page as list of items of type T. + * Skip to position within CMIS collection * - * @param pageNumber - * The number of the page to return. - * @return a page of items + * @param position + * @return iterable whose starting point is the specicied skip to position */ -// List get(int pageNumber); - - /** - * Returns if the list contains items. This method might fetch the first page to determine the - * return value! - * - * @return true if the list does not contain items, falseotherwise - */ -// boolean isEmpty(); + PagingIterable skipTo(long position); - /** - * Sets the size of the page LRU cache. A size < 1 de-activates the cache. Default cache size - * is 0. Re-setting the cache size clears the cache. - * - * @param cacheSize - * size of the cache in pages - */ -// void setCacheSize(int cacheSize); } Modified: incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-api/src/main/java/org/apache/chemistry/opencmis/client/api/util/PagingIterator.java URL: http://svn.apache.org/viewvc/incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-api/src/main/java/org/apache/chemistry/opencmis/client/api/util/PagingIterator.java?rev=934730&r1=934729&r2=934730&view=diff ============================================================================== --- incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-api/src/main/java/org/apache/chemistry/opencmis/client/api/util/PagingIterator.java (original) +++ incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-api/src/main/java/org/apache/chemistry/opencmis/client/api/util/PagingIterator.java Fri Apr 16 10:22:08 2010 @@ -20,8 +20,19 @@ package org.apache.chemistry.opencmis.cl import java.util.Iterator; + +/** + * Iterator for scrolling through CMIS collections + * + * @param + */ public interface PagingIterator extends Iterator { + /** + * Returns the current position within the iterator. + * + * @return iterator position + */ long getPosition(); /** Added: incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/runtime/util/AbstractPageFetch.java URL: http://svn.apache.org/viewvc/incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/runtime/util/AbstractPageFetch.java?rev=934730&view=auto ============================================================================== --- incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/runtime/util/AbstractPageFetch.java (added) +++ incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/runtime/util/AbstractPageFetch.java Fri Apr 16 10:22:08 2010 @@ -0,0 +1,67 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.chemistry.opencmis.client.runtime.util; + +import java.math.BigInteger; +import java.util.List; + + +/** + * Abstract page fetch. + * + * @param + */ +public abstract class AbstractPageFetch { + + /** + * Fetches the given page from the server. + * + * @param pageNumber + * number of the page (>= 0). + */ + protected abstract PageFetchResult fetchPage(long skipCount); + + + // --- fetch result class --- + + protected static class PageFetchResult { + private List page; + private BigInteger totalItems; + private Boolean hasMoreItems; + + public PageFetchResult(List page, BigInteger totalItems, Boolean hasMoreItems) { + this.page = page; + this.totalItems = totalItems; + this.hasMoreItems = hasMoreItems; + } + + public List getPage() { + return page; + } + + public BigInteger getTotalItems() { + return totalItems; + } + + public Boolean getHasMoreItems() { + return hasMoreItems; + } + } + +} Propchange: incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/runtime/util/AbstractPageFetch.java ------------------------------------------------------------------------------ svn:eol-style = native Added: incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/runtime/util/DefaultPagingIterable.java URL: http://svn.apache.org/viewvc/incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/runtime/util/DefaultPagingIterable.java?rev=934730&view=auto ============================================================================== --- incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/runtime/util/DefaultPagingIterable.java (added) +++ incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/runtime/util/DefaultPagingIterable.java Fri Apr 16 10:22:08 2010 @@ -0,0 +1,69 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.chemistry.opencmis.client.runtime.util; + +import java.util.Iterator; + +import org.apache.chemistry.opencmis.client.api.util.PagingIterable; + +/** + * Base PagingIterable implementation. + */ +public class DefaultPagingIterable implements PagingIterable { + + private AbstractPageFetch pageFetch; + private long skipCount; + + /** + * Construct + * + * @param pageFetch + */ + public DefaultPagingIterable(AbstractPageFetch pageFetch) { + this(0, pageFetch); + } + + /** + * Construct + * + * @param position + * @param pageFetch + */ + private DefaultPagingIterable(long position, AbstractPageFetch pageFetch) { + this.pageFetch = pageFetch; + this.skipCount = position; + } + + /* + * (non-Javadoc) + * @see java.lang.Iterable#iterator() + */ + public Iterator iterator() { + return new DefaultPagingIterator(skipCount, pageFetch); + } + + /* + * (non-Javadoc) + * @see org.apache.chemistry.opencmis.client.api.util.PagingIterable#skipTo(long) + */ + public PagingIterable skipTo(long position) { + return new DefaultPagingIterable(position, pageFetch); + } + +} Propchange: incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/runtime/util/DefaultPagingIterable.java ------------------------------------------------------------------------------ svn:eol-style = native Added: incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/runtime/util/DefaultPagingIterator.java URL: http://svn.apache.org/viewvc/incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/runtime/util/DefaultPagingIterator.java?rev=934730&view=auto ============================================================================== --- incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/runtime/util/DefaultPagingIterator.java (added) +++ incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/runtime/util/DefaultPagingIterator.java Fri Apr 16 10:22:08 2010 @@ -0,0 +1,157 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.chemistry.opencmis.client.runtime.util; + +import java.util.List; + +import org.apache.chemistry.opencmis.client.api.util.PagingIterator; +import org.apache.chemistry.opencmis.client.runtime.util.AbstractPageFetch.PageFetchResult; + + +/** + * Base PagingIterator implementation. + * + * @param + */ +public class DefaultPagingIterator implements PagingIterator { + + private long skipCount; + private int skipOffset = 0; + + private AbstractPageFetch pageFetch; + + private Long totalItems = null; + private PageFetchResult page = null; + + + /** + * Construct + * + * @param skipCount + * @param pageFetch + */ + public DefaultPagingIterator(long skipCount, AbstractPageFetch pageFetch) { + this.skipCount = skipCount; + this.pageFetch = pageFetch; + } + + /* + * (non-Javadoc) + * @see org.apache.chemistry.opencmis.client.api.util.PagingIterator#getPosition() + */ + public long getPosition() { + return skipCount + skipOffset; + } + + /* + * (non-Javadoc) + * @see org.apache.chemistry.opencmis.client.api.util.PagingIterator#getTotalNumItems() + */ + public long getTotalNumItems() { + if (totalItems == null) { + PageFetchResult page = getPage(); + if (page != null) { + // set number of items + if (page.getTotalItems() != null) { + totalItems = page.getTotalItems().longValue(); + } + else { + totalItems = -1L; + } + } + } + return totalItems; + } + + /* + * (non-Javadoc) + * @see java.util.Iterator#hasNext() + */ + public boolean hasNext() { + if (!hasMoreItems()) { + return false; + } + + long totalItems = getTotalNumItems(); + if (totalItems < 0) { + // we don't know better + return true; + } + + return (skipCount + skipOffset) < totalItems - 1; + } + + /* + * (non-Javadoc) + * @see java.util.Iterator#next() + */ + public T next() { + PageFetchResult currentPage = getPage(); + skipOffset++; + + List items = currentPage.getPage(); + if (items == null || items.isEmpty()) { + return null; + } + + if (skipOffset == items.size()) { + skipCount += skipOffset; + skipOffset = 0; + this.page = pageFetch.fetchPage(skipCount); + currentPage = this.page; + if (currentPage != null) { + items = currentPage.getPage(); + } + } + + if (items == null || items.isEmpty() || skipOffset == items.size()) { + return null; + } + + return items.get(skipOffset); + } + + /* + * (non-Javadoc) + * @see java.util.Iterator#remove() + */ + public void remove() { + throw new UnsupportedOperationException(); + } + + private boolean hasMoreItems() { + PageFetchResult page = getPage(); + if (page == null) { + return false; + } + if (page.getHasMoreItems() != null) { + return page.getHasMoreItems().booleanValue(); + } + return false; + } + + private PageFetchResult getPage() + { + if (page == null) { + page = pageFetch.fetchPage(skipCount); + } + return page; + } + +} Propchange: incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/runtime/util/DefaultPagingIterator.java ------------------------------------------------------------------------------ svn:eol-style = native