Class DerbyResourceDAO
- java.lang.Object
 - 
- org.linuxforhealth.fhir.persistence.jdbc.dao.impl.FHIRDbDAOImpl
 - 
- org.linuxforhealth.fhir.persistence.jdbc.dao.impl.ResourceDAOImpl
 - 
- org.linuxforhealth.fhir.persistence.jdbc.derby.DerbyResourceDAO
 
 
 
 
- 
- All Implemented Interfaces:
 FHIRDbDAO,ResourceDAO
public class DerbyResourceDAO extends ResourceDAOImpl
Data access object for writing FHIR resources to an Apache Derby database. 
- 
- 
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 DerbyResourceDAO(java.sql.Connection connection, java.lang.String schemaName, FHIRDbFlavor flavor, javax.transaction.TransactionSynchronizationRegistry trxSynchRegistry, FHIRPersistenceJDBCCache cache, ParameterTransactionDataImpl ptdi)Derby is not only used for unit tests, but can also be used to provide persistence for a stand-alone full FHIR server.DerbyResourceDAO(java.sql.Connection connection, java.lang.String schemaName, FHIRDbFlavor flavor, FHIRPersistenceJDBCCache cache)Public constructor 
- 
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intgetOrCreateResourceType(java.lang.String resourceTypeName, java.sql.Connection conn)stored-procedure-less implementation for managing the resource_types tableprotected java.lang.IntegergetResourceTypeId(java.lang.String resourceTypeName, java.sql.Connection conn)Read the id for the named typeResourceinsert(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.longstoreResource(java.lang.String tablePrefix, java.util.List<ExtractedParameterValue> parameters, java.lang.String p_logical_id, java.io.InputStream p_payload, java.sql.Timestamp p_last_updated, boolean p_is_deleted, java.lang.String p_source_key, java.lang.Integer p_version, java.lang.String p_parameterHashB64, java.sql.Connection conn, ParameterDAO parameterDao, java.lang.Integer ifNoneMatch, java.lang.String resourcePayloadKey, java.util.concurrent.atomic.AtomicInteger outInteractionStatus, java.util.concurrent.atomic.AtomicInteger outIfNoneMatchVersion, java.lang.String[] outCurrentParameterHash)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 org.linuxforhealth.fhir.persistence.jdbc.dao.impl.ResourceDAOImpl
checkIfNoneMatch, createDTO, getCache, getResourceTypeId, getSearchByIdsNoDataSql, getSearchByIdsSql, getTransactionData, history, historyCount, read, readAllResourceTypeNames, readLogicalResourceId, readLogicalResourceIdList, readResourceTypeId, search, search, searchByIds, searchCount, searchCount, searchForIds, searchWholeSystem, setInt, setPersistenceContext, setString, versionRead 
- 
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
- 
DerbyResourceDAO
public DerbyResourceDAO(java.sql.Connection connection, java.lang.String schemaName, FHIRDbFlavor flavor, FHIRPersistenceJDBCCache cache)Public constructor- Parameters:
 connection-schemaName-flavor-cache-
 
- 
DerbyResourceDAO
public DerbyResourceDAO(java.sql.Connection connection, java.lang.String schemaName, FHIRDbFlavor flavor, javax.transaction.TransactionSynchronizationRegistry trxSynchRegistry, FHIRPersistenceJDBCCache cache, ParameterTransactionDataImpl ptdi)Derby is not only used for unit tests, but can also be used to provide persistence for a stand-alone full FHIR server.- Parameters:
 strat- the connection strategytrxSynchRegistry-cache-ptdi-
 
 - 
 
- 
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: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.- 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
 
- 
storeResource
public long storeResource(java.lang.String tablePrefix, java.util.List<ExtractedParameterValue> parameters, java.lang.String p_logical_id, java.io.InputStream p_payload, java.sql.Timestamp p_last_updated, boolean p_is_deleted, java.lang.String p_source_key, java.lang.Integer p_version, java.lang.String p_parameterHashB64, java.sql.Connection conn, ParameterDAO parameterDao, java.lang.Integer ifNoneMatch, java.lang.String resourcePayloadKey, java.util.concurrent.atomic.AtomicInteger outInteractionStatus, java.util.concurrent.atomic.AtomicInteger outIfNoneMatchVersion, java.lang.String[] outCurrentParameterHash) throws java.lang.ExceptionStore 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 PostgreSQL stored procedure implementation (fhir-persistence-schema/src/main/resources/postgres/add_any_resource.sql)- Parameters:
 tablePrefix-parameters-p_logical_id-p_payload-p_last_updated-p_is_deleted-p_source_key-p_version-p_parameterHashB64-conn-parameterDao-ifNoneMatch- 0 for conditional create-on-update behavior; otherwise nullresourcePayloadKey-outInteractionStatus-outIfNoneMatchVersion-- Returns:
 - the logical_resource_id for the entry we created
 - Throws:
 java.lang.Exception
 
- 
getResourceTypeId
protected java.lang.Integer getResourceTypeId(java.lang.String resourceTypeName, java.sql.Connection conn) throws java.sql.SQLExceptionRead the id for the named type- Parameters:
 resourceTypeName-- 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.SQLExceptionstored-procedure-less implementation for managing the resource_types table- Parameters:
 resourceTypeName-- Throws:
 java.sql.SQLException
 
 - 
 
 -