diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/util/FhirTerser.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/util/FhirTerser.java index 60c4d66f9e9..777f39eb367 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/util/FhirTerser.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/util/FhirTerser.java @@ -1785,12 +1785,12 @@ public class FhirTerser { public static class ContainedResources extends EmbeddedResources { private long myNextContainedId = 1; - private Map myResourceToOrdMap; + private Map myResourceToOrdMap; @Override protected void addResource(IIdType theId, IBaseResource theResource) { super.addResource(theId, theResource); - int ordinal = getOrCreateResourceList().size(); + short ordinal = Integer.valueOf(getOrCreateResourceList().size()).shortValue(); getOrCreateResourceToOrdMap().put(theResource, ordinal); } @@ -1823,14 +1823,14 @@ public class FhirTerser { return getOrCreateResourceList(); } - private Map getOrCreateResourceToOrdMap() { + private Map getOrCreateResourceToOrdMap() { if (myResourceToOrdMap == null) { myResourceToOrdMap = new IdentityHashMap<>(); } return myResourceToOrdMap; } - public Integer getContainedResourceOrd(IBaseResource theResource) { + public Short getContainedResourceOrd(IBaseResource theResource) { return getOrCreateResourceToOrdMap().get(theResource); } } diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/migrate/tasks/HapiFhirMigrationTasks_V7_2.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/migrate/tasks/HapiFhirMigrationTasks_V7_2.java index f8a10ca6520..49823cb0125 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/migrate/tasks/HapiFhirMigrationTasks_V7_2.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/migrate/tasks/HapiFhirMigrationTasks_V7_2.java @@ -45,6 +45,5 @@ public class HapiFhirMigrationTasks_V7_2 { Builder.BuilderWithTableName tableBuilder = myVersion.onTable(idxTable); tableBuilder.addColumn(subVersionName, "contained_ord").nullable().type(ColumnTypeEnum.TINYINT); }); - } } diff --git a/hapi-fhir-jpaserver-model/src/main/java/ca/uhn/fhir/jpa/model/entity/BaseResourceIndexedSearchParam.java b/hapi-fhir-jpaserver-model/src/main/java/ca/uhn/fhir/jpa/model/entity/BaseResourceIndexedSearchParam.java index 2dba83f80c6..727dda42aaf 100644 --- a/hapi-fhir-jpaserver-model/src/main/java/ca/uhn/fhir/jpa/model/entity/BaseResourceIndexedSearchParam.java +++ b/hapi-fhir-jpaserver-model/src/main/java/ca/uhn/fhir/jpa/model/entity/BaseResourceIndexedSearchParam.java @@ -66,7 +66,7 @@ public abstract class BaseResourceIndexedSearchParam extends BaseResourceIndex { @GenericField @Column(name = "CONTAINED_ORD", nullable = true) - private Integer myContainedOrd; + private Short myContainedOrd; @Override public abstract Long getId(); @@ -143,11 +143,11 @@ public abstract class BaseResourceIndexedSearchParam extends BaseResourceIndex { return myHashIdentity; } - public Integer getContainedOrd() { + public Short getContainedOrd() { return myContainedOrd; } - public void setContainedOrd(Integer theContainedOrd) { + public void setContainedOrd(Short theContainedOrd) { if (!Objects.equals(theContainedOrd, myContainedOrd)) { myContainedOrd = theContainedOrd; clearHashes(); diff --git a/hapi-fhir-jpaserver-model/src/main/java/ca/uhn/fhir/jpa/model/entity/ResourceIndexedSearchParamToken.java b/hapi-fhir-jpaserver-model/src/main/java/ca/uhn/fhir/jpa/model/entity/ResourceIndexedSearchParamToken.java index e5477f97060..f602b8e4fbb 100644 --- a/hapi-fhir-jpaserver-model/src/main/java/ca/uhn/fhir/jpa/model/entity/ResourceIndexedSearchParamToken.java +++ b/hapi-fhir-jpaserver-model/src/main/java/ca/uhn/fhir/jpa/model/entity/ResourceIndexedSearchParamToken.java @@ -19,6 +19,7 @@ */ package ca.uhn.fhir.jpa.model.entity; +import ca.uhn.fhir.jpa.model.config.PartitionSettings; import ca.uhn.fhir.jpa.model.search.hash.ResourceIndexHasher; import ca.uhn.fhir.model.api.IQueryParameterType; import ca.uhn.fhir.rest.api.Constants; @@ -119,6 +120,19 @@ public class ResourceIndexedSearchParamToken extends BaseResourceIndexedSearchPa */ public ResourceIndexedSearchParamToken() {} + @Deprecated(since = "7.2") + public ResourceIndexedSearchParamToken( + PartitionSettings thePartitionSettings, + String theResourceType, + String theParamName, + String theSystem, + String theValue) { + setResourceType(theResourceType); + setParamName(theParamName); + setSystem(theSystem); + setValue(theValue); + } + /** * Constructor */ diff --git a/hapi-fhir-jpaserver-model/src/main/java/ca/uhn/fhir/jpa/model/search/hash/IdentityHasher.java b/hapi-fhir-jpaserver-model/src/main/java/ca/uhn/fhir/jpa/model/search/hash/IdentityHasher.java index 6eb6733154f..ebdbb35086d 100644 --- a/hapi-fhir-jpaserver-model/src/main/java/ca/uhn/fhir/jpa/model/search/hash/IdentityHasher.java +++ b/hapi-fhir-jpaserver-model/src/main/java/ca/uhn/fhir/jpa/model/search/hash/IdentityHasher.java @@ -48,12 +48,12 @@ public class IdentityHasher { Object value = pd.getReadMethod().invoke(bean); hashValue(value, hasher); } catch (Exception e) { - throw new RuntimeException( + throw new IllegalStateException( Msg.code(2510) + "Failed to access " + targetClass + "#" + pd.getName(), e); } }); } catch (IntrospectionException e) { - throw new RuntimeException(Msg.code(2510) + "Failed to introspect " + targetClass, e); + throw new IllegalStateException(Msg.code(2511) + "Failed to introspect " + targetClass, e); } return hasher.hash().asLong(); } diff --git a/hapi-fhir-jpaserver-model/src/main/java/ca/uhn/fhir/jpa/model/search/hash/ResourceIndexHasher.java b/hapi-fhir-jpaserver-model/src/main/java/ca/uhn/fhir/jpa/model/search/hash/ResourceIndexHasher.java index 7b8ea8ea62e..b6c0ee56126 100644 --- a/hapi-fhir-jpaserver-model/src/main/java/ca/uhn/fhir/jpa/model/search/hash/ResourceIndexHasher.java +++ b/hapi-fhir-jpaserver-model/src/main/java/ca/uhn/fhir/jpa/model/search/hash/ResourceIndexHasher.java @@ -143,23 +143,7 @@ public class ResourceIndexHasher { * @return the hash value */ public long hash(@Nullable RequestPartitionId theRequestPartitionId, @NotNull String... theValues) { - HashIdentity identity = new HashIdentity(theValues); - - if (myPartitionSettings.isPartitioningEnabled() - && myPartitionSettings.isIncludePartitionInSearchHashes() - && theRequestPartitionId != null - && theRequestPartitionId.hasPartitionIds()) { - if (theRequestPartitionId.getPartitionIds().size() > 1) { - throw new InternalErrorException(Msg.code(1527) - + "Can not search multiple partitions when partitions are included in search hashes"); - } - Integer partitionId = theRequestPartitionId.getFirstPartitionIdOrNull(); - identity.setPartitionId(partitionId); - } - - identity.setContained(false); - - return IdentityHasher.hash(identity); + return hash(theRequestPartitionId, false, theValues); } /** @@ -178,7 +162,7 @@ public class ResourceIndexHasher { && theRequestPartitionId != null && theRequestPartitionId.hasPartitionIds()) { if (theRequestPartitionId.getPartitionIds().size() > 1) { - throw new InternalErrorException(Msg.code(1527) + throw new InternalErrorException(Msg.code(2512) + "Can not search multiple partitions when partitions are included in search hashes"); } Integer partitionId = theRequestPartitionId.getFirstPartitionIdOrNull(); diff --git a/hapi-fhir-jpaserver-searchparam/src/main/java/ca/uhn/fhir/jpa/searchparam/extractor/SearchParamExtractorService.java b/hapi-fhir-jpaserver-searchparam/src/main/java/ca/uhn/fhir/jpa/searchparam/extractor/SearchParamExtractorService.java index e5cafaca9d7..cf34393f062 100644 --- a/hapi-fhir-jpaserver-searchparam/src/main/java/ca/uhn/fhir/jpa/searchparam/extractor/SearchParamExtractorService.java +++ b/hapi-fhir-jpaserver-searchparam/src/main/java/ca/uhn/fhir/jpa/searchparam/extractor/SearchParamExtractorService.java @@ -312,7 +312,7 @@ public class SearchParamExtractorService { } @Override - public Integer getContainedOrd(IBaseResource theResource) { + public Short getContainedOrd(IBaseResource theResource) { return containedResources.getContainedResourceOrd(theResource); } }; @@ -502,7 +502,7 @@ public class SearchParamExtractorService { return theEmbeddedResources.getResource(reference.getReferenceElement()); } - private void setContainerOrd(ResourceIndexedSearchParams theParams, Integer theContainerOrd) { + private void setContainerOrd(ResourceIndexedSearchParams theParams, Short theContainerOrd) { setContainerOrd(theParams.myStringParams, theContainerOrd); setContainerOrd(theParams.myNumberParams, theContainerOrd); setContainerOrd(theParams.myQuantityParams, theContainerOrd); @@ -514,7 +514,7 @@ public class SearchParamExtractorService { } private void setContainerOrd( - Collection theParams, Integer theContainerOrd) { + Collection theParams, Short theContainerOrd) { theParams.forEach(param -> { param.setContainedOrd(theContainerOrd); param.calculateHashes(myResourceIndexHasher); @@ -1243,7 +1243,7 @@ public class SearchParamExtractorService { boolean isIndexOnContainedResources(); - default Integer getContainedOrd(IBaseResource theResource) { + default Short getContainedOrd(IBaseResource theResource) { return null; } } diff --git a/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/dao/r4/ChainingR4SearchTest.java b/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/dao/r4/ChainingR4SearchTest.java index 3f36f9a822f..e6784680486 100644 --- a/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/dao/r4/ChainingR4SearchTest.java +++ b/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/dao/r4/ChainingR4SearchTest.java @@ -146,14 +146,14 @@ public class ChainingR4SearchTest extends BaseJpaR4Test { IIdType obsId = myObservationDao.create(obs, mySrd).getId().toUnqualifiedVersionless(); runInTransaction(()-> { - Map> containerOrdMap = new HashMap<>(); + Map> containerOrdMap = new HashMap<>(); myResourceIndexedSearchParamStringDao.findAllForResourceId(obsId.getIdPartAsLong()).forEach(param -> { String paramName = param.getParamName(); if (paramName.startsWith("patient.") || paramName.startsWith("performer.")) { - Integer containerOrd = param.getContainedOrd(); + Short containerOrd = param.getContainedOrd(); assertNotNull(containerOrd); assertTrue(containerOrd > 0L); - List list = containerOrdMap.get(paramName); + List list = containerOrdMap.get(paramName); if (list == null) { list = new ArrayList<>(); } @@ -161,8 +161,12 @@ public class ChainingR4SearchTest extends BaseJpaR4Test { containerOrdMap.put(paramName, list); } }); - assertThat(containerOrdMap.get("patient.family"), containsInAnyOrder(1)); - assertThat(containerOrdMap.get("performer.family"), containsInAnyOrder(2, 3, 4)); + List patientFamilyOrdinalList = containerOrdMap.get("patient.family"); + assertNotNull(patientFamilyOrdinalList); + assertThat(patientFamilyOrdinalList, contains(1)); + List performerFamilyOrdinalList = containerOrdMap.get("performer.family"); + assertNotNull(performerFamilyOrdinalList); + assertThat(performerFamilyOrdinalList, containsInAnyOrder(2, 3, 4)); }); } diff --git a/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/stresstest/GiantTransactionPerfTest.java b/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/stresstest/GiantTransactionPerfTest.java index fae518d2983..ad860a9011f 100644 --- a/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/stresstest/GiantTransactionPerfTest.java +++ b/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/stresstest/GiantTransactionPerfTest.java @@ -135,7 +135,6 @@ public class GiantTransactionPerfTest { private IRequestPartitionHelperSvc myRequestPartitionHelperSvc; private SearchParamWithInlineReferencesExtractor mySearchParamWithInlineReferencesExtractor; private PartitionSettings myPartitionSettings; - private ResourceIndexHasher myResourceIndexHasher; private SearchParamExtractorService mySearchParamExtractorSvc; private SearchParamExtractorR4 mySearchParamExtractor; private SearchParamRegistryImpl mySearchParamRegistry; @@ -179,8 +178,6 @@ public class GiantTransactionPerfTest { myDaoRegistry = new DaoRegistry(ourFhirContext); myPartitionSettings = new PartitionSettings(); - myResourceIndexHasher = new ResourceIndexHasher(myPartitionSettings, new StorageSettings()); - myMetaTagSorter = new MetaTagSorterAlphabetical(); myHapiTransactionService = new HapiTransactionService(); @@ -236,23 +233,25 @@ public class GiantTransactionPerfTest { mySearchParamRegistry.setStorageSettings(myStorageSettings); mySearchParamRegistry.registerListener(); + ResourceIndexHasher resourceIndexHasher = new ResourceIndexHasher(myPartitionSettings, new StorageSettings()); + mySearchParamExtractor = new SearchParamExtractorR4(); mySearchParamExtractor.setContext(ourFhirContext); mySearchParamExtractor.setSearchParamRegistry(mySearchParamRegistry); mySearchParamExtractor.setStorageSettings(myStorageSettings); - mySearchParamExtractor.setResourceIndexHasher(myResourceIndexHasher); + mySearchParamExtractor.setResourceIndexHasher(resourceIndexHasher); mySearchParamExtractor.start(); mySearchParamExtractorSvc = new SearchParamExtractorService(); mySearchParamExtractorSvc.setContext(ourFhirContext); mySearchParamExtractorSvc.setSearchParamExtractor(mySearchParamExtractor); mySearchParamExtractorSvc.setStorageSettings(myStorageSettings); - mySearchParamExtractorSvc.setResourceIndexHasher(myResourceIndexHasher); + mySearchParamExtractorSvc.setResourceIndexHasher(resourceIndexHasher); myDaoSearchParamSynchronizer = new DaoSearchParamSynchronizer(); myDaoSearchParamSynchronizer.setEntityManager(myEntityManager); - myDaoSearchParamSynchronizer.setResourceIndexHasher(myResourceIndexHasher); + myDaoSearchParamSynchronizer.setResourceIndexHasher(resourceIndexHasher); mySearchParamWithInlineReferencesExtractor = new SearchParamWithInlineReferencesExtractor(); mySearchParamWithInlineReferencesExtractor.setStorageSettings(myStorageSettings);