Package org.sonar.api.database.model

Examples of org.sonar.api.database.model.Snapshot


    }
    return snapshot;
  }

  private Snapshot persist(Project project, Resource resource, @Nullable Resource parent) {
    Snapshot snapshot;
    if (resource instanceof Project) {
      // should not occur, please use the method saveProject()
      snapshot = persistProject((Project) resource, (Project) parent);

    } else if (resource instanceof Library) {
View Full Code Here


    // TODO to be removed
    library.setId(model.getId());
    library.setUuid(model.getUuid());
    library.setEffectiveKey(library.getKey());

    Snapshot snapshot = findLibrarySnapshot(model.getId(), library.getVersion());
    if (snapshot == null) {
      snapshot = new Snapshot(model, null);
      snapshot.setCreatedAt(project.getAnalysisDate());
      snapshot.setBuildDate(new Date());
      snapshot.setVersion(library.getVersion());
      snapshot.setStatus(Snapshot.STATUS_PROCESSED);

      // see http://jira.codehaus.org/browse/SONAR-1850
      // The qualifier must be LIB, even if the resource is TRK, because this snapshot has no measures.
      snapshot.setQualifier(Qualifiers.LIBRARY);
      snapshot = session.save(snapshot);
    }
    session.commit();
    return snapshot;
  }
View Full Code Here

  /**
   * Everything except project and library
   */
  private Snapshot persistFileOrDirectory(Project project, Resource resource, @Nullable Resource parentReference) {
    Snapshot moduleSnapshot = snapshotsByResource.get(project);
    Integer moduleId = moduleSnapshot.getResourceId();
    ResourceModel model = findOrCreateModel(resource, parentReference != null ? parentReference : project);
    model.setRootId(moduleId);
    model = session.save(model);
    resource.setId(model.getId());
    resource.setUuid(model.getUuid());

    Snapshot parentSnapshot = (Snapshot) ObjectUtils.defaultIfNull(getSnapshot(parentReference), moduleSnapshot);
    Snapshot snapshot = new Snapshot(model, parentSnapshot);
    snapshot.setBuildDate(new Date());
    snapshot = session.save(snapshot);
    session.commit();
    return snapshot;
  }
View Full Code Here

    resource.setEffectiveKey(ComponentKeys.createEffectiveKey(currentProject, resource));
    bucket = new Bucket(resource).setParent(parentBucket);
    addBucket(resource, bucket);

    Resource parentResource = parentBucket != null ? parentBucket.getResource() : null;
    Snapshot snapshot = persistence.saveResource(currentProject, resource, parentResource);
    if (ResourceUtils.isPersistable(resource) && !Qualifiers.LIBRARY.equals(resource.getQualifier())) {
      graph.addComponent(resource, snapshot);
    }

    return bucket;
View Full Code Here

    PastSnapshot vs1 = new PastSnapshot("days", DateUtils.parseDate("2009-01-25"), getSession().getSingleResult(Snapshot.class, "id", 100))
      .setModeParameter("30").setIndex(1);
    PastSnapshot vs3 = new PastSnapshot("version", DateUtils.parseDate("2008-12-13"), getSession().getSingleResult(Snapshot.class, "id", 300))
      .setModeParameter("1.2.3").setIndex(3);
    when(timeMachineConfiguration.getProjectPastSnapshots()).thenReturn(Arrays.asList(vs1, vs3));
    Snapshot projectSnapshot = getSession().getSingleResult(Snapshot.class, "id", 1000);

    TimeMachineConfigurationPersister persister = new TimeMachineConfigurationPersister(timeMachineConfiguration, projectSnapshot, getSession());
    persister.persistConfiguration();

    checkTables("shouldSaveConfigurationInSnapshotsTable", "snapshots");
View Full Code Here

    assertThat(hashByRelativePath.get("src/main/java/foo/Bar.java")).isNull();
  }

  @Test
  public void should_return_null_if_no_remote_hashes() throws Exception {
    Snapshot previousSnapshot = mock(Snapshot.class);
    PastSnapshot pastSnapshot = new PastSnapshot("foo", new Date(), previousSnapshot);
    when(pastSnapshotFinder.findPreviousAnalysis(snapshot)).thenReturn(pastSnapshot);

    Map<String, String> hashByRelativePath = loader.hashByRelativePath();
    assertThat(hashByRelativePath.get("src/main/java/foo/Bar.java")).isNull();
View Full Code Here

    assertThat(hashByRelativePath.get("src/main/java/foo/Bar.java")).isNull();
  }

  @Test
  public void should_return_remote_hash() throws Exception {
    Snapshot previousSnapshot = mock(Snapshot.class);
    when(previousSnapshot.getId()).thenReturn(123);
    PastSnapshot pastSnapshot = new PastSnapshot("foo", new Date(), previousSnapshot);
    when(pastSnapshotFinder.findPreviousAnalysis(snapshot)).thenReturn(pastSnapshot);

    SnapshotDataDto snapshotDataDto = new SnapshotDataDto();
    snapshotDataDto.setData("src/main/java/foo/Bar.java=abcd1234");
View Full Code Here

  }

  @Test
  public void performanceTestOnBatchInserts() throws Exception {
    getSession().save(project1);
    Snapshot snapshot = new Snapshot(project1, true, "", new Date(1));
    getSession().save(snapshot);
    getSession().save(CoreMetrics.CLASSES);
    getSession().commit();

    Metric metric = new MeasuresDao(getSession()).getMetric(CoreMetrics.CLASSES_KEY);
    for (int i = 0; i < NB_INSERTS; i++) {
      MeasureModel pm = new MeasureModel(metric.getId(), 1.0).setSnapshotId(snapshot.getId());
      getSession().save(pm);
    }

    getSession().commit();
    assertEquals(NB_INSERTS, getHQLCount(MeasureModel.class));
View Full Code Here

        .getResultList();

    if (snapshots.isEmpty()) {
      return new PastSnapshot(CoreProperties.TIMEMACHINE_MODE_PREVIOUS_ANALYSIS);
    }
    Snapshot snapshot = snapshots.get(0);
    Date targetDate = snapshot.getCreatedAt();
    SimpleDateFormat format = new SimpleDateFormat(DateUtils.DATE_FORMAT);
    return new PastSnapshot(CoreProperties.TIMEMACHINE_MODE_PREVIOUS_ANALYSIS, targetDate, snapshot).setModeParameter(format.format(targetDate));
  }
View Full Code Here

    this.settings = settings;
    initPastSnapshots(pastSnapshotFinder, projectTree.getRootProject().getQualifier());
  }

  private void initPastSnapshots(PastSnapshotFinder pastSnapshotFinder, String rootQualifier) {
    Snapshot projectSnapshot = buildProjectSnapshot();
    projectPastSnapshots = newLinkedList();
    if (projectSnapshot != null) {
      for (int index = 1; index <= NUMBER_OF_VARIATION_SNAPSHOTS; index++) {
        PastSnapshot pastSnapshot = pastSnapshotFinder.find(projectSnapshot, rootQualifier, settings, index);
        // SONAR-4700 Add a past snapshot only if it exists
View Full Code Here

TOP

Related Classes of org.sonar.api.database.model.Snapshot

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.