]> git.aero2k.de Git - tmp/jakarta-migration.git/commitdiff
CSPACE-5943-REM: Added plumbing infrastructure work for making JDBC based partial...
authorRichard Millet <remillet@berkeley.edu>
Fri, 22 Mar 2013 23:28:13 +0000 (16:28 -0700)
committerRichard Millet <remillet@berkeley.edu>
Fri, 22 Mar 2013 23:28:13 +0000 (16:28 -0700)
services/JaxRsServiceProvider/pom.xml
services/authority/service/src/main/java/org/collectionspace/services/common/vocabulary/nuxeo/AuthorityDocumentModelHandler.java
services/authority/service/src/main/java/org/collectionspace/services/common/vocabulary/nuxeo/AuthorityItemDocumentModelHandler.java
services/common/src/main/java/org/collectionspace/services/common/document/AbstractDocumentHandlerImpl.java
services/common/src/main/java/org/collectionspace/services/common/document/DocumentHandler.java
services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/DocumentModelHandler.java
services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RepositoryJavaClientImpl.java

index 3beedc94eadec952e650c5c2f0e247fb28998774..9052aaa46a2d690a157bfe0dbd392f18be25e115 100644 (file)
         <dependency>\r
             <groupId>org.slf4j</groupId>\r
             <artifactId>slf4j-api</artifactId>\r
+            <scope>provided</scope>\r
         </dependency>\r
         <dependency>\r
             <groupId>org.slf4j</groupId>\r
             <artifactId>slf4j-log4j12</artifactId>\r
+            <scope>provided</scope>\r
         </dependency>\r
         <dependency>\r
             <groupId>log4j</groupId>\r
index 81260435ad866dfc6d6089e49c7e832ded3e33d4..87aca5fdd7877ef7b33274c20df098d3790336d2 100644 (file)
@@ -25,6 +25,9 @@ package org.collectionspace.services.common.vocabulary.nuxeo;
 
 import java.util.Map;
 
+import javax.ws.rs.core.MultivaluedMap;
+
+import org.collectionspace.services.client.IQueryManager;
 import org.collectionspace.services.client.PoxPayloadIn;
 import org.collectionspace.services.client.PoxPayloadOut;
 import org.collectionspace.services.common.api.RefName;
@@ -192,5 +195,5 @@ public abstract class AuthorityDocumentModelHandler<AuthCommon>
             objectProps.remove(AuthorityJAXBSchema.SHORT_IDENTIFIER);
             objectProps.remove(AuthorityJAXBSchema.REF_NAME);
         }
-    }
+    }    
 }
index 55e47c916465c993ea327a5245a1cbc14b90a860..d54ca7a6fa5dfb13e40cdc688191e8e90de5b45d 100644 (file)
@@ -664,4 +664,21 @@ public abstract class AuthorityItemDocumentModelHandler<AICommon>
     protected String getAuthorityItemCommonSchemaName() {
        return authorityItemCommonSchemaName;
     }
+    
+    @Override
+    public boolean isJDBCQuery() {
+       boolean result = false;
+       
+       MultivaluedMap<String, String> queryParams = getServiceContext().getQueryParams();
+       //
+       // Look the query params to see if we need to make a SQL query.
+       //
+        String partialTerm = queryParams.getFirst(IQueryManager.SEARCH_TYPE_PARTIALTERM);
+       if (partialTerm != null && partialTerm.trim().isEmpty() == false) {
+               result = true;
+       }
+       
+       return result;
+    }
+    
 }
index 8000de612703343aaed579e6bc5f93d158f7c6ce..c77961655b2839f7e12b67f33551044d35a64608 100644 (file)
@@ -439,4 +439,10 @@ public abstract class AbstractDocumentHandlerImpl<T, TL, WT, WTL>
     public boolean isCMISQuery() {
        return false;
     }
+    
+    @Override
+    public boolean isJDBCQuery() {
+       return false;
+    }
+    
 }
index 52e351eef1a8136335e8c616288308a2ac6e3b4a..075c350978ab1bd69ef01aa4414d4544f6feb3d9 100644 (file)
@@ -337,5 +337,13 @@ public interface DocumentHandler<T, TL, WT, WTL> {
      */
     public String getCMISQuery(QueryContext queryContext);
     
+    /*
+     * Returns TRUE if a CMIS query should be used (instead of an NXQL) query
+     */
     public boolean isCMISQuery();
+
+    /*
+     * Returns TRUE if an SQL query should be used (instead of an NXQL)
+     */
+       public boolean isJDBCQuery();
 }
index fddcd4cc3914b431caf9f951cf62d660a164670b..bd176053e7b94be20e67d42352ee4f46eeab25fd 100644 (file)
@@ -441,7 +441,7 @@ public abstract class DocumentModelHandler<T, TL>
        
        return result;
     }
-    
+        
        /**
         * Creates the CMIS query from the service context. Each document handler is
         * responsible for returning (can override) a valid CMIS query using the information in the
index 2a0797a5b8bb2c65c601fa4505872fe3e6402cca..032c34b82d1176aed0ff85a27806a2af5a85aba3 100644 (file)
@@ -18,6 +18,9 @@
 package org.collectionspace.services.nuxeo.client.java;
 
 import java.io.Serializable;
+import java.sql.Connection;
+import java.sql.ResultSet;
+import java.sql.Statement;
 import java.util.Hashtable;
 import java.util.Iterator;
 import java.util.List;
@@ -36,6 +39,7 @@ import org.collectionspace.services.client.workflow.WorkflowClient;
 import org.collectionspace.services.common.context.ServiceContext;
 import org.collectionspace.services.common.query.QueryContext;
 import org.collectionspace.services.common.repository.RepositoryClient;
+import org.collectionspace.services.common.storage.JDBCTools;
 import org.collectionspace.services.lifecycle.TransitionDef;
 import org.collectionspace.services.nuxeo.util.NuxeoUtils;
 
@@ -866,7 +870,9 @@ public class RepositoryJavaClientImpl implements RepositoryClient<PoxPayloadIn,
                Profiler profiler = new Profiler(this, 2);
                profiler.log("Executing NXQL query: " + query.toString());
                profiler.start();
-               if (handler.isCMISQuery() == true) {
+               if (handler.isJDBCQuery() == true) {
+                       docList = getFilteredJDBC(repoSession, ctx, handler, queryContext);
+               } else if (handler.isCMISQuery() == true) {
                        docList = getFilteredCMIS(repoSession, ctx, handler, queryContext); //FIXME: REM - Need to deal with paging info in CMIS query
                } else if ((queryContext.getDocFilter().getOffset() > 0) || (queryContext.getDocFilter().getPageSize() > 0)) {
                 docList = repoSession.query(query, null,
@@ -894,6 +900,41 @@ public class RepositoryJavaClientImpl implements RepositoryClient<PoxPayloadIn,
             }
         }
     }
+    
+    private DocumentModelList getFilteredJDBC(RepositoryInstance repoSession, ServiceContext ctx, DocumentHandler handler, QueryContext queryContext)
+            throws Exception {
+       DocumentModelList result = new DocumentModelListImpl();
+       
+       String dataSourceName = JDBCTools.NUXEO_DATASOURCE_NAME;
+       String repositoryName = ctx.getRepositoryName();
+       Connection connection = JDBCTools.getConnection(dataSourceName, repositoryName);
+       
+       String theQuery = "<build up the query and put it in this string.";
+                       
+       // make sure autocommit is off see
+       //              http://jdbc.postgresql.org/documentation/80/query.html#query-with-cursor
+       //              http://docs.oracle.com/javase/7/docs/api/java/sql/ResultSet.html
+       
+       connection.setAutoCommit(false);
+       Statement st = connection.createStatement();
+
+       MultivaluedMap<String, String> queryParams = ctx.getQueryParams();
+        String partialTerm = queryParams.getFirst(IQueryManager.SEARCH_TYPE_PARTIALTERM);
+       
+       // Turn use of the cursor on.
+       st.setFetchSize(50);
+       ResultSet rs = st.executeQuery(partialTerm);
+       while (rs.next()) {
+               String id = rs.getString("id");
+          System.out.print("A row was returned with ID:" + id);
+       }
+       rs.close();
+
+       // Close the statement.
+       st.close();     
+       
+       return result;
+    }
 
     private DocumentModelList getFilteredCMIS(RepositoryInstance repoSession, ServiceContext ctx, DocumentHandler handler, QueryContext queryContext)
             throws DocumentNotFoundException, DocumentException {