aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-core/src/main
diff options
context:
space:
mode:
authorsimonbrandhof <simon.brandhof@gmail.com>2012-01-24 14:40:27 +0100
committersimonbrandhof <simon.brandhof@gmail.com>2012-01-24 14:41:22 +0100
commit4eab0b33d1e3df3669b8ee55cebe43e3244aa2d1 (patch)
treec33bebdba41dc74ec4ba6f9d5f0499d4852ca2b9 /sonar-core/src/main
parent2480541720256002f5402ebb004c85034fb9f2de (diff)
downloadsonarqube-4eab0b33d1e3df3669b8ee55cebe43e3244aa2d1.tar.gz
sonarqube-4eab0b33d1e3df3669b8ee55cebe43e3244aa2d1.zip
Move some purge tasks to MyBatis
SONAR-2754 add the parameter sonar.dbcleaner.cleanDirectoryHistory SONAR-2757 remove fullscan requests on the table SNAPSHOTS
Diffstat (limited to 'sonar-core/src/main')
-rw-r--r--sonar-core/src/main/java/org/sonar/core/dashboard/ActiveDashboardDao.java2
-rw-r--r--sonar-core/src/main/java/org/sonar/core/dashboard/DashboardDao.java8
-rw-r--r--sonar-core/src/main/java/org/sonar/core/duplication/DuplicationDao.java8
-rw-r--r--sonar-core/src/main/java/org/sonar/core/persistence/DaoUtils.java2
-rw-r--r--sonar-core/src/main/java/org/sonar/core/persistence/DatabaseMigrator.java2
-rw-r--r--sonar-core/src/main/java/org/sonar/core/persistence/DatabaseUtils.java4
-rw-r--r--sonar-core/src/main/java/org/sonar/core/persistence/MyBatis.java20
-rw-r--r--sonar-core/src/main/java/org/sonar/core/purge/PurgeDao.java165
-rw-r--r--sonar-core/src/main/java/org/sonar/core/purge/PurgeMapper.java50
-rw-r--r--sonar-core/src/main/java/org/sonar/core/purge/PurgeSnapshotQuery.java82
-rw-r--r--sonar-core/src/main/java/org/sonar/core/resource/ResourceIndexerDao.java6
-rw-r--r--sonar-core/src/main/java/org/sonar/core/resource/ResourceMapper.java24
-rw-r--r--sonar-core/src/main/java/org/sonar/core/resource/SnapshotDto.java176
-rw-r--r--sonar-core/src/main/java/org/sonar/core/review/ReviewDao.java23
-rw-r--r--sonar-core/src/main/java/org/sonar/core/rule/RuleDao.java12
-rw-r--r--sonar-core/src/main/java/org/sonar/core/template/LoadedTemplateDao.java4
-rw-r--r--sonar-core/src/main/resources/org/sonar/core/persistence/rows-derby.sql1
-rw-r--r--sonar-core/src/main/resources/org/sonar/core/persistence/schema-derby.ddl26
-rw-r--r--sonar-core/src/main/resources/org/sonar/core/purge/PurgeMapper.xml107
-rw-r--r--sonar-core/src/main/resources/org/sonar/core/resource/ResourceMapper.xml31
20 files changed, 687 insertions, 66 deletions
diff --git a/sonar-core/src/main/java/org/sonar/core/dashboard/ActiveDashboardDao.java b/sonar-core/src/main/java/org/sonar/core/dashboard/ActiveDashboardDao.java
index 569a36b146c..1e283c6f541 100644
--- a/sonar-core/src/main/java/org/sonar/core/dashboard/ActiveDashboardDao.java
+++ b/sonar-core/src/main/java/org/sonar/core/dashboard/ActiveDashboardDao.java
@@ -39,7 +39,7 @@ public class ActiveDashboardDao implements BatchComponent, ServerComponent {
mapper.insert(activeDashboardDto);
session.commit();
} finally {
- session.close();
+ MyBatis.closeSessionQuietly(session);
}
}
diff --git a/sonar-core/src/main/java/org/sonar/core/dashboard/DashboardDao.java b/sonar-core/src/main/java/org/sonar/core/dashboard/DashboardDao.java
index ba2d1853708..b70433dbf92 100644
--- a/sonar-core/src/main/java/org/sonar/core/dashboard/DashboardDao.java
+++ b/sonar-core/src/main/java/org/sonar/core/dashboard/DashboardDao.java
@@ -33,12 +33,12 @@ public class DashboardDao implements BatchComponent, ServerComponent {
}
public DashboardDto selectGlobalDashboard(String name) {
- SqlSession sqlSession = mybatis.openSession();
+ SqlSession session = mybatis.openSession();
try {
- DashboardMapper mapper = sqlSession.getMapper(DashboardMapper.class);
+ DashboardMapper mapper = session.getMapper(DashboardMapper.class);
return mapper.selectGlobalDashboard(name);
} finally {
- sqlSession.close();
+ MyBatis.closeSessionQuietly(session);
}
}
@@ -59,7 +59,7 @@ public class DashboardDao implements BatchComponent, ServerComponent {
}
session.commit();
} finally {
- session.close();
+ MyBatis.closeSessionQuietly(session);
}
}
diff --git a/sonar-core/src/main/java/org/sonar/core/duplication/DuplicationDao.java b/sonar-core/src/main/java/org/sonar/core/duplication/DuplicationDao.java
index eb3084ddb8d..2d98f947ca8 100644
--- a/sonar-core/src/main/java/org/sonar/core/duplication/DuplicationDao.java
+++ b/sonar-core/src/main/java/org/sonar/core/duplication/DuplicationDao.java
@@ -37,12 +37,12 @@ public class DuplicationDao implements BatchComponent, ServerComponent {
}
public List<DuplicationUnitDto> selectCandidates(int resourceSnapshotId, Integer lastSnapshotId) {
- SqlSession sqlSession = mybatis.openSession();
+ SqlSession session = mybatis.openSession();
try {
- DuplicationMapper mapper = sqlSession.getMapper(DuplicationMapper.class);
+ DuplicationMapper mapper = session.getMapper(DuplicationMapper.class);
return mapper.selectCandidates(resourceSnapshotId, lastSnapshotId);
} finally {
- sqlSession.close();
+ MyBatis.closeSessionQuietly(session);
}
}
@@ -60,7 +60,7 @@ public class DuplicationDao implements BatchComponent, ServerComponent {
session.commit();
} finally {
- session.close();
+ MyBatis.closeSessionQuietly(session);
}
}
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 579645ba3a9..5f337782152 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,6 +22,7 @@ package org.sonar.core.persistence;
import org.sonar.core.dashboard.ActiveDashboardDao;
import org.sonar.core.dashboard.DashboardDao;
import org.sonar.core.duplication.DuplicationDao;
+import org.sonar.core.purge.PurgeDao;
import org.sonar.core.resource.ResourceIndexerDao;
import org.sonar.core.review.ReviewDao;
import org.sonar.core.rule.RuleDao;
@@ -42,6 +43,7 @@ public final class DaoUtils {
DashboardDao.class,
DuplicationDao.class,
LoadedTemplateDao.class,
+ PurgeDao.class,
ResourceIndexerDao.class,
ReviewDao.class,
RuleDao.class));
diff --git a/sonar-core/src/main/java/org/sonar/core/persistence/DatabaseMigrator.java b/sonar-core/src/main/java/org/sonar/core/persistence/DatabaseMigrator.java
index ef2950eed2a..0f7a0f0faac 100644
--- a/sonar-core/src/main/java/org/sonar/core/persistence/DatabaseMigrator.java
+++ b/sonar-core/src/main/java/org/sonar/core/persistence/DatabaseMigrator.java
@@ -52,7 +52,7 @@ public class DatabaseMigrator implements ServerComponent {
DdlUtils.createSchema(connection, database.getDialect().getId());
} finally {
try {
- session.close();
+ MyBatis.closeSessionQuietly(session);
// The connection is probably already closed by session.close()
// but it's not documented in mybatis javadoc.
diff --git a/sonar-core/src/main/java/org/sonar/core/persistence/DatabaseUtils.java b/sonar-core/src/main/java/org/sonar/core/persistence/DatabaseUtils.java
index be14f84242f..814c1ee26e2 100644
--- a/sonar-core/src/main/java/org/sonar/core/persistence/DatabaseUtils.java
+++ b/sonar-core/src/main/java/org/sonar/core/persistence/DatabaseUtils.java
@@ -43,7 +43,6 @@ public final class DatabaseUtils {
"active_filters",
"active_rules",
"active_rule_changes",
- "active_rule_notes",
"active_rule_parameters",
"active_rule_param_changes",
"alerts",
@@ -73,12 +72,11 @@ public final class DatabaseUtils {
"resource_index",
"reviews",
"review_comments",
- "rule_failures",
- "rule_notes",
"rules",
"rules_categories",
"rules_parameters",
"rules_profiles",
+ "rule_failures",
"schema_migrations",
"snapshots",
"snapshot_sources",
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 cd055ef0ac6..59da8b5aeea 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
@@ -26,14 +26,14 @@ import org.apache.ibatis.logging.LogFactory;
import org.apache.ibatis.mapping.Environment;
import org.apache.ibatis.session.*;
import org.apache.ibatis.transaction.jdbc.JdbcTransactionFactory;
+import org.slf4j.LoggerFactory;
import org.sonar.api.BatchComponent;
import org.sonar.api.ServerComponent;
import org.sonar.core.dashboard.*;
import org.sonar.core.duplication.DuplicationMapper;
import org.sonar.core.duplication.DuplicationUnitDto;
-import org.sonar.core.resource.ResourceDto;
-import org.sonar.core.resource.ResourceIndexDto;
-import org.sonar.core.resource.ResourceIndexerMapper;
+import org.sonar.core.purge.PurgeMapper;
+import org.sonar.core.resource.*;
import org.sonar.core.review.ReviewDto;
import org.sonar.core.review.ReviewMapper;
import org.sonar.core.rule.RuleDto;
@@ -70,6 +70,7 @@ public class MyBatis implements BatchComponent, ServerComponent {
loadAlias(conf, "Resource", ResourceDto.class);
loadAlias(conf, "ResourceIndex", ResourceIndexDto.class);
loadAlias(conf, "Rule", RuleDto.class);
+ loadAlias(conf, "Snapshot", SnapshotDto.class);
loadAlias(conf, "Widget", WidgetDto.class);
loadAlias(conf, "WidgetProperty", WidgetPropertyDto.class);
@@ -77,6 +78,8 @@ public class MyBatis implements BatchComponent, ServerComponent {
loadMapper(conf, DashboardMapper.class);
loadMapper(conf, DuplicationMapper.class);
loadMapper(conf, LoadedTemplateMapper.class);
+ loadMapper(conf, PurgeMapper.class);
+ loadMapper(conf, ResourceMapper.class);
loadMapper(conf, ReviewMapper.class);
loadMapper(conf, ResourceIndexerMapper.class);
loadMapper(conf, RuleMapper.class);
@@ -99,6 +102,17 @@ public class MyBatis implements BatchComponent, ServerComponent {
return sessionFactory.openSession(type);
}
+ public static void closeSessionQuietly(SqlSession session) {
+ if (session != null) {
+ try {
+ session.close();
+ } catch (Exception e) {
+ LoggerFactory.getLogger(MyBatis.class).warn("Fail to close session", e);
+ // do not re-throw the exception
+ }
+ }
+ }
+
private void loadMapper(Configuration conf, Class mapperClass) throws IOException {
// trick to use database-specific XML files for a single Mapper Java interface
InputStream input = getPathToMapper(mapperClass);
diff --git a/sonar-core/src/main/java/org/sonar/core/purge/PurgeDao.java b/sonar-core/src/main/java/org/sonar/core/purge/PurgeDao.java
new file mode 100644
index 00000000000..510537f9b57
--- /dev/null
+++ b/sonar-core/src/main/java/org/sonar/core/purge/PurgeDao.java
@@ -0,0 +1,165 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2008-2012 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar 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.
+ *
+ * Sonar 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 Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+package org.sonar.core.purge;
+
+import org.apache.ibatis.session.ExecutorType;
+import org.apache.ibatis.session.ResultContext;
+import org.apache.ibatis.session.ResultHandler;
+import org.apache.ibatis.session.SqlSession;
+import org.sonar.core.persistence.MyBatis;
+
+public class PurgeDao {
+ private final MyBatis mybatis;
+
+ public PurgeDao(MyBatis mybatis) {
+ this.mybatis = mybatis;
+ }
+
+ public PurgeDao disableOrphanResources(Object... handlers) {
+ SqlSession session = mybatis.openSession(ExecutorType.BATCH);
+ try {
+ final PurgeMapper mapper = session.getMapper(PurgeMapper.class);
+ final BatchSession batchSession = new BatchSession(session);
+ session.select("selectResourceIdsToDisable", new ResultHandler() {
+ public void handleResult(ResultContext context) {
+ Long resourceId = (Long) context.getResultObject();
+ // TODO execute handlers in order to close reviews
+ batchSession.increment(disableResource(resourceId, mapper));
+ }
+ });
+ batchSession.commit();
+ return this;
+
+ } finally {
+ MyBatis.closeSessionQuietly(session);
+ }
+ }
+
+ public PurgeDao disableResource(long resourceId, Object... handlers) {
+ SqlSession session = mybatis.openSession(ExecutorType.BATCH);
+ try {
+ final PurgeMapper mapper = session.getMapper(PurgeMapper.class);
+ disableResource(resourceId, mapper);
+ session.commit();
+ return this;
+
+ } finally {
+ MyBatis.closeSessionQuietly(session);
+ }
+ }
+
+ int disableResource(long resourceId, PurgeMapper mapper) {
+ mapper.disableResource(resourceId);
+ mapper.deleteResourceIndex(resourceId);
+ mapper.unsetSnapshotIslast(resourceId);
+ // TODO close reviews
+ return 3; // nb of SQL requests
+ }
+
+ public PurgeDao deleteSnapshots(PurgeSnapshotQuery query) {
+ SqlSession session = mybatis.openSession(ExecutorType.BATCH);
+ try {
+ final PurgeMapper mapper = session.getMapper(PurgeMapper.class);
+ final BatchSession batchSession = new BatchSession(session);
+ session.select("selectSnapshotIds", query, new ResultHandler() {
+ public void handleResult(ResultContext context) {
+ Long snapshotId = (Long) context.getResultObject();
+ batchSession.increment(deleteSnapshot(snapshotId, mapper));
+ }
+ });
+ batchSession.commit();
+ return this;
+
+ } finally {
+ MyBatis.closeSessionQuietly(session);
+ }
+ }
+
+ public PurgeDao purgeSnapshots(PurgeSnapshotQuery query) {
+ SqlSession session = mybatis.openSession(ExecutorType.BATCH);
+ try {
+ final PurgeMapper mapper = session.getMapper(PurgeMapper.class);
+ final BatchSession batchSession = new BatchSession(session);
+ session.select("selectSnapshotIdsToPurge", query, new ResultHandler() {
+ public void handleResult(ResultContext context) {
+ Long snapshotId = (Long) context.getResultObject();
+ batchSession.increment(purgeSnapshot(snapshotId, mapper));
+ }
+ });
+ batchSession.commit();
+ return this;
+
+ } finally {
+ MyBatis.closeSessionQuietly(session);
+ }
+ }
+
+ int purgeSnapshot(long snapshotId, PurgeMapper mapper) {
+ // note that events are not deleted.
+ mapper.deleteSnapshotDependencies(snapshotId);
+ mapper.deleteSnapshotDuplications(snapshotId);
+ mapper.deleteSnapshotSource(snapshotId);
+ mapper.deleteSnapshotViolations(snapshotId);
+ mapper.deleteSnapshotRuleMeasures(snapshotId);
+ mapper.deleteSnapshotCharacteristicMeasures(snapshotId);
+ // TODO SONAR-2061 delete wasted measures (!metric.keepHistory)
+ mapper.updatePurgeStatusToOne(snapshotId);
+ return 7; // nb of SQL requests
+ }
+
+ int deleteSnapshot(Long snapshotId, PurgeMapper mapper) {
+ mapper.deleteSnapshotDependencies(snapshotId);
+ mapper.deleteSnapshotDuplications(snapshotId);
+ mapper.deleteSnapshotEvents(snapshotId);
+ mapper.deleteSnapshotMeasureData(snapshotId);
+ mapper.deleteSnapshotMeasures(snapshotId);
+ mapper.deleteSnapshotSource(snapshotId);
+ mapper.deleteSnapshotViolations(snapshotId);
+ mapper.deleteSnapshot(snapshotId);
+ return 8; // nb of SQL requests
+ }
+
+ // TODO could be moved to org.sonar.core.persistence
+ private static class BatchSession {
+ static final int MAX_BATCH_SIZE = 1000;
+
+ int count = 0;
+ SqlSession session;
+
+ private BatchSession(SqlSession session) {
+ this.session = session;
+ }
+
+ BatchSession increment(int i) {
+ count += i;
+ if (count > MAX_BATCH_SIZE) {
+ commit();
+ }
+ return this;
+ }
+
+ BatchSession commit() {
+ session.commit();
+ count = 0;
+ return this;
+ }
+
+ }
+}
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
new file mode 100644
index 00000000000..2ee5c5857ba
--- /dev/null
+++ b/sonar-core/src/main/java/org/sonar/core/purge/PurgeMapper.java
@@ -0,0 +1,50 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2008-2012 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar 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.
+ *
+ * Sonar 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 Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+package org.sonar.core.purge;
+
+public interface PurgeMapper {
+ void deleteSnapshot(long snapshotId);
+
+ void deleteSnapshotDependencies(long snapshotId);
+
+ void deleteSnapshotDuplications(long snapshotId);
+
+ void deleteSnapshotEvents(long snapshotId);
+
+ void deleteSnapshotMeasures(long snapshotId);
+
+ void deleteSnapshotMeasureData(long snapshotId);
+
+ void deleteSnapshotSource(long snapshotId);
+
+ void deleteSnapshotViolations(long snapshotId);
+
+ void deleteSnapshotRuleMeasures(long snapshotId);
+
+ void deleteSnapshotCharacteristicMeasures(long snapshotId);
+
+ void updatePurgeStatusToOne(long snapshotId);
+
+ void disableResource(long resourceId);
+
+ void deleteResourceIndex(long resourceId);
+
+ void unsetSnapshotIslast(long resourceId);
+}
diff --git a/sonar-core/src/main/java/org/sonar/core/purge/PurgeSnapshotQuery.java b/sonar-core/src/main/java/org/sonar/core/purge/PurgeSnapshotQuery.java
new file mode 100644
index 00000000000..bb16364e559
--- /dev/null
+++ b/sonar-core/src/main/java/org/sonar/core/purge/PurgeSnapshotQuery.java
@@ -0,0 +1,82 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2008-2012 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar 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.
+ *
+ * Sonar 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 Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+package org.sonar.core.purge;
+
+import java.util.Date;
+
+public final class PurgeSnapshotQuery {
+ private Long rootProjectId;
+ private Date beforeBuildDate;
+ private String[] scopes;
+ private String[] qualifiers;
+ private String[] status;
+
+ private PurgeSnapshotQuery() {
+ }
+
+ public static PurgeSnapshotQuery create() {
+ return new PurgeSnapshotQuery();
+ }
+
+ public Long getRootProjectId() {
+ return rootProjectId;
+ }
+
+ public PurgeSnapshotQuery setRootProjectId(Long rootProjectId) {
+ this.rootProjectId = rootProjectId;
+ return this;
+ }
+
+ public Date getBeforeBuildDate() {
+ return beforeBuildDate;
+ }
+
+ public PurgeSnapshotQuery setBeforeBuildDate(Date beforeBuildDate) {
+ this.beforeBuildDate = beforeBuildDate;
+ return this;
+ }
+
+ public String[] getScopes() {
+ return scopes;
+ }
+
+ public PurgeSnapshotQuery setScopes(String[] scopes) {
+ this.scopes = scopes;
+ return this;
+ }
+
+ public String[] getQualifiers() {
+ return qualifiers;
+ }
+
+ public PurgeSnapshotQuery setQualifiers(String[] qualifiers) {
+ this.qualifiers = qualifiers;
+ return this;
+ }
+
+ public String[] getStatus() {
+ return status;
+ }
+
+ public PurgeSnapshotQuery setStatus(String[] status) {
+ this.status = status;
+ return this;
+ }
+}
diff --git a/sonar-core/src/main/java/org/sonar/core/resource/ResourceIndexerDao.java b/sonar-core/src/main/java/org/sonar/core/resource/ResourceIndexerDao.java
index 7fb493e6508..44f1d533210 100644
--- a/sonar-core/src/main/java/org/sonar/core/resource/ResourceIndexerDao.java
+++ b/sonar-core/src/main/java/org/sonar/core/resource/ResourceIndexerDao.java
@@ -58,7 +58,7 @@ public class ResourceIndexerDao {
return this;
} finally {
- session.close();
+ MyBatis.closeSessionQuietly(session);
}
}
@@ -79,7 +79,7 @@ public class ResourceIndexerDao {
return this;
} finally {
- session.close();
+ MyBatis.closeSessionQuietly(session);
}
}
@@ -160,7 +160,7 @@ public class ResourceIndexerDao {
}
}
} finally {
- session.close();
+ MyBatis.closeSessionQuietly(session);
}
}
return indexed;
diff --git a/sonar-core/src/main/java/org/sonar/core/resource/ResourceMapper.java b/sonar-core/src/main/java/org/sonar/core/resource/ResourceMapper.java
new file mode 100644
index 00000000000..deb72aeb3ad
--- /dev/null
+++ b/sonar-core/src/main/java/org/sonar/core/resource/ResourceMapper.java
@@ -0,0 +1,24 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2008-2012 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar 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.
+ *
+ * Sonar 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 Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+package org.sonar.core.resource;
+
+public interface ResourceMapper {
+ SnapshotDto selectSnapshotById(Long snapshotId);
+}
diff --git a/sonar-core/src/main/java/org/sonar/core/resource/SnapshotDto.java b/sonar-core/src/main/java/org/sonar/core/resource/SnapshotDto.java
new file mode 100644
index 00000000000..f211be6aac3
--- /dev/null
+++ b/sonar-core/src/main/java/org/sonar/core/resource/SnapshotDto.java
@@ -0,0 +1,176 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2008-2012 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar 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.
+ *
+ * Sonar 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 Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+package org.sonar.core.resource;
+
+import java.util.Date;
+
+public final class SnapshotDto {
+ private Long id;
+ private Long parentId;
+ private Long rootId;
+
+ private Date date;
+ private Date buildDate;
+ private Long resourceId;
+ private String status;
+ private Integer purgeStatus;
+ private Boolean last;
+ private String scope;
+ private String qualifier;
+ private String version;
+ private String path;
+ private Integer depth;
+ private Long rootProjectId;
+
+ public Long getId() {
+ return id;
+ }
+
+ public SnapshotDto setId(Long id) {
+ this.id = id;
+ return this;
+ }
+
+ public Long getParentId() {
+ return parentId;
+ }
+
+ public SnapshotDto setParentId(Long parentId) {
+ this.parentId = parentId;
+ return this;
+ }
+
+ public Long getRootId() {
+ return rootId;
+ }
+
+ public SnapshotDto setRootId(Long rootId) {
+ this.rootId = rootId;
+ return this;
+ }
+
+ public Date getDate() {
+ return date;
+ }
+
+ public SnapshotDto setDate(Date date) {
+ this.date = date;
+ return this;
+ }
+
+ public Date getBuildDate() {
+ return buildDate;
+ }
+
+ public SnapshotDto setBuildDate(Date buildDate) {
+ this.buildDate = buildDate;
+ return this;
+ }
+
+ public Long getResourceId() {
+ return resourceId;
+ }
+
+ public SnapshotDto setResourceId(Long resourceId) {
+ this.resourceId = resourceId;
+ return this;
+ }
+
+ public String getStatus() {
+ return status;
+ }
+
+ public SnapshotDto setStatus(String status) {
+ this.status = status;
+ return this;
+ }
+
+ public Integer getPurgeStatus() {
+ return purgeStatus;
+ }
+
+ public SnapshotDto setPurgeStatus(Integer purgeStatus) {
+ this.purgeStatus = purgeStatus;
+ return this;
+ }
+
+ public Boolean getLast() {
+ return last;
+ }
+
+ public SnapshotDto setLast(Boolean last) {
+ this.last = last;
+ return this;
+ }
+
+ public String getScope() {
+ return scope;
+ }
+
+ public SnapshotDto setScope(String scope) {
+ this.scope = scope;
+ return this;
+ }
+
+ public String getQualifier() {
+ return qualifier;
+ }
+
+ public SnapshotDto setQualifier(String qualifier) {
+ this.qualifier = qualifier;
+ return this;
+ }
+
+ public String getVersion() {
+ return version;
+ }
+
+ public SnapshotDto setVersion(String version) {
+ this.version = version;
+ return this;
+ }
+
+ public String getPath() {
+ return path;
+ }
+
+ public SnapshotDto setPath(String path) {
+ this.path = path;
+ return this;
+ }
+
+ public Integer getDepth() {
+ return depth;
+ }
+
+ public SnapshotDto setDepth(Integer depth) {
+ this.depth = depth;
+ return this;
+ }
+
+ public Long getRootProjectId() {
+ return rootProjectId;
+ }
+
+ public SnapshotDto setRootProjectId(Long rootProjectId) {
+ this.rootProjectId = rootProjectId;
+ return this;
+ }
+}
diff --git a/sonar-core/src/main/java/org/sonar/core/review/ReviewDao.java b/sonar-core/src/main/java/org/sonar/core/review/ReviewDao.java
index 438bb911021..c090251153d 100644
--- a/sonar-core/src/main/java/org/sonar/core/review/ReviewDao.java
+++ b/sonar-core/src/main/java/org/sonar/core/review/ReviewDao.java
@@ -19,14 +19,13 @@
*/
package org.sonar.core.review;
-import java.util.List;
-
+import com.google.common.collect.Lists;
import org.apache.ibatis.session.SqlSession;
import org.sonar.api.BatchComponent;
import org.sonar.api.ServerComponent;
import org.sonar.core.persistence.MyBatis;
-import com.google.common.collect.Lists;
+import java.util.List;
public class ReviewDao implements BatchComponent, ServerComponent {
private final MyBatis mybatis;
@@ -36,19 +35,19 @@ public class ReviewDao implements BatchComponent, ServerComponent {
}
public ReviewDto selectById(long id) {
- SqlSession sqlSession = mybatis.openSession();
+ SqlSession session = mybatis.openSession();
try {
- ReviewMapper mapper = sqlSession.getMapper(ReviewMapper.class);
+ ReviewMapper mapper = session.getMapper(ReviewMapper.class);
return mapper.selectById(id);
} finally {
- sqlSession.close();
+ MyBatis.closeSessionQuietly(session);
}
}
public List<ReviewDto> selectByQuery(ReviewQuery query) {
- SqlSession sqlSession = mybatis.openSession();
+ SqlSession session = mybatis.openSession();
try {
- ReviewMapper mapper = sqlSession.getMapper(ReviewMapper.class);
+ ReviewMapper mapper = session.getMapper(ReviewMapper.class);
List<ReviewDto> result;
if (query.needToPartitionQuery()) {
result = Lists.newArrayList();
@@ -60,14 +59,14 @@ public class ReviewDao implements BatchComponent, ServerComponent {
}
return result;
} finally {
- sqlSession.close();
+ MyBatis.closeSessionQuietly(session);
}
}
public Integer countByQuery(ReviewQuery query) {
- SqlSession sqlSession = mybatis.openSession();
+ SqlSession session = mybatis.openSession();
try {
- ReviewMapper mapper = sqlSession.getMapper(ReviewMapper.class);
+ ReviewMapper mapper = session.getMapper(ReviewMapper.class);
Integer result = 0;
if (query.needToPartitionQuery()) {
for (ReviewQuery partitionedQuery : query.partition()) {
@@ -78,7 +77,7 @@ public class ReviewDao implements BatchComponent, ServerComponent {
}
return result;
} finally {
- sqlSession.close();
+ MyBatis.closeSessionQuietly(session);
}
}
}
diff --git a/sonar-core/src/main/java/org/sonar/core/rule/RuleDao.java b/sonar-core/src/main/java/org/sonar/core/rule/RuleDao.java
index 76778d0b865..1b4b6545ea2 100644
--- a/sonar-core/src/main/java/org/sonar/core/rule/RuleDao.java
+++ b/sonar-core/src/main/java/org/sonar/core/rule/RuleDao.java
@@ -35,22 +35,22 @@ public class RuleDao implements BatchComponent, ServerComponent {
}
public List<RuleDto> selectAll() {
- SqlSession sqlSession = mybatis.openSession();
+ SqlSession session = mybatis.openSession();
try {
- RuleMapper mapper = sqlSession.getMapper(RuleMapper.class);
+ RuleMapper mapper = session.getMapper(RuleMapper.class);
return mapper.selectAll();
} finally {
- sqlSession.close();
+ MyBatis.closeSessionQuietly(session);
}
}
public RuleDto selectById(Long id) {
- SqlSession sqlSession = mybatis.openSession();
+ SqlSession session = mybatis.openSession();
try {
- RuleMapper mapper = sqlSession.getMapper(RuleMapper.class);
+ RuleMapper mapper = session.getMapper(RuleMapper.class);
return mapper.selectById(id);
} finally {
- sqlSession.close();
+ MyBatis.closeSessionQuietly(session);
}
}
diff --git a/sonar-core/src/main/java/org/sonar/core/template/LoadedTemplateDao.java b/sonar-core/src/main/java/org/sonar/core/template/LoadedTemplateDao.java
index 5a183c0b567..7067d03bd7c 100644
--- a/sonar-core/src/main/java/org/sonar/core/template/LoadedTemplateDao.java
+++ b/sonar-core/src/main/java/org/sonar/core/template/LoadedTemplateDao.java
@@ -38,7 +38,7 @@ public class LoadedTemplateDao implements BatchComponent, ServerComponent {
try {
return mapper.countByTypeAndKey(type, key);
} finally {
- session.close();
+ MyBatis.closeSessionQuietly(session);
}
}
@@ -49,7 +49,7 @@ public class LoadedTemplateDao implements BatchComponent, ServerComponent {
mapper.insert(loadedTemplateDto);
session.commit();
} finally {
- session.close();
+ MyBatis.closeSessionQuietly(session);
}
}
diff --git a/sonar-core/src/main/resources/org/sonar/core/persistence/rows-derby.sql b/sonar-core/src/main/resources/org/sonar/core/persistence/rows-derby.sql
index 02a2b5895b5..8144ad8cb05 100644
--- a/sonar-core/src/main/resources/org/sonar/core/persistence/rows-derby.sql
+++ b/sonar-core/src/main/resources/org/sonar/core/persistence/rows-derby.sql
@@ -170,7 +170,6 @@ INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('240');
INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('241');
INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('250');
INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('251');
-INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('252');
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', '2011-09-26 22:27:48.0', '2011-09-26 22:27:48.0', null, null);
ALTER TABLE USERS ALTER COLUMN ID RESTART WITH 2;
diff --git a/sonar-core/src/main/resources/org/sonar/core/persistence/schema-derby.ddl b/sonar-core/src/main/resources/org/sonar/core/persistence/schema-derby.ddl
index 6ddd00a816b..81491225d86 100644
--- a/sonar-core/src/main/resources/org/sonar/core/persistence/schema-derby.ddl
+++ b/sonar-core/src/main/resources/org/sonar/core/persistence/schema-derby.ddl
@@ -486,24 +486,6 @@ CREATE TABLE "ACTION_PLANS_REVIEWS" (
"REVIEW_ID" INTEGER
);
-CREATE TABLE "ACTIVE_RULE_NOTES" (
- "ID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1),
- "ACTIVE_RULE_ID" INTEGER,
- "USER_LOGIN" VARCHAR(40),
- "DATA" BLOB(2147483647),
- "CREATED_AT" TIMESTAMP,
- "UPDATED_AT" TIMESTAMP
-);
-
-CREATE TABLE "RULE_NOTES" (
- "ID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1),
- "RULE_ID" INTEGER,
- "USER_LOGIN" VARCHAR(40),
- "DATA" BLOB(2147483647),
- "CREATED_AT" TIMESTAMP,
- "UPDATED_AT" TIMESTAMP
-);
-
-- ----------------------------------------------
-- DDL Statements for indexes
@@ -597,10 +579,6 @@ CREATE INDEX "INDEX_ACTION_PLANS_REVIEWS_ON_ACTION_PLAN_ID" ON "ACTION_PLANS_REV
CREATE INDEX "INDEX_ACTION_PLANS_REVIEWS_ON_REVIEW_ID" ON "ACTION_PLANS_REVIEWS" ("REVIEW_ID");
-CREATE INDEX "INDEX_ACTIVE_RULE_NOTES_ON_ACTIVE_RULE_ID" ON "ACTIVE_RULE_NOTES" ("ACTIVE_RULE_ID");
-
-CREATE INDEX "INDEX_RULE_NOTES_ON_ACTIVE_RULE_ID" ON "RULE_NOTES" ("RULE_ID");
-
-- ----------------------------------------------
-- DDL Statements for keys
@@ -688,7 +666,3 @@ ALTER TABLE "ACTIVE_RULE_PARAMETERS" ADD CONSTRAINT "SQL110927104437560" PRIMARY
ALTER TABLE "LOADED_TEMPLATES" ADD CONSTRAINT "SQL110927104437650" PRIMARY KEY ("ID");
ALTER TABLE "ACTION_PLANS" ADD CONSTRAINT "SQL110927104447650" PRIMARY KEY ("ID");
-
-ALTER TABLE "ACTIVE_RULE_NOTES" ADD CONSTRAINT "SQL110927104847650" PRIMARY KEY ("ID");
-
-ALTER TABLE "RULE_NOTES" ADD CONSTRAINT "SQL110927184847650" PRIMARY KEY ("ID");
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
new file mode 100644
index 00000000000..aa92585f3d6
--- /dev/null
+++ b/sonar-core/src/main/resources/org/sonar/core/purge/PurgeMapper.xml
@@ -0,0 +1,107 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+
+<mapper namespace="org.sonar.core.purge.PurgeMapper">
+
+ <select id="selectSnapshotIds" parameterType="map" resultType="long">
+ select id from snapshots
+ <where>
+ islast=${_false}
+ <if test="rootProjectId != null">
+ and root_project_id=#{rootProjectId}
+ </if>
+ <if test="beforeBuildDate != null">
+ and build_date &lt;= #{beforeBuildDate}
+ </if>
+ <if test="status != null">
+ and status in
+ <foreach item="s" index="index" collection="status" open="(" separator="," close=")">#{s}</foreach>
+ </if>
+ <if test="scopes != null">
+ and scope in
+ <foreach item="scope" index="index" collection="scopes" open="(" separator="," close=")">#{scope}</foreach>
+ </if>
+ <if test="qualifiers != null">
+ and qualifier in
+ <foreach item="qualifier" index="index" collection="qualifiers" open="(" separator="," close=")">#{qualifier}
+ </foreach>
+ </if>
+ </where>
+ </select>
+
+ <select id="selectResourceIdsToDisable" resultType="long">
+ select s1.project_id from snapshots s1
+ where s1.islast=${_true} and s1.root_snapshot_id is not null and not exists(select s2.id from snapshots s2 where
+ s2.id=s1.root_snapshot_id and s2.islast=${_true})
+ </select>
+
+ <select id="selectSnapshotIdsToPurge" parameterType="map" resultType="long">
+ select id from snapshots
+ <where>
+ islast=${_false} and (purge_status is null or purge_status=0)
+ <if test="rootProjectId != null">
+ and root_project_id=#{rootProjectId}
+ </if>
+ <if test="beforeBuildDate!= null">
+ and build_date &lt;= #{beforeBuildDate}
+ </if>
+ </where>
+ </select>
+
+ <delete id="deleteSnapshotMeasures" parameterType="long">
+ delete from project_measures where snapshot_id=#{id}
+ </delete>
+
+ <delete id="deleteSnapshotMeasureData" parameterType="long">
+ delete from measure_data where snapshot_id=#{id}
+ </delete>
+
+ <delete id="deleteSnapshotSource" parameterType="long">
+ delete from snapshot_sources where snapshot_id=#{id}
+ </delete>
+
+ <delete id="deleteSnapshotViolations" parameterType="long">
+ delete from rule_failures where snapshot_id=#{id}
+ </delete>
+
+ <delete id="deleteSnapshotDependencies" parameterType="long">
+ delete from dependencies where from_snapshot_id=#{id} or to_snapshot_id=#{id} or project_snapshot_id=#{id}
+ </delete>
+
+ <delete id="deleteSnapshotDuplications" parameterType="long">
+ delete from duplications_index where snapshot_id=#{id}
+ </delete>
+
+ <delete id="deleteSnapshotEvents" parameterType="long">
+ delete from events where snapshot_id=#{id}
+ </delete>
+
+ <delete id="deleteSnapshot" parameterType="long">
+ delete from snapshots where id=#{id}
+ </delete>
+
+ <delete id="deleteSnapshotRuleMeasures" parameterType="long">
+ delete from project_measures where snapshot_id=#{id} and rule_id is not null
+ </delete>
+
+ <delete id="deleteSnapshotCharacteristicMeasures" parameterType="long">
+ delete from project_measures where snapshot_id=#{id} and characteristic_id is not null
+ </delete>
+
+ <update id="updatePurgeStatusToOne" parameterType="long">
+ update snapshots set purge_status = 1 where id = #{id}
+ </update>
+
+ <update id="disableResource" parameterType="long">
+ update projects set enabled=${_false} where id=#{id}
+ </update>
+
+ <delete id="deleteResourceIndex" parameterType="long">
+ delete from resource_index where resource_id=#{id}
+ </delete>
+
+ <update id="unsetSnapshotIslast" parameterType="long">
+ update snapshots set islast=${_false} where project_id=#{id}
+ </update>
+</mapper>
+
diff --git a/sonar-core/src/main/resources/org/sonar/core/resource/ResourceMapper.xml b/sonar-core/src/main/resources/org/sonar/core/resource/ResourceMapper.xml
new file mode 100644
index 00000000000..9ef0bcd36de
--- /dev/null
+++ b/sonar-core/src/main/resources/org/sonar/core/resource/ResourceMapper.xml
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+
+<mapper namespace="org.sonar.core.resource.ResourceMapper">
+
+
+ <resultMap id="snapshotResultMap" type="Snapshot">
+ <id property="id" column="id"/>
+ <result property="parentId" column="parent_snapshot_id"/>
+ <result property="rootId" column="root_snapshot_id"/>
+ <result property="date" column="created_at"/>
+ <result property="buildDate" column="build_date"/>
+ <result property="resourceId" column="project_id"/>
+ <result property="status" column="status"/>
+ <result property="purgeStatus" column="purge_status"/>
+ <result property="last" column="islast"/>
+ <result property="scope" column="scope"/>
+ <result property="qualifier" column="qualifier"/>
+ <result property="version" column="version"/>
+ <result property="path" column="path"/>
+ <result property="depth" column="depth"/>
+ <result property="rootProjectId" column="root_project_id"/>
+ </resultMap>
+
+
+ <select id="selectSnapshotById" parameterType="int" resultMap="snapshotResultMap">
+ select * from snapshots where id=#{id}
+ </select>
+
+</mapper>
+