Basic proof of concept for RevisionRepository/findRevisions working.

This commit is contained in:
Luke deGruchy 2023-03-01 09:40:09 -05:00
parent c0d6e6d3cb
commit cc5ac72495
6 changed files with 34 additions and 2 deletions

View File

@ -350,6 +350,10 @@
<groupId>org.hibernate</groupId> <groupId>org.hibernate</groupId>
<artifactId>hibernate-envers</artifactId> <artifactId>hibernate-envers</artifactId>
</dependency> </dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-envers</artifactId>
</dependency>
<dependency> <dependency>
<groupId>org.apache.lucene</groupId> <groupId>org.apache.lucene</groupId>
<artifactId>lucene-analyzers-phonetic</artifactId> <artifactId>lucene-analyzers-phonetic</artifactId>

View File

@ -162,6 +162,7 @@ import org.springframework.context.annotation.Lazy;
import org.springframework.context.annotation.Primary; import org.springframework.context.annotation.Primary;
import org.springframework.context.annotation.Scope; import org.springframework.context.annotation.Scope;
import org.springframework.core.task.AsyncTaskExecutor; import org.springframework.core.task.AsyncTaskExecutor;
import org.springframework.data.envers.repository.support.EnversRevisionRepositoryFactoryBean;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories; import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.scheduling.TaskScheduler; import org.springframework.scheduling.TaskScheduler;
import org.springframework.scheduling.concurrent.ConcurrentTaskScheduler; import org.springframework.scheduling.concurrent.ConcurrentTaskScheduler;
@ -193,7 +194,7 @@ import java.util.Date;
*/ */
@Configuration @Configuration
@EnableJpaRepositories(basePackages = "ca.uhn.fhir.jpa.dao.data") @EnableJpaRepositories(basePackages = "ca.uhn.fhir.jpa.dao.data", repositoryFactoryBeanClass = EnversRevisionRepositoryFactoryBean.class)
@Import({ @Import({
BeanPostProcessorConfig.class, BeanPostProcessorConfig.class,
TermCodeSystemConfig.class, TermCodeSystemConfig.class,

View File

@ -26,6 +26,7 @@ import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying; import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query; import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.history.RevisionRepository;
import org.springframework.data.repository.query.Param; import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
@ -34,7 +35,9 @@ import java.util.List;
import java.util.Optional; import java.util.Optional;
@Repository @Repository
public interface IMdmLinkJpaRepository extends JpaRepository<MdmLink, Long>, IHapiFhirJpaRepository { //TODO: Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'mdmLinkDao': Unsatisfied dependency expressed through field 'myMdmLinkDao'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'IMdmLinkJpaRepository' defined in ca.uhn.fhir.jpa.dao.data.IMdmLinkJpaRepository defined in @EnableJpaRepositories declared on BaseAppCtxPersistence: Invocation of init method failed; nested exception is org.springframework.data.repository.query.QueryCreationException: Could not create query for public abstract java.util.Optional org.springframework.data.repository.history.RevisionRepository.findRevision(java.lang.Object,java.lang.Number); Reason: Failed to create query for method public abstract java.util.Optional org.springframework.data.repository.history.RevisionRepository.findRevision(java.lang.Object,java.lang.Number)! No property 'findRevision' found for type 'MdmLink'; nested exception is java.lang.IllegalArgumentException: Failed to create query for method public abstract java.util.Optional org.springframework.data.repository.history.RevisionRepository.findRevision(java.lang.Object,java.lang.Number)! No property 'findRevision' found for type 'MdmLink'
public interface IMdmLinkJpaRepository extends RevisionRepository<MdmLink, Long, Integer>,JpaRepository<MdmLink, Long>, IHapiFhirJpaRepository {
//public interface IMdmLinkJpaRepository extends JpaRepository<MdmLink, Long>, IHapiFhirJpaRepository {
@Modifying @Modifying
@Query("DELETE FROM MdmLink f WHERE myGoldenResourcePid = :pid OR mySourcePid = :pid") @Query("DELETE FROM MdmLink f WHERE myGoldenResourcePid = :pid OR mySourcePid = :pid")
int deleteWithAnyReferenceToPid(@Param("pid") Long thePid); int deleteWithAnyReferenceToPid(@Param("pid") Long thePid);

View File

@ -38,12 +38,15 @@ import ca.uhn.fhir.rest.server.exceptions.UnprocessableEntityException;
import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.collections4.ListUtils; import org.apache.commons.collections4.ListUtils;
import org.hl7.fhir.instance.model.api.IIdType; import org.hl7.fhir.instance.model.api.IIdType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Example; import org.springframework.data.domain.Example;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl; import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Pageable;
import org.springframework.data.history.Revisions;
import javax.persistence.EntityManager; import javax.persistence.EntityManager;
import javax.persistence.TypedQuery; import javax.persistence.TypedQuery;
@ -71,6 +74,8 @@ import static ca.uhn.fhir.mdm.api.MdmQuerySearchParameters.RESOURCE_TYPE_NAME;
import static ca.uhn.fhir.mdm.api.MdmQuerySearchParameters.SOURCE_PID_NAME; import static ca.uhn.fhir.mdm.api.MdmQuerySearchParameters.SOURCE_PID_NAME;
public class MdmLinkDaoJpaImpl implements IMdmLinkDao<JpaPid, MdmLink> { public class MdmLinkDaoJpaImpl implements IMdmLinkDao<JpaPid, MdmLink> {
private static final Logger ourLog = LoggerFactory.getLogger(MdmLinkDaoJpaImpl.class);
@Autowired @Autowired
IMdmLinkJpaRepository myMdmLinkDao; IMdmLinkJpaRepository myMdmLinkDao;
@Autowired @Autowired
@ -229,6 +234,9 @@ public class MdmLinkDaoJpaImpl implements IMdmLinkDao<JpaPid, MdmLink> {
Long totalResults = myEntityManager.createQuery(countQuery).getSingleResult(); Long totalResults = myEntityManager.createQuery(countQuery).getSingleResult();
MdmPageRequest pageRequest = theParams.getPageRequest(); MdmPageRequest pageRequest = theParams.getPageRequest();
// TODO: remove this
findHistory();
List<MdmLink> result = typedQuery List<MdmLink> result = typedQuery
.setFirstResult(pageRequest.getOffset()) .setFirstResult(pageRequest.getOffset())
.setMaxResults(pageRequest.getCount()) .setMaxResults(pageRequest.getCount())
@ -300,4 +308,13 @@ public class MdmLinkDaoJpaImpl implements IMdmLinkDao<JpaPid, MdmLink> {
myMdmLinkDao.deleteLinksWithAnyReferenceToPids(chunk); myMdmLinkDao.deleteLinksWithAnyReferenceToPids(chunk);
} }
} }
@Override
public void findHistory() {
// TODO: need to extend RevisionRepository.... somewhere
long hardCodedMdmLinkId = 1L;
final Revisions<Integer, MdmLink> revisions = myMdmLinkDao.findRevisions(hardCodedMdmLinkId);
revisions.forEach(revision -> ourLog.info("MdmLink revision: {}", revision));
}
} }

View File

@ -82,4 +82,6 @@ public interface IMdmLinkDao<P extends IResourcePersistentId, M extends IMdmLink
Optional<M> findBySourcePidAndMatchResult(P theSourcePid, MdmMatchResultEnum theMatch); Optional<M> findBySourcePidAndMatchResult(P theSourcePid, MdmMatchResultEnum theMatch);
void deleteLinksWithAnyReferenceToPids(List<P> theResourcePersistentIds); void deleteLinksWithAnyReferenceToPids(List<P> theResourcePersistentIds);
void findHistory();
} }

View File

@ -1764,6 +1764,11 @@
<artifactId>hibernate-envers</artifactId> <artifactId>hibernate-envers</artifactId>
<version>${hibernate_version}</version> <version>${hibernate_version}</version>
</dependency> </dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-envers</artifactId>
<version>${spring_boot_version}</version>
</dependency>
<dependency> <dependency>
<groupId>org.hibernate.validator</groupId> <groupId>org.hibernate.validator</groupId>
<artifactId>hibernate-validator</artifactId> <artifactId>hibernate-validator</artifactId>