Package org.sonar.core.persistence

Examples of org.sonar.core.persistence.DbSession


  @Test
  public void find_all() {
    setupData("shared");

    DbSession session = getMyBatis().openSession(false);
    try {
      List<QualityProfileDto> dtos = dao.findAll(session);

      assertThat(dtos).hasSize(2);

      QualityProfileDto dto1 = dtos.get(0);
      assertThat(dto1.getId()).isEqualTo(1);
      assertThat(dto1.getName()).isEqualTo("Sonar Way");
      assertThat(dto1.getLanguage()).isEqualTo("java");
      assertThat(dto1.getParentKee()).isNull();

      QualityProfileDto dto2 = dtos.get(1);
      assertThat(dto2.getId()).isEqualTo(2);
      assertThat(dto2.getName()).isEqualTo("Sonar Way");
      assertThat(dto2.getLanguage()).isEqualTo("js");
      assertThat(dto2.getParentKee()).isNull();
    } finally {
      session.close();
    }
  }
View Full Code Here


  @Test
  public void find_children() {
    setupData("inheritance");

    DbSession session = getMyBatis().openSession(false);
    try {
      List<QualityProfileDto> dtos = dao.findChildren(session, "java_parent");

      assertThat(dtos).hasSize(2);

      QualityProfileDto dto1 = dtos.get(0);
      assertThat(dto1.getId()).isEqualTo(1);
      assertThat(dto1.getName()).isEqualTo("Child1");
      assertThat(dto1.getLanguage()).isEqualTo("java");
      assertThat(dto1.getParentKee()).isEqualTo("java_parent");

      QualityProfileDto dto2 = dtos.get(1);
      assertThat(dto2.getId()).isEqualTo(2);
      assertThat(dto2.getName()).isEqualTo("Child2");
      assertThat(dto2.getLanguage()).isEqualTo("java");
      assertThat(dto2.getParentKee()).isEqualTo("java_parent");

    } finally {
      session.close();
    }
  }
View Full Code Here

  @Test
  public void insert_parameter() {
    setupData("empty");

    DbSession session = getMyBatis().openSession(false);
    ActiveRuleParamDto dto = new ActiveRuleParamDto()
      .setActiveRuleId(1)
      .setRulesParameterId(1)
      .setKey("max")
      .setValue("20");
    dao.insert(dto, session);
    session.commit();
    session.close();

    checkTables("insert_parameter", "active_rule_parameters");
  }
View Full Code Here

public class DefaultPeriodCleanerTest {

  @Test
  public void doClean() {
    PurgeDao dao = mock(PurgeDao.class);
    DbSession session = mock(DbSession.class);
    when(dao.selectPurgeableSnapshots(123L, session)).thenReturn(Arrays.asList(
      new PurgeableSnapshotDto().setSnapshotId(999L).setDate(new Date())));
    Filter filter1 = newLazyFilter();
    Filter filter2 = newLazyFilter();
View Full Code Here

  @Test
  public void should_create_schema_on_h2() throws Exception {
    Dialect supportedDialect = new H2();
    when(dbClient.database().getDialect()).thenReturn(supportedDialect);
    Connection connection = mock(Connection.class);
    DbSession session = mock(DbSession.class);
    when(session.getConnection()).thenReturn(connection);
    when(dbClient.openSession(false)).thenReturn(session);
    when(serverUpgradeStatus.isFreshInstall()).thenReturn(true);

    DatabaseMigrator databaseMigrator = new DatabaseMigrator(dbClient, migrations, serverUpgradeStatus, null) {
      @Override
View Full Code Here

  public void save(DbSession session, DefaultIssue issue) {
    save(session, newArrayList(issue));
  }

  public void save(Iterable<DefaultIssue> issues) {
    DbSession session = mybatis.openSession(true);
    try {
      save(session, issues);
      session.commit();
    } finally {
      MyBatis.closeQuietly(session);
    }
  }
View Full Code Here

  protected abstract void doInsert(DbSession batchSession, Date now, DefaultIssue issue);

  private void update(List<DefaultIssue> toBeUpdated, Date now) {
    if (!toBeUpdated.isEmpty()) {
      DbSession session = mybatis.openSession(false);
      try {
        IssueChangeMapper issueChangeMapper = session.getMapper(IssueChangeMapper.class);
        for (DefaultIssue issue : toBeUpdated) {
          doUpdate(session, now, issue);
          insertChanges(issueChangeMapper, issue);
        }
        session.commit();
      } finally {
        MyBatis.closeQuietly(session);
      }
    }
  }
View Full Code Here

    }
    return comments;
  }

  public List<FieldDiffs> selectChangelogByIssue(String issueKey) {
    DbSession session = mybatis.openSession(false);
    try {
      List<FieldDiffs> result = Lists.newArrayList();
      for (IssueChangeDto dto : selectByIssuesAndType(session, Arrays.asList(issueKey), IssueChangeDto.TYPE_FIELD_CHANGE)) {
        result.add(dto.toFieldDiffs());
      }
View Full Code Here

      MyBatis.closeQuietly(session);
    }
  }

  public void selectChangelogOnNonClosedIssuesByModuleAndType(Integer componentId, ResultHandler handler) {
    DbSession session = mybatis.openSession(false);
    try {
      Map<String, Object> params = newHashMap();
      params.put("componentId", componentId);
      params.put("changeType", IssueChangeDto.TYPE_FIELD_CHANGE);
      session.select("org.sonar.core.issue.db.IssueChangeMapper.selectChangelogOnNonClosedIssuesByModuleAndType", params, handler);

    } finally {
      MyBatis.closeQuietly(session);
    }
  }
View Full Code Here

    }
  }

  @CheckForNull
  public DefaultIssueComment selectCommentByKey(String commentKey) {
    DbSession session = mybatis.openSession(false);
    try {
      IssueChangeMapper mapper = session.getMapper(IssueChangeMapper.class);
      IssueChangeDto dto = mapper.selectByKeyAndType(commentKey, IssueChangeDto.TYPE_COMMENT);
      return dto != null ? dto.toComment() : null;

    } finally {
      MyBatis.closeQuietly(session);
View Full Code Here

TOP

Related Classes of org.sonar.core.persistence.DbSession

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.