Package org.sonar.core.persistence

Examples of org.sonar.core.persistence.DbSession


    return null;
  }

  @CheckForNull
  public QProfile profile(String name, String language) {
    DbSession session = db.openSession(false);
    try {
      return profile(name, language, session);
    } finally {
      session.close();
    }
  }
View Full Code Here


    }
  }

  @CheckForNull
  public QProfile parent(QProfile profile) {
    DbSession session = db.openSession(false);
    try {
      String parent = profile.parent();
      if (parent != null) {
        QualityProfileDto parentDto = findQualityProfile(parent, profile.language(), session);
        if (parentDto != null) {
          return QProfile.from(parentDto);
        }
      }
      return null;
    } finally {
      session.close();
    }
  }
View Full Code Here

   */
  public void delete(int characteristicId) {
    checkPermission();

    Date updateDate = new Date(system2.now());
    DbSession session = dbClient.openSession(true);
    try {
      delete(findCharacteristic(characteristicId, session), updateDate, session);
      session.commit();
    } finally {
      MyBatis.closeQuietly(session);
    }
  }
View Full Code Here

      session.close();
    }
  }

  public List<QProfile> children(QProfile profile) {
    DbSession session = db.openSession(false);
    try {
      return children(profile, session);
    } finally {
      session.close();
    }
  }
View Full Code Here

    return toQProfiles(db.qualityProfileDao().findChildren(session, profile.key()));
  }

  public List<QProfile> ancestors(QProfile profile) {
    List<QProfile> ancestors = newArrayList();
    DbSession session = db.openSession(false);
    try {
      incrementAncestors(profile, ancestors, session);
    } finally {
      session.close();
    }
    return ancestors;
  }
View Full Code Here

    return Maps.newHashMap();
  }

  @CheckForNull
  private Map<Integer, Integer> findDataFromComponent(String fileKey, String metricKey) {
    DbSession session = myBatis.openSession(false);
    try {
      MeasureDto data = measureDao.getNullableByKey(session, MeasureKey.of(fileKey, metricKey));
      String dataValue = data != null ? data.getData() : null;
      if (dataValue != null) {
        return KeyValueFormat.parseIntInt(dataValue);
View Full Code Here

  public RuleCreator(DbClient dbClient) {
    this.dbClient = dbClient;
  }

  public RuleKey create(NewRule newRule) {
    DbSession dbSession = dbClient.openSession(false);
    try {

      if (newRule.isCustom()) {
        return createCustomRule(newRule, dbSession);
      }

      if (newRule.isManual()) {
        return createManualRule(newRule, dbSession);
      }

      throw new IllegalStateException("Only custom rule and manual rule can be created");
    } finally {
      dbSession.close();
    }
  }
View Full Code Here

      .setRequired(true);
  }

  @Override
  public void handle(Request request, Response response) throws Exception {
    DbSession dbSession = dbClient.openSession(false);
    try {
      Integer userId = UserSession.get().userId();
      DashboardDto dashboard = dbClient.dashboardDao().getAllowedByKey(dbSession, request.mandatoryParamAsLong(PARAM_KEY),
        userId != null ? userId.longValue() : null);
      if (dashboard == null) {
        throw new NotFoundException();
      }

      JsonWriter json = response.newJsonWriter();
      json.beginObject();
      json.prop("key", dashboard.getKey());
      json.prop("name", dashboard.getName());
      json.prop("layout", dashboard.getColumnLayout());
      json.prop("desc", dashboard.getDescription());
      json.prop("global", dashboard.getGlobal());
      json.prop("shared", dashboard.getShared());
      if (dashboard.getUserId() != null) {
        UserDto user = dbClient.userDao().getUser(dashboard.getUserId());
        if (user != null) {
          json.name("owner").beginObject();
          // TODO to be shared and extracted from here
          json.prop("login", user.getLogin());
          json.prop("name", user.getName());
          json.endObject();
        }
      }
      // load widgets and related properties
      json.name("widgets").beginArray();
      Collection<WidgetDto> widgets = dbClient.widgetDao().findByDashboard(dbSession, dashboard.getKey());
      ListMultimap<Long, WidgetPropertyDto> propertiesByWidget = WidgetPropertyDto.groupByWidgetId(
        dbClient.widgetPropertyDao().findByDashboard(dbSession, dashboard.getKey()));
      for (WidgetDto widget : widgets) {
        json.beginObject();
        json.prop("id", widget.getId());
        json.prop("key", widget.getWidgetKey());
        json.prop("name", widget.getName());
        json.prop("desc", widget.getDescription());
        json.prop("col", widget.getColumnIndex());
        json.prop("row", widget.getRowIndex());
        json.prop("configured", widget.getConfigured());
        json.prop("componentId", widget.getResourceId());
        json.name("props").beginArray();
        for (WidgetPropertyDto prop : propertiesByWidget.get(widget.getKey())) {
          json.beginObject();
          json.prop("key", prop.getPropertyKey());
          json.prop("val", prop.getTextValue());
          json.endObject();
        }
        json.endArray().endObject();
      }

      json.endArray();
      json.endObject();
      json.close();
    } finally {
      dbSession.close();
    }
  }
View Full Code Here

  /**
   * Returns all Quality profiles as DTOs. This is a temporary solution as long as
   * profiles are not indexed and declared as a business object
   */
  public List<QualityProfileDto> findAll() {
    DbSession dbSession = db.openSession(false);
    try {
      return db.qualityProfileDao().findAll(dbSession);
    } finally {
      dbSession.close();
    }
  }
View Full Code Here

    }
  }

  @CheckForNull
  public QualityProfileDto getByKey(String key) {
    DbSession dbSession = db.openSession(false);
    try {
      return db.qualityProfileDao().getByKey(dbSession, key);
    } finally {
      dbSession.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.