Class PlainParamValueProcessor
- java.lang.Object
-
- org.linuxforhealth.fhir.persistence.params.database.PlainParamValueProcessor
-
- All Implemented Interfaces:
IParamValueProcessor
- Direct Known Subclasses:
PlainDerbyParamValueProcessor,PlainPostgresParamValueProcessor
public abstract class PlainParamValueProcessor extends java.lang.Object implements IParamValueProcessor
Loads search parameter values into the target PostgreSQL database using the plain (non-sharded) schema variant.
-
-
Field Summary
Fields Modifier and Type Field Description protected java.sql.Connectionconnectionprotected static shortFIXED_SHARDprotected IParameterIdentityCacheidentityCacheprotected intmaxCodeSystemsPerStatementprotected intmaxCommonCanonicalValuesPerStatementprotected intmaxCommonTokenValuesPerStatementprotected intmaxLogicalResourcesPerStatementprotected java.lang.StringschemaNameprotected IDatabaseTranslatortranslator
-
Constructor Summary
Constructors Constructor Description PlainParamValueProcessor(IDatabaseTranslator translator, java.sql.Connection connection, java.lang.String schemaName, IParameterIdentityCache cache)Public constructor
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected voidaddMissingCodeSystems(java.util.List<CodeSystemValue> missing)These code systems weren't found in the database, so we need to try and add them.protected voidaddMissingCommonCanonicalValues(java.util.List<CommonCanonicalValue> missing)Add the values we think are missing from the database.protected voidaddMissingCommonTokenValues(java.util.List<CommonTokenValue> missing)Add the values we think are missing from the database.protected voidaddMissingLogicalResourceIdents(java.util.List<LogicalResourceIdentValue> missing)These logical_resource_ident values weren't found in the database, so we need to try and add them.protected PreparedStatementWrapperbuildCommonTokenValueSelectStatement(java.util.List<CommonTokenValue> values)Build and prepare a statement to fetch the common_token_value records for all the given (unresolved) code system valuesprotected java.sql.PreparedStatementbuildLogicalResourceIdentSelectStatement(java.util.List<LogicalResourceIdentValue> values)Build and prepare a statement to fetch the code_system_id and code_system_name from the code_systems table for all the given (unresolved) code system valuesvoidclose()Close out the current batch, completing the processing for any parameter values collected so farprotected java.lang.IntegercreateParameterName(java.lang.String parameterName)Create the parameter name using the stored procedure which handles any concurrency issue we may haveprotected java.util.List<CommonCanonicalValue>fetchCanonicalIds(java.util.List<CommonCanonicalValue> unresolved, java.util.Map<CommonCanonicalValueKey,CommonCanonicalValue> commonCanonicalValueMap)Fetch the common_canonical_id values for the given list of CommonCanonicalValue objects.protected java.util.List<CodeSystemValue>fetchCodeSystemIds(java.util.List<CodeSystemValue> unresolved, java.util.Map<java.lang.String,CodeSystemValue> codeSystemValueMap)Fetch all the code_system_id values for the given list of CodeSystemValue objects.protected java.util.List<CommonTokenValue>fetchCommonTokenValueIds(java.util.List<CommonTokenValue> unresolved, java.util.Map<CommonTokenValueKey,CommonTokenValue> commonTokenValueMap)Fetch the common_token_value_id values for the given list of CommonTokenValue objects.protected java.util.List<LogicalResourceIdentValue>fetchLogicalResourceIdentIds(java.util.List<LogicalResourceIdentValue> unresolved, java.util.Map<LogicalResourceIdentKey,LogicalResourceIdentValue> logicalResourceIdentMap)Fetch logical_resource_id values for the given list of LogicalResourceIdent objects.protected abstract java.lang.StringonConflict()voidpublish(BatchParameterValue bpv)Publish the given parameter value (which by now should have any FK references it needs)voidpushBatch()Push any data we've accumulated so far.voidresetBatch()Call when a transaction has been rolled back because of a deadlock or other retryable error and we want to try and process the batch againvoidresolveCanonicalValues(java.util.List<CommonCanonicalValue> unresolvedCanonicalValues, java.util.Map<CommonCanonicalValueKey,CommonCanonicalValue> commonCanonicalValueMap)voidresolveCommonTokenValues(java.util.List<CommonTokenValue> unresolvedTokenValues, java.util.Map<CommonTokenValueKey,CommonTokenValue> commonTokenValueMap)Make sure we have values for all the common_token_value records we have collected in the current batchvoidresolveLogicalResourceIdents(java.util.List<LogicalResourceIdentValue> unresolvedLogicalResourceIdents, java.util.Map<LogicalResourceIdentKey,LogicalResourceIdentValue> logicalResourceIdentMap)Make sure we have values for all the logical_resource_ident values we have collected in the current batch.voidresolveParameterNames(java.util.List<ParameterNameValue> unresolvedParameterNames, java.util.Map<java.lang.String,ParameterNameValue> parameterNameMap)voidresolveSystemValues(java.util.List<CodeSystemValue> unresolvedSystemValues, java.util.Map<java.lang.String,CodeSystemValue> codeSystemValueMap)Make sure we have values for all the code_systems we have collected in the current batchvoidstartBatch()Initialize the processor ready to start a new batch
-
-
-
Field Detail
-
FIXED_SHARD
protected static final short FIXED_SHARD
- See Also:
- Constant Field Values
-
connection
protected final java.sql.Connection connection
-
translator
protected final IDatabaseTranslator translator
-
schemaName
protected final java.lang.String schemaName
-
identityCache
protected final IParameterIdentityCache identityCache
-
maxLogicalResourcesPerStatement
protected final int maxLogicalResourcesPerStatement
- See Also:
- Constant Field Values
-
maxCodeSystemsPerStatement
protected final int maxCodeSystemsPerStatement
- See Also:
- Constant Field Values
-
maxCommonTokenValuesPerStatement
protected final int maxCommonTokenValuesPerStatement
- See Also:
- Constant Field Values
-
maxCommonCanonicalValuesPerStatement
protected final int maxCommonCanonicalValuesPerStatement
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
PlainParamValueProcessor
public PlainParamValueProcessor(IDatabaseTranslator translator, java.sql.Connection connection, java.lang.String schemaName, IParameterIdentityCache cache)
Public constructor- Parameters:
translator-connection-schemaName-cache-
-
-
Method Detail
-
startBatch
public void startBatch()
Description copied from interface:IParamValueProcessorInitialize the processor ready to start a new batch- Specified by:
startBatchin interfaceIParamValueProcessor
-
close
public void close()
Description copied from interface:IParamValueProcessorClose out the current batch, completing the processing for any parameter values collected so far- Specified by:
closein interfaceIParamValueProcessor
-
publish
public void publish(BatchParameterValue bpv) throws FHIRPersistenceException
Description copied from interface:IParamValueProcessorPublish the given parameter value (which by now should have any FK references it needs)- Specified by:
publishin interfaceIParamValueProcessor- Throws:
FHIRPersistenceException
-
pushBatch
public void pushBatch() throws FHIRPersistenceExceptionDescription copied from interface:IParamValueProcessorPush any data we've accumulated so far. This may occur if we cross a volume or functional threshold, and will always occur as the last step before the current transaction is committed.- Specified by:
pushBatchin interfaceIParamValueProcessor- Throws:
FHIRPersistenceException
-
resolveSystemValues
public void resolveSystemValues(java.util.List<CodeSystemValue> unresolvedSystemValues, java.util.Map<java.lang.String,CodeSystemValue> codeSystemValueMap) throws FHIRPersistenceException
Make sure we have values for all the code_systems we have collected in the current batch- Specified by:
resolveSystemValuesin interfaceIParamValueProcessor- Throws:
FHIRPersistenceException
-
onConflict
protected abstract java.lang.String onConflict()
-
addMissingCodeSystems
protected void addMissingCodeSystems(java.util.List<CodeSystemValue> missing) throws FHIRPersistenceException
These code systems weren't found in the database, so we need to try and add them. We have to deal with concurrency here - there's a chance another thread could also be trying to add them. To avoid deadlocks, it's important to do any inserts in a consistent order. At the end, we should be able to read back values for each entry- Parameters:
missing-- Throws:
FHIRPersistenceException
-
fetchCodeSystemIds
protected java.util.List<CodeSystemValue> fetchCodeSystemIds(java.util.List<CodeSystemValue> unresolved, java.util.Map<java.lang.String,CodeSystemValue> codeSystemValueMap) throws FHIRPersistenceException
Fetch all the code_system_id values for the given list of CodeSystemValue objects.- Parameters:
unresolved-- Returns:
- Throws:
FHIRPersistenceException
-
resolveCommonTokenValues
public void resolveCommonTokenValues(java.util.List<CommonTokenValue> unresolvedTokenValues, java.util.Map<CommonTokenValueKey,CommonTokenValue> commonTokenValueMap) throws FHIRPersistenceException
Make sure we have values for all the common_token_value records we have collected in the current batch- Specified by:
resolveCommonTokenValuesin interfaceIParamValueProcessor- Throws:
FHIRPersistenceException
-
buildCommonTokenValueSelectStatement
protected PreparedStatementWrapper buildCommonTokenValueSelectStatement(java.util.List<CommonTokenValue> values) throws java.sql.SQLException
Build and prepare a statement to fetch the common_token_value records for all the given (unresolved) code system values- Parameters:
values-- Returns:
- SELECT code_system, token_value, common_token_value_id
- Throws:
java.sql.SQLException
-
fetchCommonTokenValueIds
protected java.util.List<CommonTokenValue> fetchCommonTokenValueIds(java.util.List<CommonTokenValue> unresolved, java.util.Map<CommonTokenValueKey,CommonTokenValue> commonTokenValueMap) throws FHIRPersistenceException
Fetch the common_token_value_id values for the given list of CommonTokenValue objects.- Parameters:
unresolved-commonTokenValueMap-- Returns:
- Throws:
FHIRPersistenceException
-
addMissingCommonTokenValues
protected void addMissingCommonTokenValues(java.util.List<CommonTokenValue> missing) throws FHIRPersistenceException
Add the values we think are missing from the database. The given list should be sorted to reduce deadlocks- Parameters:
missing-- Throws:
FHIRPersistenceException
-
resolveCanonicalValues
public void resolveCanonicalValues(java.util.List<CommonCanonicalValue> unresolvedCanonicalValues, java.util.Map<CommonCanonicalValueKey,CommonCanonicalValue> commonCanonicalValueMap) throws FHIRPersistenceException
- Specified by:
resolveCanonicalValuesin interfaceIParamValueProcessor- Throws:
FHIRPersistenceException
-
fetchCanonicalIds
protected java.util.List<CommonCanonicalValue> fetchCanonicalIds(java.util.List<CommonCanonicalValue> unresolved, java.util.Map<CommonCanonicalValueKey,CommonCanonicalValue> commonCanonicalValueMap) throws FHIRPersistenceException
Fetch the common_canonical_id values for the given list of CommonCanonicalValue objects.- Parameters:
unresolved-- Returns:
- Throws:
FHIRPersistenceException
-
addMissingCommonCanonicalValues
protected void addMissingCommonCanonicalValues(java.util.List<CommonCanonicalValue> missing) throws FHIRPersistenceException
Add the values we think are missing from the database. The given list should be sorted to reduce deadlocks- Parameters:
missing-- Throws:
FHIRPersistenceException
-
resolveParameterNames
public void resolveParameterNames(java.util.List<ParameterNameValue> unresolvedParameterNames, java.util.Map<java.lang.String,ParameterNameValue> parameterNameMap) throws FHIRPersistenceException
- Specified by:
resolveParameterNamesin interfaceIParamValueProcessor- Throws:
FHIRPersistenceException
-
createParameterName
protected java.lang.Integer createParameterName(java.lang.String parameterName) throws FHIRPersistenceExceptionCreate the parameter name using the stored procedure which handles any concurrency issue we may have- Parameters:
parameterName-- Returns:
- Throws:
FHIRPersistenceException
-
resetBatch
public void resetBatch()
Description copied from interface:IParamValueProcessorCall when a transaction has been rolled back because of a deadlock or other retryable error and we want to try and process the batch again- Specified by:
resetBatchin interfaceIParamValueProcessor
-
resolveLogicalResourceIdents
public void resolveLogicalResourceIdents(java.util.List<LogicalResourceIdentValue> unresolvedLogicalResourceIdents, java.util.Map<LogicalResourceIdentKey,LogicalResourceIdentValue> logicalResourceIdentMap) throws FHIRPersistenceException
Description copied from interface:IParamValueProcessorMake sure we have values for all the logical_resource_ident values we have collected in the current batch. Need to make sure these are added in order to minimize deadlocks. Note that because we may create new logical_resource_ident records, we could be blocked by the main add_any_resource procedure run within the server CREATE/UPDATE- Specified by:
resolveLogicalResourceIdentsin interfaceIParamValueProcessor- Throws:
FHIRPersistenceException
-
buildLogicalResourceIdentSelectStatement
protected java.sql.PreparedStatement buildLogicalResourceIdentSelectStatement(java.util.List<LogicalResourceIdentValue> values) throws java.sql.SQLException
Build and prepare a statement to fetch the code_system_id and code_system_name from the code_systems table for all the given (unresolved) code system values- Parameters:
values-- Returns:
- Throws:
java.sql.SQLException
-
addMissingLogicalResourceIdents
protected void addMissingLogicalResourceIdents(java.util.List<LogicalResourceIdentValue> missing) throws FHIRPersistenceException
These logical_resource_ident values weren't found in the database, so we need to try and add them. We have to deal with concurrency here - there's a chance another thread could also be trying to add them. To avoid deadlocks, it's important to do any inserts in a consistent order. At the end, we should be able to read back values for each entry- Parameters:
missing-- Throws:
FHIRPersistenceException
-
fetchLogicalResourceIdentIds
protected java.util.List<LogicalResourceIdentValue> fetchLogicalResourceIdentIds(java.util.List<LogicalResourceIdentValue> unresolved, java.util.Map<LogicalResourceIdentKey,LogicalResourceIdentValue> logicalResourceIdentMap) throws FHIRPersistenceException
Fetch logical_resource_id values for the given list of LogicalResourceIdent objects.- Parameters:
unresolved-- Returns:
- Throws:
FHIRPersistenceException
-
-