Class PostgresResourceNoProcDAO
- java.lang.Object
-
- com.ibm.fhir.persistence.jdbc.dao.impl.FHIRDbDAOImpl
-
- com.ibm.fhir.persistence.jdbc.dao.impl.ResourceDAOImpl
-
- com.ibm.fhir.persistence.jdbc.postgres.PostgresResourceNoProcDAO
-
- All Implemented Interfaces:
FHIRDbDAO
,ResourceDAO
public class PostgresResourceNoProcDAO extends ResourceDAOImpl
Data access object for writing FHIR resources to a PostgreSQL database. Like the Derby implementation, this version uses individual SQL statements instead of a stored procedure and is useful for debugging performance and/or concurrency issues. It should not be used in production scenarios because the numerous app-database round-trips slow things down considerably.
-
-
Field Summary
-
Fields inherited from class com.ibm.fhir.persistence.jdbc.dao.impl.ResourceDAOImpl
DEFAULT_VALUE_REINDEX_TSTAMP, IDX_DATA, IDX_IS_DELETED, IDX_LAST_UPDATED, IDX_LOGICAL_ID, IDX_LOGICAL_RESOURCE_ID, IDX_RESOURCE_ID, IDX_VERSION_ID
-
-
Constructor Summary
Constructors Constructor Description PostgresResourceNoProcDAO(Connection connection, String schemaName, FHIRDbFlavor flavor, FHIRPersistenceJDBCCache cache, IResourceReferenceDAO rrd)
PostgresResourceNoProcDAO(Connection connection, String schemaName, FHIRDbFlavor flavor, TransactionSynchronizationRegistry trxSynchRegistry, FHIRPersistenceJDBCCache cache, IResourceReferenceDAO rrd, ParameterTransactionDataImpl ptdi)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description int
getOrCreateResourceType(String resourceTypeName, Connection conn)
stored-procedure-less implementation for managing the resource_types tableprotected Integer
getResourceTypeId(String resourceTypeName, Connection conn)
Read the id for the named typeResource
insert(Resource resource, List<ExtractedParameterValue> parameters, String parameterHashB64, ParameterDAO parameterDao)
Inserts the passed Resource DTO and its associated search parameters to the appropriate FHIR resource tables.Integer
readResourceTypeId(String resourceType)
Reads the id associated with the name of the passed Resource type from the Resource_Types table.long
storeResource(String tablePrefix, List<ExtractedParameterValue> parameters, String p_logical_id, InputStream p_payload, Timestamp p_last_updated, boolean p_is_deleted, String p_source_key, Integer p_version, String parameterHashB64, Connection conn, ParameterDAO parameterDao)
Store the resource in the database, creating a new logical_resource entry if this is the first version of this resource, or creating a new resource entry if this a new version of an existing logical resource.-
Methods inherited from class com.ibm.fhir.persistence.jdbc.dao.impl.ResourceDAOImpl
addResourceTypeCacheCandidate, createDTO, deleteFromParameterTable, getCache, getResourceReferenceDAO, getResourceTypeIdFromCaches, getSearchByIdsSql, getTransactionData, history, historyCount, read, readAllResourceTypeNames, search, search, search, searchByIds, searchCount, searchCount, searchCount, searchForIds, searchForIds, searchStringValues, searchWholeSystem, setPersistenceContext, versionRead
-
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
-
-
-
-
Constructor Detail
-
PostgresResourceNoProcDAO
public PostgresResourceNoProcDAO(Connection connection, String schemaName, FHIRDbFlavor flavor, FHIRPersistenceJDBCCache cache, IResourceReferenceDAO rrd)
-
PostgresResourceNoProcDAO
public PostgresResourceNoProcDAO(Connection connection, String schemaName, FHIRDbFlavor flavor, TransactionSynchronizationRegistry trxSynchRegistry, FHIRPersistenceJDBCCache cache, IResourceReferenceDAO rrd, ParameterTransactionDataImpl ptdi)
-
-
Method Detail
-
insert
public Resource insert(Resource resource, List<ExtractedParameterValue> parameters, String parameterHashB64, ParameterDAO parameterDao) throws FHIRPersistenceException
Description copied from interface:ResourceDAO
Inserts 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:
insert
in interfaceResourceDAO
- Overrides:
insert
in classResourceDAOImpl
- 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 DAO- Returns:
- Resource The Resource DTO
- Throws:
FHIRPersistenceDataAccessException
FHIRPersistenceDBConnectException
FHIRPersistenceVersionIdMismatchException
FHIRPersistenceException
-
storeResource
public long storeResource(String tablePrefix, List<ExtractedParameterValue> parameters, String p_logical_id, InputStream p_payload, Timestamp p_last_updated, boolean p_is_deleted, String p_source_key, Integer p_version, String parameterHashB64, Connection conn, ParameterDAO parameterDao) throws Exception
Store the resource in the database, creating a new logical_resource entry if this is the first version of this resource, or creating a new resource entry if this a new version of an existing logical resource. The logic tracks closely the DB2 stored procedure implementation, including locking of the logical_resource and handling concurrency issues using the standard insert-or-update pattern:SELECT FOR UPDATE -- try and get a write lock IF NOT FOUND THEN -- doesn't exist, so we don't have a lock INSERT new logical resource -- create the record - if OK, we own the lock IF DUPLICATE THEN -- someone else beat us to the create SELECT FOR UPDATE -- so we need to try again for a write lock ... ...
This works because we never delete a logical_resource record, and so don't have to deal with concurrency issues caused when deletes are mingled with inserts/updates Note the execution flow aligns very closely with the DB2 stored procedure implementation (fhir-persistence-schema/src/main/resources/add_any_resource.sql)- Parameters:
tablePrefix
-parameters
-p_logical_id
-p_payload
-p_last_updated
-p_is_deleted
-p_source_key
-p_version
-parameterHashB64
-conn
-parameterDao
-- Returns:
- the resource_id for the entry we created
- Throws:
Exception
-
getResourceTypeId
protected Integer getResourceTypeId(String resourceTypeName, Connection conn) throws SQLException
Read the id for the named type- Parameters:
resourceTypeName
-- Returns:
- the database id, or null if the named record is not found
- Throws:
SQLException
-
getOrCreateResourceType
public int getOrCreateResourceType(String resourceTypeName, Connection conn) throws SQLException
stored-procedure-less implementation for managing the resource_types table- Parameters:
resourceTypeName
-- Throws:
SQLException
-
readResourceTypeId
public Integer readResourceTypeId(String resourceType) throws FHIRPersistenceDBConnectException, FHIRPersistenceDataAccessException
Description copied from interface:ResourceDAO
Reads 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:
readResourceTypeId
in interfaceResourceDAO
- Overrides:
readResourceTypeId
in classResourceDAOImpl
- Returns:
- Integer - the id associated with the name of the passed Resource type.
- Throws:
FHIRPersistenceDBConnectException
FHIRPersistenceDataAccessException
-
-