Package org.sonar.api.database.model

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


  public DbDuplicationsIndex(ResourcePersister resourcePersister, Project currentProject, DuplicationDao dao,
                             String language) {
    this.dao = dao;
    this.resourcePersister = resourcePersister;
    Snapshot currentSnapshot = resourcePersister.getSnapshotOrFail(currentProject);
    Snapshot lastSnapshot = resourcePersister.getLastSnapshot(currentSnapshot, false);
    this.currentProjectSnapshotId = currentSnapshot.getId();
    this.lastSnapshotId = lastSnapshot == null ? null : lastSnapshot.getId();
    this.languageKey = language;
  }
View Full Code Here


  }

  void persistConfiguration() {
    List<PastSnapshot> pastSnapshots = timeMachineConfiguration.getProjectPastSnapshots();
    for (PastSnapshot pastSnapshot : pastSnapshots) {
      Snapshot snapshot = session.reattach(Snapshot.class, projectSnapshot.getId());
      updatePeriodParams(snapshot, pastSnapshot);
      updatePeriodParams(projectSnapshot, pastSnapshot);
      session.save(snapshot);
    }
    session.commit();
View Full Code Here

    file.setKey("path/to/foo.c");
  }

  @Test
  public void db_ids_should_be_optional() {
    ResourceComponent component = new ResourceComponent(file, new Snapshot());

    assertThat(component.snapshotId()).isNull();
    assertThat(component.resourceId()).isNull();
  }
View Full Code Here

    assertThat(component.resourceId()).isNull();
  }

  @Test
  public void db_ids_should_be_set() {
    Snapshot snapshot = new Snapshot();
    snapshot.setId(123);
    snapshot.setResourceId(456);
    ResourceComponent component = new ResourceComponent(file, snapshot);

    assertThat(component.snapshotId()).isEqualTo(123);
    assertThat(component.resourceId()).isEqualTo(456);
  }
View Full Code Here

  }

  private void checkCurrentAnalysisIsTheLatestOne(String projectKey, Date analysisDate) {
    ResourceModel persistedProject = databaseSession.getSingleResult(ResourceModel.class, "key", projectKey, "enabled", true);
    if (persistedProject != null) {
      Snapshot lastSnapshot = databaseSession.getSingleResult(Snapshot.class, "resourceId", persistedProject.getId(), "last", true);
      if (lastSnapshot != null && !lastSnapshot.getCreatedAt().before(analysisDate)) {
        throw new IllegalArgumentException(
          "'sonar.projectDate' property cannot be older than the date of the last known quality snapshot on this project. Value: '" +
            settings.getString(CoreProperties.PROJECT_DATE_PROPERTY) + "'. " +
            "Latest quality snapshot: '" + DateUtils.formatDateTime(lastSnapshot.getCreatedAt())
            + "'. This property may only be used to rebuild the past in a chronological order.");
      }
    }
  }
View Full Code Here

    this.resourceCache = resourceCache;
  }

  @Override
  public Snapshot saveProject(Project project, @Nullable Project parent) {
    Snapshot snapshot = snapshotsByResource.get(project);
    if (snapshot == null) {
      snapshot = persistProject(project, parent);
      addToCache(project, snapshot);
    }
    return snapshot;
View Full Code Here

    // For views
    if (project instanceof ResourceCopy) {
      model.setCopyResourceId(((ResourceCopy) project).getCopyResourceId());
    }

    Snapshot parentSnapshot = null;
    if (parent != null) {
      // assume that the parent project has already been saved
      parentSnapshot = snapshotsByResource.get(project.getParent());
      model.setRootId((Integer) ObjectUtils.defaultIfNull(parentSnapshot.getRootProjectId(), parentSnapshot.getResourceId()));
    } else {
      model.setRootId(null);
    }
    model = session.save(model);
    project.setId(model.getId());
    project.setUuid(model.getUuid());

    Snapshot snapshot = new Snapshot(model, parentSnapshot);
    snapshot.setVersion(project.getAnalysisVersion());
    snapshot.setCreatedAt(project.getAnalysisDate());
    snapshot.setBuildDate(new Date());
    snapshot = session.save(snapshot);
    session.commit();

    if (!permissions.hasRoles(project)) {
      permissions.grantDefaultRoles(project);
View Full Code Here

    }
  }

  @VisibleForTesting
  long componentId(DefaultIssue issue) {
    Snapshot snapshot = snapshotCache.get(issue.componentKey());
    if (snapshot != null) {
      return snapshot.getResourceId();
    }

    // Load from db when component does not exist in cache (deleted file for example)
    ResourceDto resourceDto = resourceDao.getResource(ResourceQuery.create().setKey(issue.componentKey()));
    if (resourceDto == null) {
View Full Code Here

    return snapshotsByResource.get(reference);
  }

  @Override
  public Snapshot getSnapshotOrFail(Resource resource) {
    Snapshot snapshot = getSnapshot(resource);
    if (snapshot == null) {
      throw new ResourceNotPersistedException(resource);
    }
    return snapshot;
  }
View Full Code Here

    return saveResource(project, resource, null);
  }

  @Override
  public Snapshot saveResource(Project project, Resource resource, @Nullable Resource parent) {
    Snapshot snapshot = snapshotsByResource.get(resource);
    if (snapshot == null) {
      snapshot = persist(project, resource, parent);
      addToCache(resource, snapshot);
    }
    return snapshot;
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.