From cf0588cdc00dd76dec356fd52e224d3ad444b96b Mon Sep 17 00:00:00 2001 From: Aron Roberts Date: Thu, 28 Mar 2013 19:24:28 -0700 Subject: [PATCH] CSPACE-5943: Add many comments. --- .../AuthorityItemDocumentModelHandler.java | 7 ++- .../storage/PreparedStatementBuilder.java | 57 ++++++++++++++++--- .../PreparedStatementSimpleBuilder.java | 32 +++++++++++ .../client/java/RepositoryJavaClientImpl.java | 17 ++++-- 4 files changed, 97 insertions(+), 16 deletions(-) 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 6e75f7260..5f1eeef91 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 @@ -697,13 +697,16 @@ public abstract class AuthorityItemDocumentModelHandler } protected String getInAuthorityValue() { - // FIXME: Replace this placeholder / stub + // FIXME: Replace this placeholder / stub with actual code + // to obtain the relevant inAuthority value return AuthorityResource.PARENT_WILDCARD; } @Override public Map getJDBCQueryParams() { - // FIXME: Get all of the following values from appropriate external constants + // FIXME: Get all of the following values from appropriate external constants. + // At present, these are duplicated in both RepositoryJavaClientImpl + // and in AuthorityItemDocumentModelHandler. final String TERM_GROUP_TABLE_NAME_PARAM = "TERM_GROUP_TABLE_NAME"; final String IN_AUTHORITY_PARAM = "IN_AUTHORITY"; diff --git a/services/common/src/main/java/org/collectionspace/services/common/storage/PreparedStatementBuilder.java b/services/common/src/main/java/org/collectionspace/services/common/storage/PreparedStatementBuilder.java index e99d70404..756517a32 100644 --- a/services/common/src/main/java/org/collectionspace/services/common/storage/PreparedStatementBuilder.java +++ b/services/common/src/main/java/org/collectionspace/services/common/storage/PreparedStatementBuilder.java @@ -1,5 +1,35 @@ /** - * Per http://stackoverflow.com/a/7127189 + * This document is a part of the source code and related artifacts + * for CollectionSpace, an open source collections management system + * for museums and related institutions: + + * http://www.collectionspace.org + * http://wiki.collectionspace.org + + * Copyright © 2009-2013 The Regents of the University of California + + * Licensed under the Educational Community License (ECL), Version 2.0. + * You may not use this file except in compliance with this License. + + * You may obtain a copy of the ECL 2.0 License at + + * https://source.collectionspace.org/collection-space/LICENSE.txt + + * 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. + */ + +/** + * PreparedStatementBuilder + * + * Simple workaround for the inability to create a JDBC + * PreparedStatement without having a current Connection + * + * See http://stackoverflow.com/a/7127189 + * and http://blog.stackoverflow.com/2009/06/stack-overflow-creative-commons-data-dump/ */ package org.collectionspace.services.common.storage; @@ -16,21 +46,32 @@ public class PreparedStatementBuilder this.sql = sql; } + /** + * A 'virtual' method to be overridden, in which to declare setup directives + * to be applied to a PreparedStatement; for instance, to add values to + * replaceable parameters or otherwise modify the statement's behavior. + * + * (The PreparedStatement will not yet exist at the time this method is overridden.) + * + * @param preparedStatement a JDBC PreparedStatement. + * @throws SQLException + */ protected void preparePrepared(final PreparedStatement preparedStatement) throws SQLException { - // This virtual method lets us declare how, when we generate our - // PreparedStatement, we want it to be set up. - - // Note that at the time this method is overridden, the - // PreparedStatement has not yet been created. } + /** + * Build a PreparedStatement by obtaining it from a JDBC Connection, + * then applying setup directives. + * + * @param conn a JDBC connection + * @return a JDBC PreparedStatement, with any + * @throws SQLException + */ public PreparedStatement build(final Connection conn) throws SQLException { - // Fetch the PreparedStatement final PreparedStatement returnable = conn.prepareStatement(sql); - // Perform setup directives preparePrepared(returnable); return returnable; } diff --git a/services/common/src/main/java/org/collectionspace/services/common/storage/PreparedStatementSimpleBuilder.java b/services/common/src/main/java/org/collectionspace/services/common/storage/PreparedStatementSimpleBuilder.java index a71f9ec14..662ba9121 100644 --- a/services/common/src/main/java/org/collectionspace/services/common/storage/PreparedStatementSimpleBuilder.java +++ b/services/common/src/main/java/org/collectionspace/services/common/storage/PreparedStatementSimpleBuilder.java @@ -1,3 +1,35 @@ +/** + * This document is a part of the source code and related artifacts + * for CollectionSpace, an open source collections management system + * for museums and related institutions: + + * http://www.collectionspace.org + * http://wiki.collectionspace.org + + * Copyright © 2009-2013 The Regents of the University of California + + * Licensed under the Educational Community License (ECL), Version 2.0. + * You may not use this file except in compliance with this License. + + * You may obtain a copy of the ECL 2.0 License at + + * https://source.collectionspace.org/collection-space/LICENSE.txt + + * 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. + */ + +/** + * PreparedStatementSimpleBuilder + * + * Specialization of PreparedStatementBuilder that simply applies a + * set of String values, in order, to each of the replaceable parameters + * in a PreparedStatement. + */ + package org.collectionspace.services.common.storage; import java.sql.PreparedStatement; 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 8fb2305dc..538860e7b 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 @@ -919,13 +919,17 @@ public class RepositoryJavaClientImpl implements RepositoryClient queryParams = ctx.getQueryParams(); final String partialTerm = queryParams.getFirst(IQueryManager.SEARCH_TYPE_PARTIALTERM); - // FIXME: Get all of the following values from appropriate external constants + // FIXME: Get all of the following values from appropriate external constants. + // At present, these are duplicated in both RepositoryJavaClientImpl + // and in AuthorityItemDocumentModelHandler. final String TERM_GROUP_TABLE_NAME_PARAM = "TERM_GROUP_TABLE_NAME"; final String IN_AUTHORITY_PARAM = "IN_AUTHORITY"; final String PARENT_WILDCARD = "_ALL_"; // Get this from AuthorityResource or equivalent // FIXME: Replace this placeholder query with an actual query resulting // from CSPACE-5945 work + + // Start with the default query String selectStatement = "SELECT DISTINCT hierarchy.id as id" + " FROM hierarchy "; @@ -940,8 +944,9 @@ public class RepositoryJavaClientImpl implements RepositoryClient params = new ArrayList<>(); - params.add(partialTerm + JDBCTools.SQL_WILDCARD); + params.add(partialTerm + JDBCTools.SQL_WILDCARD); // Value for replaceable parameter 1 in the query + // Restrict the query to filter out deleted records, if requested String includeDeleted = queryParams.getFirst(WorkflowClient.WORKFLOW_QUERY_NONDELETED); if (includeDeleted != null && includeDeleted.equalsIgnoreCase(Boolean.FALSE.toString())) { joinClauses = joinClauses @@ -952,7 +957,7 @@ public class RepositoryJavaClientImpl implements RepositoryClient