}
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<String,String> 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";
/**
- * 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;
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;
}
+/**
+ * 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;
MultivaluedMap<String, String> 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 ";
" WHERE (tg.termdisplayname ILIKE ?) ";
List<String> 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
}
// If a particular authority is specified, restrict the query further
- // to records within that authority
+ // to return only records within that authority
String inAuthorityValue = (String) handler.getJDBCQueryParams().get(IN_AUTHORITY_PARAM);
if (Tools.notBlank(inAuthorityValue)) {
// Handle the '_ALL_' case for inAuthority
+ " ON commonschema.id = hierarchy.id ";
whereClause = whereClause
+ " AND (commonschema.inauthority = ?)";
- params.add(inAuthorityValue);
+ params.add(inAuthorityValue); // Value for replaceable parameter 2 in the query
}
}
-
+
String sql = selectStatement + joinClauses + whereClause;
// FIXME: Look into whether the following performance concern around
String id;
crs.beforeFirst();
while (crs.next()) {
- id = crs.getString(1);
+ id = crs.getString(1); // There is only one column returned in this filter query
if (Tools.notBlank(id)) {
docIds.add(id);
}