chemistry-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dcaru...@apache.org
Subject svn commit: r934443 - 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 Thu, 15 Apr 2010 15:17:00 GMT
Author: dcaruana
Date: Thu Apr 15 15:16:58 2010
New Revision: 934443

URL: http://svn.apache.org/viewvc?rev=934443&view=rev
Log:
Initial cut of alternate paging list interfaces.

Added:
    incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-api/src/main/java/org/apache/chemistry/opencmis/client/api/util/PagingIterable.java
  (with props)
    incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-api/src/main/java/org/apache/chemistry/opencmis/client/api/util/PagingIterator.java
  (with props)
    incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/runtime/util/AbstractPagingIterable.java
  (with props)
    incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/runtime/util/DefaultPageIterator.java
  (with props)

Added: 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=934443&view=auto
==============================================================================
--- incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-api/src/main/java/org/apache/chemistry/opencmis/client/api/util/PagingIterable.java
(added)
+++ incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-api/src/main/java/org/apache/chemistry/opencmis/client/api/util/PagingIterable.java
Thu Apr 15 15:16:58 2010
@@ -0,0 +1,72 @@
+/*
+ * 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.api.util;
+
+
+/**
+ * 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.
+ * 
+ * @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.
+   * 
+   * @param pageNumber
+   *          The number of the page to return.
+   * @return a page of items
+   */
+//  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();
+
+  /**
+   * Sets the size of the page LRU cache. A size &lt; 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);
+}

Propchange: incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-api/src/main/java/org/apache/chemistry/opencmis/client/api/util/PagingIterable.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: 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=934443&view=auto
==============================================================================
--- incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-api/src/main/java/org/apache/chemistry/opencmis/client/api/util/PagingIterator.java
(added)
+++ incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-api/src/main/java/org/apache/chemistry/opencmis/client/api/util/PagingIterator.java
Thu Apr 15 15:16:58 2010
@@ -0,0 +1,38 @@
+/*
+ * 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.api.util;
+
+import java.util.Iterator;
+
+public interface PagingIterator<T> extends Iterator<T> {
+
+  long getPosition();
+  
+  /**
+   * Returns the total number of items. If the repository knows the total number of items
in a
+   * result set, the repository SHOULD include the number here. If the repository does not
know the
+   * number of items in a result set, this parameter SHOULD not be set. The value in the
parameter
+   * MAY NOT be accurate the next time the client retrieves the result set or the next page
in the
+   * result set.
+   * 
+   * @return total number of items or (-1)
+   */
+  long getTotalNumItems();
+
+}

Propchange: incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-api/src/main/java/org/apache/chemistry/opencmis/client/api/util/PagingIterator.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/AbstractPagingIterable.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/AbstractPagingIterable.java?rev=934443&view=auto
==============================================================================
--- incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/runtime/util/AbstractPagingIterable.java
(added)
+++ incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/runtime/util/AbstractPagingIterable.java
Thu Apr 15 15:16:58 2010
@@ -0,0 +1,134 @@
+/*
+ * 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.Iterator;
+import java.util.List;
+
+import org.apache.chemistry.opencmis.client.api.util.PagingIterable;
+
+/**
+ * Base <code>PagingList</code> implementation.
+ */
+public abstract class AbstractPagingIterable<T> implements PagingIterable<T>
{
+
+  private long skipCount = 0;
+  private long maxItems = -1;    // page size
+  
+
+  public AbstractPagingIterable(long numItems) {
+    this.maxItems = numItems;
+  }
+  
+  public AbstractPagingIterable(long position, long maxItems) {
+    this.skipCount = position;
+    this.maxItems = maxItems;
+  }
+  
+  /*
+   * (non-Javadoc)
+   * 
+   * @see java.lang.Iterable#iterator()
+   */
+  public Iterator<T> iterator() {
+    return new DefaultPageIterator<T>(skipCount, maxItems);
+  }
+
+  public PagingIterable<T> skipTo(long position) {
+    return null;
+    //return new AbstractPagingIterable<T>(position, maxItems);
+  }
+
+
+  /**
+   * Fetches the given page from the server.
+   * 
+   * @param pageNumber
+   *          number of the page (>= 0).
+   */
+  protected abstract FetchResult fetchPage(long position);
+
+  // --- fetch result class ---
+
+  protected class FetchResult {
+    private List<T> page;
+    private BigInteger totalItems;
+    private Boolean hasMoreItems;
+
+    public FetchResult(List<T> page, BigInteger maxItems, Boolean hasMoreItems) {
+      this.page = page;
+      this.totalItems = maxItems;
+      this.hasMoreItems = hasMoreItems;
+    }
+
+    public List<T> getPage() {
+      return page;
+    }
+
+    public BigInteger getTotalItems() {
+      return totalItems;
+    }
+
+    public Boolean getHasMoreItems() {
+      return hasMoreItems;
+    }
+  }
+  
+
+  /*
+   * (non-Javadoc)
+   * 
+   * @see org.apache.opencmis.client.api.util.PagingList#size()
+   */
+//  public int size() {
+//    if (getNumItems() < 1) {
+//      return -1;
+//    }
+//
+//    if (getMaxItemsPerPage() < 1) {
+//      return -1;
+//    }
+//
+//    return (int) Math.ceil(((double) getNumItems() / (double) getMaxItemsPerPage()));
+//  }
+
+  /*
+   * (non-Javadoc)
+   * 
+   * @see org.apache.opencmis.client.api.util.PagingList#isEmpty()
+   */
+//  public boolean isEmpty() {
+//    if (getNumItems() > 0) {
+//      return false;
+//    }
+//
+//    if (getNumItems() == 0) {
+//      return true;
+//    }
+//
+//    List<T> page = get(0);
+//    if (page == null) {
+//      return true;
+//    }
+//
+//    return page.isEmpty();
+//  }
+
+}

Propchange: incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/runtime/util/AbstractPagingIterable.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/DefaultPageIterator.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/DefaultPageIterator.java?rev=934443&view=auto
==============================================================================
--- incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/runtime/util/DefaultPageIterator.java
(added)
+++ incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/runtime/util/DefaultPageIterator.java
Thu Apr 15 15:16:58 2010
@@ -0,0 +1,88 @@
+/*
+ * 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 org.apache.chemistry.opencmis.client.api.util.PagingIterator;
+
+public class DefaultPageIterator<T> implements PagingIterator<T> {
+
+  private long position = -1;
+  private long maxItems = -1;
+  
+  private Long totalItems = null;
+//  private FetchResult page = null;
+  
+  
+  public DefaultPageIterator(long skipCount, long maxItems) {
+    this.position = skipCount;
+    this.maxItems = maxItems;
+  }
+  
+  public long getPosition() {
+    return position;
+  }
+
+  public long getTotalNumItems() {
+//    if (totalItems == null) {
+//      if (page == null) {
+//        page = getInternal(position);
+//      }
+//      if (page != null) {
+//        // set number of items
+//        if (page.getTotalItems() != null) {
+//          totalItems = page.getTotalItems().longValue();
+//        }
+//        else {
+//          totalItems = -1L;
+//        }
+//      }
+//    }
+//    
+//    return totalItems;
+    return -1L;
+  }
+
+  public boolean hasNext() {
+    // TODO Auto-generated method stub
+    return false;
+  }
+
+  public T next() {
+    // TODO Auto-generated method stub
+    return null;
+  }
+
+  public void remove() {
+    throw new UnsupportedOperationException();
+  }
+
+  
+
+  /**
+   * Retrieves a page or gets it from cache.
+   */
+//  protected FetchResult getInternal(long skipCount) {
+//    if (skipCount < 0) {
+//      throw new IllegalArgumentException("position must be >= 0!");
+//    }
+//
+//    return fetchPage(skipCount);
+//  }
+  
+}

Propchange: incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/runtime/util/DefaultPageIterator.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message