diff --git a/openidm-repo-jdbc/src/main/java/org/forgerock/openidm/repo/jdbc/TableHandler.java b/openidm-repo-jdbc/src/main/java/org/forgerock/openidm/repo/jdbc/TableHandler.java
index 966279032f..ab083e74c0 100644
--- a/openidm-repo-jdbc/src/main/java/org/forgerock/openidm/repo/jdbc/TableHandler.java
+++ b/openidm-repo-jdbc/src/main/java/org/forgerock/openidm/repo/jdbc/TableHandler.java
@@ -2,6 +2,7 @@
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright © 2011-2015 ForgeRock AS. All rights reserved.
+ * Portions Copyright 2023 Wren Security.
*
* The contents of this file are subject to the terms
* of the Common Development and Distribution License
@@ -23,197 +24,208 @@
*/
package org.forgerock.openidm.repo.jdbc;
-import java.io.IOException;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.List;
import java.util.Map;
-
import org.forgerock.json.JsonPointer;
import org.forgerock.json.resource.BadRequestException;
-import org.forgerock.json.resource.ConflictException;
-import org.forgerock.json.resource.ForbiddenException;
import org.forgerock.json.resource.InternalServerErrorException;
import org.forgerock.json.resource.NotFoundException;
import org.forgerock.json.resource.PreconditionFailedException;
-import org.forgerock.json.resource.ResourceResponse;
import org.forgerock.json.resource.ResourceException;
+import org.forgerock.json.resource.ResourceResponse;
import org.forgerock.util.query.QueryFilter;
+/**
+ * Handler responsible for performing SQL operations on the underlying data source.
+ *
+ *
There are two different strategies represented by the respective implementations:
+ *
+ *
+ * MappedTableHandler
– resource is being stored in its own dedicated table
+ * where properties are mapped to table columns
+ * GenericTableHandler
– resource is being stored as JSON object in a shared
+ * generic table
+ *
+ */
public interface TableHandler {
/**
- * Gets an object from the repository by identifier. The returned object is not validated
+ * Get an object from the repository by its identifier. The returned object is not validated
* against the current schema and may need processing to conform to an updated schema.
+ *
*
* The object will contain metadata properties, including object identifier {@code _id},
- * and object version {@code _rev} to enable optimistic concurrency
+ * and object version {@code _rev} to enable optimistic concurrency.
*
- * @param fullId the qualified identifier of the object to retrieve from the object set.
- * @param type is the qualifier of the object to retrieve
- * @param localId the identifier without the qualifier of the object to retrieve
- * @param connection
+ * @param fullId The qualified identifier of the object to retrieve from the object set.
+ * @param type The qualifier of the object to retrieve.
+ * @param localId The identifier without the qualifier of the object to retrieve.
+ * @param connection Database connection to use.
* @throws NotFoundException if the specified object could not be found.
- * @throws SQLException if a DB failure was reported
- * @throws IOException if a failure to convert the JSON model was reported
- * @throws InternalServerErrorException if the operation failed because of a (possibly transient) failure
- * @return the requested object.
+ * @throws SQLException if a DB failure was reported.
+ * @throws InternalServerErrorException if the operation failed because of a (possibly transient) failure.
+ * @return The requested object.
*/
- public abstract ResourceResponse read(String fullId, String type,
- String localId, Connection connection)
- throws SQLException, IOException, ResourceException;
+ ResourceResponse read(String fullId, String type, String localId, Connection connection)
+ throws SQLException, ResourceException;
/**
- * Creates a new object in the object set.
+ * Create a new object in the object set.
+ *
*
- * This method sets the {@code _id} property to the assigned identifier for the object,
- * and the {@code _rev} property to the revised object version (For optimistic concurrency)
- *
- * @param fullId the client-generated identifier to use, or {@code null} if server-generated identifier is requested.
- * @param type
- * @param localId
- * @param obj the contents of the object to create in the object set.
- * @param connection
+ * This method mutates the provided object by setting the {@code _id} property to the
+ * assigned identifier for the object and the {@code _rev} property to the revised object
+ * version (for optimistic concurrency).
+ *
+ * @param fullId The client-generated identifier to use, or {@code null} if server-generated
+ * identifier is requested.
+ * @param type The qualifier of the object to create.
+ * @param localId The identifier without the qualifier (if specified in {@code fullId} parameter).
+ * @param obj The contents of the object to create in the object set.
+ * @param connection Database connection to use.
* @throws NotFoundException if the specified id could not be resolved.
- * @throws ForbiddenException if access to the object or object set is forbidden.
* @throws PreconditionFailedException if an object with the same ID already exists.
- * @throws InternalServerErrorException if the operation failed because of a (possibly transient) failure
- * @throws java.io.IOException
- * @throws java.sql.SQLException
+ * @throws InternalServerErrorException if the operation failed because of a (possibly transient) failure.
+ * @throws java.io.IOException in case of JSON processing error.
+ * @throws java.sql.SQLException if a DB failure is reported.
*/
- public abstract void create(String fullId, String type, String localId,
- Map obj, Connection connection)
- throws SQLException, IOException, ResourceException;
+ void create(String fullId, String type, String localId, Map obj, Connection connection)
+ throws SQLException, ResourceException;
/**
- * Updates the specified object in the object set.
+ * Update the specified object in the object set.
+ *
*
- * This implementation requires MVCC and hence enforces that clients state what revision they expect
- * to be updating
- *
- * If successful, this method updates metadata properties within the passed object,
- * including: a new {@code _rev} value for the revised object's version
- *
- * @param fullId the identifier of the object to be put, or {@code null} to request a generated identifier.
- * @param type
- * @param localId
- * @param rev the version of the object to update; or {@code null} if not provided.
- * @param obj the contents of the object to put in the object set.
- * @param connection
- * @throws ConflictException if version is required but is {@code null}.
- * @throws ForbiddenException if access to the object is forbidden.
- * @throws NotFoundException if the specified object could not be found.
+ * This implementation requires MVCC and hence enforces that clients state what revision they expect
+ * to be updating.
+ *
+ *
+ * This method mutates the provided object by updating {@code _rev} property value for the revised
+ * object's version.
+ *
+ * @param fullId The identifier of the object to be updated.
+ * @param type The qualifier of the object to update.
+ * @param localId The identifier without the qualifier.
+ * @param rev The version of the object to update.
+ * @param obj The contents of the object to put in the object set.
+ * @param connection Database connection to use.
+ * @throws NotFoundException if the specified object could not be found.
* @throws PreconditionFailedException if version did not match the existing object in the set.
- * @throws BadRequestException if the passed identifier is invalid
- * @throws InternalServerErrorException if the operation failed because of a (possibly transient) failure
- * @throws java.io.IOException
- * @throws java.sql.SQLException
+ * @throws BadRequestException if the passed identifier is invalid.
+ * @throws InternalServerErrorException if the operation failed because of a (possibly transient) failure.
+ * @throws java.sql.SQLException if a DB failure is reported.
*/
- public abstract void update(String fullId, String type, String localId,
- String rev, Map obj, Connection connection)
- throws SQLException, IOException, ResourceException;
+ void update(String fullId, String type, String localId, String rev, Map obj,
+ Connection connection) throws SQLException, ResourceException;
/**
- * Deletes the specified object from the object set.
+ * Delete the specified object from the object set.
*
- * @param fullId the identifier of the object to be deleted.
- * @param type
- * @param localId
- * @param rev the version of the object to delete or {@code null} if not provided.
- * @param connection
+ * @param fullId The identifier of the object to be deleted.
+ * @param type The qualifier of the object to delete.
+ * @param localId The identifier without the qualifier.
+ * @param rev The version of the object to delete or {@code *} to match any version.
+ * @param connection Database connection to use.
* @throws NotFoundException if the specified object could not be found.
- * @throws ForbiddenException if access to the object is forbidden.
- * @throws ConflictException if version is required but is {@code null}.
* @throws PreconditionFailedException if version did not match the existing object in the set.
* @throws InternalServerErrorException if the operation failed because of a (possibly transient) failure
- * @throws java.io.IOException
- * @throws java.sql.SQLException
+ * @throws java.sql.SQLException if a DB failure is reported.
*/
- public abstract void delete(String fullId, String type, String localId,
- String rev, Connection connection)
- throws SQLException, IOException, ResourceException;
+ void delete(String fullId, String type, String localId, String rev, Connection connection)
+ throws SQLException, ResourceException;
/**
- * Performs the query on the specified object and returns the associated results.
+ * Perform a query on the specified object set and return the associated results.
+ *
*
* Queries are parametric; a set of named parameters is provided as the query criteria.
- * The query result is a JSON object structure composed of basic Java types.
- *
- * The returned map is structured as follow:
- * - The top level map contains meta-data about the query, plus an entry with the actual result records.
- * - The QueryConstants
defines the map keys, including the result records (QUERY_RESULT)
- *
- * @param type identifies the object to query.
- * @param params the parameters of the query to perform.
- * @param connection
- * @return the query results, which includes meta-data and the result records in JSON object structure format.
- * @throws NotFoundException if the specified object could not be found.
- * @throws BadRequestException if the specified params contain invalid arguments, e.g. a query id that is not
- * configured, a query expression that is invalid, or missing query substitution tokens.
- * @throws ForbiddenException if access to the object or specified query is forbidden.
+ * The query result is a JSON object structure composed of basic Java types.
+ *
+ *
+ * The query parameters map is a simple shallow map that consists of two types
+ * of key-value pairs:
+ *
+ *
+ * - meta-data about the query to perform (e.g query identifier, page size) –
+ * see {@link QueryConstants}
+ *
- named parameters for the actual (SQL) prepared statement
+ *
+ *
+ * @param type Identifies the object type (qualifier) to query.
+ * @param params The parameters for the query to perform.
+ * @param connection Database connection to use.
+ * @return List of matched records in JSON object structure format.
+ * @throws NotFoundException if the specified object could not be found.
+ * @throws BadRequestException if the specified params contain invalid arguments, e.g. a query id that
+ * is not configured, a query expression that is invalid, or missing query substitution tokens.
* @throws InternalServerErrorException if the operation failed because of a (possibly transient) failure
- * @throws java.sql.SQLException
+ * @throws java.sql.SQLException if a DB failure is reported.
*/
- public List