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 StringTRX_SYNCH_REG_JNDI_NAMEprotected static StringTXN_JNDI_NAMEprotected BooleanupdateCreateEnabledprotected UserTransactionuserTransaction
-
Constructor Summary
Constructors Constructor Description FHIRPersistenceJDBCImpl()Constructor for use when running as web application in WLP.FHIRPersistenceJDBCImpl(Properties configProps, IConnectionProvider cp)Constructor for use when running standalone, outside of any web container.FHIRPersistenceJDBCImpl(Properties configProps, IConnectionProvider cp, FHIRConfigProvider configProvider)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 ActionbuildActionChain()Build a chain of actions we want to apply to new connections.protected List<Resource>buildSortedFhirResources(ResourceDAO resourceDao, FHIRPersistenceContext context, Class<? extends Resource> resourceType, List<Long> sortedIdList, List<String> elements)This method takes the passed list of sorted Resource ids, acquires the Resource corresponding to each id, and returns those Resources in a List, sorted according to the input sorted ids.protected 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.StringgenerateResourceId()Generates a resource ID.OperationOutcomegetHealth()Returns an OperationOutcome indicating the current status of the persistence store / backendStringgetSchemaForRequestContext(Connection connection)Get the schema name for the current request contextFHIRPersistenceTransactiongetTransaction()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.booleanisDeleteSupported()Returns true iff the persistence layer implementation supports the "delete" operation.booleanisTransactional()Returns true iff the persistence layer implementation supports transactions.<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.protected UserTransactionretrieveUserTransaction(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>
SingleResourceResult<T>vread(FHIRPersistenceContext context, Class<T> resourceType, String logicalId, String versionId)Retrieves a specific version of a FHIR Resource from the datastore.
-
-
-
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() throws ExceptionConstructor for use when running as web application in WLP.- Throws:
Exception
-
FHIRPersistenceJDBCImpl
public FHIRPersistenceJDBCImpl(Properties configProps, IConnectionProvider cp) 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) 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:FHIRPersistenceStores a new FHIR Resource in the datastore.- Specified by:
createin 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:FHIRPersistenceUpdates an existing FHIR Resource by storing a new version in the datastore.- Specified by:
updatein 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:FHIRPersistencePerforms a search on the specified target resource type using the specified search parameters.- Specified by:
searchin 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
-
delete
public <T extends Resource> SingleResourceResult<T> delete(FHIRPersistenceContext context, Class<T> resourceType, String logicalId) throws FHIRPersistenceException
Description copied from interface:FHIRPersistenceDeletes the specified FHIR Resource from the datastore.- Specified by:
deletein 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:FHIRPersistenceRetrieves the most recent version of a FHIR Resource from the datastore.- Specified by:
readin 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:FHIRPersistenceRetrieves all of the versions of the specified FHIR Resource.- Specified by:
historyin 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:FHIRPersistenceRetrieves a specific version of a FHIR Resource from the datastore.- Specified by:
vreadin 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
-
buildSortedFhirResources
protected List<Resource> buildSortedFhirResources(ResourceDAO resourceDao, FHIRPersistenceContext context, Class<? extends Resource> resourceType, List<Long> sortedIdList, List<String> elements) throws FHIRException, FHIRPersistenceException, IOException
This method takes the passed list of sorted Resource ids, acquires the Resource corresponding to each id, and returns those Resources in a List, sorted according to the input sorted ids.- Parameters:
context- - The FHIR persistence context for the current request.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.elements- - An optional list of element names to include in the resources. If null, filtering will be skipped.- Returns:
- List
- A list of Resources of the passed resourceType, sorted according the order of ids in the passed sortedIdList. - Throws:
FHIRPersistenceExceptionIOExceptionFHIRException
-
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:
FHIRExceptionIOException
-
getHealth
public OperationOutcome getHealth() throws FHIRPersistenceException
Description copied from interface:FHIRPersistenceReturns an OperationOutcome indicating the current status of the persistence store / backend- Specified by:
getHealthin 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:
FHIRExceptionIOException
-
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:
FHIRExceptionIOException
-
isTransactional
public boolean isTransactional()
Description copied from interface:FHIRPersistenceReturns true iff the persistence layer implementation supports transactions.- Specified by:
isTransactionalin interfaceFHIRPersistence
-
getTransaction
public FHIRPersistenceTransaction getTransaction()
Description copied from interface:FHIRPersistenceReturns a FHIRPersistenceTransaction object associated with the persistence layer implementation in use. This can then be used to control transactional boundaries.- Specified by:
getTransactionin interfaceFHIRPersistence
-
isDeleteSupported
public boolean isDeleteSupported()
Description copied from interface:FHIRPersistenceReturns true iff the persistence layer implementation supports the "delete" operation.- Specified by:
isDeleteSupportedin interfaceFHIRPersistence
-
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
-
generateResourceId
public String generateResourceId()
Description copied from interface:FHIRPersistenceGenerates a resource ID.- Specified by:
generateResourceIdin interfaceFHIRPersistence- Returns:
- resource ID
-
-