Basic proof of concept for RevisionRepository/findRevisions working.
This commit is contained in:
parent
c0d6e6d3cb
commit
cc5ac72495
|
@ -350,6 +350,10 @@
|
|||
<groupId>org.hibernate</groupId>
|
||||
<artifactId>hibernate-envers</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.data</groupId>
|
||||
<artifactId>spring-data-envers</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.lucene</groupId>
|
||||
<artifactId>lucene-analyzers-phonetic</artifactId>
|
||||
|
|
|
@ -162,6 +162,7 @@ import org.springframework.context.annotation.Lazy;
|
|||
import org.springframework.context.annotation.Primary;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
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.scheduling.TaskScheduler;
|
||||
import org.springframework.scheduling.concurrent.ConcurrentTaskScheduler;
|
||||
|
@ -193,7 +194,7 @@ import java.util.Date;
|
|||
*/
|
||||
|
||||
@Configuration
|
||||
@EnableJpaRepositories(basePackages = "ca.uhn.fhir.jpa.dao.data")
|
||||
@EnableJpaRepositories(basePackages = "ca.uhn.fhir.jpa.dao.data", repositoryFactoryBeanClass = EnversRevisionRepositoryFactoryBean.class)
|
||||
@Import({
|
||||
BeanPostProcessorConfig.class,
|
||||
TermCodeSystemConfig.class,
|
||||
|
|
|
@ -26,6 +26,7 @@ import org.springframework.data.domain.Pageable;
|
|||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.Modifying;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.data.repository.history.RevisionRepository;
|
||||
import org.springframework.data.repository.query.Param;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
|
@ -34,7 +35,9 @@ import java.util.List;
|
|||
import java.util.Optional;
|
||||
|
||||
@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
|
||||
@Query("DELETE FROM MdmLink f WHERE myGoldenResourcePid = :pid OR mySourcePid = :pid")
|
||||
int deleteWithAnyReferenceToPid(@Param("pid") Long thePid);
|
||||
|
|
|
@ -38,12 +38,15 @@ import ca.uhn.fhir.rest.server.exceptions.UnprocessableEntityException;
|
|||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.apache.commons.collections4.ListUtils;
|
||||
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.data.domain.Example;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.PageImpl;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.history.Revisions;
|
||||
|
||||
import javax.persistence.EntityManager;
|
||||
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;
|
||||
|
||||
public class MdmLinkDaoJpaImpl implements IMdmLinkDao<JpaPid, MdmLink> {
|
||||
private static final Logger ourLog = LoggerFactory.getLogger(MdmLinkDaoJpaImpl.class);
|
||||
|
||||
@Autowired
|
||||
IMdmLinkJpaRepository myMdmLinkDao;
|
||||
@Autowired
|
||||
|
@ -229,6 +234,9 @@ public class MdmLinkDaoJpaImpl implements IMdmLinkDao<JpaPid, MdmLink> {
|
|||
Long totalResults = myEntityManager.createQuery(countQuery).getSingleResult();
|
||||
MdmPageRequest pageRequest = theParams.getPageRequest();
|
||||
|
||||
// TODO: remove this
|
||||
findHistory();
|
||||
|
||||
List<MdmLink> result = typedQuery
|
||||
.setFirstResult(pageRequest.getOffset())
|
||||
.setMaxResults(pageRequest.getCount())
|
||||
|
@ -300,4 +308,13 @@ public class MdmLinkDaoJpaImpl implements IMdmLinkDao<JpaPid, MdmLink> {
|
|||
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));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -82,4 +82,6 @@ public interface IMdmLinkDao<P extends IResourcePersistentId, M extends IMdmLink
|
|||
Optional<M> findBySourcePidAndMatchResult(P theSourcePid, MdmMatchResultEnum theMatch);
|
||||
|
||||
void deleteLinksWithAnyReferenceToPids(List<P> theResourcePersistentIds);
|
||||
|
||||
void findHistory();
|
||||
}
|
||||
|
|
5
pom.xml
5
pom.xml
|
@ -1764,6 +1764,11 @@
|
|||
<artifactId>hibernate-envers</artifactId>
|
||||
<version>${hibernate_version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.data</groupId>
|
||||
<artifactId>spring-data-envers</artifactId>
|
||||
<version>${spring_boot_version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.hibernate.validator</groupId>
|
||||
<artifactId>hibernate-validator</artifactId>
|
||||
|
|
Loading…
Reference in New Issue