aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-core
diff options
context:
space:
mode:
authorSimon Brandhof <simon.brandhof@gmail.com>2012-04-02 16:21:25 +0200
committerSimon Brandhof <simon.brandhof@gmail.com>2012-04-02 17:28:02 +0200
commit3d8fd94d37c2b397e413cd7594d765e0f944f7a9 (patch)
tree268bd71306b612196d9b16d1aaabeb1fa9865f3b /sonar-core
parentf9b3afd741501b2dd5a38f9d721fc68ec628e71e (diff)
downloadsonarqube-3d8fd94d37c2b397e413cd7594d765e0f944f7a9.tar.gz
sonarqube-3d8fd94d37c2b397e413cd7594d765e0f944f7a9.zip
Improve the way to add the new primary key RESOURCE_INDEX#ID.
- do not index files during upgrade, but only projects - new webservice POST /api/server/index_projects to index all the existing projects
Diffstat (limited to 'sonar-core')
-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/resource/ResourceIndexerDao.java93
-rw-r--r--sonar-core/src/main/java/org/sonar/core/resource/ResourceIndexerMapper.java2
-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/resource/ResourceIndexerMapper-oracle.xml6
-rw-r--r--sonar-core/src/main/resources/org/sonar/core/resource/ResourceIndexerMapper.xml6
6 files changed, 73 insertions, 37 deletions
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 193091e0f33..9b9131586a9 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
@@ -32,7 +32,7 @@ import java.util.List;
*/
public class DatabaseVersion implements BatchComponent, ServerComponent {
- public static final int LAST_VERSION = 285;
+ public static final int LAST_VERSION = 286;
public static enum Status {
UP_TO_DATE, REQUIRES_UPGRADE, REQUIRES_DOWNGRADE, FRESH_INSTALL
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 d7e26e8a00e..80553c49eed 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
@@ -85,10 +85,10 @@ public class ResourceIndexerDao {
private void doIndexProject(int rootProjectId, SqlSession session, final ResourceIndexerMapper mapper) {
// non indexed resources
ResourceIndexerQuery query = ResourceIndexerQuery.create()
- .setNonIndexedOnly(true)
- .setQualifiers(NOT_RENAMABLE_QUALIFIERS)
- .setScopes(NOT_RENAMABLE_SCOPES)
- .setRootProjectId(rootProjectId);
+ .setNonIndexedOnly(true)
+ .setQualifiers(NOT_RENAMABLE_QUALIFIERS)
+ .setScopes(NOT_RENAMABLE_SCOPES)
+ .setRootProjectId(rootProjectId);
session.select("org.sonar.core.resource.ResourceIndexerMapper.selectResources", query, new ResultHandler() {
public void handleResult(ResultContext context) {
@@ -100,10 +100,10 @@ public class ResourceIndexerDao {
// some resources can be renamed, so index must be regenerated
// -> delete existing rows and create them again
query = ResourceIndexerQuery.create()
- .setNonIndexedOnly(false)
- .setQualifiers(RENAMABLE_QUALIFIERS)
- .setScopes(RENAMABLE_SCOPES)
- .setRootProjectId(rootProjectId);
+ .setNonIndexedOnly(false)
+ .setQualifiers(RENAMABLE_QUALIFIERS)
+ .setScopes(RENAMABLE_SCOPES)
+ .setRootProjectId(rootProjectId);
session.select("org.sonar.core.resource.ResourceIndexerMapper.selectResources", query, new ResultHandler() {
public void handleResult(ResultContext context) {
@@ -120,10 +120,10 @@ public class ResourceIndexerDao {
String key = nameToKey(resource.getName());
if (key.length() >= MINIMUM_KEY_SIZE) {
ResourceIndexDto dto = new ResourceIndexDto()
- .setResourceId(resource.getId())
- .setQualifier(resource.getQualifier())
- .setRootProjectId(resource.getRootId())
- .setNameSize(resource.getName().length());
+ .setResourceId(resource.getId())
+ .setQualifier(resource.getQualifier())
+ .setRootProjectId(resource.getRootId())
+ .setNameSize(resource.getName().length());
for (int position = 0; position <= key.length() - MINIMUM_KEY_SIZE; position++) {
dto.setPosition(position);
@@ -133,35 +133,32 @@ public class ResourceIndexerDao {
}
}
- public boolean indexResource(int id, String name, String qualifier, int rootId) {
- return indexResource(id, name, qualifier, rootId, false);
+ public boolean indexResource(long id) {
+ boolean indexed = false;
+ SqlSession session = mybatis.openSession();
+ try {
+ ResourceIndexerMapper mapper = session.getMapper(ResourceIndexerMapper.class);
+ ResourceDto resource = mapper.selectResourceToIndex(id);
+ if (resource != null) {
+ Integer rootId = resource.getRootId();
+ if (rootId == null) {
+ rootId = resource.getId().intValue();
+ }
+ indexed = indexResource(resource.getId().intValue(), resource.getName(), resource.getQualifier(), rootId, session, mapper);
+ }
+ return indexed;
+ } finally {
+ MyBatis.closeQuietly(session);
+ }
}
- public boolean indexResource(int id, String name, String qualifier, int rootId, boolean force) {
+ public boolean indexResource(int id, String name, String qualifier, int rootId) {
boolean indexed = false;
- if (force || isIndexableQualifier(qualifier)) {
+ if (isIndexableQualifier(qualifier)) {
SqlSession session = mybatis.openSession();
+ ResourceIndexerMapper mapper = session.getMapper(ResourceIndexerMapper.class);
try {
- String key = nameToKey(name);
- if (key.length() >= MINIMUM_KEY_SIZE) {
- indexed = true;
- ResourceIndexerMapper mapper = session.getMapper(ResourceIndexerMapper.class);
- boolean toBeIndexed = sanitizeIndex(id, key, mapper);
- if (toBeIndexed) {
- ResourceIndexDto dto = new ResourceIndexDto()
- .setResourceId(id)
- .setQualifier(qualifier)
- .setRootProjectId(rootId)
- .setNameSize(name.length());
-
- for (int position = 0; position <= key.length() - MINIMUM_KEY_SIZE; position++) {
- dto.setPosition(position);
- dto.setKey(StringUtils.substring(key, position));
- mapper.insert(dto);
- }
- session.commit();
- }
- }
+ indexed = indexResource(id, name, qualifier, rootId, session, mapper);
} finally {
MyBatis.closeQuietly(session);
}
@@ -169,6 +166,30 @@ public class ResourceIndexerDao {
return indexed;
}
+ private boolean indexResource(int id, String name, String qualifier, int rootId, SqlSession session, ResourceIndexerMapper mapper) {
+ boolean indexed = false;
+ String key = nameToKey(name);
+ if (key.length() >= MINIMUM_KEY_SIZE) {
+ indexed = true;
+ boolean toBeIndexed = sanitizeIndex(id, key, mapper);
+ if (toBeIndexed) {
+ ResourceIndexDto dto = new ResourceIndexDto()
+ .setResourceId(id)
+ .setQualifier(qualifier)
+ .setRootProjectId(rootId)
+ .setNameSize(name.length());
+
+ for (int position = 0; position <= key.length() - MINIMUM_KEY_SIZE; position++) {
+ dto.setPosition(position);
+ dto.setKey(StringUtils.substring(key, position));
+ mapper.insert(dto);
+ }
+ session.commit();
+ }
+ }
+ return indexed;
+ }
+
/**
* Return true if the resource must be indexed, false if the resource is already indexed.
diff --git a/sonar-core/src/main/java/org/sonar/core/resource/ResourceIndexerMapper.java b/sonar-core/src/main/java/org/sonar/core/resource/ResourceIndexerMapper.java
index 53f00b440e5..1d5b7d0558c 100644
--- a/sonar-core/src/main/java/org/sonar/core/resource/ResourceIndexerMapper.java
+++ b/sonar-core/src/main/java/org/sonar/core/resource/ResourceIndexerMapper.java
@@ -23,6 +23,8 @@ public interface ResourceIndexerMapper {
ResourceIndexDto selectMasterIndexByResourceId(long resourceId);
+ ResourceDto selectResourceToIndex(long resourceId);
+
void deleteByResourceId(long resourceId);
void insert(ResourceIndexDto dto);
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 edfe15b3c26..621b7bda167 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
@@ -185,6 +185,7 @@ INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('282');
INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('283');
INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('284');
INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('285');
+INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('286');
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/resource/ResourceIndexerMapper-oracle.xml b/sonar-core/src/main/resources/org/sonar/core/resource/ResourceIndexerMapper-oracle.xml
index f65532665d2..033e59fd0ec 100644
--- a/sonar-core/src/main/resources/org/sonar/core/resource/ResourceIndexerMapper-oracle.xml
+++ b/sonar-core/src/main/resources/org/sonar/core/resource/ResourceIndexerMapper-oracle.xml
@@ -47,6 +47,12 @@
where resource_id=#{id} and position=0
</select>
+ <select id="selectResourceToIndex" parameterType="long" resultType="Resource">
+ select id, name, root_id as "rootId", qualifier
+ from projects
+ where id=#{id} and enabled=${_true}
+ </select>
+
<delete id="deleteByResourceId" parameterType="long">
delete from resource_index
where resource_id=#{id}
diff --git a/sonar-core/src/main/resources/org/sonar/core/resource/ResourceIndexerMapper.xml b/sonar-core/src/main/resources/org/sonar/core/resource/ResourceIndexerMapper.xml
index 75e37e4f5c1..faf58386640 100644
--- a/sonar-core/src/main/resources/org/sonar/core/resource/ResourceIndexerMapper.xml
+++ b/sonar-core/src/main/resources/org/sonar/core/resource/ResourceIndexerMapper.xml
@@ -47,6 +47,12 @@
where resource_id=#{id} and position=0
</select>
+ <select id="selectResourceToIndex" parameterType="long" resultType="Resource">
+ select id, name, root_id as "rootId", qualifier
+ from projects
+ where id=#{id} and enabled=${_true}
+ </select>
+
<delete id="deleteByResourceId" parameterType="long">
delete from resource_index
where resource_id=#{id}