From 8e0a904997f97a97f2d7d6ca2695a64404cfc2e9 Mon Sep 17 00:00:00 2001 From: James Date: Mon, 23 Jan 2017 21:12:48 -0500 Subject: [PATCH] Add adapter for IServerOperationInterceptor --- .../IServerOperationInterceptor.java | 7 +++++ .../ServerOperationInterceptorAdapter.java | 27 +++++++++++++++++++ .../jpa/search/StaleSearchDeletingSvc.java | 26 ++++++++++-------- 3 files changed, 49 insertions(+), 11 deletions(-) create mode 100644 hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/server/interceptor/ServerOperationInterceptorAdapter.java diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/server/interceptor/IServerOperationInterceptor.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/server/interceptor/IServerOperationInterceptor.java index 0d968387bf0..8ad2ee51ca9 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/server/interceptor/IServerOperationInterceptor.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/server/interceptor/IServerOperationInterceptor.java @@ -24,6 +24,13 @@ import org.hl7.fhir.instance.model.api.IBaseResource; import ca.uhn.fhir.rest.method.RequestDetails; +/** + * Server interceptor with added methods which can be called within the lifecycle of + * write operations (create/update/delete) or within transaction and batch + * operations that call these sub-operations. + * + * @see ServerOperationInterceptorAdapter + */ public interface IServerOperationInterceptor extends IServerInterceptor { /** diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/server/interceptor/ServerOperationInterceptorAdapter.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/server/interceptor/ServerOperationInterceptorAdapter.java new file mode 100644 index 00000000000..534eca66c43 --- /dev/null +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/server/interceptor/ServerOperationInterceptorAdapter.java @@ -0,0 +1,27 @@ +package ca.uhn.fhir.rest.server.interceptor; + +import org.hl7.fhir.instance.model.api.IBaseResource; + +import ca.uhn.fhir.rest.method.RequestDetails; + +/** + * NOP implementation of {@link IServerOperationInterceptor} + */ +public class ServerOperationInterceptorAdapter extends InterceptorAdapter implements IServerOperationInterceptor { + + @Override + public void resourceDeleted(RequestDetails theRequest, IBaseResource theResource) { + // nothing + } + + @Override + public void resourceCreated(RequestDetails theRequest, IBaseResource theResource) { + // nothing + } + + @Override + public void resourceUpdated(RequestDetails theRequest, IBaseResource theResource) { + // nothing + } + +} diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/search/StaleSearchDeletingSvc.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/search/StaleSearchDeletingSvc.java index e09d928039d..babde927392 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/search/StaleSearchDeletingSvc.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/search/StaleSearchDeletingSvc.java @@ -72,22 +72,26 @@ public class StaleSearchDeletingSvc { return; } - TransactionTemplate tt = new TransactionTemplate(myTransactionManager); for (final Search next : toDelete) { - tt.execute(new TransactionCallbackWithoutResult() { - @Override - protected void doInTransactionWithoutResult(TransactionStatus theArg0) { - Search searchToDelete = mySearchDao.findOne(next.getId()); - ourLog.info("Expiring stale search {} / {}", searchToDelete.getId(), searchToDelete.getUuid()); - mySearchIncludeDao.deleteForSearch(searchToDelete.getId()); - mySearchResultDao.deleteForSearch(searchToDelete.getId()); - mySearchDao.delete(searchToDelete); - } - }); + deleteSearch(next); } ourLog.info("Deleted {} searches, {} remaining", toDelete.size(), mySearchDao.count()); } } + protected void deleteSearch(final Search next) { + TransactionTemplate tt = new TransactionTemplate(myTransactionManager); + tt.execute(new TransactionCallbackWithoutResult() { + @Override + protected void doInTransactionWithoutResult(TransactionStatus theArg0) { + Search searchToDelete = mySearchDao.findOne(next.getId()); + ourLog.info("Expiring stale search {} / {}", searchToDelete.getId(), searchToDelete.getUuid()); + mySearchIncludeDao.deleteForSearch(searchToDelete.getId()); + mySearchResultDao.deleteForSearch(searchToDelete.getId()); + mySearchDao.delete(searchToDelete); + } + }); + } + }