aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--plugins/sonar-cpd-plugin/pom.xml5
-rw-r--r--plugins/sonar-dbcleaner-plugin/pom.xml5
-rw-r--r--plugins/sonar-email-notifications-plugin/pom.xml5
-rw-r--r--server/sonar-web/src/main/webapp/WEB-INF/db/migrate/600_mysql_mediumtext_to_longtext.rb44
-rw-r--r--server/sonar-web/src/main/webapp/WEB-INF/gems/gems/activerecord-jdbc-adapter-1.1.3/lib/arjdbc/mysql/adapter.rb2
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/index/SourcePersister.java26
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/scan/LastSnapshots.java38
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/ComponentIndexer.java1
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/index/SourcePersisterTest.java10
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/scan/LastSnapshotsTest.java40
-rw-r--r--sonar-core/src/main/java/org/sonar/core/persistence/DatabaseVersion.java2
-rw-r--r--sonar-core/src/main/java/org/sonar/core/persistence/dialect/MySql.java4
-rw-r--r--sonar-core/src/main/java/org/sonar/core/source/db/SnapshotSourceDao.java13
-rw-r--r--sonar-core/src/main/java/org/sonar/core/source/db/SnapshotSourceDto.java50
-rw-r--r--sonar-core/src/main/java/org/sonar/core/source/db/SnapshotSourceMapper.java6
-rw-r--r--sonar-core/src/main/resources/META-INF/persistence.xml1
-rw-r--r--sonar-core/src/main/resources/org/sonar/core/persistence/rows-h2.sql1
-rw-r--r--sonar-core/src/main/resources/org/sonar/core/source/db/SnapshotSourceMapper.xml4
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/database/model/SnapshotSource.java93
19 files changed, 191 insertions, 159 deletions
diff --git a/plugins/sonar-cpd-plugin/pom.xml b/plugins/sonar-cpd-plugin/pom.xml
index 468405d744f..76492a7406f 100644
--- a/plugins/sonar-cpd-plugin/pom.xml
+++ b/plugins/sonar-cpd-plugin/pom.xml
@@ -36,6 +36,11 @@
<artifactId>sonar-plugin-api</artifactId>
<scope>provided</scope>
</dependency>
+ <dependency>
+ <groupId>commons-io</groupId>
+ <artifactId>commons-io</artifactId>
+ <scope>provided</scope>
+ </dependency>
<!-- unit tests -->
<dependency>
diff --git a/plugins/sonar-dbcleaner-plugin/pom.xml b/plugins/sonar-dbcleaner-plugin/pom.xml
index d4d5b3d5544..ecbdd2379da 100644
--- a/plugins/sonar-dbcleaner-plugin/pom.xml
+++ b/plugins/sonar-dbcleaner-plugin/pom.xml
@@ -35,6 +35,11 @@
<artifactId>sonar-deprecated</artifactId>
<scope>provided</scope>
</dependency>
+ <dependency>
+ <groupId>commons-lang</groupId>
+ <artifactId>commons-lang</artifactId>
+ <scope>provided</scope>
+ </dependency>
<!-- unit tests -->
<dependency>
diff --git a/plugins/sonar-email-notifications-plugin/pom.xml b/plugins/sonar-email-notifications-plugin/pom.xml
index 8274967827c..f3528229b1f 100644
--- a/plugins/sonar-email-notifications-plugin/pom.xml
+++ b/plugins/sonar-email-notifications-plugin/pom.xml
@@ -27,6 +27,11 @@
<artifactId>commons-email</artifactId>
<version>1.3.2</version>
</dependency>
+ <dependency>
+ <groupId>commons-lang</groupId>
+ <artifactId>commons-lang</artifactId>
+ <scope>provided</scope>
+ </dependency>
<!-- unit tests -->
<dependency>
diff --git a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/600_mysql_mediumtext_to_longtext.rb b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/600_mysql_mediumtext_to_longtext.rb
new file mode 100644
index 00000000000..2f15f3b09dc
--- /dev/null
+++ b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/600_mysql_mediumtext_to_longtext.rb
@@ -0,0 +1,44 @@
+#
+# 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 4.5.1
+#
+class MysqlMediumtextToLongtext < ActiveRecord::Migration
+
+ def self.up
+ if dialect()=='mysql'
+ apply 'rules', 'description'
+ apply 'rules', 'note_data'
+ apply 'snapshot_sources', 'data'
+ apply 'properties', 'text_value'
+ apply 'measure_filters', 'data'
+ apply 'graphs', 'data'
+ apply 'snapshot_data', 'snapshot_data'
+ apply 'issue_changes', 'change_data'
+ apply 'issue_filters', 'data'
+ apply 'activities', 'data_field'
+ end
+ end
+
+ def self.apply(table, column)
+ ActiveRecord::Base.connection.execute("alter table #{table} modify #{column} longtext")
+ end
+end
diff --git a/server/sonar-web/src/main/webapp/WEB-INF/gems/gems/activerecord-jdbc-adapter-1.1.3/lib/arjdbc/mysql/adapter.rb b/server/sonar-web/src/main/webapp/WEB-INF/gems/gems/activerecord-jdbc-adapter-1.1.3/lib/arjdbc/mysql/adapter.rb
index 9b3d41f0ddb..163c27c06e7 100644
--- a/server/sonar-web/src/main/webapp/WEB-INF/gems/gems/activerecord-jdbc-adapter-1.1.3/lib/arjdbc/mysql/adapter.rb
+++ b/server/sonar-web/src/main/webapp/WEB-INF/gems/gems/activerecord-jdbc-adapter-1.1.3/lib/arjdbc/mysql/adapter.rb
@@ -103,7 +103,7 @@ module ::ArJdbc
# But we would like the bigger MEDIUMTEXT for the snapshot_sources table (16777215 characters).
# This hack works only for ActiveRecord-JDBC (Jruby use).
# See http://www.headius.com/jrubywiki/index.php/Adding_Datatypes_to_ActiveRecord-JDBC
- tp[:text] = { :name => "mediumtext" }
+ tp[:text] = { :name => "longtext" }
tp[:binary] = { :name => "longblob" }
tp[:big_integer] = { :name => "bigint"}
# /SonarQube
diff --git a/sonar-batch/src/main/java/org/sonar/batch/index/SourcePersister.java b/sonar-batch/src/main/java/org/sonar/batch/index/SourcePersister.java
index 6aced328ad6..161a5396144 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/index/SourcePersister.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/index/SourcePersister.java
@@ -20,23 +20,25 @@
package org.sonar.batch.index;
import com.google.common.collect.Sets;
-import org.sonar.api.database.DatabaseSession;
import org.sonar.api.database.model.Snapshot;
-import org.sonar.api.database.model.SnapshotSource;
import org.sonar.api.resources.DuplicatedSourceException;
import org.sonar.api.resources.Resource;
+import org.sonar.core.source.db.SnapshotSourceDao;
+import org.sonar.core.source.db.SnapshotSourceDto;
+
+import javax.annotation.CheckForNull;
import java.util.Set;
public final class SourcePersister {
- private DatabaseSession session;
private Set<Integer> savedSnapshotIds = Sets.newHashSet();
private ResourcePersister resourcePersister;
+ private final SnapshotSourceDao sourceDao;
- public SourcePersister(DatabaseSession session, ResourcePersister resourcePersister) {
- this.session = session;
+ public SourcePersister(ResourcePersister resourcePersister, SnapshotSourceDao sourceDao) {
this.resourcePersister = resourcePersister;
+ this.sourceDao = sourceDao;
}
public void saveSource(Resource resource, String source) {
@@ -44,18 +46,20 @@ public final class SourcePersister {
if (isCached(snapshot)) {
throw new DuplicatedSourceException(resource);
}
- session.save(new SnapshotSource(snapshot.getId(), source));
- session.commit();
+ SnapshotSourceDto dto = new SnapshotSourceDto();
+ dto.setSnapshotId(snapshot.getId().longValue());
+ dto.setData(source);
+ sourceDao.insert(dto);
addToCache(snapshot);
}
+ @CheckForNull
public String getSource(Resource resource) {
- SnapshotSource source = null;
Snapshot snapshot = resourcePersister.getSnapshot(resource);
- if (snapshot!=null && snapshot.getId()!=null) {
- source = session.getSingleResult(SnapshotSource.class, "snapshotId", snapshot.getId());
+ if (snapshot != null && snapshot.getId() != null) {
+ return sourceDao.selectSnapshotSource(snapshot.getId());
}
- return source!=null ? source.getData() : null;
+ return null;
}
private boolean isCached(Snapshot snapshot) {
diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/LastSnapshots.java b/sonar-batch/src/main/java/org/sonar/batch/scan/LastSnapshots.java
index b36d4dc6852..be876cbc0c9 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/scan/LastSnapshots.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/scan/LastSnapshots.java
@@ -19,33 +19,32 @@
*/
package org.sonar.batch.scan;
+import org.apache.commons.lang.StringUtils;
import org.sonar.api.BatchComponent;
-import org.sonar.api.database.DatabaseSession;
-import org.sonar.api.database.model.ResourceModel;
-import org.sonar.api.database.model.Snapshot;
-import org.sonar.api.database.model.SnapshotSource;
import org.sonar.api.resources.Resource;
import org.sonar.api.resources.ResourceUtils;
import org.sonar.api.utils.HttpDownloader;
import org.sonar.batch.bootstrap.AnalysisMode;
import org.sonar.batch.bootstrap.ServerClient;
+import org.sonar.core.source.db.SnapshotSourceDao;
-import javax.persistence.Query;
+import javax.annotation.CheckForNull;
public class LastSnapshots implements BatchComponent {
private final AnalysisMode analysisMode;
- private final DatabaseSession session;
private final ServerClient server;
+ private final SnapshotSourceDao sourceDao;
- public LastSnapshots(AnalysisMode analysisMode, DatabaseSession session, ServerClient server) {
+ public LastSnapshots(AnalysisMode analysisMode, SnapshotSourceDao dao, ServerClient server) {
this.analysisMode = analysisMode;
- this.session = session;
+ this.sourceDao = dao;
this.server = server;
}
+ @CheckForNull
public String getSource(Resource resource) {
- String source = "";
+ String source = null;
if (ResourceUtils.isFile(resource)) {
if (analysisMode.isPreview()) {
source = loadSourceFromWs(resource);
@@ -53,9 +52,10 @@ public class LastSnapshots implements BatchComponent {
source = loadSourceFromDb(resource);
}
}
- return source;
+ return StringUtils.defaultString(source, "");
}
+ @CheckForNull
private String loadSourceFromWs(Resource resource) {
try {
return server.request("/api/sources?resource=" + resource.getEffectiveKey() + "&format=txt", false, analysisMode.getPreviewReadTimeoutSec() * 1000);
@@ -67,22 +67,8 @@ public class LastSnapshots implements BatchComponent {
}
}
+ @CheckForNull
private String loadSourceFromDb(Resource resource) {
- Snapshot snapshot = getSnapshot(resource);
- if (snapshot != null) {
- SnapshotSource source = session.getSingleResult(SnapshotSource.class, "snapshotId", snapshot.getId());
- if (source != null) {
- return source.getData();
- }
- }
- return "";
- }
-
- private Snapshot getSnapshot(Resource resource) {
- Query query = session.createQuery("from " + Snapshot.class.getSimpleName() + " s where s.last=:last and s.resourceId=(select r.id from "
- + ResourceModel.class.getSimpleName() + " r where r.key=:key)");
- query.setParameter("key", resource.getEffectiveKey());
- query.setParameter("last", Boolean.TRUE);
- return session.getSingleResult(query, null);
+ return sourceDao.selectSnapshotSourceByComponentKey(resource.getEffectiveKey());
}
}
diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/ComponentIndexer.java b/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/ComponentIndexer.java
index f7f289ddf64..1e185487a05 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/ComponentIndexer.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/ComponentIndexer.java
@@ -76,6 +76,7 @@ public class ComponentIndexer implements BatchComponent {
sonarFile.setDeprecatedKey(pathFromSourceDir);
}
sonarIndex.index(sonarFile);
+
importSources(fs, shouldImportSource, inputFile, sonarFile);
}
}
diff --git a/sonar-batch/src/test/java/org/sonar/batch/index/SourcePersisterTest.java b/sonar-batch/src/test/java/org/sonar/batch/index/SourcePersisterTest.java
index 39f4095ccd2..451fa91f691 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/index/SourcePersisterTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/index/SourcePersisterTest.java
@@ -25,23 +25,25 @@ import org.sonar.api.database.model.Snapshot;
import org.sonar.api.resources.DuplicatedSourceException;
import org.sonar.api.resources.File;
import org.sonar.api.resources.Resource;
-import org.sonar.jpa.test.AbstractDbUnitTestCase;
+import org.sonar.core.persistence.AbstractDaoTestCase;
+import org.sonar.core.source.db.SnapshotSourceDao;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
-public class SourcePersisterTest extends AbstractDbUnitTestCase {
+public class SourcePersisterTest extends AbstractDaoTestCase {
private SourcePersister sourcePersister;
@Before
public void before() {
setupData("shared");
- Snapshot snapshot = getSession().getSingleResult(Snapshot.class, "id", 1000);
ResourcePersister resourcePersister = mock(ResourcePersister.class);
+ Snapshot snapshot = new Snapshot();
+ snapshot.setId(1000);
when(resourcePersister.getSnapshotOrFail(any(Resource.class))).thenReturn(snapshot);
- sourcePersister = new SourcePersister(getSession(), resourcePersister);
+ sourcePersister = new SourcePersister(resourcePersister, new SnapshotSourceDao(getMyBatis()));
}
@Test
diff --git a/sonar-batch/src/test/java/org/sonar/batch/scan/LastSnapshotsTest.java b/sonar-batch/src/test/java/org/sonar/batch/scan/LastSnapshotsTest.java
index d6cddb4447d..505b644d98e 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/scan/LastSnapshotsTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/scan/LastSnapshotsTest.java
@@ -28,7 +28,8 @@ import org.sonar.api.resources.Project;
import org.sonar.api.utils.HttpDownloader;
import org.sonar.batch.bootstrap.AnalysisMode;
import org.sonar.batch.bootstrap.ServerClient;
-import org.sonar.jpa.test.AbstractDbUnitTestCase;
+import org.sonar.core.persistence.TestDatabase;
+import org.sonar.core.source.db.SnapshotSourceDao;
import java.net.URI;
import java.net.URISyntaxException;
@@ -36,15 +37,16 @@ import java.net.URISyntaxException;
import static org.fest.assertions.Assertions.assertThat;
import static org.mockito.Matchers.anyString;
import static org.mockito.Matchers.eq;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.verifyZeroInteractions;
-import static org.mockito.Mockito.when;
+import static org.mockito.Mockito.*;
-public class LastSnapshotsTest extends AbstractDbUnitTestCase {
+public class LastSnapshotsTest {
@Rule
public ExpectedException thrown = ExpectedException.none();
+
+ @Rule
+ public TestDatabase db = new TestDatabase();
+
private AnalysisMode mode;
@Before
@@ -55,10 +57,10 @@ public class LastSnapshotsTest extends AbstractDbUnitTestCase {
@Test
public void should_get_source_of_last_snapshot() {
- setupData("last_snapshot");
- ServerClient server = mock(ServerClient.class);
+ db.prepareDbUnit(getClass(), "last_snapshot.xml");
- LastSnapshots lastSnapshots = new LastSnapshots(mode, getSession(), server);
+ ServerClient server = mock(ServerClient.class);
+ LastSnapshots lastSnapshots = new LastSnapshots(mode, new SnapshotSourceDao(db.myBatis()), server);
assertThat(lastSnapshots.getSource(newFile())).isEqualTo("this is bar");
verifyZeroInteractions(server);
@@ -66,10 +68,10 @@ public class LastSnapshotsTest extends AbstractDbUnitTestCase {
@Test
public void should_return_empty_source_if_no_last_snapshot() {
- setupData("no_last_snapshot");
+ db.prepareDbUnit(getClass(), "no_last_snapshot.xml");
ServerClient server = mock(ServerClient.class);
- LastSnapshots lastSnapshots = new LastSnapshots(mode, getSession(), server);
+ LastSnapshots lastSnapshots = new LastSnapshots(mode, new SnapshotSourceDao(db.myBatis()), server);
assertThat(lastSnapshots.getSource(newFile())).isEqualTo("");
verifyZeroInteractions(server);
@@ -77,12 +79,12 @@ public class LastSnapshotsTest extends AbstractDbUnitTestCase {
@Test
public void should_download_source_from_ws_if_preview_mode() {
- setupData("last_snapshot");
+ db.prepareDbUnit(getClass(), "last_snapshot.xml");
ServerClient server = mock(ServerClient.class);
when(server.request(anyString(), eq(false), eq(30 * 1000))).thenReturn("downloaded source of Bar.c");
when(mode.isPreview()).thenReturn(true);
- LastSnapshots lastSnapshots = new LastSnapshots(mode, getSession(), server);
+ LastSnapshots lastSnapshots = new LastSnapshots(mode, new SnapshotSourceDao(db.myBatis()), server);
String source = lastSnapshots.getSource(newFile());
assertThat(source).isEqualTo("downloaded source of Bar.c");
@@ -91,12 +93,12 @@ public class LastSnapshotsTest extends AbstractDbUnitTestCase {
@Test
public void should_fail_to_download_source_from_ws() throws URISyntaxException {
- setupData("last_snapshot");
+ db.prepareDbUnit(getClass(), "last_snapshot.xml");
ServerClient server = mock(ServerClient.class);
when(server.request(anyString(), eq(false), eq(30 * 1000))).thenThrow(new HttpDownloader.HttpException(new URI(""), 500));
when(mode.isPreview()).thenReturn(true);
- LastSnapshots lastSnapshots = new LastSnapshots(mode, getSession(), server);
+ LastSnapshots lastSnapshots = new LastSnapshots(mode, new SnapshotSourceDao(db.myBatis()), server);
thrown.expect(HttpDownloader.HttpException.class);
lastSnapshots.getSource(newFile());
@@ -104,12 +106,12 @@ public class LastSnapshotsTest extends AbstractDbUnitTestCase {
@Test
public void should_return_empty_source_if_preview_mode_and_no_last_snapshot() throws URISyntaxException {
- setupData("last_snapshot");
+ db.prepareDbUnit(getClass(), "last_snapshot.xml");
ServerClient server = mock(ServerClient.class);
when(server.request(anyString(), eq(false), eq(30 * 1000))).thenThrow(new HttpDownloader.HttpException(new URI(""), 404));
when(mode.isPreview()).thenReturn(true);
- LastSnapshots lastSnapshots = new LastSnapshots(mode, getSession(), server);
+ LastSnapshots lastSnapshots = new LastSnapshots(mode, new SnapshotSourceDao(db.myBatis()), server);
String source = lastSnapshots.getSource(newFile());
assertThat(source).isEqualTo("");
@@ -118,10 +120,10 @@ public class LastSnapshotsTest extends AbstractDbUnitTestCase {
@Test
public void should_not_load_source_of_non_files() throws URISyntaxException {
- setupData("last_snapshot");
+ db.prepareDbUnit(getClass(), "last_snapshot.xml");
ServerClient server = mock(ServerClient.class);
- LastSnapshots lastSnapshots = new LastSnapshots(mode, getSession(), server);
+ LastSnapshots lastSnapshots = new LastSnapshots(mode, new SnapshotSourceDao(db.myBatis()), server);
String source = lastSnapshots.getSource(new Project("my-project"));
assertThat(source).isEqualTo("");
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 105c8c5b58f..dcb5e436527 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
@@ -33,7 +33,7 @@ import java.util.List;
*/
public class DatabaseVersion implements BatchComponent, ServerComponent {
- public static final int LAST_VERSION = 584;
+ public static final int LAST_VERSION = 600;
public static enum Status {
UP_TO_DATE, REQUIRES_UPGRADE, REQUIRES_DOWNGRADE, FRESH_INSTALL
diff --git a/sonar-core/src/main/java/org/sonar/core/persistence/dialect/MySql.java b/sonar-core/src/main/java/org/sonar/core/persistence/dialect/MySql.java
index 8dd6bdebe48..435682d17a3 100644
--- a/sonar-core/src/main/java/org/sonar/core/persistence/dialect/MySql.java
+++ b/sonar-core/src/main/java/org/sonar/core/persistence/dialect/MySql.java
@@ -48,8 +48,8 @@ public class MySql extends AbstractDialect {
public MySqlWithDecimalDialect() {
super();
registerColumnType(Types.DOUBLE, "decimal precision");
- registerColumnType(Types.VARCHAR, DatabaseProperties.MAX_TEXT_SIZE, "mediumtext");
- registerColumnType(Types.CLOB, "mediumtext");
+ registerColumnType(Types.VARCHAR, DatabaseProperties.MAX_TEXT_SIZE, "longtext");
+ registerColumnType(Types.CLOB, "longtext");
registerColumnType(Types.BLOB, "blob");
}
}
diff --git a/sonar-core/src/main/java/org/sonar/core/source/db/SnapshotSourceDao.java b/sonar-core/src/main/java/org/sonar/core/source/db/SnapshotSourceDao.java
index e535f7a3340..3b28c5c5806 100644
--- a/sonar-core/src/main/java/org/sonar/core/source/db/SnapshotSourceDao.java
+++ b/sonar-core/src/main/java/org/sonar/core/source/db/SnapshotSourceDao.java
@@ -21,6 +21,7 @@
package org.sonar.core.source.db;
import org.apache.ibatis.session.SqlSession;
+import org.sonar.api.BatchComponent;
import org.sonar.api.ServerComponent;
import org.sonar.core.persistence.MyBatis;
@@ -29,7 +30,7 @@ import javax.annotation.CheckForNull;
/**
* @since 3.6
*/
-public class SnapshotSourceDao implements ServerComponent {
+public class SnapshotSourceDao implements BatchComponent, ServerComponent {
private final MyBatis mybatis;
@@ -66,4 +67,14 @@ public class SnapshotSourceDao implements ServerComponent {
}
}
+ public void insert(SnapshotSourceDto dto) {
+ SqlSession session = mybatis.openSession(false);
+ try {
+ session.getMapper(SnapshotSourceMapper.class).insert(dto);
+ session.commit();
+ } finally {
+ MyBatis.closeQuietly(session);
+ }
+ }
+
}
diff --git a/sonar-core/src/main/java/org/sonar/core/source/db/SnapshotSourceDto.java b/sonar-core/src/main/java/org/sonar/core/source/db/SnapshotSourceDto.java
new file mode 100644
index 00000000000..34df236684d
--- /dev/null
+++ b/sonar-core/src/main/java/org/sonar/core/source/db/SnapshotSourceDto.java
@@ -0,0 +1,50 @@
+/*
+ * 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.source.db;
+
+public class SnapshotSourceDto {
+ private Long id;
+ private Long snapshotId;
+ private String data;
+
+ public Long getId() {
+ return id;
+ }
+
+ public void setId(Long id) {
+ this.id = id;
+ }
+
+ public Long getSnapshotId() {
+ return snapshotId;
+ }
+
+ public void setSnapshotId(Long snapshotId) {
+ this.snapshotId = snapshotId;
+ }
+
+ public String getData() {
+ return data;
+ }
+
+ public void setData(String data) {
+ this.data = data;
+ }
+}
diff --git a/sonar-core/src/main/java/org/sonar/core/source/db/SnapshotSourceMapper.java b/sonar-core/src/main/java/org/sonar/core/source/db/SnapshotSourceMapper.java
index 95f5a96d2c4..565c1d09e45 100644
--- a/sonar-core/src/main/java/org/sonar/core/source/db/SnapshotSourceMapper.java
+++ b/sonar-core/src/main/java/org/sonar/core/source/db/SnapshotSourceMapper.java
@@ -20,12 +20,18 @@
package org.sonar.core.source.db;
+import javax.annotation.CheckForNull;
+
/**
* @since 3.6
*/
public interface SnapshotSourceMapper {
+ @CheckForNull
String selectSnapshotSource(long snapshotId);
+ @CheckForNull
String selectSnapshotSourceByComponentKey(String componentKey);
+
+ void insert(SnapshotSourceDto dto);
}
diff --git a/sonar-core/src/main/resources/META-INF/persistence.xml b/sonar-core/src/main/resources/META-INF/persistence.xml
index 3742d878b1f..099bd1c8c9e 100644
--- a/sonar-core/src/main/resources/META-INF/persistence.xml
+++ b/sonar-core/src/main/resources/META-INF/persistence.xml
@@ -15,7 +15,6 @@
<class>org.sonar.api.design.DependencyDto</class>
<class>org.sonar.api.measures.Metric</class>
<class>org.sonar.api.database.model.ResourceModel</class>
- <class>org.sonar.api.database.model.SnapshotSource</class>
<class>org.sonar.api.rules.Rule</class>
<class>org.sonar.api.rules.RuleParam</class>
<class>org.sonar.api.resources.ProjectLink</class>
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 d9ea9b3d667..687099904a9 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
@@ -254,6 +254,7 @@ INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('581');
INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('582');
INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('583');
INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('584');
+INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('600');
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/source/db/SnapshotSourceMapper.xml b/sonar-core/src/main/resources/org/sonar/core/source/db/SnapshotSourceMapper.xml
index de072269330..85d08e05d9f 100644
--- a/sonar-core/src/main/resources/org/sonar/core/source/db/SnapshotSourceMapper.xml
+++ b/sonar-core/src/main/resources/org/sonar/core/source/db/SnapshotSourceMapper.xml
@@ -18,5 +18,9 @@
WHERE p.kee = #{componentKey}
</select>
+ <insert id="insert" parameterType="org.sonar.core.source.db.SnapshotSourceDto" useGeneratedKeys="false">
+ insert into snapshot_sources (snapshot_id, data) values (#{snapshotId}, #{data})
+ </insert>
+
</mapper>
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/database/model/SnapshotSource.java b/sonar-plugin-api/src/main/java/org/sonar/api/database/model/SnapshotSource.java
deleted file mode 100644
index 3f403115ded..00000000000
--- a/sonar-plugin-api/src/main/java/org/sonar/api/database/model/SnapshotSource.java
+++ /dev/null
@@ -1,93 +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.api.database.model;
-
-import org.apache.commons.lang.StringUtils;
-import org.apache.commons.lang.builder.ToStringBuilder;
-import org.apache.commons.lang.builder.ToStringStyle;
-import org.sonar.api.database.BaseIdentifiable;
-import org.sonar.api.database.DatabaseProperties;
-
-import javax.persistence.Column;
-import javax.persistence.Entity;
-import javax.persistence.Lob;
-import javax.persistence.Table;
-
-@Entity
-@Table(name = "snapshot_sources")
-public class SnapshotSource extends BaseIdentifiable {
-
- @Column(name = "snapshot_id")
- private Integer snapshotId;
-
- @Lob
- @Column(name = "data", updatable = true, nullable = true, length = DatabaseProperties.MAX_TEXT_SIZE)
- private String data;
-
- public SnapshotSource() {
- }
-
- public SnapshotSource(Snapshot snapshot, String source) {
- this.snapshotId = snapshot.getId();
- this.data = source;
- }
-
- public SnapshotSource(Integer snapshotId, String source) {
- this.snapshotId = snapshotId;
- this.data = source;
- }
-
- public void setSnapshot(Snapshot snapshot) {
- this.snapshotId = snapshot.getId();
- }
-
- public String getData() {
- return data;
- }
-
- public void setData(String data) {
- this.data = data;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (!(obj instanceof SnapshotSource)) {
- return false;
- }
- if (this == obj) {
- return true;
- }
- SnapshotSource other = (SnapshotSource) obj;
- return snapshotId.equals(other.snapshotId);
- }
-
- @Override
- public int hashCode() {
- return snapshotId.hashCode();
- }
-
- @Override
- public String toString() {
- return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE)
- .append("snapshot_id", snapshotId)
- .append("data", StringUtils.abbreviate(data, 1000))
- .toString();
- }
-}