Search in sources :

Example 1 with IssueChangeMapper

use of org.sonar.db.issue.IssueChangeMapper in project sonarqube by SonarSource.

the class IssueStorage method insert.

/**
   * @return the keys of the inserted issues
   */
private Collection<String> insert(DbSession session, Iterable<DefaultIssue> issuesToInsert, long now) {
    List<String> inserted = newArrayList();
    int count = 0;
    IssueChangeMapper issueChangeMapper = session.getMapper(IssueChangeMapper.class);
    for (DefaultIssue issue : issuesToInsert) {
        String key = doInsert(session, now, issue);
        inserted.add(key);
        insertChanges(issueChangeMapper, issue);
        if (count > BatchSession.MAX_BATCH_SIZE) {
            session.commit();
        }
        count++;
    }
    session.commit();
    return inserted;
}
Also used : DefaultIssue(org.sonar.core.issue.DefaultIssue) IssueChangeMapper(org.sonar.db.issue.IssueChangeMapper)

Example 2 with IssueChangeMapper

use of org.sonar.db.issue.IssueChangeMapper in project sonarqube by SonarSource.

the class IssueStorage method update.

/**
   * @return the keys of the updated issues
   */
private Collection<String> update(List<DefaultIssue> issuesToUpdate, long now) {
    Collection<String> updated = new ArrayList<>();
    if (!issuesToUpdate.isEmpty()) {
        try (DbSession dbSession = dbClient.openSession(false)) {
            IssueChangeMapper issueChangeMapper = dbSession.getMapper(IssueChangeMapper.class);
            for (DefaultIssue issue : issuesToUpdate) {
                String key = doUpdate(dbSession, now, issue);
                updated.add(key);
                insertChanges(issueChangeMapper, issue);
            }
            dbSession.commit();
        }
    }
    return updated;
}
Also used : DbSession(org.sonar.db.DbSession) ArrayList(java.util.ArrayList) Lists.newArrayList(com.google.common.collect.Lists.newArrayList) DefaultIssue(org.sonar.core.issue.DefaultIssue) IssueChangeMapper(org.sonar.db.issue.IssueChangeMapper)

Example 3 with IssueChangeMapper

use of org.sonar.db.issue.IssueChangeMapper in project sonarqube by SonarSource.

the class PersistIssuesStep method execute.

@Override
public void execute() {
    try (DbSession dbSession = dbClient.openSession(true);
        CloseableIterator<DefaultIssue> issues = issueCache.traverse()) {
        IssueMapper mapper = dbSession.getMapper(IssueMapper.class);
        IssueChangeMapper changeMapper = dbSession.getMapper(IssueChangeMapper.class);
        while (issues.hasNext()) {
            DefaultIssue issue = issues.next();
            boolean saved = persistIssueIfRequired(mapper, issue);
            if (saved) {
                insertChanges(changeMapper, issue);
            }
        }
        dbSession.flushStatements();
        dbSession.commit();
    }
}
Also used : DbSession(org.sonar.db.DbSession) IssueMapper(org.sonar.db.issue.IssueMapper) DefaultIssue(org.sonar.core.issue.DefaultIssue) IssueChangeMapper(org.sonar.db.issue.IssueChangeMapper)

Aggregations

DefaultIssue (org.sonar.core.issue.DefaultIssue)3 IssueChangeMapper (org.sonar.db.issue.IssueChangeMapper)3 DbSession (org.sonar.db.DbSession)2 Lists.newArrayList (com.google.common.collect.Lists.newArrayList)1 ArrayList (java.util.ArrayList)1 IssueMapper (org.sonar.db.issue.IssueMapper)1