Class ReindexResourceDAO
- java.lang.Object
-
- com.ibm.fhir.persistence.jdbc.dao.impl.FHIRDbDAOImpl
-
- com.ibm.fhir.persistence.jdbc.dao.impl.ResourceDAOImpl
-
- com.ibm.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 com.ibm.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_VERSION_ID
-
-
Constructor Summary
Constructors Constructor Description ReindexResourceDAO(Connection connection, IDatabaseTranslator translator, ParameterDAO parameterDao, String schemaName, FHIRDbFlavor flavor, FHIRPersistenceJDBCCache cache, IResourceReferenceDAO rrd)
Public constructorReindexResourceDAO(Connection connection, IDatabaseTranslator translator, ParameterDAO parameterDao, String schemaName, FHIRDbFlavor flavor, TransactionSynchronizationRegistry trxSynchRegistry, FHIRPersistenceJDBCCache cache, IResourceReferenceDAO rrd, ParameterTransactionDataImpl ptdi)
Public constructor
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected ResourceIndexRecord
getNextResource(SecureRandom random, Instant reindexTstamp, Integer resourceTypeId, String logicalId)
Pick the next resource to process, then also lock it.protected ResourceIndexRecord
getResource(Instant reindexTstamp, Long logicalResourceId)
Pick a specific resource to process by logicalResourceId (primary key).ResourceIndexRecord
getResourceToReindex(Instant reindexTstamp, Long logicalResourceId, Integer resourceTypeId, String logicalId)
Get the resource record we want to reindex.protected IDatabaseTranslator
getTranslator()
Getter for the translator currently held by this DAOprotected void
updateParameterHash(Connection conn, long logicalResourceId, String parameterHashB64)
Updates the parameter hash in the LOGICAL_RESOURCES table.void
updateParameters(String tablePrefix, List<ExtractedParameterValue> parameters, String parameterHashB64, String logicalId, long logicalResourceId)
Reindex the resource by deleting existing parameters and replacing them with those passed in.-
Methods inherited from class com.ibm.fhir.persistence.jdbc.dao.impl.ResourceDAOImpl
addResourceTypeCacheCandidate, checkIfNoneMatch, createDTO, deleteFromParameterTable, getCache, getResourceReferenceDAO, getResourceTypeIdFromCaches, getSearchByIdsSql, getTransactionData, history, historyCount, insert, read, readAllResourceTypeNames, readResourceTypeId, search, search, searchByIds, searchCount, searchCount, searchForIds, searchWholeSystem, setInt, setPersistenceContext, versionRead
-
Methods inherited from class com.ibm.fhir.persistence.jdbc.dao.impl.FHIRDbDAOImpl
buildExceptionWithIssue, buildFHIRPersistenceDBConnectException, cleanup, cleanup, createDTOs, getConnection, getFlavor, getSchemaName, isDb2Database, 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 com.ibm.fhir.persistence.jdbc.dao.api.FHIRDbDAO
getConnection, getFlavor, isDb2Database
-
-
-
-
Constructor Detail
-
ReindexResourceDAO
public ReindexResourceDAO(Connection connection, IDatabaseTranslator translator, ParameterDAO parameterDao, String schemaName, FHIRDbFlavor flavor, FHIRPersistenceJDBCCache cache, IResourceReferenceDAO rrd)
Public constructor- Parameters:
connection
-translator
-parameterDao
-schemaName
-flavor
-cache
-rrd
-
-
ReindexResourceDAO
public ReindexResourceDAO(Connection connection, IDatabaseTranslator translator, ParameterDAO parameterDao, String schemaName, FHIRDbFlavor flavor, TransactionSynchronizationRegistry trxSynchRegistry, FHIRPersistenceJDBCCache cache, IResourceReferenceDAO rrd, 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(Instant reindexTstamp, Long logicalResourceId) throws 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:
Exception
-
getNextResource
protected ResourceIndexRecord getNextResource(SecureRandom random, Instant reindexTstamp, Integer resourceTypeId, String logicalId) throws 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:
Exception
-
getResourceToReindex
public ResourceIndexRecord getResourceToReindex(Instant reindexTstamp, Long logicalResourceId, Integer resourceTypeId, String logicalId) throws 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:
Exception
-
updateParameters
public void updateParameters(String tablePrefix, List<ExtractedParameterValue> parameters, String parameterHashB64, String logicalId, long logicalResourceId) throws 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:
Exception
-
updateParameterHash
protected void updateParameterHash(Connection conn, long logicalResourceId, String parameterHashB64) throws 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:
SQLException
-
-