Class ReindexResourceDAO

    • Method Detail

      • getResource

        protected ResourceIndexRecord getResource​(java.time.Instant reindexTstamp,
                                                  java.lang.Long logicalResourceId)
                                           throws java.lang.Exception
        Pick a specific resource to process by logicalResourceId (primary key). Since the logicalResourceId is specified, we avoid updating the record as the caller of $reindex operation is passing in an explicit list of resources, so no need to lock for the purpose of picking a random resource. This can improve performance (especially with PostgreSQL by avoiding the generation of tombstones).
        Parameters:
        reindexTstamp - only get resource with a reindex_tstamp less than this
        logicalResourceId - the logical resource ID (primary key) of a specific resource
        Returns:
        the resource record, or null when the resource is not found
        Throws:
        java.lang.Exception
      • lockLogicalResource

        protected ResourceIndexRecord lockLogicalResource​(ResourceIndexRecord rir)
                                                   throws java.lang.Exception
        Lock the logical resource for update
        Parameters:
        rir -
        Returns:
        the rir parameter, or null if the resource record was erased before it could be locked
        Throws:
        java.lang.Exception
      • getNextResource

        protected ResourceIndexRecord getNextResource​(java.security.SecureRandom random,
                                                      java.time.Instant reindexTstamp,
                                                      java.lang.Integer resourceTypeId,
                                                      java.lang.String logicalId)
                                               throws java.lang.Exception
        Pick the next resource to process, then also lock it. Specializations for different databases may use different techniques to optimize locking/concurrency control.
        Parameters:
        random - used to generate a random number
        reindexTstamp - only get resource with a reindex_tstamp less than this
        resourceTypeId - the resource type ID of a specific resource type, or null
        logicalId - the resource ID of a specific resource, or null
        Returns:
        the resource record, or null when there is nothing left to do
        Throws:
        java.lang.Exception
      • getResourceToReindex

        public ResourceIndexRecord getResourceToReindex​(java.time.Instant reindexTstamp,
                                                        java.lang.Long logicalResourceId,
                                                        java.lang.Integer resourceTypeId,
                                                        java.lang.String logicalId)
                                                 throws java.lang.Exception
        Get the resource record we want to reindex. This might take a few attempts, because there could be hundreds of threads all trying to do the same thing, and we may see collisions which will cause the FOR UPDATE to block, then return no rows.
        Parameters:
        reindexTstamp - only get resource with an index_tstamp less than this
        logicalResourceId - logical resource ID (primary key) of resource to reindex, or null
        resourceTypeId - the resource type ID of a specific resource type, or null; this parameter is ignored if the logicalResourceId parameter value is non-null
        logicalId - the resource ID of a specific resource, or null; this parameter is ignored if the logicalResourceId parameter value is non-null
        Returns:
        the resource record, or null when there is nothing left to do
        Throws:
        java.lang.Exception
      • updateParameters

        public void updateParameters​(java.lang.String tablePrefix,
                                     java.util.List<ExtractedParameterValue> parameters,
                                     java.lang.String parameterHashB64,
                                     java.lang.String logicalId,
                                     long logicalResourceId)
                              throws java.lang.Exception
        Reindex the resource by deleting existing parameters and replacing them with those passed in.
        Parameters:
        tablePrefix - the table prefix
        parameters - A collection of search parameters to be persisted along with the passed Resource
        parameterHashB64 - the Base64 encoded SHA-256 hash of parameters
        logicalId - the logical id
        logicalResourceId - the logical resource id
        Throws:
        java.lang.Exception
      • deleteResourceParameters

        protected void deleteResourceParameters​(java.lang.String resourceTypeName,
                                                long logicalResourceId)
                                         throws java.sql.SQLException
        Delete all the parameter values for the given resourceType/logicalResourceId
        Parameters:
        resourceTypeName -
        logicalResourceId -
        Throws:
        java.sql.SQLException
      • updateParameterHash

        protected void updateParameterHash​(java.sql.Connection conn,
                                           long logicalResourceId,
                                           java.lang.String parameterHashB64)
                                    throws java.sql.SQLException
        Updates the parameter hash in the LOGICAL_RESOURCES table.
        Parameters:
        conn - the connection
        logicalResourceId - the logical resource ID
        parameterHashB64 - the Base64 encoded SHA-256 hash of parameters
        Throws:
        java.sql.SQLException