Class 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.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected void addCanonicalCompositeParam​(List<ExtractedParameterValue> allParameters)
      Augment the given allParameters list with ibm-internal parameters that represent the relationship between the url and version parameters.
      protected void addCompartmentParams​(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 Action buildActionChain()
      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)  
      void doCachePrefill​(Connection connection)
      Prefill the caches
      com.ibm.fhir.persistence.ResourceEraseRecord erase​(com.ibm.fhir.persistence.erase.EraseDTO eraseDto)  
      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)  
      String generateResourceId()  
      com.ibm.fhir.model.resource.OperationOutcome getHealth()  
      String getSchemaForRequestContext​(Connection connection)
      Get the schema name for the current request context
      com.ibm.fhir.persistence.FHIRPersistenceTransaction getTransaction()  
      <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)  
      boolean isDeleteSupported()  
      boolean isReindexSupported()  
      boolean isTransactional()  
      boolean isUpdateCreateEnabled()  
      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 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)  
      int reindex​(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 UserTransaction retrieveUserTransaction​(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>
      void
      updateParameters​(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)  
      • Methods inherited from interface com.ibm.fhir.persistence.FHIRPersistence

        isChangesSupported
    • 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:
        create in interface com.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:
        createWithMeta in interface com.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:
        update in interface com.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:
        updateWithMeta in interface com.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.FHIRPersistenceException
        Search query implementation based on the 1385 new query builder.
        Specified by:
        search in interface com.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:
        delete in interface com.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:
        read in interface com.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 false
        com.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:
        history in interface com.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:
        vread in interface com.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 false
        com.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.FHIRPersistenceException
        IOException
        com.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.FHIRException
        IOException
      • 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. See CompartmentUtil.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. See CompartmentUtil.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:
        getHealth in interface com.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.FHIRException
        IOException
      • 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.FHIRException
        IOException
      • isTransactional

        public boolean isTransactional()
        Specified by:
        isTransactional in interface com.ibm.fhir.persistence.FHIRPersistence
      • getTransaction

        public com.ibm.fhir.persistence.FHIRPersistenceTransaction getTransaction()
        Specified by:
        getTransaction in interface com.ibm.fhir.persistence.FHIRPersistence
      • isDeleteSupported

        public boolean isDeleteSupported()
        Specified by:
        isDeleteSupported in interface com.ibm.fhir.persistence.FHIRPersistence
      • 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:
        isReindexSupported in interface com.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:
        reindex in interface com.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 record
        resourceTypeClass - the resource type class
        existingResourceDTO - the existing resource DTO
        reindexDAO - the reindex resource DAO
        operationOutcomeResult - the operation outcome result
        Throws:
        Exception
      • generateResourceId

        public String generateResourceId()
        Specified by:
        generateResourceId in interface com.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:
        fetchResourcePayloads in interface com.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:
        changes in interface com.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:
        erase in interface com.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:
        retrieveIndex in interface com.ibm.fhir.persistence.FHIRPersistence
        Throws:
        com.ibm.fhir.persistence.exception.FHIRPersistenceException
      • isUpdateCreateEnabled

        public boolean isUpdateCreateEnabled()
        Specified by:
        isUpdateCreateEnabled in interface com.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:
        storePayload in interface com.ibm.fhir.persistence.FHIRPersistence
        Throws:
        com.ibm.fhir.persistence.exception.FHIRPersistenceException