Package org.sonar.core.persistence

Examples of org.sonar.core.persistence.DbSession


    ActiveRuleDao activeRuleDao = new ActiveRuleDao(qualityProfileDao, ruleDao, System2.INSTANCE);

    DbClient client = new DbClient(db.database(), myBatis, ruleDao, activeRuleDao, qualityProfileDao);

    assertThat(client.database()).isSameAs(db.database());
    DbSession dbSession = client.openSession(true);
    assertThat(dbSession).isNotNull();
    assertThat(dbSession.getConnection().isClosed()).isFalse();
    dbSession.close();

    // DAO
    assertThat(client.qualityProfileDao()).isSameAs(qualityProfileDao);
    assertThat(client.activeRuleDao()).isSameAs(activeRuleDao);
    assertThat(client.ruleDao()).isSameAs(ruleDao);
View Full Code Here


  public void insert(ActiveRuleParamDto dto, SqlSession session) {
    session.getMapper(ActiveRuleMapper.class).insertParameter(dto);
  }

  public List<ActiveRuleParamDto> selectParamsByProfileKey(String profileKey) {
    DbSession session = mybatis.openSession(false);
    try {
      return session.getMapper(ActiveRuleMapper.class).selectParamsByProfileKey(profileKey);
    } finally {
      session.close();
    }
  }
View Full Code Here

   * Return a single result or null. If the request returns multiple rows, then
   * the first row is returned.
   */
  @CheckForNull
  public ResourceDto getResource(ResourceQuery query) {
    DbSession session = mybatis.openSession(false);
    try {
      return getResource(query, session);
    } finally {
      MyBatis.closeQuietly(session);
    }
View Full Code Here

    return null;
  }

  @CheckForNull
  public ResourceDto getRootProjectByComponentKey(String componentKey) {
    DbSession session = mybatis.openSession(false);
    try {
      return getRootProjectByComponentKey(session, componentKey);
    } finally {
      MyBatis.closeQuietly(session);
    }
View Full Code Here

   *
   * The implementation should rather use a new column already containing the root project, see https://jira.codehaus.org/browse/SONAR-5188.
   */
  @CheckForNull
  public ResourceDto getRootProjectByComponentId(long componentId) {
    DbSession session = mybatis.openSession(false);
    try {
      ResourceDto component = getParentModuleByComponentId(componentId, session);
      Long rootId = component != null ? component.getRootId() : null;
      if (rootId != null) {
        return getParentModuleByComponentId(rootId, session);
View Full Code Here

  public ResourceDto selectProvisionedProject(DbSession session, String key) {
    return session.getMapper(ResourceMapper.class).selectProvisionedProject(key);
  }

  public ResourceDto selectProvisionedProject(String key) {
    DbSession session = mybatis.openSession(false);
    try {
      return selectProvisionedProject(session, key);
    } finally {
      MyBatis.closeQuietly(session);
    }
View Full Code Here

  public ResourceKeyUpdaterDao(MyBatis mybatis) {
    this.mybatis = mybatis;
  }

  public void updateKey(long projectId, String newKey) {
    DbSession session = mybatis.openSession(true);
    ResourceKeyUpdaterMapper mapper = session.getMapper(ResourceKeyUpdaterMapper.class);
    try {
      if (mapper.countResourceByKey(newKey) > 0) {
        throw new IllegalStateException("Impossible to update key: a resource with \"" + newKey + "\" key already exists.");
      }

      // must SELECT first everything
      ResourceDto project = mapper.selectProject(projectId);
      String projectOldKey = project.getKey();
      List<ResourceDto> resources = mapper.selectProjectResources(projectId);
      resources.add(project);

      // and then proceed with the batch UPDATE at once
      runBatchUpdateForAllResources(resources, projectOldKey, newKey, mapper);

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

    }
    return result;
  }

  public void bulkUpdateKey(long projectId, String stringToReplace, String replacementString) {
    DbSession session = mybatis.openSession(true);
    ResourceKeyUpdaterMapper mapper = session.getMapper(ResourceKeyUpdaterMapper.class);
    try {
      // must SELECT first everything
      Set<ResourceDto> modules = collectAllModules(projectId, stringToReplace, mapper);
      checkNewNameOfAllModules(modules, stringToReplace, replacementString, mapper);
      Map<ResourceDto, List<ResourceDto>> allResourcesByModuleMap = Maps.newHashMap();
      for (ResourceDto module : modules) {
        allResourcesByModuleMap.put(module, mapper.selectProjectResources(module.getId()));
      }

      // and then proceed with the batch UPDATE at once
      for (ResourceDto module : modules) {
        String oldModuleKey = module.getKey();
        String newModuleKey = computeNewKey(module, stringToReplace, replacementString);
        Collection<ResourceDto> resources = Lists.newArrayList(module);
        resources.addAll(allResourcesByModuleMap.get(module));
        runBatchUpdateForAllResources(resources, oldModuleKey, newModuleKey, mapper);
      }

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

   * Testing with ids required data to be identical to all tests
   */
  @BeforeClass
  public static void setupClass() {
    tester.clearDbAndIndexes();
    DbSession session = tester.get(DbClient.class).openSession(false);
    tester.get(DbClient.class).ruleDao().insert(session,
      new RuleDto()
        .setName("Check Header")
        .setConfigKey("Checker/Treewalker/HeaderCheck")
        .setRuleKey("com.puppycrawl.tools.checkstyle.checks.header.HeaderCheck")
        .setRepositoryKey("checkstyle")
        .setSeverity(4)
        .setStatus(RuleStatus.READY),
      new RuleDto()
        .setName("Disabled checked")
        .setConfigKey("Checker/Treewalker/DisabledCheck")
        .setRuleKey("DisabledCheck")
        .setRepositoryKey("checkstyle")
        .setSeverity(4)
        .setStatus(RuleStatus.REMOVED),
      new RuleDto()
        .setName("Check Annotation")
        .setConfigKey("Checker/Treewalker/AnnotationUseStyleCheck")
        .setRuleKey("com.puppycrawl.tools.checkstyle.checks.annotation.AnnotationUseStyleCheck")
        .setRepositoryKey("checkstyle")
        .setSeverity(4)
        .setStatus(RuleStatus.READY),
      new RuleDto()
        .setName("Call Super First")
        .setConfigKey("rulesets/android.xml/CallSuperFirst")
        .setRuleKey("CallSuperFirst")
        .setRepositoryKey("pmd")
        .setSeverity(2)
        .setStatus(RuleStatus.READY),
      RuleTesting.newManualRule("Manual_Rule").setName("Manual Rule")
    );
    session.commit();
    session.close();
  }
View Full Code Here

  /**
   * Insert rows in the table DUPLICATIONS_INDEX.
   * Note that generated ids are not returned.
   */
  public void insert(Collection<DuplicationUnitDto> units) {
    DbSession session = mybatis.openSession(true);
    try {
      DuplicationMapper mapper = session.getMapper(DuplicationMapper.class);
      for (DuplicationUnitDto unit : units) {
        mapper.batchInsert(unit);
      }
      session.commit();

    } 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.