chemistry-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From f...@apache.org
Subject svn commit: r1209243 - in /chemistry/opencmis/trunk/chemistry-opencmis-client: chemistry-opencmis-client-api/src/main/java/org/apache/chemistry/opencmis/client/api/ chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/runtime/
Date Thu, 01 Dec 2011 21:17:39 GMT
Author: fmui
Date: Thu Dec  1 21:17:38 2011
New Revision: 1209243

URL: http://svn.apache.org/viewvc?rev=1209243&view=rev
Log:
CMIS-480: initial implementation of queryObjects (has tone harden)

Modified:
    chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-api/src/main/java/org/apache/chemistry/opencmis/client/api/Session.java
    chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/runtime/SessionImpl.java

Modified: chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-api/src/main/java/org/apache/chemistry/opencmis/client/api/Session.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-api/src/main/java/org/apache/chemistry/opencmis/client/api/Session.java?rev=1209243&r1=1209242&r2=1209243&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-api/src/main/java/org/apache/chemistry/opencmis/client/api/Session.java
(original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-api/src/main/java/org/apache/chemistry/opencmis/client/api/Session.java
Thu Dec  1 21:17:38 2011
@@ -299,6 +299,21 @@ public interface Session extends Seriali
     ItemIterable<QueryResult> query(String statement, boolean searchAllVersions, OperationContext
context);
 
     /**
+     * 
+     * @param type
+     *            the id of the object type
+     * @param where
+     *            the WHERE part of the query
+     * @param searchAllVersions
+     *            specifies if the latest and non-latest versions of document
+     *            objects should be included
+     * @param context
+     *            the OperationContext
+     */
+    ItemIterable<CmisObject> queryObjects(String typeId, String where, boolean searchAllVersions,
+            OperationContext context);
+
+    /**
      * Creates a query statement.
      * 
      * @param statement

Modified: chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/runtime/SessionImpl.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/runtime/SessionImpl.java?rev=1209243&r1=1209242&r2=1209243&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/runtime/SessionImpl.java
(original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/runtime/SessionImpl.java
Thu Dec  1 21:17:38 2011
@@ -577,6 +577,72 @@ public class SessionImpl implements Sess
         });
     }
 
+    public ItemIterable<CmisObject> queryObjects(String typeId, String where, final
boolean searchAllVersions,
+            OperationContext context) {
+        if (typeId == null || typeId.trim().length() == 0) {
+            throw new IllegalArgumentException("Type id must be set!");
+        }
+
+        if (context == null) {
+            throw new IllegalArgumentException("Operation context must be set!");
+        }
+
+        final DiscoveryService discoveryService = getBinding().getDiscoveryService();
+        final ObjectFactory objectFactory = this.getObjectFactory();
+        final OperationContext ctxt = new OperationContextImpl(context);
+        final StringBuilder statement = new StringBuilder("SELECT ");
+
+        String select = ctxt.getFilterString();
+        if (select == null) {
+            statement.append("*");
+        } else {
+            statement.append(select);
+        }
+
+        final ObjectType type = getTypeDefinition(typeId);
+        statement.append(" FROM ");
+        statement.append(type.getQueryName());
+
+        if (where != null && where.trim().length() > 0) {
+            statement.append(" WHERE ");
+            statement.append(where);
+        }
+
+        String orderBy = ctxt.getOrderBy();
+        if (orderBy != null && orderBy.trim().length() > 0) {
+            statement.append(" ORDER BY ");
+            statement.append(orderBy);
+        }
+
+        return new CollectionIterable<CmisObject>(new AbstractPageFetcher<CmisObject>(ctxt.getMaxItemsPerPage())
{
+
+            @Override
+            protected AbstractPageFetcher.Page<CmisObject> fetchPage(long skipCount)
{
+
+                // fetch the data
+                ObjectList resultList = discoveryService.query(getRepositoryId(), statement.toString(),
+                        searchAllVersions, ctxt.isIncludeAllowableActions(), ctxt.getIncludeRelationships(),
+                        ctxt.getRenditionFilterString(), BigInteger.valueOf(this.maxNumItems),
+                        BigInteger.valueOf(skipCount), null);
+
+                // convert query results
+                List<CmisObject> page = new ArrayList<CmisObject>();
+                if (resultList.getObjects() != null) {
+                    for (ObjectData objectData : resultList.getObjects()) {
+                        if (objectData == null) {
+                            continue;
+                        }
+
+                        page.add(objectFactory.convertObject(objectData, ctxt));
+                    }
+                }
+
+                return new AbstractPageFetcher.Page<CmisObject>(page, resultList.getNumItems(),
+                        resultList.hasMoreItems());
+            }
+        });
+    }
+
     public QueryStatement createQueryStatement(final String statement) {
         return new QueryStatementImpl(this, statement);
     }



Mime
View raw message