From 23cb8c5219db57ea19162444c421eb9b42a57cb4 Mon Sep 17 00:00:00 2001 From: Richard Millet Date: Fri, 22 Mar 2013 16:28:13 -0700 Subject: [PATCH] CSPACE-5943-REM: Added plumbing infrastructure work for making JDBC based partial term searches. --- services/JaxRsServiceProvider/pom.xml | 2 + .../nuxeo/AuthorityDocumentModelHandler.java | 5 ++- .../AuthorityItemDocumentModelHandler.java | 17 ++++++++ .../document/AbstractDocumentHandlerImpl.java | 6 +++ .../common/document/DocumentHandler.java | 8 ++++ .../client/java/DocumentModelHandler.java | 2 +- .../client/java/RepositoryJavaClientImpl.java | 43 ++++++++++++++++++- 7 files changed, 80 insertions(+), 3 deletions(-) diff --git a/services/JaxRsServiceProvider/pom.xml b/services/JaxRsServiceProvider/pom.xml index 3beedc94e..9052aaa46 100644 --- a/services/JaxRsServiceProvider/pom.xml +++ b/services/JaxRsServiceProvider/pom.xml @@ -22,10 +22,12 @@ org.slf4j slf4j-api + provided org.slf4j slf4j-log4j12 + provided log4j diff --git a/services/authority/service/src/main/java/org/collectionspace/services/common/vocabulary/nuxeo/AuthorityDocumentModelHandler.java b/services/authority/service/src/main/java/org/collectionspace/services/common/vocabulary/nuxeo/AuthorityDocumentModelHandler.java index 81260435a..87aca5fdd 100644 --- a/services/authority/service/src/main/java/org/collectionspace/services/common/vocabulary/nuxeo/AuthorityDocumentModelHandler.java +++ b/services/authority/service/src/main/java/org/collectionspace/services/common/vocabulary/nuxeo/AuthorityDocumentModelHandler.java @@ -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 objectProps.remove(AuthorityJAXBSchema.SHORT_IDENTIFIER); objectProps.remove(AuthorityJAXBSchema.REF_NAME); } - } + } } diff --git a/services/authority/service/src/main/java/org/collectionspace/services/common/vocabulary/nuxeo/AuthorityItemDocumentModelHandler.java b/services/authority/service/src/main/java/org/collectionspace/services/common/vocabulary/nuxeo/AuthorityItemDocumentModelHandler.java index 55e47c916..d54ca7a6f 100644 --- a/services/authority/service/src/main/java/org/collectionspace/services/common/vocabulary/nuxeo/AuthorityItemDocumentModelHandler.java +++ b/services/authority/service/src/main/java/org/collectionspace/services/common/vocabulary/nuxeo/AuthorityItemDocumentModelHandler.java @@ -664,4 +664,21 @@ public abstract class AuthorityItemDocumentModelHandler protected String getAuthorityItemCommonSchemaName() { return authorityItemCommonSchemaName; } + + @Override + public boolean isJDBCQuery() { + boolean result = false; + + MultivaluedMap 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; + } + } diff --git a/services/common/src/main/java/org/collectionspace/services/common/document/AbstractDocumentHandlerImpl.java b/services/common/src/main/java/org/collectionspace/services/common/document/AbstractDocumentHandlerImpl.java index 8000de612..c77961655 100644 --- a/services/common/src/main/java/org/collectionspace/services/common/document/AbstractDocumentHandlerImpl.java +++ b/services/common/src/main/java/org/collectionspace/services/common/document/AbstractDocumentHandlerImpl.java @@ -439,4 +439,10 @@ public abstract class AbstractDocumentHandlerImpl public boolean isCMISQuery() { return false; } + + @Override + public boolean isJDBCQuery() { + return false; + } + } diff --git a/services/common/src/main/java/org/collectionspace/services/common/document/DocumentHandler.java b/services/common/src/main/java/org/collectionspace/services/common/document/DocumentHandler.java index 52e351eef..075c35097 100644 --- a/services/common/src/main/java/org/collectionspace/services/common/document/DocumentHandler.java +++ b/services/common/src/main/java/org/collectionspace/services/common/document/DocumentHandler.java @@ -337,5 +337,13 @@ public interface DocumentHandler { */ 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(); } diff --git a/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/DocumentModelHandler.java b/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/DocumentModelHandler.java index fddcd4cc3..bd176053e 100644 --- a/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/DocumentModelHandler.java +++ b/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/DocumentModelHandler.java @@ -441,7 +441,7 @@ public abstract class DocumentModelHandler 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 diff --git a/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RepositoryJavaClientImpl.java b/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RepositoryJavaClientImpl.java index 2a0797a5b..032c34b82 100644 --- a/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RepositoryJavaClientImpl.java +++ b/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RepositoryJavaClientImpl.java @@ -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 0) || (queryContext.getDocFilter().getPageSize() > 0)) { docList = repoSession.query(query, null, @@ -894,6 +900,41 @@ public class RepositoryJavaClientImpl implements RepositoryClient 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 { -- 2.47.3