All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.sonar.db.version.v50.Migration50Mapper Maven / Gradle / Ivy

There is a newer version: 6.3.1
Show newest version
/*
 * SonarQube
 * Copyright (C) 2009-2016 SonarSource SA
 * mailto:contact AT sonarsource DOT com
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 3 of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */
package org.sonar.db.version.v50;

import java.util.List;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.apache.ibatis.mapping.ResultSetType;

public interface Migration50Mapper {

  /**
   * Return root projects (Views and Developers are NOT returned)
   */
  @Select("SELECT " +
    "  p.id AS \"id\", " +
    "  p.uuid AS \"uuid\", " +
    "  p.project_uuid AS \"projectUuid\", " +
    "  s.root_project_id AS \"projectId\", " +
    "  s.id AS \"snapshotId\", " +
    "  s.path AS \"snapshotPath\", " +
    "  p.scope AS \"scope\" " +
    "FROM projects p " +
    "  LEFT OUTER JOIN snapshots s ON s.project_id = p.id AND s.islast = ${_true} " +
    "  WHERE " +
    "   p.scope = 'PRJ' " +
    "   AND p.root_id IS NULL ")
  @Result(javaType = Component.class)
  @Options(resultSetType = ResultSetType.FORWARD_ONLY, fetchSize = 200)
  List selectRootProjects();

  @Select("SELECT " +
    "  p.id AS \"id\", " +
    "  p.uuid AS \"uuid\", " +
    "  p.project_uuid AS \"projectUuid\", " +
    "  p.module_uuid AS \"moduleUuid\", " +
    "  p.module_uuid_path AS \"moduleUuidPath\", " +
    "  s.root_project_id AS \"projectId\", " +
    "  s.id AS \"snapshotId\", " +
    "  s.path AS \"snapshotPath\", " +
    "  p.scope AS \"scope\" " +
    "FROM projects root " +
    "  INNER JOIN snapshots root_snapshot ON root_snapshot.project_id = root.id AND root_snapshot.islast = ${_true} " +
    "  INNER JOIN snapshots s ON s.root_snapshot_id = root_snapshot.id AND s.islast = ${_true} " +
    "  INNER JOIN projects p ON p.id = s.project_id " +
    "  WHERE root.id = #{id} ")
  @Result(javaType = Component.class)
  List selectComponentChildrenForProjects(@Param("id") Long projectId);

  /**
   * Return disabled direct children from a project (1st level modules, files on single module project)
   * For migration re-entrance, ignore components already having UUID
   */
  @Select("SELECT " +
    "  p.id AS \"id\", " +
    "  p.uuid AS \"uuid\" " +
    "FROM projects p " +
    "  INNER JOIN projects root ON root.id = p.root_id " +
    "  WHERE root.id = #{id} " +
    "   AND p.uuid IS NULL " +
    "   AND p.enabled=${_false} ")
  @Result(javaType = Component.class)
  List selectDisabledDirectComponentChildrenForProjects(@Param("id") Long projectId);

  /**
   * Return disabled none direct children (2nd level modules and more, files on modules, etc.)
   * For migration re-entrance, ignore components already having UUID
   */
  @Select("SELECT " +
    "  p.id AS \"id\", " +
    "  p.uuid AS \"uuid\" " +
    "FROM projects p " +
    "  INNER JOIN projects root_one ON root_one.id = p.root_id " +
    "  INNER JOIN projects root_two ON root_two.id = root_one.root_id " +
    "  WHERE root_two.id=#{id} " +
    "   AND p.uuid IS NULL " +
    "   AND p.enabled=${_false} ")
  @Result(javaType = Component.class)
  List selectDisabledNoneDirectComponentChildrenForProjects(@Param("id") Long projectId);

  /**
   * Return not migrated components
   */
  @Select("SELECT " +
    "  p.id AS \"id\" " +
    "FROM projects p " +
    "  WHERE p.uuid IS NULL ")
  @Result(javaType = Component.class)
  List selectComponentsWithoutUuid();

  @Select("SELECT " +
    "  p.id AS \"id\", " +
    "  p.uuid AS \"uuid\", " +
    "  p.project_uuid AS \"projectUuid\", " +
    "  p.module_uuid AS \"moduleUuid\", " +
    "  p.module_uuid_path AS \"moduleUuidPath\" " +
    "FROM projects p " +
    "  WHERE p.kee = #{key}")
  @Result(javaType = Component.class)
  Component selectComponentByKey(@Param("key") String key);

  @Update("UPDATE projects " +
    " SET uuid=#{uuid}, project_uuid=#{projectUuid}, module_uuid=#{moduleUuid}, module_uuid_path=#{moduleUuidPath} " +
    " WHERE id=#{id}")
  @Options(useGeneratedKeys = false)
  void updateComponentUuids(Component component);
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy