Class FHIRPersistenceJDBCImpl
- java.lang.Object
-
- com.ibm.fhir.persistence.jdbc.impl.FHIRPersistenceJDBCImpl
-
- All Implemented Interfaces:
com.ibm.fhir.persistence.FHIRPersistence,SchemaNameSupplier
public class FHIRPersistenceJDBCImpl extends Object implements com.ibm.fhir.persistence.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 StringTRX_SYNCH_REG_JNDI_NAMEprotected static StringTXN_JNDI_NAMEprotected BooleanupdateCreateEnabledprotected UserTransactionuserTransaction
-
Constructor Summary
Constructors Constructor Description FHIRPersistenceJDBCImpl(FHIRPersistenceJDBCCache cache, com.ibm.fhir.persistence.payload.FHIRPayloadPersistence payloadPersistence)Constructor for use when running as web application in WLP.FHIRPersistenceJDBCImpl(Properties configProps, com.ibm.fhir.database.utils.api.IConnectionProvider cp, com.ibm.fhir.config.FHIRConfigProvider configProvider, FHIRPersistenceJDBCCache cache)Constructor for use when running standalone, outside of any web container.FHIRPersistenceJDBCImpl(Properties configProps, com.ibm.fhir.database.utils.api.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 voidaddCanonicalCompositeParam(List<ExtractedParameterValue> allParameters)Augment the given allParameters list with ibm-internal parameters that represent the relationship between the url and version parameters.protected voidaddCompartmentParams(List<ExtractedParameterValue> allParameters, com.ibm.fhir.model.resource.Resource fhirResource)Augment the given allParameters list with ibm-internal parameters that represent relationships between the fhirResource to its compartments.protected ActionbuildActionChain()Build a chain of actions we want to apply to new connections.protected List<Resource>buildSortedResourceDTOList(ResourceDAO resourceDao, Class<? extends com.ibm.fhir.model.resource.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<com.ibm.fhir.persistence.ResourceChangeLogRecord>changes(int resourceCount, Instant fromLastModified, Long afterResourceId, String resourceTypeName)protected List<com.ibm.fhir.model.resource.Resource>convertResourceDTOList(ResourceDAO resourceDao, List<Resource> resourceDTOList, Class<? extends com.ibm.fhir.model.resource.Resource> resourceType, List<String> elements)Converts the passed Resource Data Transfer Object collection to a collection of FHIR Resource objects.protected <T extends com.ibm.fhir.model.resource.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<com.ibm.fhir.model.resource.Resource>convertResourceDTOListOld(List<Resource> resourceDTOList, Class<? extends com.ibm.fhir.model.resource.Resource> resourceType)Converts the passed Resource Data Transfer Object collection to a collection of FHIR Resource objects.<T extends com.ibm.fhir.model.resource.Resource>
com.ibm.fhir.persistence.SingleResourceResult<T>create(com.ibm.fhir.persistence.context.FHIRPersistenceContext context, T resource)<T extends com.ibm.fhir.model.resource.Resource>
com.ibm.fhir.persistence.SingleResourceResult<T>createWithMeta(com.ibm.fhir.persistence.context.FHIRPersistenceContext context, T updatedResource)<T extends com.ibm.fhir.model.resource.Resource>
com.ibm.fhir.persistence.SingleResourceResult<T>delete(com.ibm.fhir.persistence.context.FHIRPersistenceContext context, Class<T> resourceType, String logicalId)voiddoCachePrefill(Connection connection)Prefill the cachescom.ibm.fhir.persistence.ResourceEraseRecorderase(com.ibm.fhir.persistence.erase.EraseDTO eraseDto)com.ibm.fhir.persistence.ResourcePayloadfetchResourcePayloads(Class<? extends com.ibm.fhir.model.resource.Resource> resourceType, Instant fromLastModified, Instant toLastModified, Function<com.ibm.fhir.persistence.ResourcePayload,Boolean> processor)StringgenerateResourceId()com.ibm.fhir.model.resource.OperationOutcomegetHealth()StringgetSchemaForRequestContext(Connection connection)Get the schema name for the current request contextcom.ibm.fhir.persistence.FHIRPersistenceTransactiongetTransaction()<T extends com.ibm.fhir.model.resource.Resource>
com.ibm.fhir.persistence.MultiResourceResult<T>history(com.ibm.fhir.persistence.context.FHIRPersistenceContext context, Class<T> resourceType, String logicalId)booleanisDeleteSupported()booleanisReindexSupported()booleanisTransactional()booleanisUpdateCreateEnabled()voidpersistResourceTokenValueRecords(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 com.ibm.fhir.model.resource.Resource>
com.ibm.fhir.persistence.SingleResourceResult<T>read(com.ibm.fhir.persistence.context.FHIRPersistenceContext context, Class<T> resourceType, String logicalId)intreindex(com.ibm.fhir.persistence.context.FHIRPersistenceContext context, com.ibm.fhir.model.resource.OperationOutcome.Builder operationOutcomeResult, Instant tstamp, List<Long> indexIds, String resourceLogicalId)List<Long>retrieveIndex(int count, Instant notModifiedAfter, Long afterIndexId, String resourceTypeName)protected UserTransactionretrieveUserTransaction(String jndiName)Retrieves (via a JNDI lookup) a reference to the UserTransaction.com.ibm.fhir.persistence.MultiResourceResult<com.ibm.fhir.model.resource.Resource>search(com.ibm.fhir.persistence.context.FHIRPersistenceContext context, Class<? extends com.ibm.fhir.model.resource.Resource> resourceType)Search query implementation based on the 1385 new query builder.Future<com.ibm.fhir.persistence.payload.PayloadKey>storePayload(com.ibm.fhir.model.resource.Resource resource, String logicalId, int newVersionNumber)<T extends com.ibm.fhir.model.resource.Resource>
com.ibm.fhir.persistence.SingleResourceResult<T>update(com.ibm.fhir.persistence.context.FHIRPersistenceContext context, String logicalId, T resource)<T extends com.ibm.fhir.model.resource.Resource>
voidupdateParameters(ResourceIndexRecord rir, Class<T> resourceTypeClass, Resource existingResourceDTO, ReindexResourceDAO reindexDAO, com.ibm.fhir.model.resource.OperationOutcome.Builder operationOutcomeResult)Update the parameters for the resource described by the given DTO<T extends com.ibm.fhir.model.resource.Resource>
com.ibm.fhir.persistence.SingleResourceResult<T>updateWithMeta(com.ibm.fhir.persistence.context.FHIRPersistenceContext context, T resource)<T extends com.ibm.fhir.model.resource.Resource>
com.ibm.fhir.persistence.SingleResourceResult<T>vread(com.ibm.fhir.persistence.context.FHIRPersistenceContext context, Class<T> resourceType, String logicalId, String versionId)
-
-
-
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, com.ibm.fhir.persistence.payload.FHIRPayloadPersistence payloadPersistence) throws Exception
Constructor for use when running as web application in WLP.- Throws:
Exception
-
FHIRPersistenceJDBCImpl
public FHIRPersistenceJDBCImpl(Properties configProps, com.ibm.fhir.database.utils.api.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, com.ibm.fhir.database.utils.api.IConnectionProvider cp, com.ibm.fhir.config.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 com.ibm.fhir.model.resource.Resource> com.ibm.fhir.persistence.SingleResourceResult<T> create(com.ibm.fhir.persistence.context.FHIRPersistenceContext context, T resource) throws com.ibm.fhir.persistence.exception.FHIRPersistenceException- Specified by:
createin interfacecom.ibm.fhir.persistence.FHIRPersistence- Throws:
com.ibm.fhir.persistence.exception.FHIRPersistenceException
-
createWithMeta
public <T extends com.ibm.fhir.model.resource.Resource> com.ibm.fhir.persistence.SingleResourceResult<T> createWithMeta(com.ibm.fhir.persistence.context.FHIRPersistenceContext context, T updatedResource) throws com.ibm.fhir.persistence.exception.FHIRPersistenceException- Specified by:
createWithMetain interfacecom.ibm.fhir.persistence.FHIRPersistence- Throws:
com.ibm.fhir.persistence.exception.FHIRPersistenceException
-
update
public <T extends com.ibm.fhir.model.resource.Resource> com.ibm.fhir.persistence.SingleResourceResult<T> update(com.ibm.fhir.persistence.context.FHIRPersistenceContext context, String logicalId, T resource) throws com.ibm.fhir.persistence.exception.FHIRPersistenceException- Specified by:
updatein interfacecom.ibm.fhir.persistence.FHIRPersistence- Throws:
com.ibm.fhir.persistence.exception.FHIRPersistenceException
-
updateWithMeta
public <T extends com.ibm.fhir.model.resource.Resource> com.ibm.fhir.persistence.SingleResourceResult<T> updateWithMeta(com.ibm.fhir.persistence.context.FHIRPersistenceContext context, T resource) throws com.ibm.fhir.persistence.exception.FHIRPersistenceException- Specified by:
updateWithMetain interfacecom.ibm.fhir.persistence.FHIRPersistence- Throws:
com.ibm.fhir.persistence.exception.FHIRPersistenceException
-
search
public com.ibm.fhir.persistence.MultiResourceResult<com.ibm.fhir.model.resource.Resource> search(com.ibm.fhir.persistence.context.FHIRPersistenceContext context, Class<? extends com.ibm.fhir.model.resource.Resource> resourceType) throws com.ibm.fhir.persistence.exception.FHIRPersistenceExceptionSearch query implementation based on the 1385 new query builder.- Specified by:
searchin interfacecom.ibm.fhir.persistence.FHIRPersistence- Parameters:
context-resourceType-- Returns:
- Throws:
com.ibm.fhir.persistence.exception.FHIRPersistenceException
-
delete
public <T extends com.ibm.fhir.model.resource.Resource> com.ibm.fhir.persistence.SingleResourceResult<T> delete(com.ibm.fhir.persistence.context.FHIRPersistenceContext context, Class<T> resourceType, String logicalId) throws com.ibm.fhir.persistence.exception.FHIRPersistenceException- Specified by:
deletein interfacecom.ibm.fhir.persistence.FHIRPersistence- Throws:
com.ibm.fhir.persistence.exception.FHIRPersistenceException
-
read
public <T extends com.ibm.fhir.model.resource.Resource> com.ibm.fhir.persistence.SingleResourceResult<T> read(com.ibm.fhir.persistence.context.FHIRPersistenceContext context, Class<T> resourceType, String logicalId) throws com.ibm.fhir.persistence.exception.FHIRPersistenceException- Specified by:
readin interfacecom.ibm.fhir.persistence.FHIRPersistence- Throws:
com.ibm.fhir.persistence.exception.FHIRPersistenceResourceDeletedException- if the resource being read is currently in a deleted state and FHIRPersistenceContext.includeDeleted() is set to falsecom.ibm.fhir.persistence.exception.FHIRPersistenceException
-
history
public <T extends com.ibm.fhir.model.resource.Resource> com.ibm.fhir.persistence.MultiResourceResult<T> history(com.ibm.fhir.persistence.context.FHIRPersistenceContext context, Class<T> resourceType, String logicalId) throws com.ibm.fhir.persistence.exception.FHIRPersistenceException- Specified by:
historyin interfacecom.ibm.fhir.persistence.FHIRPersistence- Throws:
com.ibm.fhir.persistence.exception.FHIRPersistenceException
-
vread
public <T extends com.ibm.fhir.model.resource.Resource> com.ibm.fhir.persistence.SingleResourceResult<T> vread(com.ibm.fhir.persistence.context.FHIRPersistenceContext context, Class<T> resourceType, String logicalId, String versionId) throws com.ibm.fhir.persistence.exception.FHIRPersistenceException- Specified by:
vreadin interfacecom.ibm.fhir.persistence.FHIRPersistence- Throws:
com.ibm.fhir.persistence.exception.FHIRPersistenceResourceDeletedException- if the resource being read is currently in a deleted state and FHIRPersistenceContext.includeDeleted() is set to falsecom.ibm.fhir.persistence.exception.FHIRPersistenceException
-
buildSortedResourceDTOList
protected List<Resource> buildSortedResourceDTOList(ResourceDAO resourceDao, Class<? extends com.ibm.fhir.model.resource.Resource> resourceType, List<Long> sortedIdList) throws com.ibm.fhir.exception.FHIRException, com.ibm.fhir.persistence.exception.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:
com.ibm.fhir.persistence.exception.FHIRPersistenceExceptionIOExceptioncom.ibm.fhir.exception.FHIRException
-
convertResourceDTOList
protected List<com.ibm.fhir.model.resource.Resource> convertResourceDTOList(ResourceDAO resourceDao, List<Resource> resourceDTOList, Class<? extends com.ibm.fhir.model.resource.Resource> resourceType, List<String> elements) throws com.ibm.fhir.exception.FHIRException, IOException
Converts the passed Resource Data Transfer Object collection to a collection of FHIR Resource objects.- Parameters:
resourceDTOList-resourceType-- Returns:
- Throws:
com.ibm.fhir.exception.FHIRExceptionIOException
-
addCompartmentParams
protected void addCompartmentParams(List<ExtractedParameterValue> allParameters, com.ibm.fhir.model.resource.Resource fhirResource) throws com.ibm.fhir.search.exception.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:
com.ibm.fhir.search.exception.FHIRSearchException
-
addCanonicalCompositeParam
protected void addCanonicalCompositeParam(List<ExtractedParameterValue> allParameters) throws com.ibm.fhir.search.exception.FHIRSearchException
Augment the given allParameters list with ibm-internal parameters that represent the relationship between the url and version parameters. These parameter values are subsequently used in canonical reference searches. SeeCompartmentUtil.makeCompartmentParamName(String)for details on how the parameter name is composed.- Parameters:
allParameters-- Throws:
com.ibm.fhir.search.exception.FHIRSearchException
-
getHealth
public com.ibm.fhir.model.resource.OperationOutcome getHealth() throws com.ibm.fhir.persistence.exception.FHIRPersistenceException- Specified by:
getHealthin interfacecom.ibm.fhir.persistence.FHIRPersistence- Throws:
com.ibm.fhir.persistence.exception.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 com.ibm.fhir.model.resource.Resource> List<T> convertResourceDTOList(List<Resource> resourceDTOList, Class<T> resourceType) throws com.ibm.fhir.exception.FHIRException, IOException
Converts the passed Resource Data Transfer Object collection to a collection of FHIR Resource objects.- Parameters:
resourceDTOList-resourceType-- Returns:
- Throws:
com.ibm.fhir.exception.FHIRExceptionIOException
-
convertResourceDTOListOld
protected List<com.ibm.fhir.model.resource.Resource> convertResourceDTOListOld(List<Resource> resourceDTOList, Class<? extends com.ibm.fhir.model.resource.Resource> resourceType) throws com.ibm.fhir.exception.FHIRException, IOException
Converts the passed Resource Data Transfer Object collection to a collection of FHIR Resource objects.- Parameters:
resourceDTOList-resourceType-- Returns:
- Throws:
com.ibm.fhir.exception.FHIRExceptionIOException
-
isTransactional
public boolean isTransactional()
- Specified by:
isTransactionalin interfacecom.ibm.fhir.persistence.FHIRPersistence
-
getTransaction
public com.ibm.fhir.persistence.FHIRPersistenceTransaction getTransaction()
- Specified by:
getTransactionin interfacecom.ibm.fhir.persistence.FHIRPersistence
-
isDeleteSupported
public boolean isDeleteSupported()
- Specified by:
isDeleteSupportedin interfacecom.ibm.fhir.persistence.FHIRPersistence
-
getSchemaForRequestContext
public String getSchemaForRequestContext(Connection connection) throws FHIRPersistenceDBConnectException
Description copied from interface:SchemaNameSupplierGet the schema name for the current request context- Specified by:
getSchemaForRequestContextin 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 com.ibm.fhir.persistence.exception.FHIRPersistenceException
Prefill the caches- Throws:
com.ibm.fhir.persistence.exception.FHIRPersistenceException
-
isReindexSupported
public boolean isReindexSupported()
- Specified by:
isReindexSupportedin interfacecom.ibm.fhir.persistence.FHIRPersistence
-
reindex
public int reindex(com.ibm.fhir.persistence.context.FHIRPersistenceContext context, com.ibm.fhir.model.resource.OperationOutcome.Builder operationOutcomeResult, Instant tstamp, List<Long> indexIds, String resourceLogicalId) throws com.ibm.fhir.persistence.exception.FHIRPersistenceException- Specified by:
reindexin interfacecom.ibm.fhir.persistence.FHIRPersistence- Throws:
com.ibm.fhir.persistence.exception.FHIRPersistenceException
-
updateParameters
public <T extends com.ibm.fhir.model.resource.Resource> void updateParameters(ResourceIndexRecord rir, Class<T> resourceTypeClass, Resource existingResourceDTO, ReindexResourceDAO reindexDAO, com.ibm.fhir.model.resource.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()
- Specified by:
generateResourceIdin interfacecom.ibm.fhir.persistence.FHIRPersistence
-
persistResourceTokenValueRecords
public void persistResourceTokenValueRecords(Collection<ResourceTokenValueRec> records, Collection<ResourceProfileRec> profileRecs, Collection<ResourceTokenValueRec> tagRecs, Collection<ResourceTokenValueRec> securityRecs) throws com.ibm.fhir.persistence.exception.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:
com.ibm.fhir.persistence.exception.FHIRPersistenceException
-
fetchResourcePayloads
public com.ibm.fhir.persistence.ResourcePayload fetchResourcePayloads(Class<? extends com.ibm.fhir.model.resource.Resource> resourceType, Instant fromLastModified, Instant toLastModified, Function<com.ibm.fhir.persistence.ResourcePayload,Boolean> processor) throws com.ibm.fhir.persistence.exception.FHIRPersistenceException
- Specified by:
fetchResourcePayloadsin interfacecom.ibm.fhir.persistence.FHIRPersistence- Throws:
com.ibm.fhir.persistence.exception.FHIRPersistenceException
-
changes
public List<com.ibm.fhir.persistence.ResourceChangeLogRecord> changes(int resourceCount, Instant fromLastModified, Long afterResourceId, String resourceTypeName) throws com.ibm.fhir.persistence.exception.FHIRPersistenceException
- Specified by:
changesin interfacecom.ibm.fhir.persistence.FHIRPersistence- Throws:
com.ibm.fhir.persistence.exception.FHIRPersistenceException
-
erase
public com.ibm.fhir.persistence.ResourceEraseRecord erase(com.ibm.fhir.persistence.erase.EraseDTO eraseDto) throws com.ibm.fhir.persistence.exception.FHIRPersistenceException- Specified by:
erasein interfacecom.ibm.fhir.persistence.FHIRPersistence- Throws:
com.ibm.fhir.persistence.exception.FHIRPersistenceException
-
retrieveIndex
public List<Long> retrieveIndex(int count, Instant notModifiedAfter, Long afterIndexId, String resourceTypeName) throws com.ibm.fhir.persistence.exception.FHIRPersistenceException
- Specified by:
retrieveIndexin interfacecom.ibm.fhir.persistence.FHIRPersistence- Throws:
com.ibm.fhir.persistence.exception.FHIRPersistenceException
-
isUpdateCreateEnabled
public boolean isUpdateCreateEnabled()
- Specified by:
isUpdateCreateEnabledin interfacecom.ibm.fhir.persistence.FHIRPersistence
-
storePayload
public Future<com.ibm.fhir.persistence.payload.PayloadKey> storePayload(com.ibm.fhir.model.resource.Resource resource, String logicalId, int newVersionNumber) throws com.ibm.fhir.persistence.exception.FHIRPersistenceException
- Specified by:
storePayloadin interfacecom.ibm.fhir.persistence.FHIRPersistence- Throws:
com.ibm.fhir.persistence.exception.FHIRPersistenceException
-
-