-package org.collectionspace.services.common.storage;
-
-import java.sql.Connection;
-import java.sql.PreparedStatement;
/**
* Per http://stackoverflow.com/a/7127189
*/
+package org.collectionspace.services.common.storage;
+
+import java.sql.Connection;
+import java.sql.PreparedStatement;
import java.sql.SQLException;
public class PreparedStatementBuilder
--- /dev/null
+package org.collectionspace.services.common.storage;
+
+import java.sql.PreparedStatement;
+import java.sql.SQLException;
+import java.util.List;
+
+public class PreparedStatementSimpleBuilder extends PreparedStatementBuilder {
+
+ private List<String> params;
+
+ public PreparedStatementSimpleBuilder(final String sql, final List<String> params) {
+ super(sql);
+ this.params = params;
+ }
+
+ @Override
+ protected void preparePrepared(final PreparedStatement preparedStatement)
+ throws SQLException {
+ int i = 0;
+ for (String param : params) {
+ i++;
+ preparedStatement.setString(i, param);
+ }
+ }
+}
\ No newline at end of file
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.common.storage.PreparedStatementBuilder;
+import org.collectionspace.services.common.storage.PreparedStatementSimpleBuilder;
import org.collectionspace.services.lifecycle.TransitionDef;
import org.collectionspace.services.nuxeo.util.NuxeoUtils;
MultivaluedMap<String, String> queryParams = ctx.getQueryParams();
final String partialTerm = queryParams.getFirst(IQueryManager.SEARCH_TYPE_PARTIALTERM);
+
+ // FIXME: Look into whether this performance concern specific to query
+ // planning with prepared statements may be affecting us:
+ // http://stackoverflow.com/a/678452
+ // If that proves to be a significant concern, we can instead use
+ // JDBCTools.executeQuery(), and attempt to sanitize user input
+ // against potential SQL injection attacks.
// FIXME: Replace this placeholder query with an actual query resulting
// from CSPACE-5945 work
// FIXME: We might also consider skipping the JOIN on the common schema table
// in the '_ALL_' case, where we are not restricting by inAuthority value
- PreparedStatementBuilder jdbcFilterBuilder = new PreparedStatementBuilder(sql){
- @Override
- protected void preparePrepared(PreparedStatement preparedStatement)
- throws SQLException
- {
- preparedStatement.setString(1, partialTerm + JDBCTools.SQL_WILDCARD);
- }};
-
+ List<String> params = new ArrayList<>();
+ params.add(partialTerm + JDBCTools.SQL_WILDCARD);
+ PreparedStatementSimpleBuilder jdbcFilterQueryBuilder = new PreparedStatementSimpleBuilder(sql, params);
+
List<String> docIds = new ArrayList<>();
- try (CachedRowSet crs = JDBCTools.executePreparedQuery(jdbcFilterBuilder,
+ try (CachedRowSet crs = JDBCTools.executePreparedQuery(jdbcFilterQueryBuilder,
dataSourceName, repositoryName, sql)) {
// If the response to the query is null or contains zero rows,