From 4afa55ea260e136a83ea40568d7757619fdb68c0 Mon Sep 17 00:00:00 2001 From: James Agnew Date: Thu, 22 Aug 2019 08:49:34 -0400 Subject: [PATCH] Initial commit - Not yet compiling --- .../ca/uhn/fhir/jpa/config/BaseConfig.java | 7 +++++++ .../ca/uhn/fhir/jpa/dao/BaseHapiFhirDao.java | 5 +++-- ...earchDao.java => IAAAAAAAAASearchDao.java} | 2 +- ...o.java => IAAAAAAAAASearchIncludeDao.java} | 2 +- ...Dao.java => IAAAAAAAASearchResultDao.java} | 2 +- .../java/ca/uhn/fhir/jpa/search/.editorconfig | 0 .../search/PersistedJpaBundleProvider.java | 16 +++++++++------- .../cache/BaseSearchResultCacheSvcImpl.java | 4 ++++ .../DatabaseSearchResultCacheSvcImpl.java | 19 +++++++++++++++++++ .../search/cache/ISearchResultCacheSvc.java | 14 ++++++++++++++ 10 files changed, 59 insertions(+), 12 deletions(-) rename hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/data/{ISearchDao.java => IAAAAAAAAASearchDao.java} (96%) rename hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/data/{ISearchIncludeDao.java => IAAAAAAAAASearchIncludeDao.java} (92%) rename hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/data/{ISearchResultDao.java => IAAAAAAAASearchResultDao.java} (95%) delete mode 100644 hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/search/.editorconfig create mode 100644 hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/search/cache/BaseSearchResultCacheSvcImpl.java create mode 100644 hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/search/cache/DatabaseSearchResultCacheSvcImpl.java create mode 100644 hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/search/cache/ISearchResultCacheSvc.java diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/config/BaseConfig.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/config/BaseConfig.java index 0f9b12a8d94..db1975c2132 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/config/BaseConfig.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/config/BaseConfig.java @@ -14,6 +14,8 @@ import ca.uhn.fhir.jpa.provider.TerminologyUploaderProvider; import ca.uhn.fhir.jpa.search.DatabaseBackedPagingProvider; import ca.uhn.fhir.jpa.search.IStaleSearchDeletingSvc; import ca.uhn.fhir.jpa.search.StaleSearchDeletingSvcImpl; +import ca.uhn.fhir.jpa.search.cache.DatabaseSearchResultCacheSvcImpl; +import ca.uhn.fhir.jpa.search.cache.ISearchResultCacheSvc; import ca.uhn.fhir.jpa.search.reindex.IResourceReindexingSvc; import ca.uhn.fhir.jpa.search.reindex.ResourceReindexingSvcImpl; import ca.uhn.fhir.jpa.subscription.dbmatcher.CompositeInMemoryDaoSubscriptionMatcher; @@ -143,6 +145,11 @@ public abstract class BaseConfig implements SchedulingConfigurer { return new BinaryStorageInterceptor(); } + @Bean + public ISearchResultCacheSvc searchResultCacheSvc() { + return new DatabaseSearchResultCacheSvcImpl(); + } + @Bean public TaskScheduler taskScheduler() { ConcurrentTaskScheduler retVal = new ConcurrentTaskScheduler(); diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/BaseHapiFhirDao.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/BaseHapiFhirDao.java index 602daaeb653..1c915711d36 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/BaseHapiFhirDao.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/BaseHapiFhirDao.java @@ -18,6 +18,7 @@ import ca.uhn.fhir.jpa.model.search.SearchStatusEnum; import ca.uhn.fhir.jpa.model.search.StorageProcessingMessage; import ca.uhn.fhir.jpa.search.ISearchCoordinatorSvc; import ca.uhn.fhir.jpa.search.PersistedJpaBundleProvider; +import ca.uhn.fhir.jpa.search.cache.ISearchResultCacheSvc; import ca.uhn.fhir.jpa.searchparam.ResourceMetaParams; import ca.uhn.fhir.jpa.searchparam.extractor.LogicalReferenceHelper; import ca.uhn.fhir.jpa.searchparam.extractor.ResourceIndexedSearchParams; @@ -152,7 +153,7 @@ public abstract class BaseHapiFhirDao implements IDao, @Autowired private PlatformTransactionManager myPlatformTransactionManager; @Autowired - private ISearchDao mySearchDao; + private ISearchResultCacheSvc mySearchResultCacheSvc; @Autowired private ISearchParamPresenceSvc mySearchParamPresenceSvc; @Autowired @@ -466,7 +467,7 @@ public abstract class BaseHapiFhirDao implements IDao, } } - search = mySearchDao.save(search); + search = mySearchResultCacheSvc.saveNew(search); return new PersistedJpaBundleProvider(theRequest, search.getUuid(), this); } diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/data/ISearchDao.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/data/IAAAAAAAAASearchDao.java similarity index 96% rename from hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/data/ISearchDao.java rename to hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/data/IAAAAAAAAASearchDao.java index e3716f54999..b3bc8aa9bd0 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/data/ISearchDao.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/data/IAAAAAAAAASearchDao.java @@ -31,7 +31,7 @@ import java.util.Date; * #L% */ -public interface ISearchDao extends JpaRepository { +public interface IAAAAAAAAASearchDao extends JpaRepository { @Query("SELECT s FROM Search s WHERE s.myUuid = :uuid") Search findByUuid(@Param("uuid") String theUuid); diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/data/ISearchIncludeDao.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/data/IAAAAAAAAASearchIncludeDao.java similarity index 92% rename from hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/data/ISearchIncludeDao.java rename to hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/data/IAAAAAAAAASearchIncludeDao.java index 3307bb8c2be..16db58ed172 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/data/ISearchIncludeDao.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/data/IAAAAAAAAASearchIncludeDao.java @@ -27,7 +27,7 @@ import org.springframework.data.repository.query.Param; import ca.uhn.fhir.jpa.entity.SearchInclude; -public interface ISearchIncludeDao extends JpaRepository { +public interface IAAAAAAAAASearchIncludeDao extends JpaRepository { @Modifying @Query(value="DELETE FROM SearchInclude r WHERE r.mySearchPid = :search") diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/data/ISearchResultDao.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/data/IAAAAAAAASearchResultDao.java similarity index 95% rename from hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/data/ISearchResultDao.java rename to hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/data/IAAAAAAAASearchResultDao.java index 58c5c0eae06..ba9429234ee 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/data/ISearchResultDao.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/data/IAAAAAAAASearchResultDao.java @@ -34,7 +34,7 @@ import java.util.Set; * #L% */ -public interface ISearchResultDao extends JpaRepository { +public interface IAAAAAAAASearchResultDao extends JpaRepository { @Query(value="SELECT r.myResourcePid FROM SearchResult r WHERE r.mySearch = :search ORDER BY r.myOrder ASC") Page findWithSearchUuid(@Param("search") Search theSearch, Pageable thePage); diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/search/.editorconfig b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/search/.editorconfig deleted file mode 100644 index e69de29bb2d..00000000000 diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/search/PersistedJpaBundleProvider.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/search/PersistedJpaBundleProvider.java index 5f61a46a253..cf110832aaf 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/search/PersistedJpaBundleProvider.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/search/PersistedJpaBundleProvider.java @@ -31,6 +31,7 @@ import ca.uhn.fhir.jpa.entity.Search; import ca.uhn.fhir.jpa.entity.SearchTypeEnum; import ca.uhn.fhir.jpa.model.entity.BaseHasResource; import ca.uhn.fhir.jpa.model.entity.ResourceHistoryTable; +import ca.uhn.fhir.jpa.search.cache.ISearchResultCacheSvc; import ca.uhn.fhir.jpa.util.JpaInterceptorBroadcaster; import ca.uhn.fhir.model.primitive.InstantDt; import ca.uhn.fhir.rest.api.server.*; @@ -64,7 +65,7 @@ public class PersistedJpaBundleProvider implements IBundleProvider { private EntityManager myEntityManager; private PlatformTransactionManager myPlatformTransactionManager; private ISearchCoordinatorSvc mySearchCoordinatorSvc; - private ISearchDao mySearchDao; + private ISearchResultCacheSvc mySearchResultCacheSvc; private Search mySearchEntity; private String myUuid; private boolean myCacheHit; @@ -196,8 +197,12 @@ public class PersistedJpaBundleProvider implements IBundleProvider { txTemplate.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED); txTemplate.setIsolationLevel(TransactionDefinition.ISOLATION_READ_COMMITTED); return txTemplate.execute(s -> { - try { - setSearchEntity(mySearchDao.findByUuid(myUuid)); + Optional search = mySearchResultCacheSvc.fetchByUuid(myUuid); + if (!search.isPresent()) { + return false; + } + + setSearchEntity(search); if (mySearchEntity == null) { return false; @@ -209,10 +214,7 @@ public class PersistedJpaBundleProvider implements IBundleProvider { mySearchEntity.getIncludes().size(); return true; - } catch (NoResultException e) { - return false; - } - }); + }); } return true; } diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/search/cache/BaseSearchResultCacheSvcImpl.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/search/cache/BaseSearchResultCacheSvcImpl.java new file mode 100644 index 00000000000..73ff5a2d546 --- /dev/null +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/search/cache/BaseSearchResultCacheSvcImpl.java @@ -0,0 +1,4 @@ +package ca.uhn.fhir.jpa.search.cache; + +public abstract class BaseSearchResultCacheSvcImpl implements ISearchResultCacheSvc { +} diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/search/cache/DatabaseSearchResultCacheSvcImpl.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/search/cache/DatabaseSearchResultCacheSvcImpl.java new file mode 100644 index 00000000000..603d683f0f8 --- /dev/null +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/search/cache/DatabaseSearchResultCacheSvcImpl.java @@ -0,0 +1,19 @@ +package ca.uhn.fhir.jpa.search.cache; + +import ca.uhn.fhir.jpa.dao.data.IAAAAAAAAASearchDao; +import ca.uhn.fhir.jpa.entity.Search; +import org.springframework.beans.factory.annotation.Autowired; + +import javax.transaction.Transactional; + +public class DatabaseSearchResultCacheSvcImpl extends BaseSearchResultCacheSvcImpl { + + @Autowired + private IAAAAAAAAASearchDao mySearchDao; + + @Transactional(Transactional.TxType.MANDATORY) + @Override + public Search saveNew(Search theSearch) { + return mySearchDao.save(theSearch); + } +} diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/search/cache/ISearchResultCacheSvc.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/search/cache/ISearchResultCacheSvc.java new file mode 100644 index 00000000000..fbe808b0a17 --- /dev/null +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/search/cache/ISearchResultCacheSvc.java @@ -0,0 +1,14 @@ +package ca.uhn.fhir.jpa.search.cache; + +import ca.uhn.fhir.jpa.entity.Search; + +public interface ISearchResultCacheSvc { + + /** + * Places a new search of some sort in the cache. + * + * @param theSearch The search to store + * @return Returns a copy of the search as it was saved. Callers should use the returned Search object for any further processing. + */ + Search saveNew(Search theSearch); +}