Class ReindexResourceDAO
- java.lang.Object
-
- org.linuxforhealth.fhir.persistence.jdbc.dao.impl.FHIRDbDAOImpl
-
- org.linuxforhealth.fhir.persistence.jdbc.dao.impl.ResourceDAOImpl
-
- org.linuxforhealth.fhir.persistence.jdbc.dao.ReindexResourceDAO
-
- All Implemented Interfaces:
FHIRDbDAO
,ResourceDAO
- Direct Known Subclasses:
PostgresReindexResourceDAO
public class ReindexResourceDAO extends ResourceDAOImpl
DAO used to contain the logic required to reindex a given resource
-
-
Field Summary
-
Fields inherited from class org.linuxforhealth.fhir.persistence.jdbc.dao.impl.ResourceDAOImpl
DEFAULT_VALUE_REINDEX_TSTAMP, IDX_DATA, IDX_IS_DELETED, IDX_LAST_UPDATED, IDX_LOGICAL_ID, IDX_LOGICAL_RESOURCE_ID, IDX_RESOURCE_ID, IDX_RESOURCE_PAYLOAD_KEY, IDX_RESOURCE_TYPE_ID, IDX_VERSION_ID
-
-
Constructor Summary
Constructors Constructor Description ReindexResourceDAO(java.sql.Connection connection, IDatabaseTranslator translator, ParameterDAO parameterDao, java.lang.String schemaName, FHIRDbFlavor flavor, javax.transaction.TransactionSynchronizationRegistry trxSynchRegistry, FHIRPersistenceJDBCCache cache, ParameterTransactionDataImpl ptdi)
Public constructorReindexResourceDAO(java.sql.Connection connection, IDatabaseTranslator translator, ParameterDAO parameterDao, java.lang.String schemaName, FHIRDbFlavor flavor, FHIRPersistenceJDBCCache cache)
Public constructor
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
deleteResourceParameters(java.lang.String resourceTypeName, long logicalResourceId)
Delete all the parameter values for the given resourceType/logicalResourceIdprotected ResourceIndexRecord
getNextResource(java.security.SecureRandom random, java.time.Instant reindexTstamp, java.lang.Integer resourceTypeId, java.lang.String logicalId)
Pick the next resource to process, then also lock it.protected ResourceIndexRecord
getResource(java.time.Instant reindexTstamp, java.lang.Long logicalResourceId)
Pick a specific resource to process by logicalResourceId (primary key).ResourceIndexRecord
getResourceToReindex(java.time.Instant reindexTstamp, java.lang.Long logicalResourceId, java.lang.Integer resourceTypeId, java.lang.String logicalId)
Get the resource record we want to reindex.protected IDatabaseTranslator
getTranslator()
Getter for the translator currently held by this DAOResource
insert(Resource resource, java.util.List<ExtractedParameterValue> parameters, java.lang.String parameterHashB64, ParameterDAO parameterDao, java.lang.Integer ifNoneMatch)
Inserts the passed Resource DTO and its associated search parameters to the appropriate FHIR resource tables.protected ResourceIndexRecord
lockLogicalResource(ResourceIndexRecord rir)
Lock the logical resource for updateprotected void
updateParameterHash(java.sql.Connection conn, long logicalResourceId, java.lang.String parameterHashB64)
Updates the parameter hash in the LOGICAL_RESOURCES table.void
updateParameters(java.lang.String tablePrefix, java.util.List<ExtractedParameterValue> parameters, java.lang.String parameterHashB64, java.lang.String logicalId, long logicalResourceId)
Reindex the resource by deleting existing parameters and replacing them with those passed in.-
Methods inherited from class org.linuxforhealth.fhir.persistence.jdbc.dao.impl.ResourceDAOImpl
checkIfNoneMatch, createDTO, getCache, getResourceTypeId, getSearchByIdsNoDataSql, getSearchByIdsSql, getTransactionData, history, historyCount, read, readAllResourceTypeNames, readLogicalResourceId, readLogicalResourceIdList, readResourceTypeId, search, search, searchByIds, searchCount, searchCount, searchForIds, searchWholeSystem, setInt, setPersistenceContext, setString, versionRead
-
Methods inherited from class org.linuxforhealth.fhir.persistence.jdbc.dao.impl.FHIRDbDAOImpl
buildExceptionWithIssue, buildFHIRPersistenceDBConnectException, cleanup, cleanup, createDTOs, getConnection, getFlavor, getSchemaName, runCountQuery, runCountQuery, runQuery, runQuery, runQuery_STR_VALUES, severe, severe
-
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.linuxforhealth.fhir.persistence.jdbc.dao.api.FHIRDbDAO
getConnection, getFlavor
-
-
-
-
Constructor Detail
-
ReindexResourceDAO
public ReindexResourceDAO(java.sql.Connection connection, IDatabaseTranslator translator, ParameterDAO parameterDao, java.lang.String schemaName, FHIRDbFlavor flavor, FHIRPersistenceJDBCCache cache)
Public constructor- Parameters:
connection
-translator
-parameterDao
-schemaName
-flavor
-cache
-rrd
-
-
ReindexResourceDAO
public ReindexResourceDAO(java.sql.Connection connection, IDatabaseTranslator translator, ParameterDAO parameterDao, java.lang.String schemaName, FHIRDbFlavor flavor, javax.transaction.TransactionSynchronizationRegistry trxSynchRegistry, FHIRPersistenceJDBCCache cache, ParameterTransactionDataImpl ptdi)
Public constructor- Parameters:
connection
-translator
-parameterDao
-schemaName
-flavor
-trxSynchRegistry
-cache
-rrd
-
-
-
Method Detail
-
getTranslator
protected IDatabaseTranslator getTranslator()
Getter for the translator currently held by this DAO- Overrides:
getTranslator
in classFHIRDbDAOImpl
- Returns:
-
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 thislogicalResourceId
- 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 numberreindexTstamp
- only get resource with a reindex_tstamp less than thisresourceTypeId
- the resource type ID of a specific resource type, or nulllogicalId
- 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 thislogicalResourceId
- logical resource ID (primary key) of resource to reindex, or nullresourceTypeId
- the resource type ID of a specific resource type, or null; this parameter is ignored if the logicalResourceId parameter value is non-nulllogicalId
- 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 prefixparameters
- A collection of search parameters to be persisted along with the passed ResourceparameterHashB64
- the Base64 encoded SHA-256 hash of parameterslogicalId
- the logical idlogicalResourceId
- 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 connectionlogicalResourceId
- the logical resource IDparameterHashB64
- the Base64 encoded SHA-256 hash of parameters- Throws:
java.sql.SQLException
-
insert
public Resource insert(Resource resource, java.util.List<ExtractedParameterValue> parameters, java.lang.String parameterHashB64, ParameterDAO parameterDao, java.lang.Integer ifNoneMatch) throws FHIRPersistenceException
Description copied from interface:ResourceDAO
Inserts the passed Resource DTO and its associated search parameters to the appropriate FHIR resource tables. After insert, the generated primary key is acquired and set in the Resource object.- Parameters:
resource
- A Resource Data Transfer Objectparameters
- A collection of search parameters to be persisted along with the passed ResourceparameterHashB64
- Base64 encoded SHA-256 hash of parametersparameterDao
- The Parameter DAOifNoneMatch
- 0 for conditional create-on-update behavior; otherwise null- Returns:
- Resource The Resource DTO
- Throws:
FHIRPersistenceDataAccessException
FHIRPersistenceDBConnectException
FHIRPersistenceVersionIdMismatchException
FHIRPersistenceException
-
-