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,EraseResourceDAO,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 java.lang.StringDEFAULT_VALUE_REINDEX_TSTAMPstatic intIDX_DATAstatic intIDX_IS_DELETEDstatic intIDX_LAST_UPDATEDstatic intIDX_LOGICAL_IDstatic intIDX_LOGICAL_RESOURCE_IDstatic intIDX_RESOURCE_IDstatic intIDX_RESOURCE_PAYLOAD_KEYstatic intIDX_RESOURCE_TYPE_IDstatic intIDX_VERSION_ID
-
Constructor Summary
Constructors Constructor Description ResourceDAOImpl(java.sql.Connection c, java.lang.String schemaName, FHIRDbFlavor flavor, FHIRPersistenceJDBCCache cache, IResourceReferenceDAO rrd)Constructs a DAO instance for use outside a managed transaction (JEE) environmentResourceDAOImpl(java.sql.Connection c, java.lang.String schemaName, FHIRDbFlavor flavor, javax.transaction.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 protected booleancheckIfNoneMatch(java.lang.Integer ifNoneMatch, int currentVersionId)Test for If-None-Match conditional create-on-update behavior.protected ResourcecreateDTO(java.sql.ResultSet resultSet, boolean hasResourceTypeId)Creates and returns a Resource DTO based on the contents of the passed ResultSetprotected voiddeleteFromParameterTable(java.sql.Connection conn, java.lang.String tableName, long logicalResourceId)Delete all parameters for the given resourceId from the named parameter value tableprotected FHIRPersistenceJDBCCachegetCache()Getter for access to theFHIRPersistenceJDBCCachefrom subclassesprotected IResourceReferenceDAOgetResourceReferenceDAO()Getter for the IResourceReferenceDAO used by this ResourceDAO implementationprotected java.lang.IntegergetResourceTypeId(java.lang.String resourceType)Get the value of the database id for the given resourceType from the JDBCIdentityCache.protected java.lang.StringgetSearchByIdsNoDataSql(java.lang.String resourceType)protected java.lang.StringgetSearchByIdsSql(java.lang.String resourceType)protected ParameterTransactionDataImplgetTransactionData()Get the ParameterTransactionDataImpl held by this.java.util.List<Resource>history(java.lang.String resourceType, java.lang.String logicalId, java.sql.Timestamp fromDateTime, int offset, int maxResults)Reads and returns all versions of the Resource with the passed logicalId, ordered by descending version id.inthistoryCount(java.lang.String resourceType, java.lang.String logicalId, java.sql.Timestamp fromDateTime)Reads and returns the COUNT of all versions of the Resource with the passed logicalId.Resourceinsert(Resource resource, java.util.List<ExtractedParameterValue> parameters, java.lang.String parameterHashB64, ParameterDAO parameterDao, java.lang.Integer ifNoneMatch)Inserts the passed Resource DTO and its associated search parameters to the appropriate FHIR resource tables.Resourceread(java.lang.String logicalId, java.lang.String resourceType)Reads and returns the latest version of the Resource with the passed logical id and resource type.java.util.Map<java.lang.String,java.lang.Integer>readAllResourceTypeNames()Reads all rows in the resource_types table and returns the data as a Mapjava.lang.IntegerreadResourceTypeId(java.lang.String resourceType)Reads the id associated with the name of the passed Resource type from the Resource_Types table.java.util.List<Resource>search(Select select)Executes the search contained in the passedSelect, using its encapsulated search string and bind variables.java.util.List<Resource>search(java.lang.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.java.util.List<Resource>searchByIds(java.lang.String resourceType, java.util.List<java.lang.Long> resourceIds, boolean includeResourceData)Searches for Resources that contain one of the passed ids.intsearchCount(Select countQuery)Executes a count query based on the data contained in the passedSelectstatement, using its encapsulated search string and bind variables.intsearchCount(java.lang.String sqlSelectCount)Executes the passed fully-formed SQL Select COUNT statement and returns the integer count.java.util.List<java.lang.Long>searchForIds(Select dataQuery)This method supports the execution of a specialized query designed to return Resource ids, based on the contents of the passed select statement.java.util.Map<java.lang.Integer,java.util.List<java.lang.Long>>searchWholeSystem(Select wholeSystemQuery)Executes the whole-system filter search contained in the passedSelect, using its encapsulated search string and bind variables.protected voidsetInt(java.sql.PreparedStatement ps, int index, java.lang.Integer value)Set an int parameter in the statement, handling null as requiredvoidsetPersistenceContext(FHIRPersistenceContext context)Sets the current persistence contextprotected voidsetString(java.sql.PreparedStatement ps, int index, java.lang.String value)Set a String parameter in the statement, handling null as requiredResourceversionRead(java.lang.String logicalId, java.lang.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, getTranslator, isDb2Database, runCountQuery, runCountQuery, runQuery, 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 java.lang.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
-
IDX_RESOURCE_PAYLOAD_KEY
public static final int IDX_RESOURCE_PAYLOAD_KEY
- See Also:
- Constant Field Values
-
IDX_RESOURCE_TYPE_ID
public static final int IDX_RESOURCE_TYPE_ID
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
ResourceDAOImpl
public ResourceDAOImpl(java.sql.Connection c, java.lang.String schemaName, FHIRDbFlavor flavor, javax.transaction.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(java.sql.Connection c, java.lang.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(java.lang.String logicalId, java.lang.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(java.lang.String logicalId, java.lang.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(java.sql.ResultSet resultSet, boolean hasResourceTypeId) 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.hasResourceTypeId- True if the ResultSet includes the RESOURCE_TYPE_ID column- Returns:
- Resource - A Resource DTO
- Throws:
FHIRPersistenceDataAccessException
-
history
public java.util.List<Resource> history(java.lang.String resourceType, java.lang.String logicalId, java.sql.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(java.lang.String resourceType, java.lang.String logicalId, java.sql.Timestamp fromDateTime) throws FHIRPersistenceDataAccessException, FHIRPersistenceDBConnectExceptionDescription 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
-
setPersistenceContext
public void setPersistenceContext(FHIRPersistenceContext context)
Description copied from interface:ResourceDAOSets the current persistence context- Specified by:
setPersistenceContextin interfaceResourceDAO
-
readAllResourceTypeNames
public java.util.Map<java.lang.String,java.lang.Integer> readAllResourceTypeNames() throws FHIRPersistenceDBConnectException, FHIRPersistenceDataAccessExceptionDescription 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 java.lang.Integer readResourceTypeId(java.lang.String resourceType) throws FHIRPersistenceDBConnectException, FHIRPersistenceDataAccessExceptionDescription 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
-
getResourceTypeId
protected java.lang.Integer getResourceTypeId(java.lang.String resourceType) throws FHIRPersistenceExceptionGet the value of the database id for the given resourceType from the JDBCIdentityCache. If the id isn't found, then it is read from the database. Note that the resource type cache is prefilled and so we should never get a miss...but this is here as a just-in-case protection against reading the cache before the prefill is done.- Parameters:
resourceType-- Returns:
- Throws:
FHIRPersistenceException
-
checkIfNoneMatch
protected boolean checkIfNoneMatch(java.lang.Integer ifNoneMatch, int currentVersionId)Test for If-None-Match conditional create-on-update behavior. The If-None-Match header value is encoded by the REST layer (minimizes propagation of user input) using the following rulesIf-None-Match: null then ifNoneMatch = null If-None-Match: * then ifNoneMatch = 0
Other values such as W/"1" are intentionally unsupported because their behavior may be unintuitive, especially around deleted resources.- Parameters:
ifNoneMatch- the encoded If-None-Match header valuecurrentVersionId- the current version of the resource to compare with- Returns:
-
insert
public Resource insert(Resource resource, java.util.List<ExtractedParameterValue> parameters, java.lang.String parameterHashB64, ParameterDAO parameterDao, java.lang.Integer ifNoneMatch) 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 ResourceparameterHashB64- Base64 encoded SHA-256 hash of parametersparameterDao- The Parameter DAOifNoneMatch- 0 for conditional create-on-update behavior; otherwise null- Returns:
- Resource The Resource DTO
- Throws:
FHIRPersistenceDataAccessExceptionFHIRPersistenceDBConnectExceptionFHIRPersistenceVersionIdMismatchExceptionFHIRPersistenceException
-
search
public java.util.List<Resource> search(java.lang.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 java.util.List<Resource> searchByIds(java.lang.String resourceType, java.util.List<java.lang.Long> resourceIds, boolean includeResourceData) 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.includeResourceData- - fetch the resource DATA column- Returns:
- List
- A List of resources matching the the passed list of ids. - Throws:
FHIRPersistenceDataAccessExceptionFHIRPersistenceDBConnectException
-
getSearchByIdsSql
protected java.lang.String getSearchByIdsSql(java.lang.String resourceType)
-
getSearchByIdsNoDataSql
protected java.lang.String getSearchByIdsNoDataSql(java.lang.String resourceType)
-
searchCount
public int searchCount(java.lang.String sqlSelectCount) throws FHIRPersistenceDataAccessException, FHIRPersistenceDBConnectExceptionDescription 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
-
getCache
protected FHIRPersistenceJDBCCache getCache()
Getter for access to theFHIRPersistenceJDBCCachefrom subclasses- Returns:
-
searchCount
public int searchCount(Select countQuery) throws FHIRPersistenceDataAccessException, FHIRPersistenceDBConnectException
Description copied from interface:ResourceDAOExecutes a count query based on the data contained in the passedSelectstatement, using its encapsulated search string and bind variables.- Specified by:
searchCountin interfaceResourceDAO- Parameters:
countQuery- - Contains a search string and (optionally) bind variables.- Returns:
- int A count of FHIR Resources satisfying the passed search.
- Throws:
FHIRPersistenceDataAccessExceptionFHIRPersistenceDBConnectException
-
search
public java.util.List<Resource> search(Select select) throws FHIRPersistenceDataAccessException, FHIRPersistenceDBConnectException
Description copied from interface:ResourceDAOExecutes the search contained in the passedSelect, using its encapsulated search string and bind variables.- Specified by:
searchin interfaceResourceDAO- Parameters:
select- - Contains a search query and (optionally) bind variables.- Returns:
- List
A list of FHIR Resources satisfying the passed search. - Throws:
FHIRPersistenceDataAccessExceptionFHIRPersistenceDBConnectException
-
searchForIds
public java.util.List<java.lang.Long> searchForIds(Select dataQuery) 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:
- Throws:
FHIRPersistenceDataAccessExceptionFHIRPersistenceDBConnectException
-
deleteFromParameterTable
protected void deleteFromParameterTable(java.sql.Connection conn, java.lang.String tableName, long logicalResourceId) throws java.sql.SQLExceptionDelete all parameters for the given resourceId from the named parameter value table- Parameters:
conn-tableName-logicalResourceId-- Throws:
java.sql.SQLException
-
searchWholeSystem
public java.util.Map<java.lang.Integer,java.util.List<java.lang.Long>> searchWholeSystem(Select wholeSystemQuery) throws FHIRPersistenceDataAccessException, FHIRPersistenceDBConnectException
Description copied from interface:ResourceDAOExecutes the whole-system filter search contained in the passedSelect, using its encapsulated search string and bind variables.- Specified by:
searchWholeSystemin interfaceResourceDAO- Parameters:
wholeSystemQuery- - Contains a search query and (optionally) bind variables.- Returns:
- Map
> A map of FHIR resource type ID to list of logical resource IDs satisfying the passed search. - Throws:
FHIRPersistenceDataAccessExceptionFHIRPersistenceDBConnectException
-
setInt
protected void setInt(java.sql.PreparedStatement ps, int index, java.lang.Integer value) throws java.sql.SQLExceptionSet an int parameter in the statement, handling null as required- Parameters:
ps-index-value-- Throws:
java.sql.SQLException
-
setString
protected void setString(java.sql.PreparedStatement ps, int index, java.lang.String value) throws java.sql.SQLExceptionSet a String parameter in the statement, handling null as required- Parameters:
ps-index-value-- Throws:
java.sql.SQLException
-
-