diff options
author | Sébastien Lesaint <sebastien.lesaint@sonarsource.com> | 2015-08-26 11:40:01 +0200 |
---|---|---|
committer | Sébastien Lesaint <sebastien.lesaint@sonarsource.com> | 2015-08-29 15:58:41 +0200 |
commit | f9f74e5db5f8ee9b316f8ba61ba156b091a19fd6 (patch) | |
tree | f6e103a5a2f49c89450a075eb55210f097538ba5 /sonar-db | |
parent | 8bd1b2be54d39c365605d656ec0a67904ba8cd63 (diff) | |
download | sonarqube-f9f74e5db5f8ee9b316f8ba61ba156b091a19fd6.tar.gz sonarqube-f9f74e5db5f8ee9b316f8ba61ba156b091a19fd6.zip |
move DAOs, Mappers and Dtos from Views to Core
Diffstat (limited to 'sonar-db')
9 files changed, 247 insertions, 0 deletions
diff --git a/sonar-db/src/main/java/org/sonar/db/MyBatis.java b/sonar-db/src/main/java/org/sonar/db/MyBatis.java index 7732428e611..fc6308269ce 100644 --- a/sonar-db/src/main/java/org/sonar/db/MyBatis.java +++ b/sonar-db/src/main/java/org/sonar/db/MyBatis.java @@ -45,6 +45,8 @@ import org.sonar.db.component.ResourceMapper; 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; @@ -210,6 +212,8 @@ public class MyBatis { 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"); diff --git a/sonar-db/src/main/java/org/sonar/db/component/ComponentDao.java b/sonar-db/src/main/java/org/sonar/db/component/ComponentDao.java index bae57779d17..7e334fd864e 100644 --- a/sonar-db/src/main/java/org/sonar/db/component/ComponentDao.java +++ b/sonar-db/src/main/java/org/sonar/db/component/ComponentDao.java @@ -277,7 +277,15 @@ public class ComponentDao implements Dao { 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); } + } diff --git a/sonar-db/src/main/java/org/sonar/db/component/ComponentMapper.java b/sonar-db/src/main/java/org/sonar/db/component/ComponentMapper.java index 1c91905f0d4..1f405472d4f 100644 --- a/sonar-db/src/main/java/org/sonar/db/component/ComponentMapper.java +++ b/sonar-db/src/main/java/org/sonar/db/component/ComponentMapper.java @@ -125,4 +125,8 @@ public interface ComponentMapper { void insert(ComponentDto componentDto); void update(ComponentDto componentDto); + + List<ViewsComponentDto> selectRootViews(); + + List<ViewsComponentDto> selectViewTree(@Param("rootViewUuid") String rootViewUuid); } diff --git a/sonar-db/src/main/java/org/sonar/db/component/SnapshotDao.java b/sonar-db/src/main/java/org/sonar/db/component/SnapshotDao.java index 70bed820d37..46306bf9a04 100644 --- a/sonar-db/src/main/java/org/sonar/db/component/SnapshotDao.java +++ b/sonar-db/src/main/java/org/sonar/db/component/SnapshotDao.java @@ -31,6 +31,8 @@ import org.sonar.db.Dao; import org.sonar.db.DbSession; import org.sonar.db.RowNotFoundException; +import static com.google.common.collect.FluentIterable.from; + public class SnapshotDao implements Dao { @CheckForNull @@ -102,6 +104,18 @@ public class SnapshotDao implements Dao { 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); } diff --git a/sonar-db/src/main/java/org/sonar/db/component/SnapshotMapper.java b/sonar-db/src/main/java/org/sonar/db/component/SnapshotMapper.java index d9f29d97d0c..49fe34a0ee0 100644 --- a/sonar-db/src/main/java/org/sonar/db/component/SnapshotMapper.java +++ b/sonar-db/src/main/java/org/sonar/db/component/SnapshotMapper.java @@ -45,4 +45,8 @@ public interface SnapshotMapper { 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); } diff --git a/sonar-db/src/main/java/org/sonar/db/component/ViewsComponentDto.java b/sonar-db/src/main/java/org/sonar/db/component/ViewsComponentDto.java new file mode 100644 index 00000000000..8aa0669e35f --- /dev/null +++ b/sonar-db/src/main/java/org/sonar/db/component/ViewsComponentDto.java @@ -0,0 +1,109 @@ +/* + * 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 + '\'' + + '}'; + } +} diff --git a/sonar-db/src/main/java/org/sonar/db/component/ViewsSnapshotDto.java b/sonar-db/src/main/java/org/sonar/db/component/ViewsSnapshotDto.java new file mode 100644 index 00000000000..ccb247c94af --- /dev/null +++ b/sonar-db/src/main/java/org/sonar/db/component/ViewsSnapshotDto.java @@ -0,0 +1,41 @@ +/* + * 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; + } +} diff --git a/sonar-db/src/main/resources/org/sonar/db/component/ComponentMapper.xml b/sonar-db/src/main/resources/org/sonar/db/component/ComponentMapper.xml index 459e3a16e7a..3dca165678b 100644 --- a/sonar-db/src/main/resources/org/sonar/db/component/ComponentMapper.xml +++ b/sonar-db/src/main/resources/org/sonar/db/component/ComponentMapper.xml @@ -24,6 +24,17 @@ 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, @@ -384,4 +395,28 @@ 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> diff --git a/sonar-db/src/main/resources/org/sonar/db/component/SnapshotMapper.xml b/sonar-db/src/main/resources/org/sonar/db/component/SnapshotMapper.xml index c8676aa266d..6892b27e3b6 100644 --- a/sonar-db/src/main/resources/org/sonar/db/component/SnapshotMapper.xml +++ b/sonar-db/src/main/resources/org/sonar/db/component/SnapshotMapper.xml @@ -35,6 +35,11 @@ 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"/> @@ -112,6 +117,29 @@ 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, |