Class FHIRPersistenceJDBCImpl
- java.lang.Object
-
- com.ibm.fhir.persistence.jdbc.impl.FHIRPersistenceJDBCImpl
-
- All Implemented Interfaces:
FHIRPersistence
,SchemaNameSupplier
public class FHIRPersistenceJDBCImpl extends Object implements FHIRPersistence, SchemaNameSupplier
The JDBC implementation of the FHIRPersistence interface, providing implementations for CRUD APIs and search.
-
-
Field Summary
Fields Modifier and Type Field Description static String
TRX_SYNCH_REG_JNDI_NAME
protected static String
TXN_JNDI_NAME
protected Boolean
updateCreateEnabled
protected UserTransaction
userTransaction
-
Constructor Summary
Constructors Constructor Description FHIRPersistenceJDBCImpl(FHIRPersistenceJDBCCache cache)
Constructor for use when running as web application in WLP.FHIRPersistenceJDBCImpl(Properties configProps, IConnectionProvider cp, FHIRConfigProvider configProvider, FHIRPersistenceJDBCCache cache)
Constructor for use when running standalone, outside of any web container.FHIRPersistenceJDBCImpl(Properties configProps, IConnectionProvider cp, FHIRPersistenceJDBCCache cache)
Constructor for use when running standalone, outside of any web container.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
addCompartmentParams(List<ExtractedParameterValue> allParameters, Resource fhirResource)
Augment the given allParameters list with ibm-internal parameters that represent relationships between the fhirResource to its compartments.protected Action
buildActionChain()
Build a chain of actions we want to apply to new connections.protected List<Resource>
buildSortedResourceDTOList(ResourceDAO resourceDao, Class<? extends Resource> resourceType, List<Long> sortedIdList)
This method takes the passed list of sorted Resource ids, acquires the ResourceDTO corresponding to each id, and returns those ResourceDTOs in a List, sorted according to the input sorted ids.List<ResourceChangeLogRecord>
changes(int resourceCount, Instant fromLastModified, Long afterResourceId, String resourceTypeName)
Fetch up to resourceCount records from the RESOURCE_CHANGE_LOG tableprotected List<Resource>
convertResourceDTOList(List<Resource> resourceDTOList, Class<? extends Resource> resourceType, List<String> elements)
Converts the passed Resource Data Transfer Object collection to a collection of FHIR Resource objects.protected <T extends Resource>
List<T>convertResourceDTOList(List<Resource> resourceDTOList, Class<T> resourceType)
Converts the passed Resource Data Transfer Object collection to a collection of FHIR Resource objects.protected List<Resource>
convertResourceDTOListOld(List<Resource> resourceDTOList, Class<? extends Resource> resourceType)
Converts the passed Resource Data Transfer Object collection to a collection of FHIR Resource objects.<T extends Resource>
SingleResourceResult<T>create(FHIRPersistenceContext context, T resource)
Stores a new FHIR Resource in the datastore.<T extends Resource>
SingleResourceResult<T>delete(FHIRPersistenceContext context, Class<T> resourceType, String logicalId)
Deletes the specified FHIR Resource from the datastore.void
doCachePrefill(Connection connection)
Prefill the cachesResourceEraseRecord
erase(EraseDTO eraseDto)
Erases part or a whole of a resource in the data layerResourcePayload
fetchResourcePayloads(Class<? extends Resource> resourceType, Instant fromLastModified, Instant toLastModified, Function<ResourcePayload,Boolean> processor)
Special function for high speed export of resource payloads.String
generateResourceId()
Generates a resource ID.OperationOutcome
getHealth()
Returns an OperationOutcome indicating the current status of the persistence store / backendString
getSchemaForRequestContext(Connection connection)
Get the schema name for the current request contextFHIRPersistenceTransaction
getTransaction()
Returns a FHIRPersistenceTransaction object associated with the persistence layer implementation in use.<T extends Resource>
MultiResourceResult<T>history(FHIRPersistenceContext context, Class<T> resourceType, String logicalId)
Retrieves all of the versions of the specified FHIR Resource.boolean
isDeleteSupported()
Returns true iff the persistence layer implementation supports the "delete" operation.boolean
isReindexSupported()
Returns true iff the persistence layer implementation supports the "reindex" special operationboolean
isTransactional()
Returns true iff the persistence layer implementation supports transactions.MultiResourceResult<Resource>
newSearch(FHIRPersistenceContext context, Class<? extends Resource> resourceType)
Search query implementation based on the 1385 new query builder.void
persistResourceTokenValueRecords(Collection<ResourceTokenValueRec> records, Collection<ResourceProfileRec> profileRecs, Collection<ResourceTokenValueRec> tagRecs, Collection<ResourceTokenValueRec> securityRecs)
Called just prior to commit so that we can persist all the token value records that have been accumulated during the transaction.<T extends Resource>
SingleResourceResult<T>read(FHIRPersistenceContext context, Class<T> resourceType, String logicalId)
Retrieves the most recent version of a FHIR Resource from the datastore.int
reindex(FHIRPersistenceContext context, OperationOutcome.Builder operationOutcomeResult, Instant tstamp, List<Long> indexIds, String resourceLogicalId)
Initiates reindexing for either a specified list of index IDs, or a randomly chosen resource.List<Long>
retrieveIndex(int count, Instant notModifiedAfter, Long afterIndexId, String resourceTypeName)
Retrieves a list of index IDs available for reindexing.protected UserTransaction
retrieveUserTransaction(String jndiName)
Retrieves (via a JNDI lookup) a reference to the UserTransaction.MultiResourceResult<Resource>
search(FHIRPersistenceContext context, Class<? extends Resource> resourceType)
Performs a search on the specified target resource type using the specified search parameters.<T extends Resource>
SingleResourceResult<T>update(FHIRPersistenceContext context, String logicalId, T resource)
Updates an existing FHIR Resource by storing a new version in the datastore.<T extends Resource>
voidupdateParameters(ResourceIndexRecord rir, Class<T> resourceTypeClass, Resource existingResourceDTO, ReindexResourceDAO reindexDAO, OperationOutcome.Builder operationOutcomeResult)
Update the parameters for the resource described by the given DTO<T extends Resource>
SingleResourceResult<T>vread(FHIRPersistenceContext context, Class<T> resourceType, String logicalId, String versionId)
Retrieves a specific version of a FHIR Resource from the datastore.-
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.FHIRPersistence
isChangesSupported
-
-
-
-
Field Detail
-
TXN_JNDI_NAME
protected static final String TXN_JNDI_NAME
- See Also:
- Constant Field Values
-
TRX_SYNCH_REG_JNDI_NAME
public static final String TRX_SYNCH_REG_JNDI_NAME
- See Also:
- Constant Field Values
-
userTransaction
protected UserTransaction userTransaction
-
updateCreateEnabled
protected Boolean updateCreateEnabled
-
-
Constructor Detail
-
FHIRPersistenceJDBCImpl
public FHIRPersistenceJDBCImpl(FHIRPersistenceJDBCCache cache) throws Exception
Constructor for use when running as web application in WLP.- Throws:
Exception
-
FHIRPersistenceJDBCImpl
public FHIRPersistenceJDBCImpl(Properties configProps, IConnectionProvider cp, FHIRPersistenceJDBCCache cache) throws Exception
Constructor for use when running standalone, outside of any web container. The IConnectionProvider should be a pooling implementation which supports an ITransactionProvider. Uses the default adapter for reading FHIR configurations, which works OK for unit-tests.- Parameters:
configProps
-cp
-- Throws:
Exception
-
FHIRPersistenceJDBCImpl
public FHIRPersistenceJDBCImpl(Properties configProps, IConnectionProvider cp, FHIRConfigProvider configProvider, FHIRPersistenceJDBCCache cache) throws Exception
Constructor for use when running standalone, outside of any web container. The IConnectionProvider should be a pooling implementation which supports an ITransactionProvider.- Parameters:
configProps
-cp
-configProvider
- adapter to provide access to FHIR configuration- Throws:
Exception
-
-
Method Detail
-
buildActionChain
protected Action buildActionChain()
Build a chain of actions we want to apply to new connections. Current the only action we need is setting the tenant if we're in multi-tenant mode.- Returns:
- the chain of actions to be applied
-
create
public <T extends Resource> SingleResourceResult<T> create(FHIRPersistenceContext context, T resource) throws FHIRPersistenceException
Description copied from interface:FHIRPersistence
Stores a new FHIR Resource in the datastore.- Specified by:
create
in interfaceFHIRPersistence
- Parameters:
context
- the FHIRPersistenceContext instance associated with the current requestresource
- the FHIR Resource instance to be created in the datastore- Returns:
- a SingleResourceResult with a copy of resource with Meta fields updated by the persistence layer and/or an OperationOutcome with hints, warnings, or errors related to the interaction
- Throws:
FHIRPersistenceException
-
update
public <T extends Resource> SingleResourceResult<T> update(FHIRPersistenceContext context, String logicalId, T resource) throws FHIRPersistenceException
Description copied from interface:FHIRPersistence
Updates an existing FHIR Resource by storing a new version in the datastore.- Specified by:
update
in interfaceFHIRPersistence
- Parameters:
context
- the FHIRPersistenceContext instance associated with the current requestlogicalId
- the logical id of the FHIR Resource to be updatedresource
- the new contents of the FHIR Resource to be stored- Returns:
- a SingleResourceResult with a copy of resource with fields updated by the persistence layer and/or an OperationOutcome with hints, warnings, or errors related to the interaction
- Throws:
FHIRPersistenceException
-
search
public MultiResourceResult<Resource> search(FHIRPersistenceContext context, Class<? extends Resource> resourceType) throws FHIRPersistenceException
Description copied from interface:FHIRPersistence
Performs a search on the specified target resource type using the specified search parameters.- Specified by:
search
in interfaceFHIRPersistence
- Parameters:
context
- the FHIRPersistenceContext instance associated with the current requestresourceType
- the resource type which is the target of the search- Returns:
- a MultiResourceResult with the list of FHIR Resources in the search result set and/or an OperationOutcome with hints, warnings, or errors related to the interaction
- Throws:
FHIRPersistenceException
-
newSearch
public MultiResourceResult<Resource> newSearch(FHIRPersistenceContext context, Class<? extends Resource> resourceType) throws FHIRPersistenceException
Search query implementation based on the 1385 new query builder.- Parameters:
context
-resourceType
-- Returns:
- Throws:
FHIRPersistenceException
-
delete
public <T extends Resource> SingleResourceResult<T> delete(FHIRPersistenceContext context, Class<T> resourceType, String logicalId) throws FHIRPersistenceException
Description copied from interface:FHIRPersistence
Deletes the specified FHIR Resource from the datastore.- Specified by:
delete
in interfaceFHIRPersistence
- Parameters:
context
- the FHIRPersistenceContext instance associated with the current requestresourceType
- The type of FHIR Resource to be deleted.logicalId
- the logical id of the FHIR Resource to be deleted- Returns:
- a SingleResourceResult with the FHIR Resource that was deleted or null if the specified resource doesn't exist and/or an OperationOutcome with hints, warnings, or errors related to the interaction
- Throws:
FHIRPersistenceException
-
read
public <T extends Resource> SingleResourceResult<T> read(FHIRPersistenceContext context, Class<T> resourceType, String logicalId) throws FHIRPersistenceException
Description copied from interface:FHIRPersistence
Retrieves the most recent version of a FHIR Resource from the datastore.- Specified by:
read
in interfaceFHIRPersistence
- Parameters:
context
- the FHIRPersistenceContext instance associated with the current requestresourceType
- the resource type of the Resource instance to be retrievedlogicalId
- the logical id of the Resource instance to be retrieved- Returns:
- a SingleResourceResult with the FHIR Resource that was retrieved from the datastore and/or an OperationOutcome with hints, warnings, or errors related to the interaction
- Throws:
FHIRPersistenceResourceDeletedException
- if the resource being read is currently in a deleted state and FHIRPersistenceContext.includeDeleted() is set to falseFHIRPersistenceException
-
history
public <T extends Resource> MultiResourceResult<T> history(FHIRPersistenceContext context, Class<T> resourceType, String logicalId) throws FHIRPersistenceException
Description copied from interface:FHIRPersistence
Retrieves all of the versions of the specified FHIR Resource.- Specified by:
history
in interfaceFHIRPersistence
- Parameters:
context
- the FHIRPersistenceContext instance associated with the current requestresourceType
- the resource type of the Resource instances to be retrievedlogicalId
- the logical id of the Resource instances to be retrieved- Returns:
- a MultiResourceResult with a list containing the available versions of the specified FHIR Resource and/or an OperationOutcome with hints, warnings, or errors related to the interaction
- Throws:
FHIRPersistenceException
-
vread
public <T extends Resource> SingleResourceResult<T> vread(FHIRPersistenceContext context, Class<T> resourceType, String logicalId, String versionId) throws FHIRPersistenceException
Description copied from interface:FHIRPersistence
Retrieves a specific version of a FHIR Resource from the datastore.- Specified by:
vread
in interfaceFHIRPersistence
- Parameters:
context
- the FHIRPersistenceContext instance associated with the current requestresourceType
- the resource type of the Resource instance to be retrievedlogicalId
- the logical id of the Resource instance to be retrievedversionId
- the version of the Resource instance to be retrieved- Returns:
- a SingleResourceResult with the FHIR Resource that was retrieved from the datastore and/or an OperationOutcome with hints, warnings, or errors related to the interaction
- Throws:
FHIRPersistenceResourceDeletedException
- if the resource being read is currently in a deleted state and FHIRPersistenceContext.includeDeleted() is set to falseFHIRPersistenceException
-
buildSortedResourceDTOList
protected List<Resource> buildSortedResourceDTOList(ResourceDAO resourceDao, Class<? extends Resource> resourceType, List<Long> sortedIdList) throws FHIRException, FHIRPersistenceException, IOException
This method takes the passed list of sorted Resource ids, acquires the ResourceDTO corresponding to each id, and returns those ResourceDTOs in a List, sorted according to the input sorted ids.- Parameters:
resourceDao
- - The resource DAO.resourceType
- - The type of Resource that each id in the passed list represents.sortedIdList
- - A list of Resource ids representing the proper sort order for the list of Resources to be returned.- Returns:
- List
- A list of ResourcesDTOs of the passed resourceType, sorted according the order of ids in the passed sortedIdList. - Throws:
FHIRPersistenceException
IOException
FHIRException
-
convertResourceDTOList
protected List<Resource> convertResourceDTOList(List<Resource> resourceDTOList, Class<? extends Resource> resourceType, List<String> elements) throws FHIRException, IOException
Converts the passed Resource Data Transfer Object collection to a collection of FHIR Resource objects.- Parameters:
resourceDTOList
-resourceType
-- Returns:
- Throws:
FHIRException
IOException
-
addCompartmentParams
protected void addCompartmentParams(List<ExtractedParameterValue> allParameters, Resource fhirResource) throws FHIRSearchException
Augment the given allParameters list with ibm-internal parameters that represent relationships between the fhirResource to its compartments. These parameter values are subsequently used to improve the performance of compartment-based FHIR search queries. SeeCompartmentUtil.makeCompartmentParamName(String)
for details on how the parameter name is composed for each relationship.- Parameters:
allParameters
-- Throws:
FHIRSearchException
-
getHealth
public OperationOutcome getHealth() throws FHIRPersistenceException
Description copied from interface:FHIRPersistence
Returns an OperationOutcome indicating the current status of the persistence store / backend- Specified by:
getHealth
in interfaceFHIRPersistence
- Returns:
- An OperationOutcome with a list of 0 or more OperationalOutcomeIssue indicating the status of the underlying datastore
- Throws:
FHIRPersistenceException
-
retrieveUserTransaction
protected UserTransaction retrieveUserTransaction(String jndiName)
Retrieves (via a JNDI lookup) a reference to the UserTransaction. If the JNDI lookup fails, we'll assume that we're not running inside the container.
-
convertResourceDTOList
protected <T extends Resource> List<T> convertResourceDTOList(List<Resource> resourceDTOList, Class<T> resourceType) throws FHIRException, IOException
Converts the passed Resource Data Transfer Object collection to a collection of FHIR Resource objects.- Parameters:
resourceDTOList
-resourceType
-- Returns:
- Throws:
FHIRException
IOException
-
convertResourceDTOListOld
protected List<Resource> convertResourceDTOListOld(List<Resource> resourceDTOList, Class<? extends Resource> resourceType) throws FHIRException, IOException
Converts the passed Resource Data Transfer Object collection to a collection of FHIR Resource objects.- Parameters:
resourceDTOList
-resourceType
-- Returns:
- Throws:
FHIRException
IOException
-
isTransactional
public boolean isTransactional()
Description copied from interface:FHIRPersistence
Returns true iff the persistence layer implementation supports transactions.- Specified by:
isTransactional
in interfaceFHIRPersistence
-
getTransaction
public FHIRPersistenceTransaction getTransaction()
Description copied from interface:FHIRPersistence
Returns a FHIRPersistenceTransaction object associated with the persistence layer implementation in use. This can then be used to control transactional boundaries.- Specified by:
getTransaction
in interfaceFHIRPersistence
-
isDeleteSupported
public boolean isDeleteSupported()
Description copied from interface:FHIRPersistence
Returns true iff the persistence layer implementation supports the "delete" operation.- Specified by:
isDeleteSupported
in interfaceFHIRPersistence
-
getSchemaForRequestContext
public String getSchemaForRequestContext(Connection connection) throws FHIRPersistenceDBConnectException
Description copied from interface:SchemaNameSupplier
Get the schema name for the current request context- Specified by:
getSchemaForRequestContext
in interfaceSchemaNameSupplier
- Parameters:
connection
- the connection for which we want to obtain the schema name- Returns:
- the main schema name to use for the given connection
- Throws:
FHIRPersistenceDBConnectException
-
doCachePrefill
public void doCachePrefill(Connection connection) throws FHIRPersistenceException
Prefill the caches- Throws:
FHIRPersistenceException
-
isReindexSupported
public boolean isReindexSupported()
Description copied from interface:FHIRPersistence
Returns true iff the persistence layer implementation supports the "reindex" special operation- Specified by:
isReindexSupported
in interfaceFHIRPersistence
- Returns:
-
reindex
public int reindex(FHIRPersistenceContext context, OperationOutcome.Builder operationOutcomeResult, Instant tstamp, List<Long> indexIds, String resourceLogicalId) throws FHIRPersistenceException
Description copied from interface:FHIRPersistence
Initiates reindexing for either a specified list of index IDs, or a randomly chosen resource. The number of resources processed is returned. This can be used by a controller to continue processing until everything is complete.- Specified by:
reindex
in interfaceFHIRPersistence
- Parameters:
context
- the FHIRPersistenceContext instance associated with the current request.operationOutcomeResult
- accumulate issues in thisOperationOutcome.Builder
tstamp
- only reindex resources with a reindex_tstamp less than thisindexIds
- list of index IDs of resources to reindex, or nullresourceLogicalId
- resourceType/logicalId value of a specific resource to reindex, or null; this parameter is ignored if the indexIds parameter value is non-null- Returns:
- count of the number of resources reindexed by this call
- Throws:
FHIRPersistenceException
-
updateParameters
public <T extends Resource> void updateParameters(ResourceIndexRecord rir, Class<T> resourceTypeClass, Resource existingResourceDTO, ReindexResourceDAO reindexDAO, OperationOutcome.Builder operationOutcomeResult) throws Exception
Update the parameters for the resource described by the given DTO- Type Parameters:
T
-- Parameters:
rir
- the resource index recordresourceTypeClass
- the resource type classexistingResourceDTO
- the existing resource DTOreindexDAO
- the reindex resource DAOoperationOutcomeResult
- the operation outcome result- Throws:
Exception
-
generateResourceId
public String generateResourceId()
Description copied from interface:FHIRPersistence
Generates a resource ID.- Specified by:
generateResourceId
in interfaceFHIRPersistence
- Returns:
- resource ID
-
persistResourceTokenValueRecords
public void persistResourceTokenValueRecords(Collection<ResourceTokenValueRec> records, Collection<ResourceProfileRec> profileRecs, Collection<ResourceTokenValueRec> tagRecs, Collection<ResourceTokenValueRec> securityRecs) throws FHIRPersistenceException
Called just prior to commit so that we can persist all the token value records that have been accumulated during the transaction. This collection therefore contains multiple resource types, which have to be processed separately.- Parameters:
records
-profileRecs
-tagRecs
-securityRecs
-- Throws:
FHIRPersistenceException
-
fetchResourcePayloads
public ResourcePayload fetchResourcePayloads(Class<? extends Resource> resourceType, Instant fromLastModified, Instant toLastModified, Function<ResourcePayload,Boolean> processor) throws FHIRPersistenceException
Description copied from interface:FHIRPersistence
Special function for high speed export of resource payloads. The process function must process the InputStream before returning. Result processing will be stopped if the process function returns Boolean FALSE.- Specified by:
fetchResourcePayloads
in interfaceFHIRPersistence
- Parameters:
resourceType
- the resource type which is the target of the searchfromLastModified
- start reading from this timestamptoLastModified
- do not read beyond this timestampprocessor
- function to process each payload record- Returns:
- the last ResourcePayload processed, or null if no data was found
- Throws:
FHIRPersistenceException
-
changes
public List<ResourceChangeLogRecord> changes(int resourceCount, Instant fromLastModified, Long afterResourceId, String resourceTypeName) throws FHIRPersistenceException
Description copied from interface:FHIRPersistence
Fetch up to resourceCount records from the RESOURCE_CHANGE_LOG table- Specified by:
changes
in interfaceFHIRPersistence
- Parameters:
resourceCount
- the max number of resource change records to fetchfromLastModified
- filter records with record.lastUpdate >= fromLastModified. Optional.afterResourceId
- filter records with record.resourceId > afterResourceId. Optional.resourceTypeName
- filter records with record.resourceType = resourceTypeName. Optional.- Returns:
- a list containing up to resourceCount elements describing resources which have changed
- Throws:
FHIRPersistenceException
-
erase
public ResourceEraseRecord erase(EraseDTO eraseDto) throws FHIRPersistenceException
Description copied from interface:FHIRPersistence
Erases part or a whole of a resource in the data layer- Specified by:
erase
in interfaceFHIRPersistence
- Parameters:
eraseDto
- the details of the user input- Returns:
- a record indicating the success or partial success of the erase
- Throws:
FHIRPersistenceException
-
retrieveIndex
public List<Long> retrieveIndex(int count, Instant notModifiedAfter, Long afterIndexId, String resourceTypeName) throws FHIRPersistenceException
Description copied from interface:FHIRPersistence
Retrieves a list of index IDs available for reindexing.- Specified by:
retrieveIndex
in interfaceFHIRPersistence
- Parameters:
count
- the maximum nuber of index IDs to retrievenotModifiedAfter
- only retrieve index IDs for resources not last updated after the specified timestampafterIndexId
- retrieve index IDs starting after this specified index ID, or null to start with first index IDresourceTypeName
- the resource type of index IDs to return, or null- Returns:
- list of index IDs available for reindexing
- Throws:
FHIRPersistenceException
-
-