fixed code for passing tests successfully

This commit is contained in:
Kateryna Mironova 2022-11-21 15:08:00 -05:00
parent 044611a89c
commit 1b1478d7bc
35 changed files with 160 additions and 130 deletions

View File

@ -73,7 +73,7 @@ public class ResourceVersionSvcDaoImpl implements IResourceVersionSvc {
} }
List<Long> matchingIds = dao.searchForIds(theSearchParamMap, new SystemRequestDetails().setRequestPartitionId(theRequestPartitionId)).stream() List<Long> matchingIds = dao.searchForIds(theSearchParamMap, new SystemRequestDetails().setRequestPartitionId(theRequestPartitionId)).stream()
.map(ResourcePersistentId::getIdAsLong) .map(id -> ((JpaPid) id).getId())
.collect(Collectors.toList()); .collect(Collectors.toList());
List<ResourceTable> allById = new ArrayList<>(); List<ResourceTable> allById = new ArrayList<>();
@ -138,7 +138,7 @@ public class ResourceVersionSvcDaoImpl implements IResourceVersionSvc {
} }
List<JpaPid> jpaPids = myIdHelperService.resolveResourcePersistentIdsWithCache(thePartitionId, List<JpaPid> jpaPids = myIdHelperService.resolveResourcePersistentIdsWithCache(thePartitionId,
new ArrayList<>(theIds)).stream().map(id -> (JpaPid) id).toList(); new ArrayList<>(theIds)).stream().map(id -> (JpaPid) id).collect(Collectors.toList());
// we'll use this map to fetch pids that require versions // we'll use this map to fetch pids that require versions
HashMap<Long, JpaPid> pidsToVersionToResourcePid = new HashMap<>(); HashMap<Long, JpaPid> pidsToVersionToResourcePid = new HashMap<>();
@ -146,7 +146,7 @@ public class ResourceVersionSvcDaoImpl implements IResourceVersionSvc {
// fill in our map // fill in our map
for (JpaPid pid : jpaPids) { for (JpaPid pid : jpaPids) {
if (pid.getVersion() == null) { if (pid.getVersion() == null) {
pidsToVersionToResourcePid.put(pid.getIdAsLong(), pid); pidsToVersionToResourcePid.put(pid.getId(), pid);
} }
Optional<IIdType> idOp = theIds.stream() Optional<IIdType> idOp = theIds.stream()
.filter(i -> i.getIdPart().equals(pid.getAssociatedResourceId().getIdPart())) .filter(i -> i.getIdPart().equals(pid.getAssociatedResourceId().getIdPart()))

View File

@ -1729,9 +1729,9 @@ public abstract class BaseHapiFhirDao<T extends IBaseResource> extends BaseStora
protected void addPidToResource(IBasePersistedResource theEntity, IBaseResource theResource) { protected void addPidToResource(IBasePersistedResource theEntity, IBaseResource theResource) {
if (theResource instanceof IAnyResource) { if (theResource instanceof IAnyResource) {
IDao.RESOURCE_PID.put((IAnyResource) theResource, theEntity.getPersistentId().getIdAsLong()); IDao.RESOURCE_PID.put((IAnyResource) theResource, ((JpaPid) theEntity.getPersistentId()).getId());
} else if (theResource instanceof IResource) { } else if (theResource instanceof IResource) {
IDao.RESOURCE_PID.put((IResource) theResource, theEntity.getPersistentId().getIdAsLong()); IDao.RESOURCE_PID.put((IResource) theResource, ((JpaPid) theEntity.getPersistentId()).getId());
} }
} }

View File

@ -301,12 +301,12 @@ public abstract class BaseHapiFhirResourceDao<T extends IBaseResource> extends B
return myTxTemplate.execute(tx -> { return myTxTemplate.execute(tx -> {
IIdType retVal = myIdHelperService.translatePidIdToForcedId(myFhirContext, myResourceName, pid); IIdType retVal = myIdHelperService.translatePidIdToForcedId(myFhirContext, myResourceName, pid);
if (!retVal.hasVersionIdPart()) { if (!retVal.hasVersionIdPart()) {
IIdType idWithVersion = myMemoryCacheService.getIfPresent(MemoryCacheService.CacheEnum.RESOURCE_CONDITIONAL_CREATE_VERSION, pid.getIdAsLong()); IIdType idWithVersion = myMemoryCacheService.getIfPresent(MemoryCacheService.CacheEnum.RESOURCE_CONDITIONAL_CREATE_VERSION, pid.getId());
if (idWithVersion == null) { if (idWithVersion == null) {
Long version = myResourceTableDao.findCurrentVersionByPid(pid.getIdAsLong()); Long version = myResourceTableDao.findCurrentVersionByPid(pid.getId());
if (version != null) { if (version != null) {
retVal = myFhirContext.getVersion().newIdType().setParts(retVal.getBaseUrl(), retVal.getResourceType(), retVal.getIdPart(), Long.toString(version)); retVal = myFhirContext.getVersion().newIdType().setParts(retVal.getBaseUrl(), retVal.getResourceType(), retVal.getIdPart(), Long.toString(version));
myMemoryCacheService.putAfterCommit(MemoryCacheService.CacheEnum.RESOURCE_CONDITIONAL_CREATE_VERSION, pid.getIdAsLong(), retVal); myMemoryCacheService.putAfterCommit(MemoryCacheService.CacheEnum.RESOURCE_CONDITIONAL_CREATE_VERSION, pid.getId(), retVal);
} }
} else { } else {
retVal = idWithVersion; retVal = idWithVersion;
@ -667,7 +667,7 @@ public abstract class BaseHapiFhirResourceDao<T extends IBaseResource> extends B
TransactionDetails transactionDetails = new TransactionDetails(); TransactionDetails transactionDetails = new TransactionDetails();
List<ResourceTable> deletedResources = new ArrayList<>(); List<ResourceTable> deletedResources = new ArrayList<>();
for (ResourcePersistentId pid : theResourceIds) { for (ResourcePersistentId pid : theResourceIds) {
ResourceTable entity = myEntityManager.find(ResourceTable.class, pid.getIdAsLong()); ResourceTable entity = myEntityManager.find(ResourceTable.class, ((JpaPid) pid).getId());
deletedResources.add(entity); deletedResources.add(entity);
T resourceToDelete = toResource(myResourceType, entity, null, false); T resourceToDelete = toResource(myResourceType, entity, null, false);
@ -1198,10 +1198,11 @@ public abstract class BaseHapiFhirResourceDao<T extends IBaseResource> extends B
@Transactional @Transactional
public T readByPid(ResourcePersistentId thePid, boolean theDeletedOk) { public T readByPid(ResourcePersistentId thePid, boolean theDeletedOk) {
StopWatch w = new StopWatch(); StopWatch w = new StopWatch();
JpaPid jpaPid = (JpaPid) thePid;
Optional<ResourceTable> entity = myResourceTableDao.findById(thePid.getIdAsLong()); Optional<ResourceTable> entity = myResourceTableDao.findById(jpaPid.getId());
if (!entity.isPresent()) { if (!entity.isPresent()) {
throw new ResourceNotFoundException(Msg.code(975) + "No resource found with PID " + thePid); throw new ResourceNotFoundException(Msg.code(975) + "No resource found with PID " + jpaPid);
} }
if (isDeleted(entity.get()) && !theDeletedOk) { if (isDeleted(entity.get()) && !theDeletedOk) {
throw createResourceGoneException(entity.get()); throw createResourceGoneException(entity.get());
@ -1209,7 +1210,7 @@ public abstract class BaseHapiFhirResourceDao<T extends IBaseResource> extends B
T retVal = toResource(myResourceType, entity.get(), null, false); T retVal = toResource(myResourceType, entity.get(), null, false);
ourLog.debug("Processed read on {} in {}ms", thePid, w.getMillis()); ourLog.debug("Processed read on {} in {}ms", jpaPid, w.getMillis());
return retVal; return retVal;
} }
@ -1287,9 +1288,9 @@ public abstract class BaseHapiFhirResourceDao<T extends IBaseResource> extends B
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@Override @Override
public void reindex(ResourcePersistentId theResourcePersistentId, RequestDetails theRequest, TransactionDetails theTransactionDetails) { public void reindex(ResourcePersistentId theResourcePersistentId, RequestDetails theRequest, TransactionDetails theTransactionDetails) {
Optional<ResourceTable> entityOpt = myResourceTableDao.findById(theResourcePersistentId.getIdAsLong()); Optional<ResourceTable> entityOpt = myResourceTableDao.findById(((JpaPid) theResourcePersistentId).getId());
if (!entityOpt.isPresent()) { if (!entityOpt.isPresent()) {
ourLog.warn("Unable to find entity with PID: {}", theResourcePersistentId.getId()); ourLog.warn("Unable to find entity with PID: {}", ((JpaPid) theResourcePersistentId).getId());
return; return;
} }
@ -1314,21 +1315,21 @@ public abstract class BaseHapiFhirResourceDao<T extends IBaseResource> extends B
JpaPid pid = (JpaPid) myIdHelperService.resolveResourcePersistentIds(requestPartitionId, getResourceName(), theId.getIdPart()); JpaPid pid = (JpaPid) myIdHelperService.resolveResourcePersistentIds(requestPartitionId, getResourceName(), theId.getIdPart());
Set<Integer> readPartitions = null; Set<Integer> readPartitions = null;
if (requestPartitionId.isAllPartitions()) { if (requestPartitionId.isAllPartitions()) {
entity = myEntityManager.find(ResourceTable.class, pid.getIdAsLong()); entity = myEntityManager.find(ResourceTable.class, pid.getId());
} else { } else {
readPartitions = myRequestPartitionHelperService.toReadPartitions(requestPartitionId); readPartitions = myRequestPartitionHelperService.toReadPartitions(requestPartitionId);
if (readPartitions.size() == 1) { if (readPartitions.size() == 1) {
if (readPartitions.contains(null)) { if (readPartitions.contains(null)) {
entity = myResourceTableDao.readByPartitionIdNull(pid.getIdAsLong()).orElse(null); entity = myResourceTableDao.readByPartitionIdNull(pid.getId()).orElse(null);
} else { } else {
entity = myResourceTableDao.readByPartitionId(readPartitions.iterator().next(), pid.getIdAsLong()).orElse(null); entity = myResourceTableDao.readByPartitionId(readPartitions.iterator().next(), pid.getId()).orElse(null);
} }
} else { } else {
if (readPartitions.contains(null)) { if (readPartitions.contains(null)) {
List<Integer> readPartitionsWithoutNull = readPartitions.stream().filter(t -> t != null).collect(Collectors.toList()); List<Integer> readPartitionsWithoutNull = readPartitions.stream().filter(t -> t != null).collect(Collectors.toList());
entity = myResourceTableDao.readByPartitionIdsOrNull(readPartitionsWithoutNull, pid.getIdAsLong()).orElse(null); entity = myResourceTableDao.readByPartitionIdsOrNull(readPartitionsWithoutNull, pid.getId()).orElse(null);
} else { } else {
entity = myResourceTableDao.readByPartitionIds(readPartitions, pid.getIdAsLong()).orElse(null); entity = myResourceTableDao.readByPartitionIds(readPartitions, pid.getId()).orElse(null);
} }
} }
} }

View File

@ -112,7 +112,7 @@ public abstract class BaseHapiFhirResourceDaoObservation<T extends IBaseResource
if (nextOr instanceof ReferenceParam) { if (nextOr instanceof ReferenceParam) {
ReferenceParam ref = (ReferenceParam) nextOr; ReferenceParam ref = (ReferenceParam) nextOr;
JpaPid pid = (JpaPid) myIdHelperService.resolveResourcePersistentIds(requestPartitionId, ref.getResourceType(), ref.getIdPart()); JpaPid pid = (JpaPid) myIdHelperService.resolveResourcePersistentIds(requestPartitionId, ref.getResourceType(), ref.getIdPart());
orderedSubjectReferenceMap.put(pid.getIdAsLong(), nextOr); orderedSubjectReferenceMap.put(pid.getId(), nextOr);
} else { } else {
throw new IllegalArgumentException(Msg.code(942) + "Invalid token type (expecting ReferenceParam): " + nextOr.getClass()); throw new IllegalArgumentException(Msg.code(942) + "Invalid token type (expecting ReferenceParam): " + nextOr.getClass());
} }

View File

@ -5,6 +5,7 @@ import ca.uhn.fhir.jpa.api.config.DaoConfig;
import ca.uhn.fhir.jpa.api.dao.IFhirSystemDao; import ca.uhn.fhir.jpa.api.dao.IFhirSystemDao;
import ca.uhn.fhir.jpa.api.model.ExpungeOptions; import ca.uhn.fhir.jpa.api.model.ExpungeOptions;
import ca.uhn.fhir.jpa.api.model.ExpungeOutcome; import ca.uhn.fhir.jpa.api.model.ExpungeOutcome;
import ca.uhn.fhir.jpa.model.dao.JpaPid;
import ca.uhn.fhir.jpa.model.entity.ResourceHistoryTable; import ca.uhn.fhir.jpa.model.entity.ResourceHistoryTable;
import ca.uhn.fhir.jpa.model.entity.ResourceTable; import ca.uhn.fhir.jpa.model.entity.ResourceTable;
import ca.uhn.fhir.jpa.search.builder.SearchBuilder; import ca.uhn.fhir.jpa.search.builder.SearchBuilder;
@ -146,7 +147,7 @@ public abstract class BaseHapiFhirSystemDao<T extends IBaseBundle, MT> extends B
public void preFetchResources(List<ResourcePersistentId> theResolvedIds) { public void preFetchResources(List<ResourcePersistentId> theResolvedIds) {
List<Long> pids = theResolvedIds List<Long> pids = theResolvedIds
.stream() .stream()
.map(t -> t.getIdAsLong()) .map(t -> ((JpaPid) t).getId())
.collect(Collectors.toList()); .collect(Collectors.toList());
new QueryChunker<Long>().chunk(pids, ids->{ new QueryChunker<Long>().chunk(pids, ids->{

View File

@ -165,12 +165,12 @@ public class TransactionProcessor extends BaseTransactionProcessor {
} }
} }
List<JpaPid> outcome = myIdHelperService.resolveResourcePersistentIdsWithCache(requestPartitionId, idsToPreResolve) List<JpaPid> outcome = myIdHelperService.resolveResourcePersistentIdsWithCache(requestPartitionId, idsToPreResolve)
.stream().map(id -> (JpaPid) id).toList(); .stream().map(id -> (JpaPid) id).collect(Collectors.toList());
for (JpaPid next : outcome) { for (JpaPid next : outcome) {
foundIds.add(next.getAssociatedResourceId().toUnqualifiedVersionless().getValue()); foundIds.add(next.getAssociatedResourceId().toUnqualifiedVersionless().getValue());
theTransactionDetails.addResolvedResourceId(next.getAssociatedResourceId(), next); theTransactionDetails.addResolvedResourceId(next.getAssociatedResourceId(), next);
if (myDaoConfig.getResourceClientIdStrategy() != DaoConfig.ClientIdStrategyEnum.ANY || !next.getAssociatedResourceId().isIdPartValidLong()) { if (myDaoConfig.getResourceClientIdStrategy() != DaoConfig.ClientIdStrategyEnum.ANY || !next.getAssociatedResourceId().isIdPartValidLong()) {
idsToPreFetch.add(next.getIdAsLong()); idsToPreFetch.add(next.getId());
} }
} }
for (IIdType next : idsToPreResolve) { for (IIdType next : idsToPreResolve) {
@ -193,7 +193,7 @@ public class TransactionProcessor extends BaseTransactionProcessor {
if ("PUT".equals(verb) && requestUrl != null && requestUrl.contains("?")) { if ("PUT".equals(verb) && requestUrl != null && requestUrl.contains("?")) {
JpaPid cachedId = (JpaPid) myMatchResourceUrlService.processMatchUrlUsingCacheOnly(resourceType, requestUrl); JpaPid cachedId = (JpaPid) myMatchResourceUrlService.processMatchUrlUsingCacheOnly(resourceType, requestUrl);
if (cachedId != null) { if (cachedId != null) {
idsToPreFetch.add(cachedId.getIdAsLong()); idsToPreFetch.add(cachedId.getId());
} else if (SINGLE_PARAMETER_MATCH_URL_PATTERN.matcher(requestUrl).matches()) { } else if (SINGLE_PARAMETER_MATCH_URL_PATTERN.matcher(requestUrl).matches()) {
RuntimeResourceDefinition resourceDefinition = myFhirContext.getResourceDefinition(resource); RuntimeResourceDefinition resourceDefinition = myFhirContext.getResourceDefinition(resource);
SearchParameterMap matchUrlSearchMap = myMatchUrlService.translateMatchUrl(requestUrl, resourceDefinition); SearchParameterMap matchUrlSearchMap = myMatchUrlService.translateMatchUrl(requestUrl, resourceDefinition);
@ -202,7 +202,7 @@ public class TransactionProcessor extends BaseTransactionProcessor {
} else if ("POST".equals(verb) && requestIfNoneExist != null && requestIfNoneExist.contains("?")) { } else if ("POST".equals(verb) && requestIfNoneExist != null && requestIfNoneExist.contains("?")) {
JpaPid cachedId = (JpaPid) myMatchResourceUrlService.processMatchUrlUsingCacheOnly(resourceType, requestIfNoneExist); JpaPid cachedId = (JpaPid) myMatchResourceUrlService.processMatchUrlUsingCacheOnly(resourceType, requestIfNoneExist);
if (cachedId != null) { if (cachedId != null) {
idsToPreFetch.add(cachedId.getIdAsLong()); idsToPreFetch.add(cachedId.getId());
} else if (SINGLE_PARAMETER_MATCH_URL_PATTERN.matcher(requestIfNoneExist).matches()) { } else if (SINGLE_PARAMETER_MATCH_URL_PATTERN.matcher(requestIfNoneExist).matches()) {
RuntimeResourceDefinition resourceDefinition = myFhirContext.getResourceDefinition(resource); RuntimeResourceDefinition resourceDefinition = myFhirContext.getResourceDefinition(resource);
SearchParameterMap matchUrlSearchMap = myMatchUrlService.translateMatchUrl(requestIfNoneExist, resourceDefinition); SearchParameterMap matchUrlSearchMap = myMatchUrlService.translateMatchUrl(requestIfNoneExist, resourceDefinition);

View File

@ -129,13 +129,14 @@ public class ResourceExpungeService implements IResourceExpungeService {
@Transactional @Transactional
public List<ResourcePersistentId> findHistoricalVersionsOfNonDeletedResources(String theResourceName, ResourcePersistentId theResourceId, int theRemainingCount) { public List<ResourcePersistentId> findHistoricalVersionsOfNonDeletedResources(String theResourceName, ResourcePersistentId theResourceId, int theRemainingCount) {
Pageable page = PageRequest.of(0, theRemainingCount); Pageable page = PageRequest.of(0, theRemainingCount);
JpaPid jpaPid = (JpaPid) theResourceId;
Slice<Long> ids; Slice<Long> ids;
if (theResourceId != null && theResourceId.getId() != null) { if (jpaPid != null && jpaPid.getId() != null) {
if (theResourceId.getVersion() != null) { if (jpaPid.getVersion() != null) {
ids = toSlice(myResourceHistoryTableDao.findForIdAndVersionAndFetchProvenance(theResourceId.getIdAsLong(), theResourceId.getVersion())); ids = toSlice(myResourceHistoryTableDao.findForIdAndVersionAndFetchProvenance(jpaPid.getId(), jpaPid.getVersion()));
} else { } else {
ids = myResourceHistoryTableDao.findIdsOfPreviousVersionsOfResourceId(page, theResourceId.getIdAsLong()); ids = myResourceHistoryTableDao.findIdsOfPreviousVersionsOfResourceId(page, jpaPid.getId());
} }
} else { } else {
if (theResourceName != null) { if (theResourceName != null) {
@ -154,7 +155,7 @@ public class ResourceExpungeService implements IResourceExpungeService {
Pageable page = PageRequest.of(0, theRemainingCount); Pageable page = PageRequest.of(0, theRemainingCount);
Slice<Long> ids; Slice<Long> ids;
if (theResourceId != null) { if (theResourceId != null) {
ids = myResourceTableDao.findIdsOfDeletedResourcesOfType(page, theResourceId.getIdAsLong(), theResourceName); ids = myResourceTableDao.findIdsOfDeletedResourcesOfType(page, ((JpaPid) theResourceId).getId(), theResourceName);
ourLog.info("Expunging {} deleted resources of type[{}] and ID[{}]", ids.getNumberOfElements(), theResourceName, theResourceId); ourLog.info("Expunging {} deleted resources of type[{}] and ID[{}]", ids.getNumberOfElements(), theResourceName, theResourceId);
} else { } else {
if (theResourceName != null) { if (theResourceName != null) {
@ -172,7 +173,7 @@ public class ResourceExpungeService implements IResourceExpungeService {
@Transactional @Transactional
public void expungeCurrentVersionOfResources(RequestDetails theRequestDetails, List<ResourcePersistentId> theResourceIds, AtomicInteger theRemainingCount) { public void expungeCurrentVersionOfResources(RequestDetails theRequestDetails, List<ResourcePersistentId> theResourceIds, AtomicInteger theRemainingCount) {
for (ResourcePersistentId next : theResourceIds) { for (ResourcePersistentId next : theResourceIds) {
expungeCurrentVersionOfResource(theRequestDetails, next.getIdAsLong(), theRemainingCount); expungeCurrentVersionOfResource(theRequestDetails, ((JpaPid) next).getId(), theRemainingCount);
if (theRemainingCount.get() <= 0) { if (theRemainingCount.get() <= 0) {
return; return;
} }
@ -230,7 +231,7 @@ public class ResourceExpungeService implements IResourceExpungeService {
@Transactional @Transactional
public void expungeHistoricalVersionsOfIds(RequestDetails theRequestDetails, List<ResourcePersistentId> theResourceIds, AtomicInteger theRemainingCount) { public void expungeHistoricalVersionsOfIds(RequestDetails theRequestDetails, List<ResourcePersistentId> theResourceIds, AtomicInteger theRemainingCount) {
for (ResourcePersistentId next : theResourceIds) { for (ResourcePersistentId next : theResourceIds) {
expungeHistoricalVersionsOfId(theRequestDetails, next.getIdAsLong(), theRemainingCount); expungeHistoricalVersionsOfId(theRequestDetails, ((JpaPid) next).getId(), theRemainingCount);
if (theRemainingCount.get() <= 0) { if (theRemainingCount.get() <= 0) {
return; return;
} }
@ -241,7 +242,7 @@ public class ResourceExpungeService implements IResourceExpungeService {
@Transactional @Transactional
public void expungeHistoricalVersions(RequestDetails theRequestDetails, List<ResourcePersistentId> theHistoricalIds, AtomicInteger theRemainingCount) { public void expungeHistoricalVersions(RequestDetails theRequestDetails, List<ResourcePersistentId> theHistoricalIds, AtomicInteger theRemainingCount) {
for (ResourcePersistentId next : theHistoricalIds) { for (ResourcePersistentId next : theHistoricalIds) {
expungeHistoricalVersion(theRequestDetails, next.getIdAsLong(), theRemainingCount); expungeHistoricalVersion(theRequestDetails, ((JpaPid) next).getId(), theRemainingCount);
if (theRemainingCount.get() <= 0) { if (theRemainingCount.get() <= 0) {
return; return;
} }
@ -275,43 +276,44 @@ public class ResourceExpungeService implements IResourceExpungeService {
@Override @Override
@Transactional @Transactional
public void deleteAllSearchParams(ResourcePersistentId theResourceId) { public void deleteAllSearchParams(ResourcePersistentId theResourceId) {
ResourceTable resource = myResourceTableDao.findById(theResourceId.getIdAsLong()).orElse(null); Long theResourceLongId = ((JpaPid) theResourceId).getId();
ResourceTable resource = myResourceTableDao.findById(theResourceLongId).orElse(null);
if (resource == null || resource.isParamsUriPopulated()) { if (resource == null || resource.isParamsUriPopulated()) {
myResourceIndexedSearchParamUriDao.deleteByResourceId(theResourceId.getIdAsLong()); myResourceIndexedSearchParamUriDao.deleteByResourceId(theResourceLongId);
} }
if (resource == null || resource.isParamsCoordsPopulated()) { if (resource == null || resource.isParamsCoordsPopulated()) {
myResourceIndexedSearchParamCoordsDao.deleteByResourceId(theResourceId.getIdAsLong()); myResourceIndexedSearchParamCoordsDao.deleteByResourceId(theResourceLongId);
} }
if (resource == null || resource.isParamsDatePopulated()) { if (resource == null || resource.isParamsDatePopulated()) {
myResourceIndexedSearchParamDateDao.deleteByResourceId(theResourceId.getIdAsLong()); myResourceIndexedSearchParamDateDao.deleteByResourceId(theResourceLongId);
} }
if (resource == null || resource.isParamsNumberPopulated()) { if (resource == null || resource.isParamsNumberPopulated()) {
myResourceIndexedSearchParamNumberDao.deleteByResourceId(theResourceId.getIdAsLong()); myResourceIndexedSearchParamNumberDao.deleteByResourceId(theResourceLongId);
} }
if (resource == null || resource.isParamsQuantityPopulated()) { if (resource == null || resource.isParamsQuantityPopulated()) {
myResourceIndexedSearchParamQuantityDao.deleteByResourceId(theResourceId.getIdAsLong()); myResourceIndexedSearchParamQuantityDao.deleteByResourceId(theResourceLongId);
} }
if (resource == null || resource.isParamsQuantityNormalizedPopulated()) { if (resource == null || resource.isParamsQuantityNormalizedPopulated()) {
myResourceIndexedSearchParamQuantityNormalizedDao.deleteByResourceId(theResourceId.getIdAsLong()); myResourceIndexedSearchParamQuantityNormalizedDao.deleteByResourceId(theResourceLongId);
} }
if (resource == null || resource.isParamsStringPopulated()) { if (resource == null || resource.isParamsStringPopulated()) {
myResourceIndexedSearchParamStringDao.deleteByResourceId(theResourceId.getIdAsLong()); myResourceIndexedSearchParamStringDao.deleteByResourceId(theResourceLongId);
} }
if (resource == null || resource.isParamsTokenPopulated()) { if (resource == null || resource.isParamsTokenPopulated()) {
myResourceIndexedSearchParamTokenDao.deleteByResourceId(theResourceId.getIdAsLong()); myResourceIndexedSearchParamTokenDao.deleteByResourceId(theResourceLongId);
} }
if (resource == null || resource.isParamsComboStringUniquePresent()) { if (resource == null || resource.isParamsComboStringUniquePresent()) {
myResourceIndexedCompositeStringUniqueDao.deleteByResourceId(theResourceId.getIdAsLong()); myResourceIndexedCompositeStringUniqueDao.deleteByResourceId(theResourceLongId);
} }
if (resource == null || resource.isParamsComboTokensNonUniquePresent()) { if (resource == null || resource.isParamsComboTokensNonUniquePresent()) {
myResourceIndexedComboTokensNonUniqueDao.deleteByResourceId(theResourceId.getIdAsLong()); myResourceIndexedComboTokensNonUniqueDao.deleteByResourceId(theResourceLongId);
} }
if (myDaoConfig.getIndexMissingFields() == DaoConfig.IndexEnabledEnum.ENABLED) { if (myDaoConfig.getIndexMissingFields() == DaoConfig.IndexEnabledEnum.ENABLED) {
mySearchParamPresentDao.deleteByResourceId(theResourceId.getIdAsLong()); mySearchParamPresentDao.deleteByResourceId(theResourceLongId);
} }
if (resource == null || resource.isHasLinks()) { if (resource == null || resource.isHasLinks()) {
myResourceLinkDao.deleteByResourceId(theResourceId.getIdAsLong()); myResourceLinkDao.deleteByResourceId(theResourceLongId);
} }
} }

View File

@ -432,7 +432,7 @@ public class IdHelperService implements IIdHelperService {
@Override @Override
public Optional<String> translatePidIdToForcedIdWithCache(ResourcePersistentId theId) { public Optional<String> translatePidIdToForcedIdWithCache(ResourcePersistentId theId) {
return myMemoryCacheService.get(MemoryCacheService.CacheEnum.PID_TO_FORCED_ID, theId.getIdAsLong(), pid -> myForcedIdDao.findByResourcePid(pid).map(ForcedId::asTypedFhirResourceId)); return myMemoryCacheService.get(MemoryCacheService.CacheEnum.PID_TO_FORCED_ID, ((JpaPid) theId).getId(), pid -> myForcedIdDao.findByResourcePid(pid).map(ForcedId::asTypedFhirResourceId));
} }
private ListMultimap<String, String> organizeIdsByResourceType(Collection<IIdType> theIds) { private ListMultimap<String, String> organizeIdsByResourceType(Collection<IIdType> theIds) {
@ -597,7 +597,7 @@ public class IdHelperService implements IIdHelperService {
@Override @Override
public PersistentIdToForcedIdMap translatePidsToForcedIds(Set<ResourcePersistentId> theResourceIds) { public PersistentIdToForcedIdMap translatePidsToForcedIds(Set<ResourcePersistentId> theResourceIds) {
assert myDontCheckActiveTransactionForUnitTest || TransactionSynchronizationManager.isSynchronizationActive(); assert myDontCheckActiveTransactionForUnitTest || TransactionSynchronizationManager.isSynchronizationActive();
Set<Long> thePids = theResourceIds.stream().map(t -> t.getIdAsLong()).collect(Collectors.toSet()); Set<Long> thePids = theResourceIds.stream().map(t -> ((JpaPid) t).getId()).collect(Collectors.toSet());
Map<Long, Optional<String>> retVal = new HashMap<>(myMemoryCacheService.getAllPresent(MemoryCacheService.CacheEnum.PID_TO_FORCED_ID, thePids)); Map<Long, Optional<String>> retVal = new HashMap<>(myMemoryCacheService.getAllPresent(MemoryCacheService.CacheEnum.PID_TO_FORCED_ID, thePids));
List<Long> remainingPids = thePids List<Long> remainingPids = thePids
@ -638,20 +638,21 @@ public class IdHelperService implements IIdHelperService {
*/ */
@Override @Override
public void addResolvedPidToForcedId(ResourcePersistentId theResourcePersistentId, @Nonnull RequestPartitionId theRequestPartitionId, String theResourceType, @Nullable String theForcedId, @Nullable Date theDeletedAt) { public void addResolvedPidToForcedId(ResourcePersistentId theResourcePersistentId, @Nonnull RequestPartitionId theRequestPartitionId, String theResourceType, @Nullable String theForcedId, @Nullable Date theDeletedAt) {
JpaPid jpaPid = (JpaPid) theResourcePersistentId;
if (theForcedId != null) { if (theForcedId != null) {
if (theResourcePersistentId.getAssociatedResourceId() == null) { if (theResourcePersistentId.getAssociatedResourceId() == null) {
populateAssociatedResourceId(theResourceType, theForcedId, (JpaPid) theResourcePersistentId); populateAssociatedResourceId(theResourceType, theForcedId, jpaPid);
} }
myMemoryCacheService.putAfterCommit(MemoryCacheService.CacheEnum.PID_TO_FORCED_ID, theResourcePersistentId.getIdAsLong(), Optional.of(theResourceType + "/" + theForcedId)); myMemoryCacheService.putAfterCommit(MemoryCacheService.CacheEnum.PID_TO_FORCED_ID, jpaPid.getId(), Optional.of(theResourceType + "/" + theForcedId));
String key = toForcedIdToPidKey(theRequestPartitionId, theResourceType, theForcedId); String key = toForcedIdToPidKey(theRequestPartitionId, theResourceType, theForcedId);
myMemoryCacheService.putAfterCommit(MemoryCacheService.CacheEnum.FORCED_ID_TO_PID, key, theResourcePersistentId); myMemoryCacheService.putAfterCommit(MemoryCacheService.CacheEnum.FORCED_ID_TO_PID, key, theResourcePersistentId);
} else { } else {
myMemoryCacheService.putAfterCommit(MemoryCacheService.CacheEnum.PID_TO_FORCED_ID, theResourcePersistentId.getIdAsLong(), Optional.empty()); myMemoryCacheService.putAfterCommit(MemoryCacheService.CacheEnum.PID_TO_FORCED_ID, jpaPid.getId(), Optional.empty());
} }
if (!myDaoConfig.isDeleteEnabled()) { if (!myDaoConfig.isDeleteEnabled()) {
ResourceLookup lookup = new ResourceLookup(theResourceType, theResourcePersistentId.getIdAsLong(), theDeletedAt); ResourceLookup lookup = new ResourceLookup(theResourceType, jpaPid.getId(), theDeletedAt);
String nextKey = theResourcePersistentId.toString(); String nextKey = theResourcePersistentId.toString();
myMemoryCacheService.putAfterCommit(MemoryCacheService.CacheEnum.RESOURCE_LOOKUP, nextKey, lookup); myMemoryCacheService.putAfterCommit(MemoryCacheService.CacheEnum.RESOURCE_LOOKUP, nextKey, lookup);
} }
@ -686,14 +687,17 @@ public class IdHelperService implements IIdHelperService {
@Override @Override
@Nullable @Nullable
public ResourcePersistentId getPidOrNull(@Nonnull RequestPartitionId theRequestPartitionId, IBaseResource theResource) { public ResourcePersistentId getPidOrNull(@Nonnull RequestPartitionId theRequestPartitionId, IBaseResource theResource) {
JpaPid retVal = new JpaPid(Long.parseLong(theResource.getUserData(RESOURCE_PID).toString())); Object resourceId = theResource.getUserData(RESOURCE_PID);
if (retVal.getId() == null) { JpaPid retVal;
if (resourceId == null) {
IIdType id = theResource.getIdElement(); IIdType id = theResource.getIdElement();
try { try {
retVal = (JpaPid) resolveResourcePersistentIds(theRequestPartitionId, id.getResourceType(), id.getIdPart()); retVal = (JpaPid) resolveResourcePersistentIds(theRequestPartitionId, id.getResourceType(), id.getIdPart());
} catch (ResourceNotFoundException e) { } catch (ResourceNotFoundException e) {
return null; return null;
} }
} else {
retVal = new JpaPid(Long.parseLong(resourceId.toString()));
} }
return retVal; return retVal;
} }
@ -718,7 +722,7 @@ public class IdHelperService implements IIdHelperService {
@Override @Override
public IIdType resourceIdFromPidOrThrowException(ResourcePersistentId thePid, String theResourceType) { public IIdType resourceIdFromPidOrThrowException(ResourcePersistentId thePid, String theResourceType) {
Optional<ResourceTable> optionalResource = myResourceTableDao.findById(thePid.getIdAsLong()); Optional<ResourceTable> optionalResource = myResourceTableDao.findById(((JpaPid) thePid).getId());
if (!optionalResource.isPresent()) { if (!optionalResource.isPresent()) {
throw new ResourceNotFoundException(Msg.code(2124) + "Requested resource not found"); throw new ResourceNotFoundException(Msg.code(2124) + "Requested resource not found");
} }

View File

@ -59,8 +59,8 @@ public class JpaIdHelperService extends IdHelperService implements IJpaIdHelperS
@Nonnull @Nonnull
public List<Long> getPidsOrThrowException(List<IIdType> theIds) { public List<Long> getPidsOrThrowException(List<IIdType> theIds) {
List<JpaPid> resourcePersistentIds = super.resolveResourcePersistentIdsWithCache(RequestPartitionId.allPartitions(), theIds) List<JpaPid> resourcePersistentIds = super.resolveResourcePersistentIdsWithCache(RequestPartitionId.allPartitions(), theIds)
.stream().map(id -> (JpaPid) id).toList(); .stream().map(id -> (JpaPid) id).collect(Collectors.toList());
return resourcePersistentIds.stream().map(ResourcePersistentId::getIdAsLong).collect(Collectors.toList()); return resourcePersistentIds.stream().map(JpaPid::getId).collect(Collectors.toList());
} }
@ -78,7 +78,9 @@ public class JpaIdHelperService extends IdHelperService implements IJpaIdHelperS
if (retVal == null) { if (retVal == null) {
IIdType id = theResource.getIdElement(); IIdType id = theResource.getIdElement();
try { try {
retVal = super.resolveResourcePersistentIds(RequestPartitionId.allPartitions(), id.getResourceType(), id.getIdPart()).getIdAsLong(); JpaPid jpaPid = (JpaPid) super.resolveResourcePersistentIds(
RequestPartitionId.allPartitions(), id.getResourceType(), id.getIdPart());
retVal = jpaPid.getId();
} catch (ResourceNotFoundException e) { } catch (ResourceNotFoundException e) {
return null; return null;
} }
@ -98,8 +100,9 @@ public class JpaIdHelperService extends IdHelperService implements IJpaIdHelperS
assert TransactionSynchronizationManager.isSynchronizationActive(); assert TransactionSynchronizationManager.isSynchronizationActive();
List<IIdType> ids = Collections.singletonList(theId); List<IIdType> ids = Collections.singletonList(theId);
List<JpaPid> resourcePersistentIds = super.resolveResourcePersistentIdsWithCache(RequestPartitionId.allPartitions(), ids).stream().map(id -> (JpaPid) id).toList();; List<JpaPid> resourcePersistentIds = super.resolveResourcePersistentIdsWithCache(
return resourcePersistentIds.get(0).getIdAsLong(); RequestPartitionId.allPartitions(), ids).stream().map(id -> (JpaPid) id).collect(Collectors.toList());
return resourcePersistentIds.get(0).getId();
} }
@Override @Override

View File

@ -67,17 +67,17 @@ public class MdmLinkDaoJpaImpl implements IMdmLinkDao<MdmLink> {
@Override @Override
public int deleteWithAnyReferenceToPid(ResourcePersistentId thePid) { public int deleteWithAnyReferenceToPid(ResourcePersistentId thePid) {
return myMdmLinkDao.deleteWithAnyReferenceToPid(thePid.getIdAsLong()); return myMdmLinkDao.deleteWithAnyReferenceToPid(((JpaPid) thePid).getId());
} }
@Override @Override
public int deleteWithAnyReferenceToPidAndMatchResultNot(ResourcePersistentId thePid, MdmMatchResultEnum theMatchResult) { public int deleteWithAnyReferenceToPidAndMatchResultNot(ResourcePersistentId thePid, MdmMatchResultEnum theMatchResult) {
return myMdmLinkDao.deleteWithAnyReferenceToPidAndMatchResultNot(thePid.getIdAsLong(), theMatchResult); return myMdmLinkDao.deleteWithAnyReferenceToPidAndMatchResultNot(((JpaPid) thePid).getId(), theMatchResult);
} }
@Override @Override
public List<MdmPidTuple> expandPidsFromGroupPidGivenMatchResult(ResourcePersistentId theGroupPid, MdmMatchResultEnum theMdmMatchResultEnum) { public List<MdmPidTuple> expandPidsFromGroupPidGivenMatchResult(ResourcePersistentId theGroupPid, MdmMatchResultEnum theMdmMatchResultEnum) {
return myMdmLinkDao.expandPidsFromGroupPidGivenMatchResult(theGroupPid.getIdAsLong(), theMdmMatchResultEnum) return myMdmLinkDao.expandPidsFromGroupPidGivenMatchResult(((JpaPid) theGroupPid).getId(), theMdmMatchResultEnum)
.stream() .stream()
.map( theMdmPidTuple -> new MdmPidTuple() .map( theMdmPidTuple -> new MdmPidTuple()
.setSourcePid(new JpaPid(theMdmPidTuple.getSourcePid())) .setSourcePid(new JpaPid(theMdmPidTuple.getSourcePid()))
@ -87,7 +87,7 @@ public class MdmLinkDaoJpaImpl implements IMdmLinkDao<MdmLink> {
@Override @Override
public List<MdmPidTuple> expandPidsBySourcePidAndMatchResult(ResourcePersistentId theSourcePid, MdmMatchResultEnum theMdmMatchResultEnum) { public List<MdmPidTuple> expandPidsBySourcePidAndMatchResult(ResourcePersistentId theSourcePid, MdmMatchResultEnum theMdmMatchResultEnum) {
return myMdmLinkDao.expandPidsBySourcePidAndMatchResult(theSourcePid.getIdAsLong(), theMdmMatchResultEnum) return myMdmLinkDao.expandPidsBySourcePidAndMatchResult(((JpaPid) theSourcePid).getId(), theMdmMatchResultEnum)
.stream() .stream()
.map( theMdmPidTuple -> new MdmPidTuple() .map( theMdmPidTuple -> new MdmPidTuple()
.setSourcePid(new JpaPid(theMdmPidTuple.getSourcePid())) .setSourcePid(new JpaPid(theMdmPidTuple.getSourcePid()))
@ -97,7 +97,7 @@ public class MdmLinkDaoJpaImpl implements IMdmLinkDao<MdmLink> {
@Override @Override
public List<MdmPidTuple> expandPidsByGoldenResourcePidAndMatchResult(ResourcePersistentId theSourcePid, MdmMatchResultEnum theMdmMatchResultEnum) { public List<MdmPidTuple> expandPidsByGoldenResourcePidAndMatchResult(ResourcePersistentId theSourcePid, MdmMatchResultEnum theMdmMatchResultEnum) {
return myMdmLinkDao.expandPidsByGoldenResourcePidAndMatchResult(theSourcePid.getIdAsLong(), theMdmMatchResultEnum) return myMdmLinkDao.expandPidsByGoldenResourcePidAndMatchResult(((JpaPid) theSourcePid).getId(), theMdmMatchResultEnum)
.stream() .stream()
.map( theMdmPidTuple -> new MdmPidTuple() .map( theMdmPidTuple -> new MdmPidTuple()
.setSourcePid(new JpaPid(theMdmPidTuple.getSourcePid())) .setSourcePid(new JpaPid(theMdmPidTuple.getSourcePid()))
@ -123,13 +123,13 @@ public class MdmLinkDaoJpaImpl implements IMdmLinkDao<MdmLink> {
@Override @Override
public List<MdmLink> findAllById(List<ResourcePersistentId> thePids) { public List<MdmLink> findAllById(List<ResourcePersistentId> thePids) {
List<Long> theLongPids = thePids.stream().map(theResourcePersistentId -> theResourcePersistentId.getIdAsLong()).collect(Collectors.toList()); List<Long> theLongPids = thePids.stream().map(thePid -> ((JpaPid) thePid).getId()).collect(Collectors.toList());
return myMdmLinkDao.findAllById(theLongPids); return myMdmLinkDao.findAllById(theLongPids);
} }
@Override @Override
public Optional<MdmLink> findById(ResourcePersistentId thePid) { public Optional<MdmLink> findById(ResourcePersistentId thePid) {
return myMdmLinkDao.findById(thePid.getIdAsLong()); return myMdmLinkDao.findById(((JpaPid) thePid).getId());
} }
public void deleteAll(List<MdmLink> theLinks) { public void deleteAll(List<MdmLink> theLinks) {
@ -191,11 +191,11 @@ public class MdmLinkDaoJpaImpl implements IMdmLinkDao<MdmLink> {
List<Predicate> andPredicates = new ArrayList<>(); List<Predicate> andPredicates = new ArrayList<>();
if (theGoldenResourceId != null) { if (theGoldenResourceId != null) {
Predicate goldenResourcePredicate = criteriaBuilder.equal(from.get("myGoldenResourcePid").as(Long.class), myIdHelperService.getPidOrThrowException(RequestPartitionId.allPartitions(), theGoldenResourceId).getIdAsLong()); Predicate goldenResourcePredicate = criteriaBuilder.equal(from.get("myGoldenResourcePid").as(Long.class), ((JpaPid) myIdHelperService.getPidOrThrowException(RequestPartitionId.allPartitions(), theGoldenResourceId)).getId());
andPredicates.add(goldenResourcePredicate); andPredicates.add(goldenResourcePredicate);
} }
if (theSourceId != null) { if (theSourceId != null) {
Predicate sourceIdPredicate = criteriaBuilder.equal(from.get("mySourcePid").as(Long.class), myIdHelperService.getPidOrThrowException(RequestPartitionId.allPartitions(), theSourceId).getIdAsLong()); Predicate sourceIdPredicate = criteriaBuilder.equal(from.get("mySourcePid").as(Long.class), ((JpaPid) myIdHelperService.getPidOrThrowException(RequestPartitionId.allPartitions(), theSourceId)).getId());
andPredicates.add(sourceIdPredicate); andPredicates.add(sourceIdPredicate);
} }
if (theMatchResult != null) { if (theMatchResult != null) {
@ -228,12 +228,12 @@ public class MdmLinkDaoJpaImpl implements IMdmLinkDao<MdmLink> {
@Override @Override
public Optional<? extends IMdmLink> findBySourcePidAndMatchResult(ResourcePersistentId theSourcePid, MdmMatchResultEnum theMatch) { public Optional<? extends IMdmLink> findBySourcePidAndMatchResult(ResourcePersistentId theSourcePid, MdmMatchResultEnum theMatch) {
return myMdmLinkDao.findBySourcePidAndMatchResult(theSourcePid.getIdAsLong(), theMatch); return myMdmLinkDao.findBySourcePidAndMatchResult(((JpaPid) theSourcePid).getId(), theMatch);
} }
@Override @Override
public void deleteLinksWithAnyReferenceToPids(List<ResourcePersistentId> theResourcePersistentIds) { public void deleteLinksWithAnyReferenceToPids(List<ResourcePersistentId> theResourcePersistentIds) {
List<Long> goldenResourcePids = theResourcePersistentIds.stream().map(ResourcePersistentId::getIdAsLong).collect(Collectors.toList()); List<Long> goldenResourcePids = theResourcePersistentIds.stream().map(pid -> ((JpaPid) pid).getId()).collect(Collectors.toList());
// Split into chunks of 500 so older versions of Oracle don't run into issues (500 = 1000 / 2 since the dao // Split into chunks of 500 so older versions of Oracle don't run into issues (500 = 1000 / 2 since the dao
// method uses the list twice in the sql predicate) // method uses the list twice in the sql predicate)
List<List<Long>> chunks = ListUtils.partition(goldenResourcePids, 500); List<List<Long>> chunks = ListUtils.partition(goldenResourcePids, 500);

View File

@ -22,6 +22,7 @@ package ca.uhn.fhir.jpa.delete.batch2;
import ca.uhn.fhir.jpa.api.svc.IDeleteExpungeSvc; import ca.uhn.fhir.jpa.api.svc.IDeleteExpungeSvc;
import ca.uhn.fhir.jpa.dao.IFulltextSearchSvc; import ca.uhn.fhir.jpa.dao.IFulltextSearchSvc;
import ca.uhn.fhir.jpa.model.dao.JpaPid;
import ca.uhn.fhir.jpa.model.entity.ResourceTable; import ca.uhn.fhir.jpa.model.entity.ResourceTable;
import ca.uhn.fhir.rest.api.server.storage.ResourcePersistentId; import ca.uhn.fhir.rest.api.server.storage.ResourcePersistentId;
import org.slf4j.Logger; import org.slf4j.Logger;
@ -70,7 +71,7 @@ public class DeleteExpungeSvcImpl implements IDeleteExpungeSvc {
*/ */
private void clearHibernateSearchIndex(List<ResourcePersistentId> thePersistentIds) { private void clearHibernateSearchIndex(List<ResourcePersistentId> thePersistentIds) {
if (myFullTextSearchSvc != null) { if (myFullTextSearchSvc != null) {
List<Object> objectIds = thePersistentIds.stream().map(ResourcePersistentId::getIdAsLong).collect(Collectors.toList()); List<Object> objectIds = thePersistentIds.stream().map(id -> ((JpaPid) id).getId()).collect(Collectors.toList());
myFullTextSearchSvc.deleteIndexedDocumentsByTypeAndId(ResourceTable.class, objectIds); myFullTextSearchSvc.deleteIndexedDocumentsByTypeAndId(ResourceTable.class, objectIds);
ourLog.info("Cleared Hibernate Search indexes."); ourLog.info("Cleared Hibernate Search indexes.");
} }

View File

@ -157,9 +157,10 @@ public class MdmLink extends BasePartitionable implements IMdmLink {
@Override @Override
public IMdmLink setGoldenResourcePersistenceId(ResourcePersistentId theGoldenResourcePid) { public IMdmLink setGoldenResourcePersistenceId(ResourcePersistentId theGoldenResourcePid) {
setPersonPid(theGoldenResourcePid.getIdAsLong()); Long longPid = ((JpaPid) theGoldenResourcePid).getId();
setPersonPid(longPid);
myGoldenResourcePid = theGoldenResourcePid.getIdAsLong(); myGoldenResourcePid = longPid;
return this; return this;
} }
@ -170,7 +171,7 @@ public class MdmLink extends BasePartitionable implements IMdmLink {
@Override @Override
public IMdmLink setSourcePersistenceId(ResourcePersistentId theSourcePid) { public IMdmLink setSourcePersistenceId(ResourcePersistentId theSourcePid) {
mySourcePid = theSourcePid.getIdAsLong(); mySourcePid = ((JpaPid) theSourcePid).getId();
return this; return this;
} }

View File

@ -528,7 +528,7 @@ public class SearchBuilder implements ISearchBuilder {
// add the pids to targetPids // add the pids to targetPids
for (ResourcePersistentId pid : idToPid.values()) { for (ResourcePersistentId pid : idToPid.values()) {
myAlsoIncludePids.add(pid); myAlsoIncludePids.add(pid);
theTargetPids.add(pid.getIdAsLong()); theTargetPids.add(((JpaPid) pid).getId());
} }
} }
@ -852,7 +852,7 @@ public class SearchBuilder implements ISearchBuilder {
if (resourcePidToVersion == null) { if (resourcePidToVersion == null) {
resourcePidToVersion = new HashMap<>(); resourcePidToVersion = new HashMap<>();
} }
resourcePidToVersion.put(next.getIdAsLong(), next.getVersion()); resourcePidToVersion.put(((JpaPid) next).getId(), next.getVersion());
} }
} }
@ -955,11 +955,11 @@ public class SearchBuilder implements ISearchBuilder {
for (ResourceTag tag : tagList) { for (ResourceTag tag : tagList) {
resourceId = new JpaPid(tag.getResourceId()); resourceId = new JpaPid(tag.getResourceId());
tagCol = tagMap.get(resourceId.getIdAsLong()); tagCol = tagMap.get(resourceId.getId());
if (tagCol == null) { if (tagCol == null) {
tagCol = new ArrayList<>(); tagCol = new ArrayList<>();
tagCol.add(tag); tagCol.add(tag);
tagMap.put(resourceId.getIdAsLong(), tagCol); tagMap.put(resourceId.getId(), tagCol);
} else { } else {
tagCol.add(tag); tagCol.add(tag);
} }
@ -1024,7 +1024,7 @@ public class SearchBuilder implements ISearchBuilder {
// Do we use the fulltextsvc via hibernate-search to load resources or be backwards compatible with older ES only impl // Do we use the fulltextsvc via hibernate-search to load resources or be backwards compatible with older ES only impl
// to handle lastN? // to handle lastN?
if (myDaoConfig.isAdvancedHSearchIndexing() && myDaoConfig.isStoreResourceInHSearchIndex()) { if (myDaoConfig.isAdvancedHSearchIndexing() && myDaoConfig.isStoreResourceInHSearchIndex()) {
List<Long> pidList = thePids.stream().map(ResourcePersistentId::getIdAsLong).collect(Collectors.toList()); List<Long> pidList = thePids.stream().map(pid -> ((JpaPid) pid).getId()).collect(Collectors.toList());
List<IBaseResource> resources = myFulltextSearchSvc.getResources(pidList); List<IBaseResource> resources = myFulltextSearchSvc.getResources(pidList);
return resources; return resources;

View File

@ -20,6 +20,7 @@ package ca.uhn.fhir.jpa.search.builder;
* #L% * #L%
*/ */
import ca.uhn.fhir.jpa.model.dao.JpaPid;
import ca.uhn.fhir.rest.api.server.storage.ResourcePersistentId; import ca.uhn.fhir.rest.api.server.storage.ResourcePersistentId;
import org.apache.commons.lang3.Validate; import org.apache.commons.lang3.Validate;
@ -119,8 +120,8 @@ public class SearchQueryExecutors {
@Override @Override
public Long next() { public Long next() {
ResourcePersistentId next = myIterator.next(); JpaPid next = (JpaPid) myIterator.next();
return next==null?null:next.getIdAsLong(); return next == null ? null : next.getId();
} }
} }

View File

@ -323,7 +323,7 @@ public class TermCodeSystemStorageSvcImpl implements ITermCodeSystemStorageSvc {
IIdType csId = myTerminologyVersionAdapterSvc.createOrUpdateCodeSystem(theCodeSystemResource, theRequest); IIdType csId = myTerminologyVersionAdapterSvc.createOrUpdateCodeSystem(theCodeSystemResource, theRequest);
JpaPid codeSystemResourcePid = (JpaPid) myIdHelperService.resolveResourcePersistentIds(RequestPartitionId.allPartitions(), csId.getResourceType(), csId.getIdPart()); JpaPid codeSystemResourcePid = (JpaPid) myIdHelperService.resolveResourcePersistentIds(RequestPartitionId.allPartitions(), csId.getResourceType(), csId.getIdPart());
ResourceTable resource = myResourceTableDao.getOne(codeSystemResourcePid.getIdAsLong()); ResourceTable resource = myResourceTableDao.getOne(codeSystemResourcePid.getId());
ourLog.info("CodeSystem resource has ID: {}", csId.getValue()); ourLog.info("CodeSystem resource has ID: {}", csId.getValue());

View File

@ -265,7 +265,7 @@ public class JpaBulkExportProcessorTest {
pids.add(new JpaPid(((IdDt) type).getIdPartAsLong())); pids.add(new JpaPid(((IdDt) type).getIdPartAsLong()));
} }
MdmPidTuple tuple = createTuple(groupId.getIdAsLong(), groupGoldenPid); MdmPidTuple tuple = createTuple(groupId.getId(), groupGoldenPid);
IFhirResourceDao<Group> groupDao = mock(IFhirResourceDao.class); IFhirResourceDao<Group> groupDao = mock(IFhirResourceDao.class);
parameters.setExpandMdm(theMdm); // set mdm expansion parameters.setExpandMdm(theMdm); // set mdm expansion
@ -322,7 +322,7 @@ public class JpaBulkExportProcessorTest {
assertTrue(pidIterator.hasNext()); assertTrue(pidIterator.hasNext());
while (pidIterator.hasNext()) { while (pidIterator.hasNext()) {
JpaPid pid = (JpaPid) pidIterator.next(); JpaPid pid = (JpaPid) pidIterator.next();
long idAsLong = pid.getIdAsLong(); long idAsLong = pid.getId();
boolean existing = pids.contains(new JpaPid(idAsLong)); boolean existing = pids.contains(new JpaPid(idAsLong));
if (!existing) { if (!existing) {
assertTrue(theMdm); assertTrue(theMdm);
@ -353,7 +353,7 @@ public class JpaBulkExportProcessorTest {
Arrays.asList(pid, pid2) Arrays.asList(pid, pid2)
); );
MdmPidTuple tuple = createTuple(groupId.getIdAsLong(), groupGoldenPid); MdmPidTuple tuple = createTuple(groupId.getId(), groupGoldenPid);
List<IPrimitiveType> patientTypes = createPatientTypes(); List<IPrimitiveType> patientTypes = createPatientTypes();
IFhirResourceDao<Group> groupDao = mock(IFhirResourceDao.class); IFhirResourceDao<Group> groupDao = mock(IFhirResourceDao.class);

View File

@ -39,6 +39,7 @@ import ca.uhn.fhir.mdm.util.MdmResourceUtil;
import ca.uhn.fhir.model.api.TemporalPrecisionEnum; import ca.uhn.fhir.model.api.TemporalPrecisionEnum;
import ca.uhn.fhir.rest.api.Constants; import ca.uhn.fhir.rest.api.Constants;
import ca.uhn.fhir.rest.api.server.IBundleProvider; import ca.uhn.fhir.rest.api.server.IBundleProvider;
import ca.uhn.fhir.rest.api.server.storage.ResourcePersistentId;
import ca.uhn.fhir.rest.param.TokenParam; import ca.uhn.fhir.rest.param.TokenParam;
import ca.uhn.fhir.rest.server.servlet.ServletRequestDetails; import ca.uhn.fhir.rest.server.servlet.ServletRequestDetails;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
@ -363,8 +364,8 @@ abstract public class BaseMdmR4Test extends BaseJpaR4Test {
Optional<? extends IMdmLink> matchedLinkForTargetPid = myMdmLinkDaoSvc.getMatchedLinkForSourcePid(runInTransaction(() -> myIdHelperService.getPidOrNull(RequestPartitionId.allPartitions(), theBaseResource))); Optional<? extends IMdmLink> matchedLinkForTargetPid = myMdmLinkDaoSvc.getMatchedLinkForSourcePid(runInTransaction(() -> myIdHelperService.getPidOrNull(RequestPartitionId.allPartitions(), theBaseResource)));
if (matchedLinkForTargetPid.isPresent()) { if (matchedLinkForTargetPid.isPresent()) {
Long goldenResourcePid = matchedLinkForTargetPid.get().getGoldenResourcePersistenceId().getIdAsLong(); JpaPid jpaPid = (JpaPid) matchedLinkForTargetPid.get().getGoldenResourcePersistenceId();
return (T) relevantDao.readByPid(new JpaPid(goldenResourcePid)); return (T) relevantDao.readByPid(jpaPid);
} else { } else {
return null; return null;
} }
@ -372,7 +373,7 @@ abstract public class BaseMdmR4Test extends BaseJpaR4Test {
protected <T extends IBaseResource> T getTargetResourceFromMdmLink(IMdmLink theMdmLink, String theResourceType) { protected <T extends IBaseResource> T getTargetResourceFromMdmLink(IMdmLink theMdmLink, String theResourceType) {
IFhirResourceDao resourceDao = myDaoRegistry.getResourceDao(theResourceType); IFhirResourceDao resourceDao = myDaoRegistry.getResourceDao(theResourceType);
return (T) resourceDao.readByPid(new JpaPid(theMdmLink.getGoldenResourcePersistenceId().getIdAsLong())); return (T) resourceDao.readByPid(theMdmLink.getGoldenResourcePersistenceId());
} }
protected Patient addExternalEID(Patient thePatient, String theEID) { protected Patient addExternalEID(Patient thePatient, String theEID) {

View File

@ -85,8 +85,8 @@ public class MdmLinkDaoSvcTest extends BaseMdmR4Test {
lists.stream() lists.stream()
.forEach(tuple -> { .forEach(tuple -> {
assertThat(tuple.getGoldenPid().getIdAsLong(), is(equalTo(golden.getIdElement().getIdPartAsLong()))); assertThat(((JpaPid) tuple.getGoldenPid()).getId(), is(equalTo(golden.getIdElement().getIdPartAsLong())));
assertThat(tuple.getSourcePid().getIdAsLong(), is(in(expectedExpandedPids))); assertThat(((JpaPid)tuple.getSourcePid()).getId(), is(in(expectedExpandedPids)));
}); });
} }

View File

@ -213,7 +213,7 @@ public class MdmStorageInterceptorIT extends BaseMdmR4Test {
// Updating a Golden Resource Patient who was created via MDM should fail. // Updating a Golden Resource Patient who was created via MDM should fail.
IMdmLink mdmLink = runInTransaction(() -> myMdmLinkDaoSvc.getMatchedLinkForSourcePid(myIdHelperService.getPidOrNull(RequestPartitionId.allPartitions(), patient)).orElseThrow(() -> new IllegalStateException())); IMdmLink mdmLink = runInTransaction(() -> myMdmLinkDaoSvc.getMatchedLinkForSourcePid(myIdHelperService.getPidOrNull(RequestPartitionId.allPartitions(), patient)).orElseThrow(() -> new IllegalStateException()));
Long sourcePatientPid = mdmLink.getGoldenResourcePersistenceId().getIdAsLong(); Long sourcePatientPid = ((JpaPid) mdmLink.getGoldenResourcePersistenceId()).getId();
Patient goldenResourcePatient = myPatientDao.readByPid(new JpaPid(sourcePatientPid)); Patient goldenResourcePatient = myPatientDao.readByPid(new JpaPid(sourcePatientPid));
goldenResourcePatient.setGender(Enumerations.AdministrativeGender.MALE); goldenResourcePatient.setGender(Enumerations.AdministrativeGender.MALE);
try { try {

View File

@ -70,10 +70,10 @@ public class MdmGoldenResourceMergerSvcTest extends BaseMdmR4Test {
public void before() { public void before() {
myFromGoldenPatient = createGoldenPatient(); myFromGoldenPatient = createGoldenPatient();
IdType fromSourcePatientId = myFromGoldenPatient.getIdElement().toUnqualifiedVersionless(); IdType fromSourcePatientId = myFromGoldenPatient.getIdElement().toUnqualifiedVersionless();
myFromGoldenPatientPid = runInTransaction(()->myIdHelperService.getPidOrThrowException(RequestPartitionId.allPartitions(), fromSourcePatientId)).getIdAsLong(); myFromGoldenPatientPid = ((JpaPid) runInTransaction(()->myIdHelperService.getPidOrThrowException(RequestPartitionId.allPartitions(), fromSourcePatientId))).getId();
myToGoldenPatient = createGoldenPatient(); myToGoldenPatient = createGoldenPatient();
IdType toGoldenPatientId = myToGoldenPatient.getIdElement().toUnqualifiedVersionless(); IdType toGoldenPatientId = myToGoldenPatient.getIdElement().toUnqualifiedVersionless();
myToGoldenPatientPid = runInTransaction(()->myIdHelperService.getPidOrThrowException(RequestPartitionId.allPartitions(), toGoldenPatientId)).getIdAsLong(); myToGoldenPatientPid = ((JpaPid) runInTransaction(()->myIdHelperService.getPidOrThrowException(RequestPartitionId.allPartitions(), toGoldenPatientId))).getId();
myTargetPatient1 = createPatient(); myTargetPatient1 = createPatient();
myTargetPatient2 = createPatient(); myTargetPatient2 = createPatient();

View File

@ -93,8 +93,8 @@ public class MdmLinkSvcTest extends BaseMdmR4Test {
JpaPid goldenPatient1Pid = (JpaPid) runInTransaction(()->myIdHelperService.getPidOrNull(RequestPartitionId.allPartitions(), goldenPatient1)); JpaPid goldenPatient1Pid = (JpaPid) runInTransaction(()->myIdHelperService.getPidOrNull(RequestPartitionId.allPartitions(), goldenPatient1));
JpaPid goldenPatient2Pid = (JpaPid) runInTransaction(()->myIdHelperService.getPidOrNull(RequestPartitionId.allPartitions(), goldenPatient2)); JpaPid goldenPatient2Pid = (JpaPid) runInTransaction(()->myIdHelperService.getPidOrNull(RequestPartitionId.allPartitions(), goldenPatient2));
assertFalse(myMdmLinkDaoSvc.getLinkByGoldenResourcePidAndSourceResourcePid(goldenPatient1Pid.getIdAsLong(), goldenPatient2Pid.getIdAsLong()).isPresent()); assertFalse(myMdmLinkDaoSvc.getLinkByGoldenResourcePidAndSourceResourcePid(goldenPatient1Pid.getId(), goldenPatient2Pid.getId()).isPresent());
assertFalse(myMdmLinkDaoSvc.getLinkByGoldenResourcePidAndSourceResourcePid(goldenPatient2Pid.getIdAsLong(), goldenPatient1Pid.getIdAsLong()).isPresent()); assertFalse(myMdmLinkDaoSvc.getLinkByGoldenResourcePidAndSourceResourcePid(goldenPatient2Pid.getId(), goldenPatient1Pid.getId()).isPresent());
saveNoMatchLink(goldenPatient1Pid, goldenPatient2Pid); saveNoMatchLink(goldenPatient1Pid, goldenPatient2Pid);
@ -111,8 +111,8 @@ public class MdmLinkSvcTest extends BaseMdmR4Test {
JpaPid goldenPatient1Pid = (JpaPid) runInTransaction(()->myIdHelperService.getPidOrNull(RequestPartitionId.allPartitions(), goldenPatient1)); JpaPid goldenPatient1Pid = (JpaPid) runInTransaction(()->myIdHelperService.getPidOrNull(RequestPartitionId.allPartitions(), goldenPatient1));
JpaPid goldenPatient2Pid = (JpaPid) runInTransaction(()->myIdHelperService.getPidOrNull(RequestPartitionId.allPartitions(), goldenPatient2)); JpaPid goldenPatient2Pid = (JpaPid) runInTransaction(()->myIdHelperService.getPidOrNull(RequestPartitionId.allPartitions(), goldenPatient2));
assertFalse(myMdmLinkDaoSvc.getLinkByGoldenResourcePidAndSourceResourcePid(goldenPatient1Pid.getIdAsLong(), goldenPatient2Pid.getIdAsLong()).isPresent()); assertFalse(myMdmLinkDaoSvc.getLinkByGoldenResourcePidAndSourceResourcePid(goldenPatient1Pid.getId(), goldenPatient2Pid.getId()).isPresent());
assertFalse(myMdmLinkDaoSvc.getLinkByGoldenResourcePidAndSourceResourcePid(goldenPatient2Pid.getIdAsLong(), goldenPatient1Pid.getIdAsLong()).isPresent()); assertFalse(myMdmLinkDaoSvc.getLinkByGoldenResourcePidAndSourceResourcePid(goldenPatient2Pid.getId(), goldenPatient1Pid.getId()).isPresent());
saveNoMatchLink(goldenPatient2Pid, goldenPatient1Pid); saveNoMatchLink(goldenPatient2Pid, goldenPatient1Pid);
@ -175,7 +175,7 @@ public class MdmLinkSvcTest extends BaseMdmR4Test {
//assertEquals(patient1.getIdElement().toVersionless().getValue(), sourcePatient.getLinkFirstRep().getTarget().getReference()); //assertEquals(patient1.getIdElement().toVersionless().getValue(), sourcePatient.getLinkFirstRep().getTarget().getReference());
List<String> actual = targets List<String> actual = targets
.stream() .stream()
.map(link -> link.getSourcePersistenceId().getId().toString()) .map(link -> ((JpaPid) link.getSourcePersistenceId()).getId().toString())
.collect(Collectors.toList()); .collect(Collectors.toList());
List<String> expected = Arrays.asList(patient1, patient2) List<String> expected = Arrays.asList(patient1, patient2)

View File

@ -6,6 +6,7 @@ import ca.uhn.fhir.batch2.model.JobInstance;
import ca.uhn.fhir.jpa.entity.MdmLink; import ca.uhn.fhir.jpa.entity.MdmLink;
import ca.uhn.fhir.jpa.mdm.BaseMdmR4Test; import ca.uhn.fhir.jpa.mdm.BaseMdmR4Test;
import ca.uhn.fhir.jpa.mdm.helper.MdmHelperR4; import ca.uhn.fhir.jpa.mdm.helper.MdmHelperR4;
import ca.uhn.fhir.jpa.model.dao.JpaPid;
import ca.uhn.fhir.jpa.partition.SystemRequestDetails; import ca.uhn.fhir.jpa.partition.SystemRequestDetails;
import ca.uhn.fhir.jpa.searchparam.SearchParameterMap; import ca.uhn.fhir.jpa.searchparam.SearchParameterMap;
import ca.uhn.fhir.mdm.api.MdmLinkSourceEnum; import ca.uhn.fhir.mdm.api.MdmLinkSourceEnum;
@ -53,8 +54,8 @@ class MdmClearStepTest extends BaseMdmR4Test {
goldenPatient.setId(myGoldenId); goldenPatient.setId(myGoldenId);
myPatientDao.update(goldenPatient); myPatientDao.update(goldenPatient);
mySourcePid = myIdHelperService.getPidOrThrowException(sourcePatient).getIdAsLong(); mySourcePid = ((JpaPid) myIdHelperService.getPidOrThrowException(sourcePatient)).getId();
myGoldenPid = myIdHelperService.getPidOrThrowException(goldenPatient).getIdAsLong(); myGoldenPid = ((JpaPid) myIdHelperService.getPidOrThrowException(goldenPatient)).getId();
myLink = buildMdmLink(mySourcePid, myGoldenPid); myLink = buildMdmLink(mySourcePid, myGoldenPid);
myMdmLinkDaoSvc.save(myLink); myMdmLinkDaoSvc.save(myLink);

View File

@ -18,7 +18,7 @@ public class JpaPid extends ResourcePersistentId<Long> {
public static List<Long> toLongList(Collection<ResourcePersistentId> thePids) { public static List<Long> toLongList(Collection<ResourcePersistentId> thePids) {
List<Long> retVal = new ArrayList<>(thePids.size()); List<Long> retVal = new ArrayList<>(thePids.size());
for (ResourcePersistentId next : thePids) { for (ResourcePersistentId next : thePids) {
retVal.add(next.getIdAsLong()); retVal.add(((JpaPid) next).getId());
} }
return retVal; return retVal;
} }

View File

@ -401,7 +401,7 @@ public class SearchParamExtractorService {
* need to resolve it again * need to resolve it again
*/ */
myResourceLinkResolver.validateTypeOrThrowException(type); myResourceLinkResolver.validateTypeOrThrowException(type);
resourceLink = ResourceLink.forLocalReference(thePathAndRef.getPath(), theEntity, typeString, resolvedTargetId.getIdAsLong(), targetId, transactionDate, targetVersionId); resourceLink = ResourceLink.forLocalReference(thePathAndRef.getPath(), theEntity, typeString, ((JpaPid) resolvedTargetId).getId(), targetId, transactionDate, targetVersionId);
} else if (theFailOnInvalidReference) { } else if (theFailOnInvalidReference) {
@ -498,10 +498,10 @@ public class SearchParamExtractorService {
private ResourceLink resolveTargetAndCreateResourceLinkOrReturnNull(@Nonnull RequestPartitionId theRequestPartitionId, String theSourceResourceName, PathAndRef thePathAndRef, ResourceTable theEntity, Date theUpdateTime, IIdType theNextId, RequestDetails theRequest, TransactionDetails theTransactionDetails) { private ResourceLink resolveTargetAndCreateResourceLinkOrReturnNull(@Nonnull RequestPartitionId theRequestPartitionId, String theSourceResourceName, PathAndRef thePathAndRef, ResourceTable theEntity, Date theUpdateTime, IIdType theNextId, RequestDetails theRequest, TransactionDetails theTransactionDetails) {
assert theRequestPartitionId != null; assert theRequestPartitionId != null;
ResourcePersistentId resolvedResourceId = theTransactionDetails.getResolvedResourceId(theNextId); JpaPid resolvedResourceId = (JpaPid) theTransactionDetails.getResolvedResourceId(theNextId);
if (resolvedResourceId != null) { if (resolvedResourceId != null) {
String targetResourceType = theNextId.getResourceType(); String targetResourceType = theNextId.getResourceType();
Long targetResourcePid = resolvedResourceId.getIdAsLong(); Long targetResourcePid = resolvedResourceId.getId();
String targetResourceIdPart = theNextId.getIdPart(); String targetResourceIdPart = theNextId.getIdPart();
Long targetVersion = theNextId.getVersionIdPartAsLong(); Long targetVersion = theNextId.getVersionIdPartAsLong();
return ResourceLink.forLocalReference(thePathAndRef.getPath(), theEntity, targetResourceType, targetResourcePid, targetResourceIdPart, theUpdateTime, targetVersion); return ResourceLink.forLocalReference(thePathAndRef.getPath(), theEntity, targetResourceType, targetResourcePid, targetResourceIdPart, theUpdateTime, targetVersion);
@ -526,7 +526,7 @@ public class SearchParamExtractorService {
} }
String targetResourceType = targetResource.getResourceType(); String targetResourceType = targetResource.getResourceType();
Long targetResourcePid = targetResource.getPersistentId().getIdAsLong(); Long targetResourcePid = ((JpaPid) targetResource.getPersistentId()).getId();
String targetResourceIdPart = theNextId.getIdPart(); String targetResourceIdPart = theNextId.getIdPart();
Long targetVersion = theNextId.getVersionIdPartAsLong(); Long targetVersion = theNextId.getVersionIdPartAsLong();
return ResourceLink.forLocalReference(thePathAndRef.getPath(), theEntity, targetResourceType, targetResourcePid, targetResourceIdPart, theUpdateTime, targetVersion); return ResourceLink.forLocalReference(thePathAndRef.getPath(), theEntity, targetResourceType, targetResourcePid, targetResourceIdPart, theUpdateTime, targetVersion);

View File

@ -211,8 +211,8 @@ public class SearchCoordinatorSvcImplTest extends BaseSearchSvc{
verify(mySearchCacheSvc, atLeastOnce()).save(searchCaptor.capture()); verify(mySearchCacheSvc, atLeastOnce()).save(searchCaptor.capture());
assertEquals(790, allResults.size()); assertEquals(790, allResults.size());
assertEquals(10, allResults.get(0).getIdAsLong().longValue()); assertEquals(10, allResults.get(0).getId());
assertEquals(799, allResults.get(789).getIdAsLong().longValue()); assertEquals(799, allResults.get(789).getId());
myExpectedNumberOfSearchBuildersCreated = 4; myExpectedNumberOfSearchBuildersCreated = 4;
} }

View File

@ -26,6 +26,7 @@ import java.util.Date;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.function.Function; import java.util.function.Function;
import java.util.stream.Collectors;
import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.hasSize; import static org.hamcrest.Matchers.hasSize;
@ -154,7 +155,7 @@ public class IdHelperServiceTest {
public void testResolveResourceIdentity_defaultFunctionality(){ public void testResolveResourceIdentity_defaultFunctionality(){
RequestPartitionId partitionId = RequestPartitionId.fromPartitionIdAndName(1, "partition"); RequestPartitionId partitionId = RequestPartitionId.fromPartitionIdAndName(1, "partition");
String resourceType = "Patient"; String resourceType = "Patient";
String resourceForcedId = "AAA"; String resourceForcedId = "123L";
Object[] forcedIdView = new Object[4]; Object[] forcedIdView = new Object[4];
forcedIdView[0] = resourceType; forcedIdView[0] = resourceType;
@ -168,7 +169,7 @@ public class IdHelperServiceTest {
IResourceLookup result = myHelperService.resolveResourceIdentity(partitionId, resourceType, resourceForcedId); IResourceLookup result = myHelperService.resolveResourceIdentity(partitionId, resourceType, resourceForcedId);
assertEquals(forcedIdView[0], result.getResourceType()); assertEquals(forcedIdView[0], result.getResourceType());
assertEquals(forcedIdView[1], result.getPersistentId().getId()); assertEquals(forcedIdView[1], ((JpaPid) result.getPersistentId()).getId());
assertEquals(forcedIdView[3], result.getDeleted()); assertEquals(forcedIdView[3], result.getDeleted());
} }
@ -185,7 +186,8 @@ public class IdHelperServiceTest {
.thenReturn(resourcePersistentId1) .thenReturn(resourcePersistentId1)
.thenReturn(resourcePersistentId2) .thenReturn(resourcePersistentId2)
.thenReturn(resourcePersistentId3); .thenReturn(resourcePersistentId3);
Map<String, ResourcePersistentId> result = myHelperService.resolveResourcePersistentIds(partitionId, resourceType, ids); Map<String, JpaPid> result = myHelperService.resolveResourcePersistentIds(partitionId, resourceType, ids)
.entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, entry -> (JpaPid) entry.getValue()));
assertThat(result.keySet(), hasSize(3)); assertThat(result.keySet(), hasSize(3));
assertEquals(1L, result.get("A").getId()); assertEquals(1L, result.get("A").getId());
assertEquals(2L, result.get("B").getId()); assertEquals(2L, result.get("B").getId());
@ -199,6 +201,7 @@ public class IdHelperServiceTest {
Long id = 1L; Long id = 1L;
JpaPid jpaPid1 = new JpaPid(id); JpaPid jpaPid1 = new JpaPid(id);
when(myDaoConfig.getResourceClientIdStrategy()).thenReturn(DaoConfig.ClientIdStrategyEnum.ANY);
when(myMemoryCacheService.getThenPutAfterCommit(any(), any(), any())).thenReturn(jpaPid1); when(myMemoryCacheService.getThenPutAfterCommit(any(), any(), any())).thenReturn(jpaPid1);
JpaPid result = (JpaPid) myHelperService.resolveResourcePersistentIds(partitionId, resourceType, id.toString()); JpaPid result = (JpaPid) myHelperService.resolveResourcePersistentIds(partitionId, resourceType, id.toString());
assertEquals(id, result.getId()); assertEquals(id, result.getId());

View File

@ -68,7 +68,7 @@ public class FhirSearchDaoR4Test extends BaseJpaR4Test {
// verify results // verify results
Assertions.assertEquals(1, ids.size()); Assertions.assertEquals(1, ids.size());
Assertions.assertEquals(id1, ids.get(0).getIdAsLong()); Assertions.assertEquals(id1, ids.get(0).getId());
} }
@Test @Test

View File

@ -4,8 +4,10 @@ import ca.uhn.fhir.interceptor.api.Pointcut;
import ca.uhn.fhir.jpa.api.config.DaoConfig; import ca.uhn.fhir.jpa.api.config.DaoConfig;
import ca.uhn.fhir.jpa.api.dao.IDao; import ca.uhn.fhir.jpa.api.dao.IDao;
import ca.uhn.fhir.jpa.api.svc.IIdHelperService; import ca.uhn.fhir.jpa.api.svc.IIdHelperService;
import ca.uhn.fhir.jpa.model.dao.JpaPid;
import ca.uhn.fhir.jpa.provider.BaseResourceProviderR4Test; import ca.uhn.fhir.jpa.provider.BaseResourceProviderR4Test;
import ca.uhn.fhir.rest.api.MethodOutcome; import ca.uhn.fhir.rest.api.MethodOutcome;
import ca.uhn.fhir.rest.api.server.storage.ResourcePersistentId;
import ca.uhn.fhir.rest.server.provider.ProviderConstants; import ca.uhn.fhir.rest.server.provider.ProviderConstants;
import org.hl7.fhir.instance.model.api.IAnyResource; import org.hl7.fhir.instance.model.api.IAnyResource;
import org.hl7.fhir.instance.model.api.IBaseResource; import org.hl7.fhir.instance.model.api.IBaseResource;
@ -21,6 +23,7 @@ import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import java.util.Collections; import java.util.Collections;
import java.util.List;
import java.util.concurrent.atomic.AtomicLong; import java.util.concurrent.atomic.AtomicLong;
import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
@ -113,7 +116,9 @@ public class HookInterceptorR4Test extends BaseResourceProviderR4Test {
IIdType savedPatientId = myClient.create().resource(new Patient()).execute().getId(); IIdType savedPatientId = myClient.create().resource(new Patient()).execute().getId();
runInTransaction(() -> { runInTransaction(() -> {
Long savedPatientPid = myIdHelperService.resolveResourcePersistentIdsWithCache(null, Collections.singletonList(savedPatientId)).get(0).getIdAsLong(); List<ResourcePersistentId> pids = myIdHelperService.resolveResourcePersistentIdsWithCache(null,
Collections.singletonList(savedPatientId));
Long savedPatientPid = ((JpaPid) pids.get(0)).getId();
assertEquals(savedPatientPid.longValue(), pid.get()); assertEquals(savedPatientPid.longValue(), pid.get());
}); });
} }
@ -128,7 +133,7 @@ public class HookInterceptorR4Test extends BaseResourceProviderR4Test {
pid.set(resourcePid); pid.set(resourcePid);
}); });
IIdType savedPatientId = myClient.create().resource(new Patient()).execute().getId(); IIdType savedPatientId = myClient.create().resource(new Patient()).execute().getId();
Long savedPatientPid = runInTransaction(() -> myIdHelperService.resolveResourcePersistentIdsWithCache(null, Collections.singletonList(savedPatientId)).get(0).getIdAsLong()); Long savedPatientPid = runInTransaction(() -> ((JpaPid) myIdHelperService.resolveResourcePersistentIdsWithCache(null, Collections.singletonList(savedPatientId)).get(0)).getId());
myClient.delete().resourceById(savedPatientId).execute(); myClient.delete().resourceById(savedPatientId).execute();
Parameters parameters = new Parameters(); Parameters parameters = new Parameters();
@ -165,7 +170,7 @@ public class HookInterceptorR4Test extends BaseResourceProviderR4Test {
patient.setActive(true); patient.setActive(true);
myClient.update().resource(patient).execute(); myClient.update().resource(patient).execute();
runInTransaction(() -> { runInTransaction(() -> {
Long savedPatientPid = myIdHelperService.resolveResourcePersistentIdsWithCache(null, Collections.singletonList(savedPatientId)).get(0).getIdAsLong(); Long savedPatientPid = ((JpaPid) myIdHelperService.resolveResourcePersistentIdsWithCache(null, Collections.singletonList(savedPatientId)).get(0)).getId();
assertEquals(savedPatientPid.longValue(), pidOld.get()); assertEquals(savedPatientPid.longValue(), pidOld.get());
assertEquals(savedPatientPid.longValue(), pidNew.get()); assertEquals(savedPatientPid.longValue(), pidNew.get());
}); });

View File

@ -242,7 +242,7 @@ public class ResourceReindexingSvcImplTest extends BaseJpaTest {
when(myDaoRegistry.getResourceDao(eq("Patient"))).thenReturn(myResourceDao); when(myDaoRegistry.getResourceDao(eq("Patient"))).thenReturn(myResourceDao);
when(myDaoRegistry.getResourceDao(eq(Patient.class))).thenReturn(myResourceDao); when(myDaoRegistry.getResourceDao(eq(Patient.class))).thenReturn(myResourceDao);
when(myResourceDao.readByPid(any(), anyBoolean())).thenAnswer(t->{ when(myResourceDao.readByPid(any(), anyBoolean())).thenAnswer(t->{
int idx = t.getArgument(0, JpaPid.class).getIdAsLong().intValue(); int idx = t.getArgument(0, JpaPid.class).getId().intValue();
return resources.get(idx); return resources.get(idx);
}); });
@ -350,7 +350,7 @@ public class ResourceReindexingSvcImplTest extends BaseJpaTest {
when(myDaoRegistry.getResourceDao(eq("Observation"))).thenReturn(myResourceDao); when(myDaoRegistry.getResourceDao(eq("Observation"))).thenReturn(myResourceDao);
when(myDaoRegistry.getResourceDao(eq(Observation.class))).thenReturn(myResourceDao); when(myDaoRegistry.getResourceDao(eq(Observation.class))).thenReturn(myResourceDao);
when(myResourceDao.readByPid(any(), anyBoolean())).thenAnswer(t->{ when(myResourceDao.readByPid(any(), anyBoolean())).thenAnswer(t->{
int idx = t.getArgument(0, JpaPid.class).getIdAsLong().intValue(); int idx = t.getArgument(0, JpaPid.class).getId().intValue();
return resources.get(idx); return resources.get(idx);
}); });
} }

View File

@ -96,7 +96,7 @@ public class ResourceVersionSvcTest {
matches.add(getResourceTableRecordForResourceTypeAndPid( matches.add(getResourceTableRecordForResourceTypeAndPid(
pack.MyResourceId.getResourceType(), pack.MyResourceId.getResourceType(),
pack.MyPid.getIdAsLong(), ((JpaPid) pack.MyPid).getId(),
pack.MyVersion pack.MyVersion
)); ));
} }

View File

@ -20,6 +20,7 @@ package ca.uhn.fhir.mdm.model;
* #L% * #L%
*/ */
import ca.uhn.fhir.jpa.model.dao.JpaPid;
import ca.uhn.fhir.rest.api.server.storage.ResourcePersistentId; import ca.uhn.fhir.rest.api.server.storage.ResourcePersistentId;
public class MdmPidTuple { public class MdmPidTuple {
@ -45,11 +46,11 @@ public class MdmPidTuple {
} }
public Long getGoldenPidAsLong() { public Long getGoldenPidAsLong() {
return myGoldenPid.getIdAsLong(); return ((JpaPid) myGoldenPid).getId();
} }
public Long getSourcePidAsLong() { public Long getSourcePidAsLong() {
return mySourcePid.getIdAsLong(); return ((JpaPid) myGoldenPid).getId();
} }
public String getGoldenPidAsString() { public String getGoldenPidAsString() {

View File

@ -20,6 +20,7 @@ package ca.uhn.fhir.batch2.jobs.models;
* #L% * #L%
*/ */
import ca.uhn.fhir.jpa.model.dao.JpaPid;
import ca.uhn.fhir.model.api.IModelJson; import ca.uhn.fhir.model.api.IModelJson;
import ca.uhn.fhir.rest.api.server.storage.ResourcePersistentId; import ca.uhn.fhir.rest.api.server.storage.ResourcePersistentId;
import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonProperty;
@ -77,7 +78,7 @@ public class Id implements IModelJson {
public static Id getIdFromPID(ResourcePersistentId thePID, String theResourceType) { public static Id getIdFromPID(ResourcePersistentId thePID, String theResourceType) {
Id id = new Id(); Id id = new Id();
id.setId(thePID.getId().toString()); id.setId(((JpaPid)thePID).getId().toString());
id.setResourceType(theResourceType); id.setResourceType(theResourceType);
return id; return id;
} }

View File

@ -97,7 +97,7 @@ public class ExpandResourcesStepTest {
ArrayList<IBaseResource> resources = new ArrayList<>(); ArrayList<IBaseResource> resources = new ArrayList<>();
ArrayList<Id> ids = new ArrayList<>(); ArrayList<Id> ids = new ArrayList<>();
for (int i = 0; i < 100; i++) { for (int i = 0; i < 100; i++) {
String stringId = "Patient/" + i; String stringId = String.valueOf(i);
Id id = new Id(); Id id = new Id();
id.setResourceType("Patient"); id.setResourceType("Patient");
id.setId(stringId); id.setId(stringId);

View File

@ -23,6 +23,7 @@ package ca.uhn.fhir.jpa.dao.expunge;
import ca.uhn.fhir.i18n.Msg; import ca.uhn.fhir.i18n.Msg;
import ca.uhn.fhir.jpa.api.model.ExpungeOptions; import ca.uhn.fhir.jpa.api.model.ExpungeOptions;
import ca.uhn.fhir.jpa.api.model.ExpungeOutcome; import ca.uhn.fhir.jpa.api.model.ExpungeOutcome;
import ca.uhn.fhir.jpa.model.dao.JpaPid;
import ca.uhn.fhir.rest.api.server.RequestDetails; import ca.uhn.fhir.rest.api.server.RequestDetails;
import ca.uhn.fhir.rest.api.server.storage.ResourcePersistentId; import ca.uhn.fhir.rest.api.server.storage.ResourcePersistentId;
import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException; import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException;
@ -48,14 +49,15 @@ public class ExpungeService {
} }
public ExpungeOutcome expunge(String theResourceName, ResourcePersistentId theResourceId, ExpungeOptions theExpungeOptions, RequestDetails theRequest) { public ExpungeOutcome expunge(String theResourceName, ResourcePersistentId theResourceId, ExpungeOptions theExpungeOptions, RequestDetails theRequest) {
ourLog.info("Expunge: ResourceName[{}] Id[{}] Version[{}] Options[{}]", theResourceName, theResourceId != null ? theResourceId.getId() : null, theResourceId != null ? theResourceId.getVersion() : null, theExpungeOptions); JpaPid jpaPid = (JpaPid) theResourceId;
ExpungeOperation expungeOperation = getExpungeOperation(theResourceName, theResourceId, theExpungeOptions, theRequest); ourLog.info("Expunge: ResourceName[{}] Id[{}] Version[{}] Options[{}]", theResourceName, jpaPid != null ? jpaPid.getId() : null, jpaPid != null ? jpaPid.getVersion() : null, theExpungeOptions);
ExpungeOperation expungeOperation = getExpungeOperation(theResourceName, jpaPid, theExpungeOptions, theRequest);
if (theExpungeOptions.getLimit() < 1) { if (theExpungeOptions.getLimit() < 1) {
throw new InvalidRequestException(Msg.code(1087) + "Expunge limit may not be less than 1. Received expunge limit " + theExpungeOptions.getLimit() + "."); throw new InvalidRequestException(Msg.code(1087) + "Expunge limit may not be less than 1. Received expunge limit " + theExpungeOptions.getLimit() + ".");
} }
if (theResourceName == null && (theResourceId == null || (theResourceId.getId() == null && theResourceId.getVersion() == null))) { if (theResourceName == null && (jpaPid == null || (jpaPid.getId() == null && jpaPid.getVersion() == null))) {
if (theExpungeOptions.isExpungeEverything()) { if (theExpungeOptions.isExpungeEverything()) {
myExpungeEverythingService.expungeEverything(theRequest); myExpungeEverythingService.expungeEverything(theRequest);
return new ExpungeOutcome().setDeletedCount(myExpungeEverythingService.getExpungeDeletedEntityCount()); return new ExpungeOutcome().setDeletedCount(myExpungeEverythingService.getExpungeDeletedEntityCount());

View File

@ -95,10 +95,10 @@ public class DaoResourceLinkResolver implements IResourceLinkResolver {
RuntimeSearchParam searchParam = mySearchParamRegistry.getActiveSearchParam(theSourceResourceName, thePathAndRef.getSearchParamName()); RuntimeSearchParam searchParam = mySearchParamRegistry.getActiveSearchParam(theSourceResourceName, thePathAndRef.getSearchParamName());
ResourcePersistentId persistentId = null; JpaPid persistentId = null;
if (theTransactionDetails != null) { if (theTransactionDetails != null) {
ResourcePersistentId resolvedResourceId = theTransactionDetails.getResolvedResourceId(targetResourceId); JpaPid resolvedResourceId = (JpaPid) theTransactionDetails.getResolvedResourceId(targetResourceId);
if (resolvedResourceId != null && resolvedResourceId.getIdAsLong() != null && resolvedResourceId.getAssociatedResourceId() != null) { if (resolvedResourceId != null && resolvedResourceId.getId() != null && resolvedResourceId.getAssociatedResourceId() != null) {
persistentId = resolvedResourceId; persistentId = resolvedResourceId;
} }
} }
@ -141,7 +141,8 @@ public class DaoResourceLinkResolver implements IResourceLinkResolver {
} }
if (persistentId == null) { if (persistentId == null) {
persistentId = new JpaPid((Long) resolvedResource.getPersistentId().getId()); persistentId = ((JpaPid) resolvedResource.getPersistentId());
persistentId = new JpaPid(persistentId.getId());
persistentId.setAssociatedResourceId(targetResourceId); persistentId.setAssociatedResourceId(targetResourceId);
if (theTransactionDetails != null) { if (theTransactionDetails != null) {
theTransactionDetails.addResolvedResourceId(targetResourceId, persistentId); theTransactionDetails.addResolvedResourceId(targetResourceId, persistentId);
@ -184,7 +185,8 @@ public class DaoResourceLinkResolver implements IResourceLinkResolver {
valueOf = placeholderResourceDao.create(newResource, theRequest).getEntity(); valueOf = placeholderResourceDao.create(newResource, theRequest).getEntity();
} }
JpaPid persistentId = new JpaPid((Long) valueOf.getPersistentId().getId(), 1L); JpaPid persistentId = (JpaPid) valueOf.getPersistentId();
persistentId = new JpaPid(persistentId.getId(), 1L);
persistentId.setAssociatedResourceId(valueOf.getIdDt()); persistentId.setAssociatedResourceId(valueOf.getIdDt());
theTransactionDetails.addResolvedResourceId(persistentId.getAssociatedResourceId(), persistentId); theTransactionDetails.addResolvedResourceId(persistentId.getAssociatedResourceId(), persistentId);
} }