Package org.sonar.core.persistence

Examples of org.sonar.core.persistence.DbSession


    clearDb();
    clearIndexes();
  }

  public void clearDb() {
    DbSession dbSession = myBatis.openSession(false);
    Connection connection = dbSession.getConnection();
    try {
      for (String table : DatabaseVersion.TABLES) {
        try {
          connection.createStatement().execute("TRUNCATE TABLE " + table.toLowerCase());
          // commit is useless on some databases
View Full Code Here


  public List<Action> listAllActions() {
    return actions.list();
  }

  public List<Action> listAvailableActions(String issueKey) {
    DbSession session = dbClient.openSession(false);
    try {
      return listAvailableActions(issueService.getByKeyForUpdate(session, issueKey).toDefaultIssue());
    } finally {
      session.close();
    }
  }
View Full Code Here

   * Reset data in order to to be in same state as a fresh installation (but without having to drop db and restart the server).
   *
   * Please be careful when updating this method as it's called by Orchestrator.
   */
  public void resetData() {
    DbSession dbSession = myBatis.openSession(false);
    Connection connection = dbSession.getConnection();
    try {
      // Clear inspection tables
      for (String table : INSPECTION_TABLES) {
        try {
          connection.createStatement().execute("TRUNCATE TABLE " + table.toLowerCase());
          // commit is useless on some databases
          connection.commit();
        } catch (Exception e) {
          throw new IllegalStateException("Fail to truncate db table " + table, e);
        }
      }

      // Clear resource related tables
      for (String relatedTable : RESOURCE_RELATED_TABLES) {
        deleteWhereResourceIdNotNull(relatedTable, connection);
      }

      deleteManualRules(connection);

      // Clear inspection indexes
      clearIndex(IndexDefinition.ISSUES);

    } finally {
      dbSession.close();
      DbUtils.closeQuietly(connection);
    }
  }
View Full Code Here

  }

  public Issue execute(String issueKey, String actionKey, UserSession userSession) {
    Preconditions.checkArgument(!Strings.isNullOrEmpty(actionKey), "Missing action");

    DbSession session = dbClient.openSession(false);
    try {
      DefaultIssue issue = issueService.getByKeyForUpdate(session, issueKey).toDefaultIssue();
      Action action = getAction(actionKey);
      if (action == null) {
        throw new IllegalArgumentException("Action is not found : " + actionKey);
      }
      if (!action.supports(issue)) {
        throw new IllegalStateException("A condition is not respected");
      }

      IssueChangeContext changeContext = IssueChangeContext.createUser(new Date(), userSession.login());
      Component project = dbClient.componentDao().getByKey(session, issue.projectKey());
      FunctionContext functionContext = new FunctionContext(issue, updater, changeContext, getProjectSettings(project));
      for (Function function : action.functions()) {
        function.execute(functionContext);
      }
      issueStorage.save(issue);
      return issue;
    } finally {
      session.close();
    }
  }
View Full Code Here

    UserSession userSession = UserSession.get();
    if (userSession.isLoggedIn()) {
      userLogins.add(userSession.login());
    }

    DbSession session = dbClient.openSession(false);
    try {
      List<DefaultIssueComment> comments = issueChangeDao.selectCommentsByIssues(session, issueKeys);
      for (DefaultIssueComment issueComment : comments) {
        userLogins.add(issueComment.userLogin());
        commentsByIssues.put(issueComment.issueKey(), issueComment);
      }
      usersByLogin = getUsersByLogin(userLogins);

      List<ComponentDto> fileDtos = dbClient.componentDao().getByUuids(session, componentUuids);
      List<ComponentDto> subProjectDtos = dbClient.componentDao().findSubProjectsByComponentUuids(session, componentUuids);
      componentDtos.addAll(fileDtos);
      componentDtos.addAll(subProjectDtos);
      for (ComponentDto component: componentDtos) {
        projectUuids.add(component.projectUuid());
      }

      projectDtos = dbClient.componentDao().getByUuids(session, projectUuids);
      componentDtos.addAll(projectDtos);
      for (ComponentDto componentDto : componentDtos) {
        componentsByUuid.put(componentDto.uuid(), componentDto);
      }
      projectsByComponentUuid = getProjectsByComponentUuid(componentDtos, projectDtos);

      writeProjects(json, projectDtos);
      writeComponents(json, componentDtos, projectsByComponentUuid);
    } finally {
      session.close();
    }

    Map<String, ActionPlan> actionPlanByKeys = getActionPlanByKeys(actionPlanKeys);

    writeIssues(result, commentsByIssues, usersByLogin, actionPlanByKeys, componentsByUuid, projectsByComponentUuid,
View Full Code Here

  }

  public void start() {
    TimeProfiler profiler = new TimeProfiler(LOGGER).start("Register Quality Profiles");

    DbSession session = dbClient.openSession(false);
    try {
      ListMultimap<String, RulesProfile> profilesByLanguage = profilesByLanguage();
      for (String language : profilesByLanguage.keySet()) {
        List<RulesProfile> defs = profilesByLanguage.get(language);
        verifyLanguage(language, defs);

        for (Map.Entry<String, Collection<RulesProfile>> entry : profilesByName(defs).entrySet()) {
          String name = entry.getKey();
          QProfileName profileName = new QProfileName(language, name);
          if (shouldRegister(profileName, session)) {
            register(profileName, entry.getValue(), session);
            session.commit();
          }
          builtInProfiles.put(language, name);
        }
        setDefault(language, defs, session);
        session.commit();
      }

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

   * List of available transitions.
   * <p/>
   * Never return null, but return an empty list if the issue does not exist.
   */
  public List<Transition> listTransitions(String issueKey) {
    DbSession session = dbClient.openSession(false);
    try {
      return listTransitions(getByKeyForUpdate(session, issueKey).toDefaultIssue());
    } finally {
      session.close();
    }
  }
View Full Code Here

  }

  public Issue doTransition(String issueKey, String transitionKey) {
    verifyLoggedIn();

    DbSession session = dbClient.openSession(false);
    try {
      DefaultIssue defaultIssue = getByKeyForUpdate(session, issueKey).toDefaultIssue();
      IssueChangeContext context = IssueChangeContext.createUser(new Date(), UserSession.get().login());
      checkTransitionPermission(transitionKey, UserSession.get(), defaultIssue);
      if (workflow.doTransition(defaultIssue, transitionKey, context)) {
        saveIssue(session, defaultIssue, context, null);
      }
      return defaultIssue;

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

  }

  public Issue assign(String issueKey, @Nullable String assignee) {
    verifyLoggedIn();

    DbSession session = dbClient.openSession(false);
    try {
      DefaultIssue issue = getByKeyForUpdate(session, issueKey).toDefaultIssue();
      User user = null;
      if (!Strings.isNullOrEmpty(assignee)) {
        user = userFinder.findByLogin(assignee);
        if (user == null) {
          throw new NotFoundException("Unknown user: " + assignee);
        }
      }
      IssueChangeContext context = IssueChangeContext.createUser(new Date(), UserSession.get().login());
      if (issueUpdater.assign(issue, user, context)) {
        saveIssue(session, issue, context, null);
      }
      return issue;

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

  }

  public Issue plan(String issueKey, @Nullable String actionPlanKey) {
    verifyLoggedIn();

    DbSession session = dbClient.openSession(false);
    try {
      ActionPlan actionPlan = null;
      if (!Strings.isNullOrEmpty(actionPlanKey)) {
        actionPlan = actionPlanService.findByKey(actionPlanKey, UserSession.get());
        if (actionPlan == null) {
          throw new NotFoundException("Unknown action plan: " + actionPlanKey);
        }
      }
      DefaultIssue issue = getByKeyForUpdate(session, issueKey).toDefaultIssue();

      IssueChangeContext context = IssueChangeContext.createUser(new Date(), UserSession.get().login());
      if (issueUpdater.plan(issue, actionPlan, context)) {
        saveIssue(session, issue, context, null);
      }
      return issue;

    } finally {
      session.close();
    }
  }
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.