Class PostgresResourceDAO
- java.lang.Object
-
- org.linuxforhealth.fhir.persistence.jdbc.dao.impl.FHIRDbDAOImpl
-
- org.linuxforhealth.fhir.persistence.jdbc.dao.impl.ResourceDAOImpl
-
- org.linuxforhealth.fhir.persistence.jdbc.postgres.PostgresResourceDAO
-
- All Implemented Interfaces:
FHIRDbDAO
,ResourceDAO
- Direct Known Subclasses:
CitusResourceDAO
public class PostgresResourceDAO extends ResourceDAOImpl
Data access object for writing FHIR resources to an postgresql database using the stored procedure (or function, in this case)
-
-
Field Summary
-
Fields inherited from class org.linuxforhealth.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_RESOURCE_PAYLOAD_KEY, IDX_RESOURCE_TYPE_ID, IDX_VERSION_ID
-
-
Constructor Summary
Constructors Constructor Description PostgresResourceDAO(java.sql.Connection connection, java.lang.String schemaName, FHIRDbFlavor flavor, javax.transaction.TransactionSynchronizationRegistry trxSynchRegistry, FHIRPersistenceJDBCCache cache, ParameterTransactionDataImpl ptdi, java.lang.Short shardKey)
Public constructor used when UserTransaction is availablePostgresResourceDAO(java.sql.Connection connection, java.lang.String schemaName, FHIRDbFlavor flavor, FHIRPersistenceJDBCCache cache, java.lang.Short shardKey)
Public constructor used in runtimes without UserTransaction support
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description int
getOrCreateResourceType(java.lang.String resourceTypeName, java.sql.Connection conn)
stored-procedure-less implementation for managing the resource_types tableprotected java.lang.Integer
getResourceTypeId(java.lang.String resourceTypeName, java.sql.Connection conn)
Read the id for the named typeResource
insert(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.Resource
read(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.lang.Integer
readResourceTypeId(java.lang.String resourceType)
Reads the id associated with the name of the passed Resource type from the Resource_Types table.Resource
versionRead(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 org.linuxforhealth.fhir.persistence.jdbc.dao.impl.ResourceDAOImpl
checkIfNoneMatch, createDTO, getCache, getResourceTypeId, getSearchByIdsNoDataSql, getSearchByIdsSql, getTransactionData, history, historyCount, readAllResourceTypeNames, readLogicalResourceId, readLogicalResourceIdList, search, search, searchByIds, searchCount, searchCount, searchForIds, searchWholeSystem, setInt, setPersistenceContext, setString
-
Methods inherited from class org.linuxforhealth.fhir.persistence.jdbc.dao.impl.FHIRDbDAOImpl
buildExceptionWithIssue, buildFHIRPersistenceDBConnectException, cleanup, cleanup, createDTOs, getConnection, getFlavor, getSchemaName, getTranslator, 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 org.linuxforhealth.fhir.persistence.jdbc.dao.api.FHIRDbDAO
getConnection, getFlavor
-
-
-
-
Constructor Detail
-
PostgresResourceDAO
public PostgresResourceDAO(java.sql.Connection connection, java.lang.String schemaName, FHIRDbFlavor flavor, FHIRPersistenceJDBCCache cache, java.lang.Short shardKey)
Public constructor used in runtimes without UserTransaction support- Parameters:
connection
-schemaName
-flavor
-cache
-shardKey
-
-
PostgresResourceDAO
public PostgresResourceDAO(java.sql.Connection connection, java.lang.String schemaName, FHIRDbFlavor flavor, javax.transaction.TransactionSynchronizationRegistry trxSynchRegistry, FHIRPersistenceJDBCCache cache, ParameterTransactionDataImpl ptdi, java.lang.Short shardKey)
Public constructor used when UserTransaction is available- Parameters:
connection
-schemaName
-flavor
-trxSynchRegistry
-cache
-ptdi
-shardKey
-
-
-
Method Detail
-
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: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.- 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:
FHIRPersistenceDataAccessException
FHIRPersistenceDBConnectException
FHIRPersistenceVersionIdMismatchException
FHIRPersistenceException
-
read
public Resource read(java.lang.String logicalId, java.lang.String resourceType) throws FHIRPersistenceDataAccessException, FHIRPersistenceDBConnectException
Description copied from interface:ResourceDAO
Reads 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:
read
in interfaceResourceDAO
- Overrides:
read
in classResourceDAOImpl
- Returns:
- Resource - The most recent version of the Resource with the passed logical id and resource type, or null if not found.
- Throws:
FHIRPersistenceDataAccessException
FHIRPersistenceDBConnectException
-
versionRead
public Resource versionRead(java.lang.String logicalId, java.lang.String resourceType, int versionId) throws FHIRPersistenceDataAccessException, FHIRPersistenceDBConnectException
Description copied from interface:ResourceDAO
Reads 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:
versionRead
in interfaceResourceDAO
- Overrides:
versionRead
in classResourceDAOImpl
- Returns:
- Resource - The version of the Resource with the passed logical id, resource type, and version id or null if not found.
- Throws:
FHIRPersistenceDataAccessException
FHIRPersistenceDBConnectException
-
getResourceTypeId
protected java.lang.Integer getResourceTypeId(java.lang.String resourceTypeName, java.sql.Connection conn) throws java.sql.SQLException
Read the id for the named type- Parameters:
resourceTypeName
-conn
-- Returns:
- the database id, or null if the named record is not found
- Throws:
java.sql.SQLException
-
getOrCreateResourceType
public int getOrCreateResourceType(java.lang.String resourceTypeName, java.sql.Connection conn) throws java.sql.SQLException
stored-procedure-less implementation for managing the resource_types table- Parameters:
resourceTypeName
-conn
-- Throws:
java.sql.SQLException
-
readResourceTypeId
public java.lang.Integer readResourceTypeId(java.lang.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
-
-