diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/subscription/SubscriptionActivatingSubscriber.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/subscription/SubscriptionActivatingSubscriber.java index 8a37edbb3f7..fd5919eaa75 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/subscription/SubscriptionActivatingSubscriber.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/subscription/SubscriptionActivatingSubscriber.java @@ -32,6 +32,8 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.messaging.Message; import org.springframework.messaging.MessagingException; +import org.springframework.transaction.support.TransactionSynchronizationAdapter; +import org.springframework.transaction.support.TransactionSynchronizationManager; import java.util.concurrent.ConcurrentHashMap; @@ -53,22 +55,27 @@ public class SubscriptionActivatingSubscriber { myCtx = theSubscriptionDao.getContext(); } - public void activateAndRegisterSubscriptionIfRequired(IBaseResource theSubscription) { + public void activateAndRegisterSubscriptionIfRequired(final IBaseResource theSubscription) { boolean subscriptionTypeApplies = BaseSubscriptionSubscriber.subscriptionTypeApplies(myCtx, theSubscription, myChannelType); if (subscriptionTypeApplies == false) { return; } - IPrimitiveType status = myCtx.newTerser().getSingleValueOrNull(theSubscription, BaseSubscriptionInterceptor.SUBSCRIPTION_STATUS, IPrimitiveType.class); + final IPrimitiveType status = myCtx.newTerser().getSingleValueOrNull(theSubscription, BaseSubscriptionInterceptor.SUBSCRIPTION_STATUS, IPrimitiveType.class); String statusString = status.getValueAsString(); - String requestedStatus = Subscription.SubscriptionStatus.REQUESTED.toCode(); - String activeStatus = Subscription.SubscriptionStatus.ACTIVE.toCode(); + final String requestedStatus = Subscription.SubscriptionStatus.REQUESTED.toCode(); + final String activeStatus = Subscription.SubscriptionStatus.ACTIVE.toCode(); if (requestedStatus.equals(statusString)) { - status.setValueAsString(activeStatus); - ourLog.info("Activating and registering subscription {} from status {} to {}", theSubscription.getIdElement().toUnqualified().getValue(), requestedStatus, activeStatus); - mySubscriptionDao.update(theSubscription); - mySubscriptionInterceptor.registerSubscription(theSubscription.getIdElement(), theSubscription); + TransactionSynchronizationManager.registerSynchronization(new TransactionSynchronizationAdapter() { + @Override + public void afterCommit() { + status.setValueAsString(activeStatus); + ourLog.info("Activating and registering subscription {} from status {} to {}", theSubscription.getIdElement().toUnqualified().getValue(), requestedStatus, activeStatus); + mySubscriptionDao.update(theSubscription); + mySubscriptionInterceptor.registerSubscription(theSubscription.getIdElement(), theSubscription); + } + }); } else if (activeStatus.equals(statusString)) { if (!mySubscriptionInterceptor.hasSubscription(theSubscription.getIdElement())) { ourLog.info("Registering active subscription {}", theSubscription.getIdElement().toUnqualified().getValue()); diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/config/TestDstu3Config.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/config/TestDstu3Config.java index 1170d275109..c827bb7d27e 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/config/TestDstu3Config.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/config/TestDstu3Config.java @@ -93,7 +93,7 @@ public class TestDstu3Config extends BaseJavaConfigDstu3 { * and catch any potential deadlocks caused by database connection * starvation */ - int maxThreads = (int) (Math.random() * 6) + 1; + int maxThreads = (int) (Math.random() * 6.0) + 1; retVal.setMaxTotal(maxThreads); return retVal; @@ -105,8 +105,8 @@ public class TestDstu3Config extends BaseJavaConfigDstu3 { DataSource dataSource = ProxyDataSourceBuilder .create(basicDataSource()) - .logQueryBySlf4j(SLF4JLogLevel.INFO, "SQL") -// .logSlowQueryBySlf4j(100, TimeUnit.MILLISECONDS) +// .logQueryBySlf4j(SLF4JLogLevel.INFO, "SQL") + .logSlowQueryBySlf4j(1000, TimeUnit.MILLISECONDS) .countQuery() .build(); diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/config/TestR4Config.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/config/TestR4Config.java index 8794a67ebd8..82b78e27799 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/config/TestR4Config.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/config/TestR4Config.java @@ -94,12 +94,12 @@ public class TestR4Config extends BaseJavaConfigR4 { * and catch any potential deadlocks caused by database connection * starvation */ - int maxThreads = (int) (Math.random() * 6) + 1; + int maxThreads = (int) (Math.random() * 6.0) + 1; retVal.setMaxTotal(maxThreads); DataSource dataSource = ProxyDataSourceBuilder .create(retVal) - .logQueryBySlf4j(SLF4JLogLevel.INFO, "SQL") +// .logQueryBySlf4j(SLF4JLogLevel.INFO, "SQL") .logSlowQueryBySlf4j(10, TimeUnit.SECONDS) .countQuery(new ThreadQueryCountHolder()) .build(); diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu2/FhirResourceDaoDstu2SearchNoFtTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu2/FhirResourceDaoDstu2SearchNoFtTest.java index f0cc7d84364..cadec9a7a90 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu2/FhirResourceDaoDstu2SearchNoFtTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu2/FhirResourceDaoDstu2SearchNoFtTest.java @@ -921,7 +921,6 @@ public class FhirResourceDaoDstu2SearchNoFtTest extends BaseJpaDstu2Test { List patients = toList(myPatientDao.search(params)); assertEquals(1, patients.size()); assertEquals(id1.getIdPart(), patients.get(0).getId().getIdPart()); - assertEquals("P1TITLE", ResourceMetadataKeyEnum.TITLE.get(patients.get(0))); // Given name shouldn't return for family param params = new SearchParameterMap(); diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/subscription/r4/RestHookTestR4Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/subscription/r4/RestHookTestR4Test.java index 515e85d82e4..78505b03617 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/subscription/r4/RestHookTestR4Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/subscription/r4/RestHookTestR4Test.java @@ -51,7 +51,9 @@ public class RestHookTestR4Test extends BaseResourceProviderR4Test { @After public void afterUnregisterRestHookListener() { for (IIdType next : mySubscriptionIds) { - ourClient.delete().resourceById(next).execute(); + IIdType nextId = next.toUnqualifiedVersionless(); + ourLog.info("Deleting: {}", nextId); + ourClient.delete().resourceById(nextId).execute(); } mySubscriptionIds.clear(); diff --git a/hapi-fhir-jpaserver-uhnfhirtest/derby_maintenance.txt b/hapi-fhir-jpaserver-uhnfhirtest/derby_maintenance.txt index 21e69afe88a..1e8c7df6044 100644 --- a/hapi-fhir-jpaserver-uhnfhirtest/derby_maintenance.txt +++ b/hapi-fhir-jpaserver-uhnfhirtest/derby_maintenance.txt @@ -74,4 +74,24 @@ drop table trm_concept cascade constraints; drop table trm_concept_pc_link cascade constraints; drop table trm_concept_property cascade constraints; +# Delete all resources +update hfj_res_ver set forced_id_pid = null where res_id in (select res_id from hfj_resource); +update hfj_resource set forced_id_pid = null where res_id in (select res_id from hfj_resource); +delete from hfj_history_tag where res_id in (select res_id from hfj_resource); +delete from hfj_res_ver where res_id in (select res_id from hfj_resource); +delete from hfj_forced_id where resource_pid in (select res_id from hfj_resource); +delete from hfj_res_link where src_resource_id in (select res_id from hfj_resource); +delete from hfj_res_link where target_resource_id in (select res_id from hfj_resource); +delete from hfj_spidx_coords where res_id in (select res_id from hfj_resource); +delete from hfj_spidx_date where res_id in (select res_id from hfj_resource); +delete from hfj_spidx_number where res_id in (select res_id from hfj_resource); +delete from hfj_spidx_quantity where res_id in (select res_id from hfj_resource); +delete from hfj_spidx_string where res_id in (select res_id from hfj_resource); +delete from hfj_spidx_token where res_id in (select res_id from hfj_resource); +delete from hfj_spidx_uri where res_id in (select res_id from hfj_resource); +delete from hfj_res_tag where res_id in (select res_id from hfj_resource); +delete from hfj_search_result where resource_pid in (select res_id from hfj_resource); +delete from hfj_res_param_present where res_id in (select res_id from hfj_resource); +delete from hfj_resource where res_id in (select res_id from hfj_resource); +