import org.sonar.db.component.SnapshotDto;
import org.sonar.db.component.SnapshotMapper;
import org.sonar.db.component.UuidWithProjectUuidDto;
+import org.sonar.db.component.ViewsComponentDto;
+import org.sonar.db.component.ViewsSnapshotDto;
import org.sonar.db.compute.AnalysisReportDto;
import org.sonar.db.compute.AnalysisReportMapper;
import org.sonar.db.dashboard.ActiveDashboardDto;
confBuilder.loadAlias("UuidWithProjectUuid", UuidWithProjectUuidDto.class);
confBuilder.loadAlias("Event", EventDto.class);
confBuilder.loadAlias("CustomMeasure", CustomMeasureDto.class);
+ confBuilder.loadAlias("ViewsComponent", ViewsComponentDto.class);
+ confBuilder.loadAlias("ViewsSnapshot", ViewsSnapshotDto.class);
// AuthorizationMapper has to be loaded before IssueMapper because this last one used it
confBuilder.loadMapper("org.sonar.db.user.AuthorizationMapper");
mapper(session).update(item);
}
+ public List<ViewsComponentDto> selectRootViews(DbSession dbSession) {
+ return mapper(dbSession).selectRootViews();
+ }
+
+ public List<ViewsComponentDto> selectViewTree(DbSession dbSession, String rootViewUuid) {
+ return mapper(dbSession).selectViewTree(rootViewUuid);
+ }
private ComponentMapper mapper(DbSession session) {
return session.getMapper(ComponentMapper.class);
}
+
}
void insert(ComponentDto componentDto);
void update(ComponentDto componentDto);
+
+ List<ViewsComponentDto> selectRootViews();
+
+ List<ViewsComponentDto> selectViewTree(@Param("rootViewUuid") String rootViewUuid);
}
import org.sonar.db.DbSession;
import org.sonar.db.RowNotFoundException;
+import static com.google.common.collect.FluentIterable.from;
+
public class SnapshotDao implements Dao {
@CheckForNull
insert(session, Lists.asList(item, others));
}
+ @CheckForNull
+ public ViewsSnapshotDto selectSnapshotBefore(long componentId, long date, DbSession dbSession) {
+ return from(mapper(dbSession).selectSnapshotBefore(componentId, date))
+ .first()
+ .orNull();
+ }
+
+ @CheckForNull
+ public ViewsSnapshotDto selectLatestSnapshot(long componentId, DbSession dbSession) {
+ return mapper(dbSession).selectLatestSnapshot(componentId);
+ }
+
private SnapshotMapper mapper(DbSession session) {
return session.getMapper(SnapshotMapper.class);
}
int updateSnapshotAndChildrenLastFlag(@Param(value = "root") Long rootId, @Param(value = "pathRootId") Long pathRootId,
@Param(value = "path") String path, @Param(value = "isLast") boolean isLast);
+
+ List<ViewsSnapshotDto> selectSnapshotBefore(@Param("componentId") long componentId, @Param("date") long date);
+
+ ViewsSnapshotDto selectLatestSnapshot(@Param("componentId") long componentId);
}
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube 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.
+ *
+ * SonarQube 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.component;
+
+public class ViewsComponentDto {
+ private Long id;
+ private String name;
+ private String uuid;
+ private String kee;
+ private String scope;
+ private String qualifier;
+ private Long copyResourceId;
+ private String moduleUuid;
+
+ public Long getId() {
+ return id;
+ }
+
+ public void setId(Long id) {
+ this.id = id;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public String getUuid() {
+ return uuid;
+ }
+
+ public void setUuid(String uuid) {
+ this.uuid = uuid;
+ }
+
+ public String getKee() {
+ return kee;
+ }
+
+ public void setKee(String kee) {
+ this.kee = kee;
+ }
+
+ public String getScope() {
+ return scope;
+ }
+
+ public void setScope(String scope) {
+ this.scope = scope;
+ }
+
+ public String getQualifier() {
+ return qualifier;
+ }
+
+ public void setQualifier(String qualifier) {
+ this.qualifier = qualifier;
+ }
+
+ public Long getCopyResourceId() {
+ return copyResourceId;
+ }
+
+ public void setCopyResourceId(Long copyResourceId) {
+ this.copyResourceId = copyResourceId;
+ }
+
+ public String getModuleUuid() {
+ return moduleUuid;
+ }
+
+ public void setModuleUuid(String moduleUuid) {
+ this.moduleUuid = moduleUuid;
+ }
+
+ @Override
+ public String toString() {
+ return "ViewsComponentDto{" +
+ "id=" + id +
+ ", name='" + name + '\'' +
+ ", uuid='" + uuid + '\'' +
+ ", kee='" + kee + '\'' +
+ ", scope='" + scope + '\'' +
+ ", qualifier='" + qualifier + '\'' +
+ ", copyResourceId='" + copyResourceId + '\'' +
+ ", moduleUuid='" + moduleUuid + '\'' +
+ '}';
+ }
+}
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube 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.
+ *
+ * SonarQube 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.component;
+
+public class ViewsSnapshotDto {
+ private Long id;
+ private Long createdAt;
+
+ public Long getId() {
+ return id;
+ }
+
+ public void setId(Long id) {
+ this.id = id;
+ }
+
+ public Long getCreatedAt() {
+ return createdAt;
+ }
+
+ public void setCreatedAt(Long createdAt) {
+ this.createdAt = createdAt;
+ }
+}
p.created_at as createdAt
</sql>
+ <sql id="viewsComponentColumns">
+ p.id,
+ p.name,
+ p.uuid as uuid,
+ p.kee as kee,
+ p.qualifier as qualifier,
+ p.scope as scope,
+ P.copy_resource_id as copyResourceId,
+ p.module_uuid as moduleUuid
+ </sql>
+
<sql id="authorizedComponentColumns">
p.id,
p.uuid as uuid,
WHERE uuid=#{uuid}
</insert>
+ <select id="selectRootViews" resultType="ViewsComponent">
+ SELECT
+ <include refid="viewsComponentColumns"/>
+ FROM projects p
+ <where>
+ p.scope = 'PRJ'
+ and p.qualifier = 'VW'
+ </where>
+ </select>
+
+ <select id="selectViewTree" resultType="ViewsComponent" parameterType="String">
+ select
+ <include refid="viewsComponentColumns"/>
+ from projects p
+ <where>
+ project_uuid = #{rootViewUuid}
+ and p.uuid != #{rootViewUuid}
+ and p.scope in ('PRJ', 'FIL')
+ and p.qualifier in ('VW', 'SVW', 'TRK')
+ and p.enabled = ${_true}
+ </where>
+ order by module_uuid_path;
+ </select>
+
</mapper>
s.period5_date as period5Date
</sql>
+ <sql id="viewsSnapshotColumns">
+ s.id,
+ s.created_at as createdAt
+ </sql>
+
<select id="selectByKey" parameterType="Long" resultType="Snapshot">
SELECT
<include refid="snapshotColumns"/>
AND (s.id = #{snapshot} or s.root_snapshot_id = #{snapshot})
</select>
+ <select id="selectSnapshotBefore" resultType="ViewsSnapshot">
+ SELECT
+ <include refid="viewsSnapshotColumns"/>
+ FROM snapshots s
+ <where>
+ and s.project_id = #{componentId}
+ and s.status = 'P'
+ and s.created_at < #{date}
+ </where>
+ order by created_at desc
+ </select>
+
+ <select id="selectLatestSnapshot" resultType="ViewsSnapshot">
+ SELECT
+ <include refid="viewsSnapshotColumns"/>
+ FROM snapshots s
+ <where>
+ and s.project_id = #{componentId}
+ and s.status = 'P'
+ and s.islast = ${_true}
+ </where>
+ </select>
+
<sql id="insertColumns">
(parent_snapshot_id, root_snapshot_id, root_project_id, project_id, created_at, build_date, status, purge_status,
islast, scope, qualifier, version, path, depth,