Class ResourceDAOImpl
- java.lang.Object
-
- com.ibm.fhir.persistence.jdbc.dao.impl.FHIRDbDAOImpl
-
- com.ibm.fhir.persistence.jdbc.dao.impl.ResourceDAOImpl
-
- All Implemented Interfaces:
FHIRDbDAO,ResourceDAO
- Direct Known Subclasses:
DerbyResourceDAO,PostgresResourceDAO,PostgresResourceNoProcDAO,ReindexResourceDAO
public class ResourceDAOImpl extends FHIRDbDAOImpl implements ResourceDAO
This Data Access Object implements the ResourceDAO interface for creating, updating, and retrieving rows in the IBM FHIR Server resource tables.
-
-
Field Summary
Fields Modifier and Type Field Description static StringDEFAULT_VALUE_REINDEX_TSTAMPstatic intIDX_DATAstatic intIDX_IS_DELETEDstatic intIDX_LAST_UPDATEDstatic intIDX_LOGICAL_IDstatic intIDX_LOGICAL_RESOURCE_IDstatic intIDX_RESOURCE_IDstatic intIDX_VERSION_ID
-
Constructor Summary
Constructors Constructor Description ResourceDAOImpl(Connection c, String schemaName, FHIRDbFlavor flavor, FHIRPersistenceJDBCCache cache, IResourceReferenceDAO rrd)Constructs a DAO instance for use outside a managed transaction (JEE) environmentResourceDAOImpl(Connection c, String schemaName, FHIRDbFlavor flavor, TransactionSynchronizationRegistry trxSynchRegistry, FHIRPersistenceJDBCCache cache, IResourceReferenceDAO rrd, ParameterTransactionDataImpl ptdi)Constructs a DAO instance suitable for acquiring connections from a JDBC Datasource object.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddResourceTypeCacheCandidate(String resourceType, Integer resourceTypeId)Adds a resource type/ resource id pair to a candidate collection for population into the ResourceTypesCache.protected ResourcecreateDTO(ResultSet resultSet)Creates and returns a Resource DTO based on the contents of the passed ResultSetprotected FHIRPersistenceJDBCCachegetCache()Getter for access to theFHIRPersistenceJDBCCachefrom subclassesprotected IResourceReferenceDAOgetResourceReferenceDAO()Getter for the IResourceReferenceDAO used by this ResourceDAO implementationprotected IntegergetResourceTypeIdFromCaches(String resourceType)protected StringgetSearchByIdsSql(String resourceType)protected ParameterTransactionDataImplgetTransactionData()Get the ParameterTransactionDataImpl held by this.List<Resource>history(String resourceType, String logicalId, Timestamp fromDateTime, int offset, int maxResults)Reads and returns all versions of the Resource with the passed logicalId, ordered by descending version id.inthistoryCount(String resourceType, String logicalId, Timestamp fromDateTime)Reads and returns the COUNT of all versions of the Resource with the passed logicalId.Resourceinsert(Resource resource, List<ExtractedParameterValue> parameters, ParameterDAO parameterDao)Inserts the passed Resource DTO and its associated search parameters to the appropriate FHIR resource tables.Resourceread(String logicalId, String resourceType)Reads and returns the latest version of the Resource with the passed logical id and resource type.Map<String,Integer>readAllResourceTypeNames()Reads all rows in the resource_types table and returns the data as a MapIntegerreadResourceTypeId(String resourceType)Reads the id associated with the name of the passed Resource type from the Resource_Types table.List<Resource>search(SqlQueryData queryData)Executes the search contained in the passed SqlQueryData, using it's encapsulated search string and bind variables.List<Resource>search(String sqlSelect)Executes the passed fully-formed SQL Select statement and returns the results If no matching resources are found, an empty collection is returned.List<Resource>searchByIds(String resourceType, List<Long> resourceIds)Searches for Resources that contain one of the passed ids.intsearchCount(SqlQueryData queryData)Executes a count query based on the data contained in the passed SqlQueryData, using it's encapsulated search string and bind variables.intsearchCount(String sqlSelectCount)Executes the passed fully-formed SQL Select COUNT statement and returns the integer count.List<Long>searchForIds(SqlQueryData queryData)This method supports the execution of a specialized query designed to return Resource ids, based on the contents of the passed select statement.List<String>searchStringValues(SqlQueryData queryData)Executes the search contained in the passed SqlQueryData, using it's encapsulated search string and bind variables.voidsetPersistenceContext(FHIRPersistenceContext context)Sets the current persistence contextResourceversionRead(String logicalId, String resourceType, int versionId)Reads and returns the version of the Resource with the passed logical id, resource type, and version id.-
Methods inherited from class com.ibm.fhir.persistence.jdbc.dao.impl.FHIRDbDAOImpl
buildExceptionWithIssue, buildFHIRPersistenceDBConnectException, cleanup, cleanup, createDTOs, getConnection, getFlavor, getSchemaName, isDb2Database, runCountQuery, runQuery, runQuery_STR_VALUES, severe, severe
-
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.jdbc.dao.api.FHIRDbDAO
getConnection, getFlavor, isDb2Database
-
-
-
-
Field Detail
-
DEFAULT_VALUE_REINDEX_TSTAMP
public static final String DEFAULT_VALUE_REINDEX_TSTAMP
- See Also:
- Constant Field Values
-
IDX_RESOURCE_ID
public static final int IDX_RESOURCE_ID
- See Also:
- Constant Field Values
-
IDX_LOGICAL_RESOURCE_ID
public static final int IDX_LOGICAL_RESOURCE_ID
- See Also:
- Constant Field Values
-
IDX_VERSION_ID
public static final int IDX_VERSION_ID
- See Also:
- Constant Field Values
-
IDX_LAST_UPDATED
public static final int IDX_LAST_UPDATED
- See Also:
- Constant Field Values
-
IDX_IS_DELETED
public static final int IDX_IS_DELETED
- See Also:
- Constant Field Values
-
IDX_DATA
public static final int IDX_DATA
- See Also:
- Constant Field Values
-
IDX_LOGICAL_ID
public static final int IDX_LOGICAL_ID
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
ResourceDAOImpl
public ResourceDAOImpl(Connection c, String schemaName, FHIRDbFlavor flavor, TransactionSynchronizationRegistry trxSynchRegistry, FHIRPersistenceJDBCCache cache, IResourceReferenceDAO rrd, ParameterTransactionDataImpl ptdi)
Constructs a DAO instance suitable for acquiring connections from a JDBC Datasource object.- Parameters:
c-schemaName-flavor-trxSyncRegistry-
-
ResourceDAOImpl
public ResourceDAOImpl(Connection c, String schemaName, FHIRDbFlavor flavor, FHIRPersistenceJDBCCache cache, IResourceReferenceDAO rrd)
Constructs a DAO instance for use outside a managed transaction (JEE) environment- Parameters:
c-schemaName-flavor-
-
-
Method Detail
-
getResourceReferenceDAO
protected IResourceReferenceDAO getResourceReferenceDAO()
Getter for the IResourceReferenceDAO used by this ResourceDAO implementation- Returns:
-
getTransactionData
protected ParameterTransactionDataImpl getTransactionData()
Get the ParameterTransactionDataImpl held by this.- Returns:
- the transactionData object. Can be null.
-
read
public Resource read(String logicalId, String resourceType) throws FHIRPersistenceDataAccessException, FHIRPersistenceDBConnectException
Description copied from interface:ResourceDAOReads and returns the latest version of the Resource with the passed logical id and resource type. If no matching resource is found, null is returned.- Specified by:
readin interfaceResourceDAO- Returns:
- Resource - The most recent version of the Resource with the passed logical id and resource type, or null if not found.
- Throws:
FHIRPersistenceDataAccessExceptionFHIRPersistenceDBConnectException
-
versionRead
public Resource versionRead(String logicalId, String resourceType, int versionId) throws FHIRPersistenceDataAccessException, FHIRPersistenceDBConnectException
Description copied from interface:ResourceDAOReads and returns the version of the Resource with the passed logical id, resource type, and version id. If no matching resource is found, null is returned.- Specified by:
versionReadin interfaceResourceDAO- Returns:
- Resource - The version of the Resource with the passed logical id, resource type, and version id or null if not found.
- Throws:
FHIRPersistenceDataAccessExceptionFHIRPersistenceDBConnectException
-
createDTO
protected Resource createDTO(ResultSet resultSet) throws FHIRPersistenceDataAccessException
Creates and returns a Resource DTO based on the contents of the passed ResultSet- Overrides:
createDTOin classFHIRDbDAOImpl- Parameters:
resultSet- A ResultSet containing FHIR persistent object data.- Returns:
- Resource - A Resource DTO
- Throws:
FHIRPersistenceDataAccessException
-
history
public List<Resource> history(String resourceType, String logicalId, Timestamp fromDateTime, int offset, int maxResults) throws FHIRPersistenceDataAccessException, FHIRPersistenceDBConnectException
Description copied from interface:ResourceDAOReads and returns all versions of the Resource with the passed logicalId, ordered by descending version id. If non-null, the passed fromDateTime is used to limit the returned Resource versions to those that were updated after the fromDateTime.- Specified by:
historyin interfaceResourceDAO- Parameters:
resourceType- - The name of a FHIR Resource typelogicalId- - The logical id of a FHIR ResourcefromDateTime- - The starting date/time of the version history.- Returns:
- List
- An ordered list of Resource versions. - Throws:
FHIRPersistenceDataAccessExceptionFHIRPersistenceDBConnectException
-
historyCount
public int historyCount(String resourceType, String logicalId, Timestamp fromDateTime) throws FHIRPersistenceDataAccessException, FHIRPersistenceDBConnectException
Description copied from interface:ResourceDAOReads and returns the COUNT of all versions of the Resource with the passed logicalId. If non-null, the passed fromDateTime is used to limit the count of Resource versions to those that were updated after the fromDateTime.- Specified by:
historyCountin interfaceResourceDAO- Parameters:
resourceType- - The name of a FHIR Resource typelogicalId- - The logical id of a FHIR ResourcefromDateTime- - The starting date/time of the version history.- Returns:
- int - The count of Resource versions.
- Throws:
FHIRPersistenceDataAccessExceptionFHIRPersistenceDBConnectException
-
search
public List<Resource> search(SqlQueryData queryData) throws FHIRPersistenceDataAccessException, FHIRPersistenceDBConnectException
Description copied from interface:ResourceDAOExecutes the search contained in the passed SqlQueryData, using it's encapsulated search string and bind variables.- Specified by:
searchin interfaceResourceDAO- Parameters:
queryData- - Contains a search string and (optionally) bind variables.- Returns:
- List
A list of FHIR Resources satisfying the passed search. - Throws:
FHIRPersistenceDataAccessExceptionFHIRPersistenceDBConnectException
-
searchCount
public int searchCount(SqlQueryData queryData) throws FHIRPersistenceDataAccessException, FHIRPersistenceDBConnectException
Description copied from interface:ResourceDAOExecutes a count query based on the data contained in the passed SqlQueryData, using it's encapsulated search string and bind variables.- Specified by:
searchCountin interfaceResourceDAO- Parameters:
queryData- - Contains a search string and (optionally) bind variables.- Returns:
- int A count of FHIR Resources satisfying the passed search.
- Throws:
FHIRPersistenceDataAccessExceptionFHIRPersistenceDBConnectException
-
setPersistenceContext
public void setPersistenceContext(FHIRPersistenceContext context)
Description copied from interface:ResourceDAOSets the current persistence context- Specified by:
setPersistenceContextin interfaceResourceDAO
-
readAllResourceTypeNames
public Map<String,Integer> readAllResourceTypeNames() throws FHIRPersistenceDBConnectException, FHIRPersistenceDataAccessException
Description copied from interface:ResourceDAOReads all rows in the resource_types table and returns the data as a Map- Specified by:
readAllResourceTypeNamesin interfaceResourceDAO- Returns:
- Map
- A map containing key=parameter-name, value=parameter-name-id - Throws:
FHIRPersistenceDBConnectExceptionFHIRPersistenceDataAccessException
-
readResourceTypeId
public Integer readResourceTypeId(String resourceType) throws FHIRPersistenceDBConnectException, FHIRPersistenceDataAccessException
Description copied from interface:ResourceDAOReads the id associated with the name of the passed Resource type from the Resource_Types table. If the id for the passed name is not present in the database, an id is generated, persisted, and returned.- Specified by:
readResourceTypeIdin interfaceResourceDAO- Returns:
- Integer - the id associated with the name of the passed Resource type.
- Throws:
FHIRPersistenceDBConnectExceptionFHIRPersistenceDataAccessException
-
searchForIds
public List<Long> searchForIds(SqlQueryData queryData) throws FHIRPersistenceDataAccessException, FHIRPersistenceDBConnectException
Description copied from interface:ResourceDAOThis method supports the execution of a specialized query designed to return Resource ids, based on the contents of the passed select statement. Note that the first column to be selected MUST be the Resource.id column.- Specified by:
searchForIdsin interfaceResourceDAO- Returns:
- - A List of resource ids that satisfy the passed SQL query.
- Throws:
FHIRPersistenceDataAccessExceptionFHIRPersistenceDBConnectException
-
addResourceTypeCacheCandidate
public void addResourceTypeCacheCandidate(String resourceType, Integer resourceTypeId) throws FHIRPersistenceException
Adds a resource type/ resource id pair to a candidate collection for population into the ResourceTypesCache. This pair must be present as a row in the FHIR DB RESOURCE_TYPES table.- Specified by:
addResourceTypeCacheCandidatein interfaceResourceDAO- Parameters:
resourceType- A valid FHIR resource type.resourceTypeId- The corresponding id for the resource type.- Throws:
FHIRPersistenceException
-
insert
public Resource insert(Resource resource, List<ExtractedParameterValue> parameters, ParameterDAO parameterDao) throws FHIRPersistenceException
Description copied from interface:ResourceDAOInserts the passed Resource DTO and its associated search parameters to the appropriate FHIR resource tables. After insert, the generated primary key is acquired and set in the Resource object.- Specified by:
insertin interfaceResourceDAO- Parameters:
resource- A Resource Data Transfer Objectparameters- A collection of search parameters to be persisted along with the passed ResourceparameterDao- The Parameter DAO- Returns:
- Resource The Resource DTO
- Throws:
FHIRPersistenceDataAccessExceptionFHIRPersistenceDBConnectExceptionFHIRPersistenceVersionIdMismatchExceptionFHIRPersistenceException
-
search
public List<Resource> search(String sqlSelect) throws FHIRPersistenceDataAccessException, FHIRPersistenceDBConnectException
Description copied from interface:ResourceDAOExecutes the passed fully-formed SQL Select statement and returns the results If no matching resources are found, an empty collection is returned.- Specified by:
searchin interfaceResourceDAO- Parameters:
sqlSelect- - A fully formed SQL select statement.- Returns:
- List
- A List of Resources that satisfy the passed SQL query string. - Throws:
FHIRPersistenceDataAccessExceptionFHIRPersistenceDBConnectException
-
searchByIds
public List<Resource> searchByIds(String resourceType, List<Long> resourceIds) throws FHIRPersistenceDataAccessException, FHIRPersistenceDBConnectException
Description copied from interface:ResourceDAOSearches for Resources that contain one of the passed ids.- Specified by:
searchByIdsin interfaceResourceDAO- Parameters:
resourceType- - The type of the FHIR ResourceresourceIds- - A List of resource ids.- Returns:
- List
- A List of resources matching the the passed list of ids. - Throws:
FHIRPersistenceDataAccessExceptionFHIRPersistenceDBConnectException
-
searchCount
public int searchCount(String sqlSelectCount) throws FHIRPersistenceDataAccessException, FHIRPersistenceDBConnectException
Description copied from interface:ResourceDAOExecutes the passed fully-formed SQL Select COUNT statement and returns the integer count.- Specified by:
searchCountin interfaceResourceDAO- Returns:
- int - The count of resources that fulfill the passed SQL select statement.
- Throws:
FHIRPersistenceDataAccessExceptionFHIRPersistenceDBConnectException
-
searchStringValues
public List<String> searchStringValues(SqlQueryData queryData) throws FHIRPersistenceDataAccessException, FHIRPersistenceDBConnectException
Description copied from interface:ResourceDAOExecutes the search contained in the passed SqlQueryData, using it's encapsulated search string and bind variables.- Specified by:
searchStringValuesin interfaceResourceDAO- Parameters:
queryData- - Contains a search string and (optionally) bind variables.- Returns:
- List
A list of strings satisfying the passed search. - Throws:
FHIRPersistenceDataAccessExceptionFHIRPersistenceDBConnectException
-
getCache
protected FHIRPersistenceJDBCCache getCache()
Getter for access to theFHIRPersistenceJDBCCachefrom subclasses- Returns:
-
-