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. <code>PagingList</code>
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 <T>
*/
public interface PagingIterable<T> extends Iterable<T> {
- PagingIterable<T> 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
<code>numItems</code> and
- * <code>maxItemsPerPage</code>. If the number of <code>numItems</code> 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<T> get(int pageNumber);
-
- /**
- * Returns if the list contains items. This method might fetch the first
page to determine the
- * return value!
- *
- * @return <code>true</code> if the list does not contain items,
<code>false</code>otherwise
- */
-// boolean isEmpty();
+ PagingIterable<T> 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 <T>
+ */
public interface PagingIterator<T> extends Iterator<T> {
+ /**
+ * 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 <T>
+ */
+public abstract class AbstractPageFetch<T> {
+
+ /**
+ * Fetches the given page from the server.
+ *
+ * @param pageNumber
+ * number of the page (>= 0).
+ */
+ protected abstract PageFetchResult<T> fetchPage(long skipCount);
+
+
+ // --- fetch result class ---
+
+ protected static class PageFetchResult<T> {
+ private List<T> page;
+ private BigInteger totalItems;
+ private Boolean hasMoreItems;
+
+ public PageFetchResult(List<T> page, BigInteger totalItems, Boolean
hasMoreItems) {
+ this.page = page;
+ this.totalItems = totalItems;
+ this.hasMoreItems = hasMoreItems;
+ }
+
+ public List<T> 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 <code>PagingIterable</code> implementation.
+ */
+public class DefaultPagingIterable<T> implements PagingIterable<T> {
+
+ private AbstractPageFetch<T> pageFetch;
+ private long skipCount;
+
+ /**
+ * Construct
+ *
+ * @param pageFetch
+ */
+ public DefaultPagingIterable(AbstractPageFetch<T> pageFetch) {
+ this(0, pageFetch);
+ }
+
+ /**
+ * Construct
+ *
+ * @param position
+ * @param pageFetch
+ */
+ private DefaultPagingIterable(long position, AbstractPageFetch<T> pageFetch)
{
+ this.pageFetch = pageFetch;
+ this.skipCount = position;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see java.lang.Iterable#iterator()
+ */
+ public Iterator<T> iterator() {
+ return new DefaultPagingIterator<T>(skipCount, pageFetch);
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see
org.apache.chemistry.opencmis.client.api.util.PagingIterable#skipTo(long)
+ */
+ public PagingIterable<T> skipTo(long position) {
+ return new DefaultPagingIterable<T>(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 <code>PagingIterator</code> implementation.
+ *
+ * @param <T>
+ */
+public class DefaultPagingIterator<T> implements PagingIterator<T> {
+
+ private long skipCount;
+ private int skipOffset = 0;
+
+ private AbstractPageFetch<T> pageFetch;
+
+ private Long totalItems = null;
+ private PageFetchResult<T> page = null;
+
+
+ /**
+ * Construct
+ *
+ * @param skipCount
+ * @param pageFetch
+ */
+ public DefaultPagingIterator(long skipCount, AbstractPageFetch<T> 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<T> 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<T> currentPage = getPage();
+ skipOffset++;
+
+ List<T> 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<T> page = getPage();
+ if (page == null) {
+ return false;
+ }
+ if (page.getHasMoreItems() != null) {
+ return page.getHasMoreItems().booleanValue();
+ }
+ return false;
+ }
+
+ private PageFetchResult<T> 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