当前位置: 首页>>代码示例>>Java>>正文


Java QueryBuilder类代码示例

本文整理汇总了Java中org.javers.repository.jql.QueryBuilder的典型用法代码示例。如果您正苦于以下问题:Java QueryBuilder类的具体用法?Java QueryBuilder怎么用?Java QueryBuilder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


QueryBuilder类属于org.javers.repository.jql包,在下文中一共展示了QueryBuilder类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getChangesByType

import org.javers.repository.jql.QueryBuilder; //导入依赖的package包/类
private List<Change> getChangesByType(Class type, UUID id, String author,
                                      String changedPropertyName, Pageable page) {
  QueryBuilder queryBuilder;

  if (id != null) {
    queryBuilder = QueryBuilder.byInstanceId(id, type);
  } else {
    queryBuilder = QueryBuilder.byClass(type);
  }

  int skip = Pagination.getPageNumber(page);
  int limit = Pagination.getPageSize(page);

  queryBuilder = queryBuilder.withNewObjectChanges(true).skip(skip).limit(limit);

  if ( StringUtils.isNotBlank(author) ) {
    queryBuilder = queryBuilder.byAuthor(author);
  }
  if ( StringUtils.isNotBlank(changedPropertyName) ) {
    queryBuilder = queryBuilder.andProperty(changedPropertyName);
  }

  /* Depending on the business' preference, we can either use findSnapshots() or findChanges().
     Whereas the former returns the entire state of the object as it was at each commit, the later
     returns only the property and values which changed. */
  //List<Change> changes = javers.findSnapshots(queryBuilder.build());
  List<Change> changes = javers.findChanges(queryBuilder.build());

  changes.sort((o1, o2) -> -1 * o1.getCommitMetadata().get().getCommitDate()
                                .compareTo(o2.getCommitMetadata().get().getCommitDate()));
  return changes;
}
 
开发者ID:OpenLMIS,项目名称:openlmis-template-service,代码行数:33,代码来源:BaseController.java

示例2: initJaversForStudies

import org.javers.repository.jql.QueryBuilder; //导入依赖的package包/类
/**
 * Init Javers with all current studies if there are no study commits in Javers yet.
 */
@PostConstruct
public void initJaversForStudies() {
  if (!metadataManagementProperties.getServer().getInstanceIndex().equals(0)) {
    log.debug("This is server instance {} therefore skipping javers init for studies.", 
        metadataManagementProperties.getServer().getInstanceIndex());
    return;
  }
  List<CdoSnapshot> snapshots =
      javers.findSnapshots(QueryBuilder.byClass(Study.class).limit(1).build());
  // only init if there are no studies yet
  if (snapshots.isEmpty()) {
    log.debug("Going to init javers with all current studies");
    studyRepository.streamAllBy().forEach(study -> {
      javers.commit(study.getLastModifiedBy(), study);
    });
  }
}
 
开发者ID:dzhw,项目名称:metadatamanagement,代码行数:21,代码来源:StudyVersionsService.java

示例3: findPreviousStudyVersions

import org.javers.repository.jql.QueryBuilder; //导入依赖的package包/类
/**
 * Get the previous 10 versions of the study.
 * 
 * @param studyId The id of the study
 * @param limit like page size
 * @param skip for skipping n versions
 * 
 * @return A list of previous study versions or null if no study found
 
 */
public List<Study> findPreviousStudyVersions(String studyId, int limit, int skip) {
  Study study = studyRepository.findOne(studyId);
  
  if (study == null) {
    return null;
  }
  
  QueryBuilder jqlQuery = QueryBuilder.byInstance(study)
      .withScopeDeepPlus(100)
      .limit(limit).skip(skip);

  List<Shadow<Study>> previousVersions = javers.findShadows(jqlQuery.build());

  return previousVersions.stream().map(shadow -> {
    Study studyVersion = shadow.get();
    if (studyVersion.getId() == null) {
      // deleted shadow        
      studyVersion.setLastModifiedBy(shadow.getCommitMetadata().getAuthor());
      studyVersion.setLastModifiedDate(shadow.getCommitMetadata().getCommitDate());
    }
    return studyVersion;
  }).collect(Collectors.toList());
}
 
开发者ID:dzhw,项目名称:metadatamanagement,代码行数:34,代码来源:StudyVersionsService.java

示例4: handle

import org.javers.repository.jql.QueryBuilder; //导入依赖的package包/类
@Override
public void handle(RepositoryMetadata repositoryMetadata, Object domainObjectOrId) {
    Map<String, String> props = commitPropertiesProvider.provide();
    String author = authorProvider.provide();

    if (isIdClass(repositoryMetadata, domainObjectOrId)) {
        if (javers.findSnapshots(QueryBuilder.byInstanceId(domainObjectOrId, repositoryMetadata.getDomainType()).build()).size() == 0) {
            return;
        }

        javers.commitShallowDeleteById(author, instanceId(domainObjectOrId, repositoryMetadata.getDomainType()), props);
    } else if (isDomainClass(repositoryMetadata, domainObjectOrId)) {
        if (javers.findSnapshots(QueryBuilder.byInstance(domainObjectOrId).build()).size() == 0) {
            return;
        }

        javers.commitShallowDelete(author, domainObjectOrId, props);
    } else {
        throw new IllegalArgumentException("Domain object or object id expected");
    }
}
 
开发者ID:javers,项目名称:javers,代码行数:22,代码来源:OnDeleteAuditChangeHandler.java

示例5: shouldCommitToJaversRepository

import org.javers.repository.jql.QueryBuilder; //导入依赖的package包/类
@Test
public void shouldCommitToJaversRepository() {
    //given:

    // prepare JaVers instance. By default, JaVers uses InMemoryRepository,
    // it's useful for testing
    Javers javers = JaversBuilder.javers().build();

    // init your data
    Person robert = new Person("bob", "Robert Martin");
    // and persist initial commit
    javers.commit("user", robert);

    // do some changes
    robert.setName("Robert C.");
    // and persist another commit
    javers.commit("user", robert);

    // when:
    List<CdoSnapshot> snapshots = javers.findSnapshots(
        QueryBuilder.byInstanceId("bob", Person.class).build());

    // then:
    // there should be two Snapshots with Bob's state
    assertThat(snapshots).hasSize(2);
}
 
开发者ID:javers,项目名称:javers,代码行数:27,代码来源:BasicCommitExample.java

示例6: shouldListStateHistory

import org.javers.repository.jql.QueryBuilder; //导入依赖的package包/类
@Test
public void shouldListStateHistory() {
    // given:
    // commit some changes
    Javers javers = JaversBuilder.javers().build();
    Person robert = new Person("bob", "Robert Martin");
    javers.commit("user", robert);

    robert.setName("Robert C.");
    javers.commit("user", robert);

    // when:
    // list state history - last 10 snapshots
    List<CdoSnapshot> snapshots = javers.findSnapshots(
        QueryBuilder.byInstanceId("bob", Person.class).limit(10).build());

    // then:
    // there should be two Snapshots with Bob's state
    assertThat(snapshots).hasSize(2);
    CdoSnapshot newState = snapshots.get(0);
    CdoSnapshot oldState = snapshots.get(1);
    assertThat(oldState.getPropertyValue("name")).isEqualTo("Robert Martin");
    assertThat(newState.getPropertyValue("name")).isEqualTo("Robert C.");
}
 
开发者ID:javers,项目名称:javers,代码行数:25,代码来源:BasicCommitExample.java

示例7: shouldListChangeHistory

import org.javers.repository.jql.QueryBuilder; //导入依赖的package包/类
@Test
public void shouldListChangeHistory() {
    // given:
    // commit some changes
    Javers javers = JaversBuilder.javers().build();
    Person robert = new Person("bob", "Robert Martin");
    javers.commit("user", robert);

    robert.setName("Robert C.");
    javers.commit("user", robert);

    // when:
    // list change history
    List<Change> changes = javers.findChanges(
        QueryBuilder.byInstanceId("bob", Person.class).build());

    // then:
    // there should be one ValueChange with Bob's firstName
    assertThat(changes).hasSize(1);
    ValueChange change = (ValueChange) changes.get(0);
    assertThat(change.getPropertyName()).isEqualTo("name");
    assertThat(change.getLeft()).isEqualTo("Robert Martin");
    assertThat(change.getRight()).isEqualTo("Robert C.");
}
 
开发者ID:javers,项目名称:javers,代码行数:25,代码来源:BasicCommitExample.java

示例8: createSnapshot

import org.javers.repository.jql.QueryBuilder; //导入依赖的package包/类
private void createSnapshot(Object object) {
  //...check whether there exists a snapshot for it in the audit log.
  // Note that we don't care about checking for logged changes, per se,
  // and thus use findSnapshots() rather than findChanges()
  BaseEntity baseEntity = (BaseEntity) object;

  QueryBuilder jqlQuery = QueryBuilder.byInstanceId(baseEntity.getId(), object.getClass());
  List<CdoSnapshot> snapshots = javers.findSnapshots(jqlQuery.build());

  //If there are no snapshots of the domain object, then take one
  if (snapshots.size() == 0) {
    javers.commit("System: AuditLogInitializer", baseEntity);
  }
}
 
开发者ID:OpenLMIS,项目名称:openlmis-template-service,代码行数:15,代码来源:AuditLogInitializer.java

示例9: shouldAlwaysCommitWithUtcTimeZone

import org.javers.repository.jql.QueryBuilder; //导入依赖的package包/类
@Test
public void shouldAlwaysCommitWithUtcTimeZone() throws IOException {

  //given
  Widget widget = new Widget();
  widget.setId(UUID.randomUUID());
  widget.setName("name_1");

  //when
  DateTimeZone.setDefault(DateTimeZone.forID("UTC"));
  javers.commit(COMMIT_AUTHOR, widget);

  DateTimeZone.setDefault(DateTimeZone.forID("Africa/Johannesburg"));
  widget.setName("name_2");
  javers.commit(COMMIT_AUTHOR, widget);

  //then
  List<CdoSnapshot> snapshots = javers.findSnapshots(
                                          QueryBuilder.byClass(Widget.class).build());
  assertEquals(2, snapshots.size());

  LocalDateTime commitTime1 = snapshots.get(0).getCommitMetadata().getCommitDate();
  LocalDateTime commitTime2 = snapshots.get(1).getCommitMetadata().getCommitDate();

  int delta = Math.abs(Seconds.secondsBetween(commitTime1, commitTime2).getSeconds());
  assertTrue(delta < 1);
}
 
开发者ID:OpenLMIS,项目名称:openlmis-template-service,代码行数:28,代码来源:JaVersIntegrationTest.java

示例10: initJaversForStudyAttachments

import org.javers.repository.jql.QueryBuilder; //导入依赖的package包/类
/**
 * Init Javers with all current study attachments if there are no 
 * study attachment commits in Javers yet.
 */
@PostConstruct
public void initJaversForStudyAttachments() {
  if (!metadataManagementProperties.getServer().getInstanceIndex().equals(0)) {
    log.debug("This is server instance {} therefore skipping javers init for study attachments.", 
        metadataManagementProperties.getServer().getInstanceIndex());
    return;
  }
  List<CdoSnapshot> snapshots =
      javers.findSnapshots(QueryBuilder.byClass(StudyAttachmentMetadata.class).limit(1).build());
  // only init if there are no studies yet
  if (snapshots.isEmpty()) {
    log.debug("Going to init javers with all current study attachment");
    List<GridFSDBFile> files = operations.find(
        new Query(GridFsCriteria.whereFilename().regex(
            StudyAttachmentFilenameBuilder.ALL_STUDY_ATTACHMENTS)));
    files.stream().forEach(file -> {
      StudyAttachmentMetadata studyAttachmentMetadata = mongoTemplate.getConverter().read(
          StudyAttachmentMetadata.class, file.getMetaData());
      studyAttachmentMetadata.generateId();
      DBObject dbObject = new BasicDBObject();
      mongoTemplate.getConverter().write(studyAttachmentMetadata, dbObject);
      file.setMetaData(dbObject);
      file.save();
      javers.commit(studyAttachmentMetadata.getLastModifiedBy(), studyAttachmentMetadata);
    });
  }
}
 
开发者ID:dzhw,项目名称:metadatamanagement,代码行数:32,代码来源:StudyAttachmentVersionsService.java

示例11: findPreviousStudyAttachmentVersions

import org.javers.repository.jql.QueryBuilder; //导入依赖的package包/类
/**
 * Get the previous 10 versions of the study attachment.
 * 
 * @param studyId The id of the study
 * @param filename The filename of the attachment
 * @param limit like page size
 * @param skip for skipping n versions
 * 
 * @return A list of previous study versions or null if no study found
 */
public List<StudyAttachmentMetadata> findPreviousStudyAttachmentVersions(String studyId,
    String filename, int limit, int skip) {
  GridFSDBFile file = operations.findOne(
      new Query(GridFsCriteria.whereFilename().is(
          StudyAttachmentFilenameBuilder.buildFileName(studyId, filename))));
  
  if (file == null) {
    return null;
  }
  
  StudyAttachmentMetadata studyAttachmentMetadata = mongoTemplate.getConverter().read(
      StudyAttachmentMetadata.class, file.getMetaData());
  
  QueryBuilder jqlQuery = QueryBuilder.byInstance(studyAttachmentMetadata)
      .withScopeDeepPlus(100)
      .limit(limit).skip(skip);

  List<Shadow<StudyAttachmentMetadata>> previousVersions = javers.findShadows(jqlQuery.build());

  return previousVersions.stream().map(shadow -> {
    StudyAttachmentMetadata metadata = shadow.get();
    if (metadata.getId() == null) {
      // deleted shadow        
      metadata.setLastModifiedBy(shadow.getCommitMetadata().getAuthor());
      metadata.setLastModifiedDate(shadow.getCommitMetadata().getCommitDate());
    }
    return metadata;
  }).collect(Collectors.toList());
}
 
开发者ID:dzhw,项目名称:metadatamanagement,代码行数:40,代码来源:StudyAttachmentVersionsService.java


注:本文中的org.javers.repository.jql.QueryBuilder类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。