From aac5b47155d3f4de3191951f8c2edb6eb415d385 Mon Sep 17 00:00:00 2001 From: Simon Brandhof Date: Tue, 19 May 2015 19:22:32 +0200 Subject: [PATCH] SONAR-6418 delete table GRAPHS --- .../sonar/server/platform/BackendCleanup.java | 2 +- .../platformlevel/PlatformLevel4.java | 2 - .../sonar/server/test/CoverageService.java | 25 +--- .../server/test/CoverageServiceTest.java | 25 +--- .../db/migrate/915_drop_table_graphs.rb | 31 +++++ .../sonar/batch/phases/GraphPersister.java | 101 --------------- .../batch/scan/ProjectScanContainer.java | 2 - .../core/component/SnapshotPerspectives.java | 88 ------------- .../java/org/sonar/core/graph/SubGraph.java | 82 ------------ .../org/sonar/core/graph/jdbc/GraphDao.java | 53 -------- .../org/sonar/core/graph/jdbc/GraphDto.java | 103 --------------- .../sonar/core/graph/jdbc/GraphDtoMapper.java | 30 ----- .../sonar/core/graph/jdbc/package-info.java | 23 ---- .../org/sonar/core/persistence/DaoUtils.java | 22 ++-- .../core/persistence/DatabaseVersion.java | 3 +- .../org/sonar/core/persistence/MyBatis.java | 5 +- .../org/sonar/core/purge/PurgeCommands.java | 20 --- .../org/sonar/core/purge/PurgeMapper.java | 4 - .../sonar/core/graph/jdbc/GraphDtoMapper.xml | 29 ----- .../org/sonar/core/persistence/rows-h2.sql | 1 + .../org/sonar/core/persistence/schema-h2.ddl | 15 --- .../org/sonar/core/purge/PurgeMapper.xml | 14 --- .../org/sonar/core/graph/SubGraphTest.java | 118 ------------------ .../sonar/core/graph/jdbc/GraphDaoTest.java | 79 ------------ .../core/graph/jdbc/GraphDaoTest/shared.xml | 9 -- 25 files changed, 52 insertions(+), 834 deletions(-) create mode 100644 server/sonar-web/src/main/webapp/WEB-INF/db/migrate/915_drop_table_graphs.rb delete mode 100644 sonar-batch/src/main/java/org/sonar/batch/phases/GraphPersister.java delete mode 100644 sonar-core/src/main/java/org/sonar/core/component/SnapshotPerspectives.java delete mode 100644 sonar-core/src/main/java/org/sonar/core/graph/SubGraph.java delete mode 100644 sonar-core/src/main/java/org/sonar/core/graph/jdbc/GraphDao.java delete mode 100644 sonar-core/src/main/java/org/sonar/core/graph/jdbc/GraphDto.java delete mode 100644 sonar-core/src/main/java/org/sonar/core/graph/jdbc/GraphDtoMapper.java delete mode 100644 sonar-core/src/main/java/org/sonar/core/graph/jdbc/package-info.java delete mode 100644 sonar-core/src/main/resources/org/sonar/core/graph/jdbc/GraphDtoMapper.xml delete mode 100644 sonar-core/src/test/java/org/sonar/core/graph/SubGraphTest.java delete mode 100644 sonar-core/src/test/java/org/sonar/core/graph/jdbc/GraphDaoTest.java delete mode 100644 sonar-core/src/test/resources/org/sonar/core/graph/jdbc/GraphDaoTest/shared.xml diff --git a/server/sonar-server/src/main/java/org/sonar/server/platform/BackendCleanup.java b/server/sonar-server/src/main/java/org/sonar/server/platform/BackendCleanup.java index 3a4d87a78c0..22e7c803569 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/platform/BackendCleanup.java +++ b/server/sonar-server/src/main/java/org/sonar/server/platform/BackendCleanup.java @@ -39,7 +39,7 @@ import java.sql.SQLException; public class BackendCleanup { private static final String[] INSPECTION_TABLES = { - "action_plans", "authors", "dependencies", "duplications_index", "events", "graphs", "issues", "issue_changes", "manual_measures", + "action_plans", "authors", "dependencies", "duplications_index", "events", "issues", "issue_changes", "manual_measures", "notifications", "project_links", "project_measures", "projects", "resource_index", "semaphores", "snapshots", "file_sources" }; diff --git a/server/sonar-server/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel4.java b/server/sonar-server/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel4.java index c20b5177782..0f08118e17b 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel4.java +++ b/server/sonar-server/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel4.java @@ -31,7 +31,6 @@ import org.sonar.api.resources.ResourceTypes; import org.sonar.api.rules.AnnotationRuleParser; import org.sonar.api.rules.XMLRuleParser; import org.sonar.api.server.rule.RulesDefinitionXmlLoader; -import org.sonar.core.component.SnapshotPerspectives; import org.sonar.core.computation.dbcleaner.DefaultPurgeTask; import org.sonar.core.computation.dbcleaner.IndexPurgeListener; import org.sonar.core.computation.dbcleaner.ProjectCleaner; @@ -637,7 +636,6 @@ public class PlatformLevel4 extends PlatformLevel { // graphs and perspective related classes TestablePerspectiveLoader.class, TestPlanPerspectiveLoader.class, - SnapshotPerspectives.class, // Type validation TypeValidations.class, diff --git a/server/sonar-server/src/main/java/org/sonar/server/test/CoverageService.java b/server/sonar-server/src/main/java/org/sonar/server/test/CoverageService.java index b56a58b7f5a..d52a4bfc100 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/test/CoverageService.java +++ b/server/sonar-server/src/main/java/org/sonar/server/test/CoverageService.java @@ -20,25 +20,19 @@ package org.sonar.server.test; +import com.google.common.collect.Maps; import java.util.Map; - import javax.annotation.CheckForNull; - import org.sonar.api.ServerSide; import org.sonar.api.measures.CoreMetrics; -import org.sonar.api.test.MutableTestable; -import org.sonar.api.test.Testable; import org.sonar.api.utils.KeyValueFormat; import org.sonar.api.web.UserRole; -import org.sonar.core.component.SnapshotPerspectives; import org.sonar.core.measure.db.MeasureDto; import org.sonar.core.persistence.DbSession; import org.sonar.core.persistence.MyBatis; import org.sonar.server.measure.persistence.MeasureDao; import org.sonar.server.user.UserSession; -import com.google.common.collect.Maps; - @ServerSide public class CoverageService { @@ -48,13 +42,11 @@ public class CoverageService { private final MyBatis myBatis; private final MeasureDao measureDao; - private final SnapshotPerspectives snapshotPerspectives; private final UserSession userSession; - public CoverageService(MyBatis myBatis, MeasureDao measureDao, SnapshotPerspectives snapshotPerspectives, UserSession userSession) { + public CoverageService(MyBatis myBatis, MeasureDao measureDao, UserSession userSession) { this.myBatis = myBatis; this.measureDao = measureDao; - this.snapshotPerspectives = snapshotPerspectives; this.userSession = userSession; } @@ -95,19 +87,6 @@ public class CoverageService { } } - /** - * Test cases is only return for unit tests - */ - public Map getTestCases(String fileKey, CoverageService.TYPE type) { - if (TYPE.UT.equals(type)) { - Testable testable = snapshotPerspectives.as(MutableTestable.class, fileKey); - if (testable != null) { - return testable.testCasesByLines(); - } - } - return Maps.newHashMap(); - } - @CheckForNull private Map findDataFromComponent(String fileKey, String metricKey) { DbSession session = myBatis.openSession(false); diff --git a/server/sonar-server/src/test/java/org/sonar/server/test/CoverageServiceTest.java b/server/sonar-server/src/test/java/org/sonar/server/test/CoverageServiceTest.java index f018335a00e..5f71cb5ffa5 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/test/CoverageServiceTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/test/CoverageServiceTest.java @@ -29,9 +29,7 @@ import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.runners.MockitoJUnitRunner; import org.sonar.api.measures.CoreMetrics; -import org.sonar.api.test.MutableTestable; import org.sonar.api.web.UserRole; -import org.sonar.core.component.SnapshotPerspectives; import org.sonar.core.persistence.DbSession; import org.sonar.core.persistence.MyBatis; import org.sonar.server.measure.persistence.MeasureDao; @@ -57,15 +55,13 @@ public class CoverageServiceTest { DbSession session; @Mock MeasureDao measureDao; - @Mock - SnapshotPerspectives snapshotPerspectives; CoverageService service; @Before public void setUp() { MyBatis myBatis = mock(MyBatis.class); when(myBatis.openSession(false)).thenReturn(session); - service = new CoverageService(myBatis, measureDao, snapshotPerspectives, userSessionRule); + service = new CoverageService(myBatis, measureDao, userSessionRule); } @Test @@ -117,23 +113,4 @@ public class CoverageServiceTest { service.getCoveredConditions(COMPONENT_KEY, CoverageService.TYPE.OVERALL); verify(measureDao).findByComponentKeyAndMetricKey(session, COMPONENT_KEY, CoreMetrics.OVERALL_COVERED_CONDITIONS_BY_LINE_KEY); } - - @Test - public void get_test_cases_by_lines() { - MutableTestable testable = mock(MutableTestable.class); - when(snapshotPerspectives.as(MutableTestable.class, COMPONENT_KEY)).thenReturn(testable); - - service.getTestCases(COMPONENT_KEY, CoverageService.TYPE.UT); - verify(testable).testCasesByLines(); - - assertThat(service.getTestCases(COMPONENT_KEY, CoverageService.TYPE.IT)).isEmpty(); - } - - @Test - public void not_get_test_cases_by_lines_if_no_testable() { - when(snapshotPerspectives.as(MutableTestable.class, COMPONENT_KEY)).thenReturn(null); - - assertThat(service.getTestCases(COMPONENT_KEY, CoverageService.TYPE.UT)).isEqualTo(Collections.emptyMap()); - } - } diff --git a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/915_drop_table_graphs.rb b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/915_drop_table_graphs.rb new file mode 100644 index 00000000000..0b5f27341f0 --- /dev/null +++ b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/915_drop_table_graphs.rb @@ -0,0 +1,31 @@ +# +# 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. +# + +# +# SonarQube 5.1 +# +class DropTableGraphs < ActiveRecord::Migration + + def self.up + remove_index 'graphs', :name => 'graphs_perspectives' + drop_table 'graphs' + end + +end diff --git a/sonar-batch/src/main/java/org/sonar/batch/phases/GraphPersister.java b/sonar-batch/src/main/java/org/sonar/batch/phases/GraphPersister.java deleted file mode 100644 index 1cc8b4bd6cf..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/phases/GraphPersister.java +++ /dev/null @@ -1,101 +0,0 @@ -/* - * 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.batch.phases; - -import com.tinkerpop.blueprints.Graph; -import org.sonar.api.component.Perspective; -import org.sonar.batch.index.ScanPersister; -import org.sonar.core.component.ComponentVertex; -import org.sonar.core.component.GraphPerspectiveBuilder; -import org.sonar.core.component.PerspectiveBuilder; -import org.sonar.core.component.ScanGraph; -import org.sonar.core.graph.SubGraph; -import org.sonar.core.graph.graphson.GraphsonMode; -import org.sonar.core.graph.graphson.GraphsonWriter; -import org.sonar.core.graph.jdbc.GraphDto; -import org.sonar.core.graph.jdbc.GraphDtoMapper; -import org.sonar.core.persistence.DbSession; -import org.sonar.core.persistence.MyBatis; - -import java.io.IOException; -import java.io.StringWriter; - -public class GraphPersister implements ScanPersister { - private final MyBatis myBatis; - private final ScanGraph projectGraph; - private final GraphPerspectiveBuilder[] builders; - - public GraphPersister(MyBatis myBatis, ScanGraph projectGraph, GraphPerspectiveBuilder[] builders) { - this.myBatis = myBatis; - this.projectGraph = projectGraph; - this.builders = builders; - } - - @Override - public void persist() { - DbSession session = myBatis.openSession(true); - GraphDtoMapper mapper = session.getMapper(GraphDtoMapper.class); - try { - for (ComponentVertex component : projectGraph.getComponents()) { - persistComponentGraph(mapper, component); - } - session.commit(); - } finally { - session.close(); - } - } - - private void persistComponentGraph(GraphDtoMapper mapper, ComponentVertex component) { - Long snapshotId = (Long) component.element().getProperty("sid"); - if (snapshotId != null) { - for (PerspectiveBuilder builder : builders) { - GraphPerspectiveBuilder graphPerspectiveBuilder = (GraphPerspectiveBuilder) builder; - Perspective perspective = graphPerspectiveBuilder.getPerspectiveLoader().load(component); - if (perspective != null) { - serializePerspectiveData(mapper, component, snapshotId, graphPerspectiveBuilder); - } - } - } - } - - private void serializePerspectiveData(GraphDtoMapper mapper, ComponentVertex component, Long snapshotId, - GraphPerspectiveBuilder builder) { - Graph subGraph = SubGraph.extract(component.element(), builder.path()); - String data = write(subGraph); - mapper.insert(new GraphDto() - .setData(data) - .setFormat("graphson") - .setPerspective(builder.getPerspectiveLoader().getPerspectiveKey()) - .setVersion(1) - .setResourceId((Long) component.element().getProperty("rid")) - .setSnapshotId(snapshotId) - .setRootVertexId(component.element().getId().toString()) - ); - } - - private String write(Graph graph) { - try (StringWriter output = new StringWriter()) { - new GraphsonWriter().write(graph, output, GraphsonMode.EXTENDED); - return output.toString(); - } catch (IOException e) { - throw new IllegalStateException("Unable to write graph", e); - } - } -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/ProjectScanContainer.java b/sonar-batch/src/main/java/org/sonar/batch/scan/ProjectScanContainer.java index 08b4ba77719..a1c3bbb8202 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/scan/ProjectScanContainer.java +++ b/sonar-batch/src/main/java/org/sonar/batch/scan/ProjectScanContainer.java @@ -54,7 +54,6 @@ import org.sonar.batch.issue.tracking.InitialOpenIssuesStack; import org.sonar.batch.issue.tracking.LocalIssueTracking; import org.sonar.batch.issue.tracking.ServerIssueRepository; import org.sonar.batch.mediumtest.ScanTaskObservers; -import org.sonar.batch.phases.GraphPersister; import org.sonar.batch.phases.PhasesTimeProfiler; import org.sonar.batch.profiling.PhasesSumUpTimeProfiler; import org.sonar.batch.qualitygate.QualityGateProvider; @@ -222,7 +221,6 @@ public class ProjectScanContainer extends ComponentContainer { add( PastMeasuresLoader.class, ResourcePersister.class, - GraphPersister.class, // Users DefaultUserFinder.class, diff --git a/sonar-core/src/main/java/org/sonar/core/component/SnapshotPerspectives.java b/sonar-core/src/main/java/org/sonar/core/component/SnapshotPerspectives.java deleted file mode 100644 index 03a1e2c30f7..00000000000 --- a/sonar-core/src/main/java/org/sonar/core/component/SnapshotPerspectives.java +++ /dev/null @@ -1,88 +0,0 @@ -/* - * 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.core.component; - -import com.google.common.collect.Maps; -import com.tinkerpop.blueprints.impls.tg.TinkerGraph; -import org.sonar.api.ServerSide; -import org.sonar.api.component.Perspective; -import org.sonar.core.graph.graphson.GraphsonReader; -import org.sonar.core.graph.jdbc.GraphDao; -import org.sonar.core.graph.jdbc.GraphDto; - -import javax.annotation.CheckForNull; - -import java.io.StringReader; -import java.util.Map; - -@ServerSide -public class SnapshotPerspectives { - - private final GraphDao dao; - private final Map, GraphPerspectiveLoader> loaders = Maps.newHashMap(); - - public SnapshotPerspectives(GraphDao dao, GraphPerspectiveLoader[] loaders) { - this.dao = dao; - for (GraphPerspectiveLoader loader : loaders) { - // TODO check duplications - this.loaders.put(loader.getPerspectiveClass(), loader); - } - } - - @CheckForNull - public T as(Class perspectiveClass, String componentKey) { - GraphPerspectiveLoader builder = (GraphPerspectiveLoader) loaders.get(perspectiveClass); - if (builder == null) { - throw new IllegalStateException(); - } - GraphDto graphDto = dao.selectByComponent(builder.getPerspectiveKey(), componentKey); - return doAs(builder, graphDto); - } - - @CheckForNull - public T as(Class perspectiveClass, long snapshotId) { - GraphPerspectiveLoader builder = (GraphPerspectiveLoader) loaders.get(perspectiveClass); - if (builder == null) { - throw new IllegalStateException(); - } - GraphDto graphDto = dao.selectBySnapshot(builder.getPerspectiveKey(), snapshotId); - return doAs(builder, graphDto); - } - - private T doAs(GraphPerspectiveLoader loader, GraphDto graphDto) { - T result = null; - if (graphDto != null) { - SnapshotGraph graph = read(graphDto.getData(), graphDto.getRootVertexId()); - result = loader.load(graph.wrap(graph.getComponentRoot(), ComponentVertex.class)); - } - return result; - } - - private SnapshotGraph read(String data, String rootVertexId) { - StringReader input = new StringReader(data); - try { - TinkerGraph graph = new TinkerGraph(); - new GraphsonReader().read(input, graph); - return new SnapshotGraph(graph, rootVertexId); - } catch (Exception e) { - throw new IllegalStateException(e); - } - } -} diff --git a/sonar-core/src/main/java/org/sonar/core/graph/SubGraph.java b/sonar-core/src/main/java/org/sonar/core/graph/SubGraph.java deleted file mode 100644 index 34bb34bb2e1..00000000000 --- a/sonar-core/src/main/java/org/sonar/core/graph/SubGraph.java +++ /dev/null @@ -1,82 +0,0 @@ -/* - * 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.core.graph; - -import com.google.common.collect.Sets; -import com.tinkerpop.blueprints.Direction; -import com.tinkerpop.blueprints.Edge; -import com.tinkerpop.blueprints.Graph; -import com.tinkerpop.blueprints.Vertex; -import com.tinkerpop.blueprints.impls.tg.TinkerGraph; -import com.tinkerpop.blueprints.util.ElementHelper; - -import java.util.List; -import java.util.Set; - -/** - * Not thread-safe - */ -public class SubGraph { - - private TinkerGraph sub = new TinkerGraph(); - private Set edgesToCopy = Sets.newHashSet(); - - private SubGraph() { - } - - public static Graph extract(Vertex start, EdgePath edgePath) { - return new SubGraph().process(start, edgePath); - } - - private Graph process(Vertex start, EdgePath edgePath) { - copy(start); - browse(start, 0, edgePath.getElements()); - for (Edge edge : edgesToCopy) { - Vertex from = edge.getVertex(Direction.OUT); - Vertex to = edge.getVertex(Direction.IN); - Edge copyEdge = sub.addEdge(edge.getId(), sub.getVertex(from.getId()), sub.getVertex(to.getId()), edge.getLabel()); - ElementHelper.copyProperties(edge, copyEdge); - } - return sub; - } - - private void browse(Vertex from, int cursor, List edgePath) { - if (from != null && cursor < edgePath.size()) { - Direction edgeDirection = (Direction) edgePath.get(cursor); - String edgeLabel = (String) edgePath.get(cursor + 1); - Iterable edges = from.getEdges(edgeDirection, edgeLabel); - for (Edge edge : edges) { - edgesToCopy.add(edge); - Vertex tail = edge.getVertex(edgeDirection.opposite()); - copy(tail); - browse(tail, cursor + 2, edgePath); - } - } - } - - private Vertex copy(Vertex v) { - Vertex to = sub.getVertex(v.getId()); - if (to == null) { - to = sub.addVertex(v.getId()); - ElementHelper.copyProperties(v, to); - } - return to; - } -} diff --git a/sonar-core/src/main/java/org/sonar/core/graph/jdbc/GraphDao.java b/sonar-core/src/main/java/org/sonar/core/graph/jdbc/GraphDao.java deleted file mode 100644 index 40b1740c9f3..00000000000 --- a/sonar-core/src/main/java/org/sonar/core/graph/jdbc/GraphDao.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * 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.core.graph.jdbc; - -import org.sonar.core.persistence.DbSession; -import org.sonar.core.persistence.MyBatis; - -public class GraphDao { - private final MyBatis mybatis; - - public GraphDao(MyBatis mybatis) { - this.mybatis = mybatis; - } - - public GraphDto selectBySnapshot(String perspectiveKey, long snapshotId) { - DbSession session = mybatis.openSession(true); - try { - GraphDtoMapper mapper = session.getMapper(GraphDtoMapper.class); - return mapper.selectBySnapshot(perspectiveKey, snapshotId); - - } finally { - MyBatis.closeQuietly(session); - } - } - - public GraphDto selectByComponent(String perspectiveKey, String componentKey) { - DbSession session = mybatis.openSession(true); - try { - GraphDtoMapper mapper = session.getMapper(GraphDtoMapper.class); - return mapper.selectByComponent(perspectiveKey, componentKey); - - } finally { - MyBatis.closeQuietly(session); - } - } -} diff --git a/sonar-core/src/main/java/org/sonar/core/graph/jdbc/GraphDto.java b/sonar-core/src/main/java/org/sonar/core/graph/jdbc/GraphDto.java deleted file mode 100644 index 7e36c786ede..00000000000 --- a/sonar-core/src/main/java/org/sonar/core/graph/jdbc/GraphDto.java +++ /dev/null @@ -1,103 +0,0 @@ -/* - * 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.core.graph.jdbc; - -public class GraphDto { - private long id; - private long resourceId; - private long snapshotId; - private String format; - private String perspective; - private int version; - private String rootVertexId; - private String data; - - public long getId() { - return id; - } - - public GraphDto setId(long id) { - this.id = id; - return this; - } - - public long getResourceId() { - return resourceId; - } - - public GraphDto setResourceId(long resourceId) { - this.resourceId = resourceId; - return this; - } - - public long getSnapshotId() { - return snapshotId; - } - - public GraphDto setSnapshotId(long snapshotId) { - this.snapshotId = snapshotId; - return this; - } - - public String getPerspective() { - return perspective; - } - - public GraphDto setPerspective(String perspective) { - this.perspective = perspective; - return this; - } - - public String getFormat() { - return format; - } - - public GraphDto setFormat(String format) { - this.format = format; - return this; - } - - public int getVersion() { - return version; - } - - public GraphDto setVersion(int version) { - this.version = version; - return this; - } - - public String getRootVertexId() { - return rootVertexId; - } - - public GraphDto setRootVertexId(String rootVertexId) { - this.rootVertexId = rootVertexId; - return this; - } - - public String getData() { - return data; - } - - public GraphDto setData(String data) { - this.data = data; - return this; - } -} diff --git a/sonar-core/src/main/java/org/sonar/core/graph/jdbc/GraphDtoMapper.java b/sonar-core/src/main/java/org/sonar/core/graph/jdbc/GraphDtoMapper.java deleted file mode 100644 index 23bb6437f66..00000000000 --- a/sonar-core/src/main/java/org/sonar/core/graph/jdbc/GraphDtoMapper.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * 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.core.graph.jdbc; - -import org.apache.ibatis.annotations.Param; - -public interface GraphDtoMapper { - void insert(GraphDto graph); - - GraphDto selectBySnapshot(@Param("perspective") String perspectiveKey, @Param("sid") long snapshotId); - - GraphDto selectByComponent(@Param("perspective") String perspectiveKey, @Param("key") String componentKey); -} diff --git a/sonar-core/src/main/java/org/sonar/core/graph/jdbc/package-info.java b/sonar-core/src/main/java/org/sonar/core/graph/jdbc/package-info.java deleted file mode 100644 index 148e4e943c0..00000000000 --- a/sonar-core/src/main/java/org/sonar/core/graph/jdbc/package-info.java +++ /dev/null @@ -1,23 +0,0 @@ -/* - * 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. - */ -@ParametersAreNonnullByDefault -package org.sonar.core.graph.jdbc; - -import javax.annotation.ParametersAreNonnullByDefault; diff --git a/sonar-core/src/main/java/org/sonar/core/persistence/DaoUtils.java b/sonar-core/src/main/java/org/sonar/core/persistence/DaoUtils.java index 052120c913b..935bc122b29 100644 --- a/sonar-core/src/main/java/org/sonar/core/persistence/DaoUtils.java +++ b/sonar-core/src/main/java/org/sonar/core/persistence/DaoUtils.java @@ -22,11 +22,18 @@ package org.sonar.core.persistence; import com.google.common.base.Function; import com.google.common.collect.ImmutableList; import com.google.common.collect.Lists; +import java.util.Collection; +import java.util.Collections; +import java.util.List; import org.sonar.core.dashboard.ActiveDashboardDao; import org.sonar.core.dashboard.DashboardDao; import org.sonar.core.duplication.DuplicationDao; -import org.sonar.core.graph.jdbc.GraphDao; -import org.sonar.core.issue.db.*; +import org.sonar.core.issue.db.ActionPlanDao; +import org.sonar.core.issue.db.ActionPlanStatsDao; +import org.sonar.core.issue.db.IssueChangeDao; +import org.sonar.core.issue.db.IssueDao; +import org.sonar.core.issue.db.IssueFilterDao; +import org.sonar.core.issue.db.IssueFilterFavouriteDao; import org.sonar.core.notification.db.NotificationQueueDao; import org.sonar.core.permission.PermissionDao; import org.sonar.core.permission.PermissionTemplateDao; @@ -40,11 +47,11 @@ import org.sonar.core.resource.ResourceKeyUpdaterDao; import org.sonar.core.rule.RuleDao; import org.sonar.core.technicaldebt.db.CharacteristicDao; import org.sonar.core.template.LoadedTemplateDao; -import org.sonar.core.user.*; - -import java.util.Collection; -import java.util.Collections; -import java.util.List; +import org.sonar.core.user.AuthorDao; +import org.sonar.core.user.AuthorizationDao; +import org.sonar.core.user.GroupMembershipDao; +import org.sonar.core.user.RoleDao; +import org.sonar.core.user.UserDao; import static com.google.common.collect.Lists.newArrayList; @@ -67,7 +74,6 @@ public final class DaoUtils { AuthorizationDao.class, DashboardDao.class, DuplicationDao.class, - GraphDao.class, GroupMembershipDao.class, IssueDao.class, IssueChangeDao.class, diff --git a/sonar-core/src/main/java/org/sonar/core/persistence/DatabaseVersion.java b/sonar-core/src/main/java/org/sonar/core/persistence/DatabaseVersion.java index 334245aa769..17fa55201f7 100644 --- a/sonar-core/src/main/java/org/sonar/core/persistence/DatabaseVersion.java +++ b/sonar-core/src/main/java/org/sonar/core/persistence/DatabaseVersion.java @@ -35,7 +35,7 @@ import java.util.List; @ServerSide public class DatabaseVersion { - public static final int LAST_VERSION = 914; + public static final int LAST_VERSION = 915; /** * List of all the tables.n @@ -56,7 +56,6 @@ public class DatabaseVersion { "duplications_index", "events", "file_sources", - "graphs", "groups", "groups_users", "group_roles", diff --git a/sonar-core/src/main/java/org/sonar/core/persistence/MyBatis.java b/sonar-core/src/main/java/org/sonar/core/persistence/MyBatis.java index 35d49d5a0d4..7480d60edbe 100644 --- a/sonar-core/src/main/java/org/sonar/core/persistence/MyBatis.java +++ b/sonar-core/src/main/java/org/sonar/core/persistence/MyBatis.java @@ -66,8 +66,6 @@ import org.sonar.core.duplication.DuplicationMapper; import org.sonar.core.duplication.DuplicationUnitDto; import org.sonar.core.event.EventDto; import org.sonar.core.event.db.EventMapper; -import org.sonar.core.graph.jdbc.GraphDto; -import org.sonar.core.graph.jdbc.GraphDtoMapper; import org.sonar.core.issue.db.ActionPlanDto; import org.sonar.core.issue.db.ActionPlanMapper; import org.sonar.core.issue.db.ActionPlanStatsDto; @@ -197,7 +195,6 @@ public class MyBatis { loadAlias(conf, "ComponentLink", ComponentLinkDto.class); loadAlias(conf, "Dashboard", DashboardDto.class); loadAlias(conf, "DuplicationUnit", DuplicationUnitDto.class); - loadAlias(conf, "Graph", GraphDto.class); loadAlias(conf, "Group", GroupDto.class); loadAlias(conf, "GroupRole", GroupRoleDto.class); loadAlias(conf, "GroupMembership", GroupMembershipDto.class); @@ -253,7 +250,7 @@ public class MyBatis { loadMapper(conf, "org.sonar.core.permission.PermissionMapper"); Class[] mappers = {ActivityMapper.class, ActiveDashboardMapper.class, AuthorMapper.class, DashboardMapper.class, - FileDependencyMapper.class, DuplicationMapper.class, GraphDtoMapper.class, + FileDependencyMapper.class, DuplicationMapper.class, IssueMapper.class, IssueChangeMapper.class, IssueFilterMapper.class, IssueFilterFavouriteMapper.class, IsAliveMapper.class, LoadedTemplateMapper.class, MeasureFilterMapper.class, Migration44Mapper.class, PermissionTemplateMapper.class, PropertiesMapper.class, PurgeMapper.class, diff --git a/sonar-core/src/main/java/org/sonar/core/purge/PurgeCommands.java b/sonar-core/src/main/java/org/sonar/core/purge/PurgeCommands.java index 438f416177c..b8c9c49edd5 100644 --- a/sonar-core/src/main/java/org/sonar/core/purge/PurgeCommands.java +++ b/sonar-core/src/main/java/org/sonar/core/purge/PurgeCommands.java @@ -132,13 +132,6 @@ class PurgeCommands { session.commit(); profiler.stop(); - profiler.start("deleteResourceGraphs (graphs)"); - for (List partResourceIds : componentIdPartitions) { - purgeMapper.deleteResourceGraphs(partResourceIds); - } - session.commit(); - profiler.stop(); - profiler.start("deleteResource (projects)"); for (List partResourceIds : componentIdPartitions) { purgeMapper.deleteResource(partResourceIds); @@ -181,8 +174,6 @@ class PurgeCommands { session.commit(); profiler.stop(); - deleteSnapshotGraphs(snapshotIdsPartition); - profiler.start("deleteSnapshot (snapshots)"); for (List partSnapshotIds : snapshotIdsPartition) { purgeMapper.deleteSnapshot(partSnapshotIds); @@ -204,8 +195,6 @@ class PurgeCommands { deleteSnapshotDuplications(snapshotIdsPartition); - deleteSnapshotGraphs(snapshotIdsPartition); - profiler.start("deleteSnapshotWastedMeasures (project_measures)"); List metricIdsWithoutHistoricalData = purgeMapper.selectMetricIdsWithoutHistoricalData(); for (List partSnapshotIds : snapshotIdsPartition) { @@ -222,15 +211,6 @@ class PurgeCommands { profiler.stop(); } - private void deleteSnapshotGraphs(final List> snapshotIdsPartition) { - profiler.start("deleteSnapshotGraphs (graphs)"); - for (List partSnapshotIds : snapshotIdsPartition) { - purgeMapper.deleteSnapshotGraphs(partSnapshotIds); - } - session.commit(); - profiler.stop(); - } - private void deleteSnapshotDuplications(final List> snapshotIdsPartition) { profiler.start("deleteSnapshotDuplications (duplications_index)"); for (List partSnapshotIds : snapshotIdsPartition) { diff --git a/sonar-core/src/main/java/org/sonar/core/purge/PurgeMapper.java b/sonar-core/src/main/java/org/sonar/core/purge/PurgeMapper.java index 2dda5e52837..3c5e7131463 100644 --- a/sonar-core/src/main/java/org/sonar/core/purge/PurgeMapper.java +++ b/sonar-core/src/main/java/org/sonar/core/purge/PurgeMapper.java @@ -49,8 +49,6 @@ public interface PurgeMapper { void deleteSnapshotMeasures(@Param("snapshotIds") List snapshotIds); - void deleteSnapshotGraphs(@Param("snapshotIds") List snapshotIds); - List selectMetricIdsWithoutHistoricalData(); void deleteSnapshotWastedMeasures(@Param("snapshotIds") List snapshotIds, @Param("mids") List metricIds); @@ -83,8 +81,6 @@ public interface PurgeMapper { void deleteResourceActionPlans(@Param("resourceIds") List resourceIds); - void deleteResourceGraphs(@Param("resourceIds") List resourceIds); - void deleteAuthors(@Param("resourceIds") List resourceIds); List selectPurgeableSnapshotsWithEvents(long resourceId); diff --git a/sonar-core/src/main/resources/org/sonar/core/graph/jdbc/GraphDtoMapper.xml b/sonar-core/src/main/resources/org/sonar/core/graph/jdbc/GraphDtoMapper.xml deleted file mode 100644 index 704090274f5..00000000000 --- a/sonar-core/src/main/resources/org/sonar/core/graph/jdbc/GraphDtoMapper.xml +++ /dev/null @@ -1,29 +0,0 @@ - - - - - - - - - - - insert into graphs - (resource_id, snapshot_id, format, version, perspective, root_vertex_id, data, created_at, updated_at) - values ( - #{resourceId}, #{snapshotId}, #{format}, #{version}, #{perspective}, #{rootVertexId}, - #{data}, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP) - - - - diff --git a/sonar-core/src/main/resources/org/sonar/core/persistence/rows-h2.sql b/sonar-core/src/main/resources/org/sonar/core/persistence/rows-h2.sql index 92a6baa5be6..a985006dde7 100644 --- a/sonar-core/src/main/resources/org/sonar/core/persistence/rows-h2.sql +++ b/sonar-core/src/main/resources/org/sonar/core/persistence/rows-h2.sql @@ -338,6 +338,7 @@ INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('911'); INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('912'); INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('913'); INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('914'); +INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('915'); INSERT INTO USERS(ID, LOGIN, NAME, EMAIL, CRYPTED_PASSWORD, SALT, CREATED_AT, UPDATED_AT, REMEMBER_TOKEN, REMEMBER_TOKEN_EXPIRES_AT) VALUES (1, 'admin', 'Administrator', '', 'a373a0e667abb2604c1fd571eb4ad47fe8cc0878', '48bc4b0d93179b5103fd3885ea9119498e9d161b', '1418215735482', '1418215735482', null, null); ALTER TABLE USERS ALTER COLUMN ID RESTART WITH 2; diff --git a/sonar-core/src/main/resources/org/sonar/core/persistence/schema-h2.ddl b/sonar-core/src/main/resources/org/sonar/core/persistence/schema-h2.ddl index ff932e6131e..f1b4b16c6c4 100644 --- a/sonar-core/src/main/resources/org/sonar/core/persistence/schema-h2.ddl +++ b/sonar-core/src/main/resources/org/sonar/core/persistence/schema-h2.ddl @@ -437,19 +437,6 @@ CREATE TABLE "MEASURE_FILTER_FAVOURITES" ( "CREATED_AT" TIMESTAMP ); -CREATE TABLE "GRAPHS" ( - "ID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1), - "RESOURCE_ID" INTEGER NOT NULL, - "SNAPSHOT_ID" INTEGER NOT NULL, - "FORMAT" VARCHAR(20), - "PERSPECTIVE" VARCHAR(30), - "VERSION" VARCHAR(20), - "ROOT_VERTEX_ID" VARCHAR(30), - "DATA" CLOB(2147483647), - "CREATED_AT" TIMESTAMP, - "UPDATED_AT" TIMESTAMP -); - CREATE TABLE "ISSUES" ( "ID" BIGINT NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1), "KEE" VARCHAR(50) UNIQUE NOT NULL, @@ -665,8 +652,6 @@ CREATE INDEX "MEASURE_FILTERS_NAME" ON "MEASURE_FILTERS" ("NAME"); CREATE INDEX "MEASURE_FILTER_FAVS_USERID" ON "MEASURE_FILTER_FAVOURITES" ("USER_ID"); -CREATE UNIQUE INDEX "GRAPHS_PERSPECTIVES" ON "GRAPHS" ("SNAPSHOT_ID", "PERSPECTIVE"); - CREATE UNIQUE INDEX "ISSUES_KEE" ON "ISSUES" ("KEE"); CREATE INDEX "ISSUES_COMPONENT_UUID" ON "ISSUES" ("COMPONENT_UUID"); diff --git a/sonar-core/src/main/resources/org/sonar/core/purge/PurgeMapper.xml b/sonar-core/src/main/resources/org/sonar/core/purge/PurgeMapper.xml index 6ba17308f50..454cebefd32 100644 --- a/sonar-core/src/main/resources/org/sonar/core/purge/PurgeMapper.xml +++ b/sonar-core/src/main/resources/org/sonar/core/purge/PurgeMapper.xml @@ -103,13 +103,6 @@ - - delete from graphs where snapshot_id in - - #{snapshotId} - - - delete from dependencies where from_snapshot_id in @@ -252,13 +245,6 @@ - - delete from graphs where resource_id in - - #{resourceId} - - - delete from authors where person_id in diff --git a/sonar-core/src/test/java/org/sonar/core/graph/SubGraphTest.java b/sonar-core/src/test/java/org/sonar/core/graph/SubGraphTest.java deleted file mode 100644 index 9323c28e6d2..00000000000 --- a/sonar-core/src/test/java/org/sonar/core/graph/SubGraphTest.java +++ /dev/null @@ -1,118 +0,0 @@ -/* - * 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.core.graph; - -import com.tinkerpop.blueprints.Direction; -import com.tinkerpop.blueprints.Edge; -import com.tinkerpop.blueprints.Graph; -import com.tinkerpop.blueprints.Vertex; -import com.tinkerpop.blueprints.impls.tg.TinkerGraph; -import com.tinkerpop.blueprints.util.GraphHelper; -import org.junit.Test; - -import static org.assertj.core.api.Assertions.assertThat; - -public class SubGraphTest { - - @Test - public void should_extract_graph() { - TinkerGraph graph = new TinkerGraph(); - Vertex a = GraphHelper.addVertex(graph, null, "key", "a"); - Vertex b = GraphHelper.addVertex(graph, null, "key", "b"); - Vertex c = GraphHelper.addVertex(graph, null, "key", "c"); - Vertex d = GraphHelper.addVertex(graph, null, "key", "d"); - Vertex e = GraphHelper.addVertex(graph, null, "key", "e"); - - Edge ab = GraphHelper.addEdge(graph, null, a, b, "uses"); - Edge bc = GraphHelper.addEdge(graph, null, b, c, "inherits"); - Edge ad = GraphHelper.addEdge(graph, null, a, d, "uses"); - Edge de = GraphHelper.addEdge(graph, null, d, e, "implements"); - - // a -uses-> b -inherits -> c - // a -uses-> d -implements-> e - - Graph sub = SubGraph.extract(a, EdgePath.create(Direction.OUT, "uses", Direction.OUT, "implements")); - - // a -uses-> b - // a -uses-> d -implements-> e - assertThat(sub.getVertices()).hasSize(4); - assertThat(sub.getVertex(a.getId()).getProperty("key")).isEqualTo("a"); - assertThat(sub.getVertex(b.getId()).getProperty("key")).isEqualTo("b"); - assertThat(sub.getVertex(c.getId())).isNull(); - assertThat(sub.getVertex(d.getId()).getProperty("key")).isEqualTo("d"); - assertThat(sub.getVertex(e.getId()).getProperty("key")).isEqualTo("e"); - - assertThat(sub.getEdges()).hasSize(3); - assertThat(sub.getEdge(ab.getId()).getLabel()).isEqualTo("uses"); - assertThat(sub.getEdge(ab.getId()).toString()).isEqualTo(ab.toString()); - assertThat(sub.getEdge(bc.getId())).isNull(); - assertThat(sub.getEdge(ad.getId()).toString()).isEqualTo(ad.toString()); - assertThat(sub.getEdge(de.getId()).toString()).isEqualTo(de.toString()); - } - - @Test - public void should_extract_cyclic_graph() { - TinkerGraph graph = new TinkerGraph(); - Vertex a = GraphHelper.addVertex(graph, null, "key", "a"); - Vertex b = GraphHelper.addVertex(graph, null, "key", "b"); - Vertex c = GraphHelper.addVertex(graph, null, "key", "c"); - Vertex d = GraphHelper.addVertex(graph, null, "key", "d"); - Vertex e = GraphHelper.addVertex(graph, null, "key", "e"); - - Edge ab = GraphHelper.addEdge(graph, null, a, b, "uses"); - Edge bc = GraphHelper.addEdge(graph, null, b, c, "implements"); - Edge ce = GraphHelper.addEdge(graph, null, c, e, "package"); - Edge ad = GraphHelper.addEdge(graph, null, a, d, "uses"); - Edge dc = GraphHelper.addEdge(graph, null, d, c, "implements"); - - // a -uses-> b -implements-> c -package-> e - // a -uses-> d -implements-> c -package-> e - - Graph sub = SubGraph.extract(a, EdgePath.create(Direction.OUT, "uses", Direction.OUT, "implements", Direction.OUT, "package")); - - // same graph - assertThat(sub.getVertices()).hasSize(5); - assertThat(sub.getEdges()).hasSize(5); - } - - @Test - public void should_check_edge_direction() { - TinkerGraph graph = new TinkerGraph(); - Vertex a = GraphHelper.addVertex(graph, null, "key", "a"); - Vertex b = GraphHelper.addVertex(graph, null, "key", "b"); - Vertex c = GraphHelper.addVertex(graph, null, "key", "c"); - Vertex d = GraphHelper.addVertex(graph, null, "key", "d"); - Vertex e = GraphHelper.addVertex(graph, null, "key", "e"); - - Edge ab = GraphHelper.addEdge(graph, null, a, b, "uses"); - Edge bc = GraphHelper.addEdge(graph, null, b, c, "inherits"); - Edge ad = GraphHelper.addEdge(graph, null, a, d, "uses"); - Edge de = GraphHelper.addEdge(graph, null, d, e, "implements"); - - // a -uses-> b -inherits -> c - // a -uses-> d -implements-> e - - Graph sub = SubGraph.extract(a, EdgePath.create(Direction.IN /* instead of out */, "uses", Direction.OUT, "implements")); - - assertThat(sub.getVertices()).hasSize(1); - assertThat(sub.getVertex(a.getId())).isNotNull(); - assertThat(sub.getEdges()).isEmpty(); - } -} diff --git a/sonar-core/src/test/java/org/sonar/core/graph/jdbc/GraphDaoTest.java b/sonar-core/src/test/java/org/sonar/core/graph/jdbc/GraphDaoTest.java deleted file mode 100644 index 4b84ef03c87..00000000000 --- a/sonar-core/src/test/java/org/sonar/core/graph/jdbc/GraphDaoTest.java +++ /dev/null @@ -1,79 +0,0 @@ -/* - * 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.core.graph.jdbc; - -import org.junit.Before; -import org.junit.Test; -import org.sonar.core.persistence.AbstractDaoTestCase; - -import static org.assertj.core.api.Assertions.assertThat; - -public class GraphDaoTest extends AbstractDaoTestCase { - private GraphDao dao; - - @Before - public void createDao() { - dao = new GraphDao(getMyBatis()); - setupData("shared"); - } - - @Test - public void select_graph_by_snapshot() { - GraphDto testPlan = dao.selectBySnapshot("testplan", 11L); - - assertThat(testPlan.getId()).isEqualTo(101L); - assertThat(testPlan.getResourceId()).isEqualTo(1L); - assertThat(testPlan.getSnapshotId()).isEqualTo(11L); - assertThat(testPlan.getFormat()).isEqualTo("graphson"); - assertThat(testPlan.getVersion()).isEqualTo(1); - assertThat(testPlan.getPerspective()).isEqualTo("testplan"); - assertThat(testPlan.getRootVertexId()).isEqualTo("3456"); - assertThat(testPlan.getData()).isEqualTo("{testplan of snapshot 123}"); - } - - @Test - public void select_by_snapshot_and_missing_perspective() { - assertThat(dao.selectBySnapshot("duplicable", 123L)).isNull(); - } - - @Test - public void select_by_missing_snapshot() { - assertThat(dao.selectBySnapshot("duplicable", 7777L)).isNull(); - } - - @Test - public void select_by_component() { - GraphDto testPlan = dao.selectByComponent("testplan", "org.apache.struts:struts"); - - assertThat(testPlan.getId()).isEqualTo(101L); - assertThat(testPlan.getResourceId()).isEqualTo(1L); - assertThat(testPlan.getSnapshotId()).isEqualTo(11L); - assertThat(testPlan.getFormat()).isEqualTo("graphson"); - assertThat(testPlan.getVersion()).isEqualTo(1); - assertThat(testPlan.getPerspective()).isEqualTo("testplan"); - assertThat(testPlan.getRootVertexId()).isEqualTo("3456"); - assertThat(testPlan.getData()).isEqualTo("{testplan of snapshot 123}"); - } - - @Test - public void select_by_missing_component() { - assertThat(dao.selectByComponent("testplan", "org.other:unknown")).isNull(); - } -} diff --git a/sonar-core/src/test/resources/org/sonar/core/graph/jdbc/GraphDaoTest/shared.xml b/sonar-core/src/test/resources/org/sonar/core/graph/jdbc/GraphDaoTest/shared.xml deleted file mode 100644 index 9345cfcf402..00000000000 --- a/sonar-core/src/test/resources/org/sonar/core/graph/jdbc/GraphDaoTest/shared.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - - - - \ No newline at end of file -- 2.39.5